summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/input.py13
-rw-r--r--lib/stitch_plan/stitch_plan.py14
-rw-r--r--lib/svg/rendering.py24
3 files changed, 37 insertions, 14 deletions
diff --git a/lib/extensions/input.py b/lib/extensions/input.py
index a82cdfca..65542bb3 100644
--- a/lib/extensions/input.py
+++ b/lib/extensions/input.py
@@ -13,22 +13,21 @@ class Input(object):
def affect(self, args):
embroidery_file = args[0]
pattern = pyembroidery.read(embroidery_file)
- pattern = pattern.get_pattern_interpolate_trim(3)
stitch_plan = StitchPlan()
color_block = None
for raw_stitches, thread in pattern.get_as_colorblocks():
color_block = stitch_plan.new_color_block(thread)
- trim_after = False
for x, y, command in raw_stitches:
if command == pyembroidery.STITCH:
- if trim_after:
- color_block.add_stitch(trim=True)
- trim_after = False
color_block.add_stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0)
- if len(color_block) > 0 and command == pyembroidery.TRIM:
- trim_after = True
+ if len(color_block) > 0:
+ if command == pyembroidery.TRIM:
+ color_block.add_stitch(trim=True)
+ elif command == pyembroidery.STOP:
+ color_block.add_stitch(stop=True)
+ color_block = stitch_plan.new_color_block(thread)
stitch_plan.delete_empty_color_blocks()
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index b621ef07..c62ebe98 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -210,6 +210,20 @@ class ColorBlock(object):
else:
return False
+ @property
+ def trim_after(self):
+ # If there's a STOP, it will be at the end. We still want to return
+ # True.
+ for stitch in reversed(self.stitches):
+ if stitch.stop or stitch.jump:
+ continue
+ elif stitch.trim:
+ return True
+ else:
+ break
+
+ return False
+
def filter_duplicate_stitches(self):
if not self.stitches:
return
diff --git a/lib/svg/rendering.py b/lib/svg/rendering.py
index 532748bf..42a603c5 100644
--- a/lib/svg/rendering.py
+++ b/lib/svg/rendering.py
@@ -147,7 +147,7 @@ def color_block_to_point_lists(color_block):
point_lists.append([])
continue
- if not stitch.jump and not stitch.color_change:
+ if not stitch.jump and not stitch.color_change and not stitch.stop:
point_lists[-1].append(stitch.as_tuple())
# filter out empty point lists
@@ -190,21 +190,23 @@ def color_block_to_realistic_stitches(color_block, svg, destination):
def color_block_to_paths(color_block, svg, destination):
+ # If we try to import these above, we get into a mess of circular
+ # imports.
+ from ..commands import add_commands
+ from ..elements.stroke import Stroke
+
# We could emit just a single path with one subpath per point list, but
# emitting multiple paths makes it easier for the user to manipulate them.
first = True
+ path = None
for point_list in color_block_to_point_lists(color_block):
if first:
first = False
else:
- # If we try to import these above, we get into a mess of circular
- # imports.
- from ..commands import add_commands
- from ..elements.stroke import Stroke
add_commands(Stroke(destination[-1]), ["trim"])
color = color_block.color.visible_on_white.to_hex_str()
- destination.append(inkex.etree.Element(
+ path = inkex.etree.Element(
SVG_PATH_TAG,
{'style': simplestyle.formatStyle(
{'stroke': color,
@@ -213,7 +215,15 @@ def color_block_to_paths(color_block, svg, destination):
'd': "M" + " ".join(" ".join(str(coord) for coord in point) for point in point_list),
'transform': get_correction_transform(svg),
'embroider_manual_stitch': 'true'
- }))
+ })
+ destination.append(path)
+
+ if path is not None:
+ if color_block.trim_after:
+ add_commands(Stroke(path), ["trim"])
+
+ if color_block.stop_after:
+ add_commands(Stroke(path), ["stop"])
def render_stitch_plan(svg, stitch_plan, realistic=False):