summaryrefslogtreecommitdiff
path: root/lib/stitch_plan/stitch_group.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2021-08-07 11:21:13 -0400
committerLex Neva <github.com@lexneva.name>2021-08-07 11:21:13 -0400
commit84cb4e2c333d331eb863714797a55589f41e51b2 (patch)
treeaaf46187dd21e719600875bf432349ad1ce31530 /lib/stitch_plan/stitch_group.py
parent12ef0c84aa732623b210fdce1a7b8301aa435217 (diff)
move StitchGroup into lib.stitch_plan
Diffstat (limited to 'lib/stitch_plan/stitch_group.py')
-rw-r--r--lib/stitch_plan/stitch_group.py34
1 files changed, 34 insertions, 0 deletions
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])