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.
pull/8/head
Lex Neva 2017-11-19 01:18:48 +00:00
rodzic 06d985f11d
commit 2695507dc3
1 zmienionych plików z 19 dodań i 18 usunięć

Wyświetl plik

@ -1724,37 +1724,38 @@ def patches_to_stitches(patch_list, collapse_len_px=0):
return stitches return stitches
def stitches_to_polylines(stitches):
def stitches_to_paths(stitches): polylines = []
paths = []
last_color = None last_color = None
last_stitch = None last_stitch = None
for stitch in stitches: for stitch in stitches:
if stitch.jump_stitch: #if stitch.jump_stitch:
if last_color == stitch.color: #if last_color == stitch.color:
paths.append([None, []]) # polylines.append([None, [last_stitch.as_tuple(), stitch.as_tuple()]])
if last_stitch is not None:
paths[-1][1].append(['M', last_stitch.as_tuple()]) # last_color = None
paths[-1][1].append(['L', stitch.as_tuple()])
last_color = None if stitch.color != last_color or stitch.jump_stitch:
if stitch.color != last_color: polylines.append([stitch.color, []])
paths.append([stitch.color, []])
paths[-1][1].append(['L' if len(paths[-1][1]) > 0 else 'M', stitch.as_tuple()]) polylines[-1][1].append(stitch.as_tuple())
last_color = stitch.color last_color = stitch.color
last_stitch = stitch last_stitch = stitch
return paths
return polylines
def emit_inkscape(parent, stitches): def emit_inkscape(parent, stitches):
for color, path in stitches_to_paths(stitches): for color, polyline in stitches_to_polylines(stitches):
# dbg.write('path: %s %s\n' % (color, repr(path))) # dbg.write('polyline: %s %s\n' % (color, repr(polyline)))
inkex.etree.SubElement(parent, inkex.etree.SubElement(parent,
inkex.addNS('path', 'svg'), inkex.addNS('polyline', 'svg'),
{'style': simplestyle.formatStyle( {'style': simplestyle.formatStyle(
{'stroke': color if color is not None else '#000000', {'stroke': color if color is not None else '#000000',
'stroke-width': "0.4", 'stroke-width': "0.4",
'fill': 'none'}), 'fill': 'none'}),
'd': simplepath.formatPath(path), 'points': " ".join(",".join(str(coord) for coord in point) for point in polyline),
}) })