From 84cb4e2c333d331eb863714797a55589f41e51b2 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 7 Aug 2021 11:21:13 -0400 Subject: move StitchGroup into lib.stitch_plan --- lib/stitch_plan/stitch_group.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/stitch_plan/stitch_group.py (limited to 'lib/stitch_plan/stitch_group.py') diff --git a/lib/stitch_plan/stitch_group.py b/lib/stitch_plan/stitch_group.py new file mode 100644 index 00000000..d1e6bae7 --- /dev/null +++ b/lib/stitch_plan/stitch_group.py @@ -0,0 +1,34 @@ +class StitchGroup: + """A collection of Stitch objects with attached instructions. + + StitchGroups will later be combined to make ColorBlocks, which in turn are + combined to make a StitchPlan. Jump stitches are allowed between + StitchGroups, but not between stitches inside a StitchGroup. This means + that EmbroideryElement classes should produce multiple StitchGroups only if + they want to allow for the possibility of jump stitches to be added in + between them by the stitch plan generation code. + """ + + def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, tie_modus=0, stitch_as_is=False): + self.color = color + self.stitches = stitches or [] + self.trim_after = trim_after + self.stop_after = stop_after + self.tie_modus = tie_modus + self.stitch_as_is = stitch_as_is + + def __add__(self, other): + if isinstance(other, StitchGroup): + return StitchGroup(self.color, self.stitches + other.stitches) + else: + raise TypeError("StitchGroup can only be added to another StitchGroup") + + def __len__(self): + # This method allows `len(patch)` and `if patch: + return len(self.stitches) + + def add_stitch(self, stitch): + self.stitches.append(stitch) + + def reverse(self): + return StitchGroup(self.color, self.stitches[::-1]) -- cgit v1.2.3 From 28e394b2ae7f4dabcc331d456103d4b3d0efae84 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 7 Aug 2021 12:00:56 -0400 Subject: StitchGroups now contain only Stitches --- lib/stitch_plan/stitch_group.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/stitch_plan/stitch_group.py') diff --git a/lib/stitch_plan/stitch_group.py b/lib/stitch_plan/stitch_group.py index d1e6bae7..548ad892 100644 --- a/lib/stitch_plan/stitch_group.py +++ b/lib/stitch_plan/stitch_group.py @@ -1,5 +1,8 @@ +from .stitch import Stitch + + class StitchGroup: - """A collection of Stitch objects with attached instructions. + """A collection of Stitch objects with attached instructions and attributes. StitchGroups will later be combined to make ColorBlocks, which in turn are combined to make a StitchPlan. Jump stitches are allowed between @@ -11,11 +14,14 @@ class StitchGroup: def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, tie_modus=0, stitch_as_is=False): self.color = color - self.stitches = stitches or [] self.trim_after = trim_after self.stop_after = stop_after self.tie_modus = tie_modus self.stitch_as_is = stitch_as_is + self.stitches = [] + + if stitches: + self.add_stitches(stitches) def __add__(self, other): if isinstance(other, StitchGroup): @@ -27,7 +33,15 @@ class StitchGroup: # This method allows `len(patch)` and `if patch: return len(self.stitches) + def add_stitches(self, stitches): + for stitch in stitches: + self.add_stitch(stitch) + def add_stitch(self, stitch): + if not isinstance(stitch, Stitch): + # probably a Point + stitch = Stitch(stitch) + self.stitches.append(stitch) def reverse(self): -- cgit v1.2.3 From 3b7994c01add202c8f3475956f093a143890160f Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 7 Aug 2021 12:38:41 -0400 Subject: add headers --- lib/stitch_plan/stitch_group.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/stitch_plan/stitch_group.py') diff --git a/lib/stitch_plan/stitch_group.py b/lib/stitch_plan/stitch_group.py index 548ad892..ee077f26 100644 --- a/lib/stitch_plan/stitch_group.py +++ b/lib/stitch_plan/stitch_group.py @@ -1,3 +1,8 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + from .stitch import Stitch -- cgit v1.2.3 From dd865008356d1e04b29a5eb59a8480900f255628 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 15 Aug 2021 17:24:59 -0400 Subject: keep underlay, underpath, and border travel --- lib/stitch_plan/stitch_group.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/stitch_plan/stitch_group.py') diff --git a/lib/stitch_plan/stitch_group.py b/lib/stitch_plan/stitch_group.py index ee077f26..98d9799e 100644 --- a/lib/stitch_plan/stitch_group.py +++ b/lib/stitch_plan/stitch_group.py @@ -17,7 +17,7 @@ class StitchGroup: between them by the stitch plan generation code. """ - def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, tie_modus=0, stitch_as_is=False): + def __init__(self, color=None, stitches=None, trim_after=False, stop_after=False, tie_modus=0, stitch_as_is=False, tags=None): self.color = color self.trim_after = trim_after self.stop_after = stop_after @@ -28,6 +28,9 @@ class StitchGroup: if stitches: self.add_stitches(stitches) + if tags: + self.add_tags(tags) + def __add__(self, other): if isinstance(other, StitchGroup): return StitchGroup(self.color, self.stitches + other.stitches) @@ -51,3 +54,11 @@ class StitchGroup: def reverse(self): return StitchGroup(self.color, self.stitches[::-1]) + + def add_tags(self, tags): + for stitch in self.stitches: + stitch.add_tags(tags) + + def add_tag(self, tag): + for stitch in self.stitches: + stitch.add_tag(tag) -- cgit v1.2.3