summaryrefslogtreecommitdiff
path: root/lib/stitch_plan/stitch_plan.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stitch_plan/stitch_plan.py')
-rw-r--r--lib/stitch_plan/stitch_plan.py56
1 files changed, 40 insertions, 16 deletions
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index 741ec006..1a846099 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -10,7 +10,6 @@ from inkex import errormsg
from ..i18n import _
from ..svg import PIXELS_PER_MM
from .color_block import ColorBlock
-from .ties import add_ties
from ..utils.threading import check_stop_flag
@@ -31,9 +30,13 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_le
if collapse_len is None:
collapse_len = 3.0
collapse_len = collapse_len * PIXELS_PER_MM
+
stitch_plan = StitchPlan()
color_block = stitch_plan.new_color_block(color=stitch_groups[0].color)
+ previous_stitch_group = None
+ need_tie_in = True
+
for stitch_group in stitch_groups:
check_stop_flag()
@@ -49,22 +52,42 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_le
# We'll just claim this new block as ours:
color_block.color = stitch_group.color
else:
+ # add a lock stitch to the last element of the previous group
+ lock_stitches = previous_stitch_group.get_lock_stitches("end", disable_ties)
+ if lock_stitches:
+ color_block.add_stitches(stitches=lock_stitches)
+ need_tie_in = True
+
# end the previous block with a color change
color_block.add_stitch(color_change=True)
# make a new block of our color
color_block = stitch_plan.new_color_block(color=stitch_group.color)
-
- # always start a color with a JUMP to the first stitch position
- color_block.add_stitch(stitch_group.stitches[0], jump=True, tie_modus=stitch_group.tie_modus)
else:
- if (len(color_block) and
+ if (len(color_block) and not need_tie_in and
((stitch_group.stitches[0] - color_block.stitches[-1]).length() > collapse_len or
- color_block.stitches[-1].force_lock_stitches)):
- color_block.add_stitch(stitch_group.stitches[0], jump=True, tie_modus=stitch_group.tie_modus)
+ previous_stitch_group.force_lock_stitches)):
+ lock_stitches = previous_stitch_group.get_lock_stitches("end", disable_ties)
+ if lock_stitches:
+ color_block.add_stitches(stitches=lock_stitches)
+ need_tie_in = True
+
+ if need_tie_in is True:
+ lock_stitches = stitch_group.get_lock_stitches("start", disable_ties)
+ if lock_stitches:
+ color_block.add_stitch(lock_stitches[0], jump=True)
+ color_block.add_stitches(stitches=lock_stitches)
+ else:
+ color_block.add_stitch(stitch_group.stitches[0], jump=True)
+ need_tie_in = False
- color_block.add_stitches(stitches=stitch_group.stitches, tie_modus=stitch_group.tie_modus,
- force_lock_stitches=stitch_group.force_lock_stitches, no_ties=stitch_group.stitch_as_is)
+ color_block.add_stitches(stitches=stitch_group.stitches)
+
+ if stitch_group.trim_after or stitch_group.stop_after:
+ lock_stitches = stitch_group.get_lock_stitches("end", disable_ties)
+ if lock_stitches:
+ color_block.add_stitches(stitches=lock_stitches)
+ need_tie_in = True
if stitch_group.trim_after:
color_block.add_stitch(trim=True)
@@ -73,15 +96,20 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_le
color_block.add_stitch(stop=True)
color_block = stitch_plan.new_color_block(color_block.color)
+ previous_stitch_group = stitch_group
+
+ if not need_tie_in:
+ # tie off at the end if we haven't already
+ lock_stitches = stitch_group.get_lock_stitches("end", disable_ties)
+ if lock_stitches:
+ color_block.add_stitches(stitches=lock_stitches)
+
if len(color_block) == 0:
# last block ended in a stop, so now we have an empty block
del stitch_plan.color_blocks[-1]
stitch_plan.filter_duplicate_stitches(min_stitch_len)
- if not disable_ties:
- stitch_plan.add_ties()
-
return stitch_plan
@@ -111,10 +139,6 @@ class StitchPlan(object):
for color_block in self:
color_block.filter_duplicate_stitches(min_stitch_len)
- def add_ties(self):
- # see ties.py
- add_ties(self)
-
def __iter__(self):
return iter(self.color_blocks)