summaryrefslogtreecommitdiff
path: root/lib/stitch_plan/stitch_group.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stitch_plan/stitch_group.py')
-rw-r--r--lib/stitch_plan/stitch_group.py64
1 files changed, 64 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..98d9799e
--- /dev/null
+++ b/lib/stitch_plan/stitch_group.py
@@ -0,0 +1,64 @@
+# 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
+
+
+class StitchGroup:
+ """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
+ 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, tags=None):
+ self.color = color
+ 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)
+
+ if tags:
+ self.add_tags(tags)
+
+ 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_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):
+ 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)