diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2021-08-16 19:40:44 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-16 19:40:44 -0400 |
| commit | 3ebc238561dd2403b19a56a0f3147c70eb4ebe3d (patch) | |
| tree | c7e4c618335fac2196d42e03f26c3c2ad2a4251d /lib/stitch_plan/stitch_group.py | |
| parent | 5a7b7276759b6fb4c85891b13d9ee7a2da8150ab (diff) | |
| parent | b49f7d28314f30727f9f963bddb795b88a95f2bd (diff) | |
Merge pull request #1254 from inkstitch/kaalleen/satin-patterns
Satin pattern and split stitch
Diffstat (limited to 'lib/stitch_plan/stitch_group.py')
| -rw-r--r-- | lib/stitch_plan/stitch_group.py | 64 |
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) |
