summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-04-06 22:09:26 -0400
committerLex Neva <github.com@lexneva.name>2018-04-06 22:09:26 -0400
commitfef53dcc77d8891cfef3a5e459b457f9ac16e04b (patch)
treefdcb680d4ef1f2a377cbfb483e5ea63c2fa0fb49
parent6aebbdeb5cb22884dee8883595adc9e024ce2725 (diff)
don't add ties for manual stitch
-rw-r--r--inkstitch/__init__.py5
-rw-r--r--inkstitch/elements/element.py3
-rw-r--r--inkstitch/elements/stroke.py2
-rw-r--r--inkstitch/stitch_plan/stitch_plan.py16
-rw-r--r--inkstitch/stitch_plan/ties.py5
5 files changed, 22 insertions, 9 deletions
diff --git a/inkstitch/__init__.py b/inkstitch/__init__.py
index 2e7a55f6..45eed3a6 100644
--- a/inkstitch/__init__.py
+++ b/inkstitch/__init__.py
@@ -161,16 +161,17 @@ def get_stroke_scale(node):
class Stitch(Point):
- def __init__(self, x, y, color=None, jump=False, stop=False, trim=False):
+ def __init__(self, x, y, color=None, jump=False, stop=False, trim=False, no_ties=False):
self.x = x
self.y = y
self.color = color
self.jump = jump
self.trim = trim
self.stop = stop
+ self.no_ties = no_ties
def __repr__(self):
- return "Stitch(%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 "")
+ 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 make_thread(color):
diff --git a/inkstitch/elements/element.py b/inkstitch/elements/element.py
index a6db7189..cfca3782 100644
--- a/inkstitch/elements/element.py
+++ b/inkstitch/elements/element.py
@@ -14,11 +14,12 @@ from cspsubdiv import cspsubdiv
class Patch:
"""A raw collection of stitches with attached instructions."""
- def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False):
+ def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, stitch_as_is=False):
self.color = color
self.stitches = stitches or []
self.trim_after = trim_after
self.stop_after = stop_after
+ self.stitch_as_is = stitch_as_is
def __add__(self, other):
if isinstance(other, Patch):
diff --git a/inkstitch/elements/stroke.py b/inkstitch/elements/stroke.py
index f245f370..0ce3fa67 100644
--- a/inkstitch/elements/stroke.py
+++ b/inkstitch/elements/stroke.py
@@ -110,7 +110,7 @@ class Stroke(EmbroideryElement):
for path in self.paths:
path = [Point(x, y) for x, y in path]
if self.manual_stitch_mode:
- patch = Patch(color=self.color, stitches=path)
+ patch = Patch(color=self.color, stitches=path, stitch_as_is=True)
elif self.is_running_stitch():
patch = self.stroke_points(path, self.running_stitch_length, stroke_width=0.0)
else:
diff --git a/inkstitch/stitch_plan/stitch_plan.py b/inkstitch/stitch_plan/stitch_plan.py
index 3a95942c..82584bbc 100644
--- a/inkstitch/stitch_plan/stitch_plan.py
+++ b/inkstitch/stitch_plan/stitch_plan.py
@@ -44,7 +44,7 @@ def patches_to_stitch_plan(patches, collapse_len=3.0 * PIXELS_PER_MM):
color_block.color = patch.color
color_block.filter_duplicate_stitches()
- color_block.add_stitches(patch.stitches)
+ color_block.add_stitches(patch.stitches, no_ties=patch.stitch_as_is)
if patch.trim_after:
# a trim needs to be followed by a jump to the next stitch, so
@@ -76,6 +76,9 @@ class StitchPlan(object):
def __len__(self):
return len(self.color_blocks)
+ def __repr__(self):
+ return "StitchPlan(%s)" % ", ".join(repr(cb) for cb in self.color_blocks)
+
@property
def num_colors(self):
"""Number of unique colors in the stitch plan."""
@@ -110,6 +113,9 @@ class ColorBlock(object):
def __iter__(self):
return iter(self.stitches)
+ def __repr__(self):
+ return "ColorBlock(%s, %s)" % (self.color, self.stitches)
+
def has_color(self):
return self._color is not None
@@ -177,16 +183,16 @@ class ColorBlock(object):
if isinstance(args[0], Stitch):
self.stitches.append(args[0])
elif isinstance(args[0], Point):
- self.stitches.append(Stitch(args[0].x, args[0].y))
+ self.stitches.append(Stitch(args[0].x, args[0].y, *args[1:], **kwargs))
else:
self.stitches.append(Stitch(*args, **kwargs))
- def add_stitches(self, stitches):
+ def add_stitches(self, stitches, *args, **kwargs):
for stitch in stitches:
if isinstance(stitch, (Stitch, Point)):
- self.add_stitch(stitch)
+ self.add_stitch(stitch, *args, **kwargs)
else:
- self.add_stitch(*stitch)
+ self.add_stitch(*(list(stitch) + args), **kwargs)
def replace_stitches(self, stitches):
self.stitches = stitches
diff --git a/inkstitch/stitch_plan/ties.py b/inkstitch/stitch_plan/ties.py
index 9c688e6b..1207ea51 100644
--- a/inkstitch/stitch_plan/ties.py
+++ b/inkstitch/stitch_plan/ties.py
@@ -4,6 +4,11 @@ from .. import Stitch
from copy import deepcopy
def add_tie(stitches, tie_path):
+ if stitches[-1].no_ties:
+ # It's from a manual stitch block, so don't add tie stitches. The user
+ # will add them if they want them.
+ return
+
tie_path = cut_path(tie_path, 0.6)
tie_stitches = running_stitch(tie_path, 0.3)
tie_stitches = [Stitch(stitch.x, stitch.y) for stitch in tie_stitches]