summaryrefslogtreecommitdiff
path: root/lib/stitch_plan
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stitch_plan')
-rw-r--r--lib/stitch_plan/stitch.py5
-rw-r--r--lib/stitch_plan/stitch_plan.py6
-rw-r--r--lib/stitch_plan/stop.py23
-rw-r--r--lib/stitch_plan/ties.py4
4 files changed, 25 insertions, 13 deletions
diff --git a/lib/stitch_plan/stitch.py b/lib/stitch_plan/stitch.py
index 23acec73..12642a60 100644
--- a/lib/stitch_plan/stitch.py
+++ b/lib/stitch_plan/stitch.py
@@ -2,17 +2,18 @@ from ..utils.geometry import Point
class Stitch(Point):
- def __init__(self, x, y, color=None, jump=False, stop=False, trim=False, no_ties=False):
+ def __init__(self, x, y, color=None, jump=False, stop=False, trim=False, color_change=False, no_ties=False):
self.x = x
self.y = y
self.color = color
self.jump = jump
self.trim = trim
self.stop = stop
+ self.color_change = color_change
self.no_ties = no_ties
def __repr__(self):
return "Stitch(%s, %s, %s, %s, %s, %s, %s)" % (self.x, self.y, self.color, "JUMP" if self.jump else " ", "TRIM" if self.trim else " ", "STOP" if self.stop else " ", "NO TIES" if self.no_ties else " ")
def copy(self):
- return Stitch(self.x, self.y, self.color, self.jump, self.stop, self.trim, self.no_ties)
+ return Stitch(self.x, self.y, self.color, self.jump, self.stop, self.trim, self.color_change, self.no_ties)
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index f7dfb307..2a35f9aa 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -39,10 +39,10 @@ def patches_to_stitch_plan(patches, collapse_len=3.0 * PIXELS_PER_MM):
color_block.add_stitch(patch.stitches[0].x, patch.stitches[0].y, jump=True)
else:
- # add a color change (only if the last stitch wasn't a "STOP after")
- if not color_block.last_stitch.stop:
+ # add a color change (only if we didn't just do a "STOP after")
+ if not color_block.last_stitch.color_change:
stitch = color_block.last_stitch.copy()
- stitch.stop = True
+ stitch.color_change = True
color_block.add_stitch(stitch)
color_block = stitch_plan.new_color_block()
diff --git a/lib/stitch_plan/stop.py b/lib/stitch_plan/stop.py
index 83afeb36..81dec1da 100644
--- a/lib/stitch_plan/stop.py
+++ b/lib/stitch_plan/stop.py
@@ -5,20 +5,29 @@ def process_stop(color_block):
be useful for applique and similar on multi-needle machines that
normally would not stop between colors.
- On such machines, the user assigns needles to the colors in the
- design before starting stitching. C01, C02, etc are normal
+ In machine embroidery files, there's no such thing as an actual
+ "STOP" instruction. All that exists is a "color change" command
+ (which libembroidery calls STOP just to be confusing).
+
+ On multi-needle machines, the user assigns needles to the colors in
+ the design before starting stitching. C01, C02, etc are normal
needles, but C00 is special. For a block of stitches assigned
to C00, the machine will continue sewing with the last color it
had and pause after it completes the C00 block.
- That means we need to introduce an artificial color change
- shortly before the current stitch so that the user can set that
- to C00. We'll go back 3 stitches and do that:
+ That means we need to add an artificial color change instruction
+ shortly before the current stitch so that the user can set that color
+ block to C00. We'll go back 3 stitches and mark the start of the C00
+ block:
"""
if len(color_block.stitches) >= 3:
- # make a copy of the stitch and turn it into a STOP code
+ # make a copy of the stitch and set it as a color change
stitch = color_block.stitches[-3].copy()
+ stitch.color_change = True
+
+ # mark this stitch as a "stop" so that we can avoid
+ # adding tie stitches in ties.py
stitch.stop = True
# insert it after the stitch
@@ -28,7 +37,7 @@ def process_stop(color_block):
# block:
stitch = color_block.stitches[-1].copy()
- stitch.stop = True
+ stitch.color_change = True
color_block.add_stitch(stitch)
# reference for the above: https://github.com/lexelby/inkstitch/pull/29#issuecomment-359175447
diff --git a/lib/stitch_plan/ties.py b/lib/stitch_plan/ties.py
index f9c5b721..6d07ac71 100644
--- a/lib/stitch_plan/ties.py
+++ b/lib/stitch_plan/ties.py
@@ -34,7 +34,9 @@ def add_ties(stitch_plan):
need_tie_in = True
new_stitches = []
for i, stitch in enumerate(color_block.stitches):
- is_special = stitch.trim or stitch.jump or stitch.stop
+ # Tie before and after TRIMs, JUMPs, and color changes, but ignore
+ # the fake color change introduced by a "STOP after" (see stop.py).
+ is_special = stitch.trim or stitch.jump or (stitch.color_change and not stitch.stop)
if is_special and not need_tie_in:
add_tie_off(new_stitches)