summaryrefslogtreecommitdiff
path: root/embroider.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2017-11-19 01:18:48 +0000
committerLex Neva <github.com@lexneva.name>2017-11-19 01:18:48 +0000
commit2695507dc3d74a17198d2a9976f7ced7e6346132 (patch)
tree4d7e2a7275edeb958ede67b87b5740aae4f3e33b /embroider.py
parent06d985f11d53299871af542aed00eb37b51e63dc (diff)
switch stitch view from paths to polylines
Polylines in SVG are essentially the same thing as paths, but with no curves. But inkscape-embroidery treats polylines as literal stitches; it does not do satins, fills, etc but instead takes the coordinates and uses them directly as stitches. The advantage in this case is that one can re-run the extension on its own output and get back the same stitch output. Why would you want to do this? Consider the case where you have a basic embroidery machine that can only do a 4x4" square. If you have something that's a bit bigger than 4 inches wide, it might still fit in the square if you turn it at an angle. But working with your entire design rotated at an angle is a total pain, and you'd also have to rotate the angles of all the fills to compensate. Instead, just run the extension, rotate the stitches to fit, and re-run, and your stitch file will work on your 4x4" machine.
Diffstat (limited to 'embroider.py')
-rw-r--r--embroider.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/embroider.py b/embroider.py
index b7148b29..df25f04a 100644
--- a/embroider.py
+++ b/embroider.py
@@ -1724,37 +1724,38 @@ def patches_to_stitches(patch_list, collapse_len_px=0):
return stitches
-
-def stitches_to_paths(stitches):
- paths = []
+def stitches_to_polylines(stitches):
+ polylines = []
last_color = None
last_stitch = None
+
for stitch in stitches:
- if stitch.jump_stitch:
- if last_color == stitch.color:
- paths.append([None, []])
- if last_stitch is not None:
- paths[-1][1].append(['M', last_stitch.as_tuple()])
- paths[-1][1].append(['L', stitch.as_tuple()])
- last_color = None
- if stitch.color != last_color:
- paths.append([stitch.color, []])
- paths[-1][1].append(['L' if len(paths[-1][1]) > 0 else 'M', stitch.as_tuple()])
+ #if stitch.jump_stitch:
+ #if last_color == stitch.color:
+ # polylines.append([None, [last_stitch.as_tuple(), stitch.as_tuple()]])
+
+ # last_color = None
+
+ if stitch.color != last_color or stitch.jump_stitch:
+ polylines.append([stitch.color, []])
+
+ polylines[-1][1].append(stitch.as_tuple())
+
last_color = stitch.color
last_stitch = stitch
- return paths
+ return polylines
def emit_inkscape(parent, stitches):
- for color, path in stitches_to_paths(stitches):
- # dbg.write('path: %s %s\n' % (color, repr(path)))
+ for color, polyline in stitches_to_polylines(stitches):
+ # dbg.write('polyline: %s %s\n' % (color, repr(polyline)))
inkex.etree.SubElement(parent,
- inkex.addNS('path', 'svg'),
+ inkex.addNS('polyline', 'svg'),
{'style': simplestyle.formatStyle(
{'stroke': color if color is not None else '#000000',
'stroke-width': "0.4",
'fill': 'none'}),
- 'd': simplepath.formatPath(path),
+ 'points': " ".join(",".join(str(coord) for coord in point) for point in polyline),
})