From 77d6b78f92d507cdb22e744b1c93712fc6d67e5b Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 28 May 2018 20:06:26 -0400 Subject: fix STOP handling Apparently STOP codes (a.k.a. color changes) should be by themselves, not attached to another stitch. To add a STOP code at a given stitch, we should clone the stitch and then set the STOP command on the new stitch. --- lib/stitch_plan/stitch_plan.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/stitch_plan/stitch_plan.py') diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index 570a7645..fef7f61d 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -39,8 +39,12 @@ 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 - color_block.add_stitch(color_block.last_stitch.x, color_block.last_stitch.y, stop=True) + # add a color change (only if the last stitch wasn't a "STOP after") + if not color_block.last_stitch.stop: + stitch = color_block.last_stitch.copy() + stitch.stop = True + color_block.add_stitch(stitch) + color_block = stitch_plan.new_color_block() color_block.color = patch.color -- cgit v1.2.3 From 9c2350eff7c3ba48f69858f5e3a710a4dd404846 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 28 May 2018 21:34:33 -0400 Subject: don't bother trimming before a color change --- lib/stitch_plan/stitch_plan.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/stitch_plan/stitch_plan.py') diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index fef7f61d..f7dfb307 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -23,15 +23,15 @@ def patches_to_stitch_plan(patches, collapse_len=3.0 * PIXELS_PER_MM): if not patch.stitches: continue - if need_trim: - process_trim(color_block, patch.stitches[0]) - need_trim = False - if not color_block.has_color(): # set the color for the first color block color_block.color = patch.color if color_block.color == patch.color: + if need_trim: + process_trim(color_block, patch.stitches[0]) + need_trim = False + # add a jump stitch between patches if the distance is more # than the collapse length if color_block.last_stitch: -- cgit v1.2.3 From f0c8c6a27b2ea2688bceaea0b86e1c182dee39c9 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 28 May 2018 22:15:07 -0400 Subject: don't do ties around the fake color change of a "STOP after" --- lib/stitch_plan/stitch_plan.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/stitch_plan/stitch_plan.py') 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() -- cgit v1.2.3 From b32a37178aaa1a31beb608d69504e6b4a822a1b5 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Mon, 28 May 2018 22:31:42 -0400 Subject: add a JUMP at the start of each color block This seems to be the way other digitizing software does it, so it's probably required. --- lib/stitch_plan/stitch_plan.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/stitch_plan/stitch_plan.py') diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py index 2a35f9aa..93bcd195 100644 --- a/lib/stitch_plan/stitch_plan.py +++ b/lib/stitch_plan/stitch_plan.py @@ -59,11 +59,21 @@ def patches_to_stitch_plan(patches, collapse_len=3.0 * PIXELS_PER_MM): if patch.stop_after: process_stop(color_block) + add_jumps(stitch_plan) add_ties(stitch_plan) return stitch_plan +def add_jumps(stitch_plan): + """Add a JUMP stitch at the start of each color block.""" + + for color_block in stitch_plan: + stitch = color_block.stitches[0].copy() + stitch.jump = True + color_block.stitches.insert(0, stitch) + + class StitchPlan(object): """Holds a set of color blocks, each containing stitches.""" -- cgit v1.2.3