add SVG debugging with LineStrings

pull/409/head
Lex Neva 2019-03-28 15:52:37 -04:00
rodzic 56f1d85647
commit 1995015021
4 zmienionych plików z 54 dodań i 2 usunięć

1
.gitignore vendored
Wyświetl plik

@ -13,3 +13,4 @@ messages.po
.pydevproject
.project
/debug.log
/debug.svg

Wyświetl plik

@ -1,17 +1,27 @@
import atexit
from datetime import datetime
import os
import socket
import sys
import time
from inkex import etree
import inkex
from simplestyle import formatStyle
from svg import line_strings_to_path
from svg.tags import INKSCAPE_GROUPMODE, INKSCAPE_LABEL
class Debug(object):
def __init__(self):
self.last_log_time = None
self.current_layer = None
def enable(self):
self.enable_log()
self.enable_debugger()
self.enable_svg()
def enable_log(self):
self.log = self._log
@ -48,6 +58,23 @@ class Debug(object):
sys.stderr = stderr
def enable_svg(self):
self.svg = etree.Element("svg", nsmap=inkex.NSS)
atexit.register(self.save_svg)
def save_svg(self):
tree = etree.ElementTree(self.svg)
with open(os.path.join(os.path.dirname(os.path.dirname(__file__)), "debug.svg"), "w") as debug_svg:
tree.write(debug_svg)
def add_layer(self, name="Debug"):
layer = etree.Element("g", {
INKSCAPE_GROUPMODE: "layer",
INKSCAPE_LABEL: name
})
self.svg.append(layer)
self.current_layer = layer
def _noop(self, *args, **kwargs):
pass
@ -79,6 +106,21 @@ class Debug(object):
return decorated
def log_svg_element(self, element):
if self.current_layer is None:
self.add_layer()
self.current_layer.append(element)
def log_line_string(self, line_string, color="#000000"):
"""Add a Shapely LineString to the SVG log."""
self.log_line_strings(self, [line_string])
def log_line_strings(self, line_strings, color="#000000"):
path = line_strings_to_path(line_strings)
path.set('style', formatStyle({"stroke": color, "stroke-width": "0.3"}))
self.log_svg_element(path)
debug = Debug()
enable = debug.enable

Wyświetl plik

@ -1,4 +1,4 @@
from .guides import get_guides
from .path import apply_transforms, get_node_transform, get_correction_transform, line_strings_to_csp, point_lists_to_csp, line_strings_to_path
from .svg import color_block_to_point_lists, render_stitch_plan
from .units import *
from .path import apply_transforms, get_node_transform, get_correction_transform, line_strings_to_csp, point_lists_to_csp
from .guides import get_guides

Wyświetl plik

@ -1,3 +1,4 @@
import cubicsuperpath
import inkex
import simpletransform
@ -80,3 +81,11 @@ def point_lists_to_csp(point_lists):
csp.append(subpath)
return csp
def line_strings_to_path(line_strings):
csp = line_strings_to_csp(line_strings)
return inkex.etree.Element("path", {
"d": cubicsuperpath.formatPath(csp)
})