diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2023-01-15 20:04:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-15 20:04:10 +0100 |
| commit | 1cdb3538a83a13d97907d08908750f0d85de6978 (patch) | |
| tree | ddccf347d43ff850f4e8eca0e4c541dbd3cf2e4f /lib/elements | |
| parent | 4156c4adb4eadaf024b29df1df6bf1c91d3777a8 (diff) | |
Add bean stitch repeat pattern (#1938)
! backward compatibility warning:
Users need to fix their documents if they used comma separated values for multiple fill underlays (without a space)
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/element.py | 10 | ||||
| -rw-r--r-- | lib/elements/fill_stitch.py | 6 | ||||
| -rw-r--r-- | lib/elements/stroke.py | 12 |
3 files changed, 21 insertions, 7 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py index 75f9fc10..692d8228 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -162,6 +162,16 @@ class EmbroideryElement(object): def get_split_mm_param_as_px(self, param, default): return self.get_split_float_param(param, default) * PIXELS_PER_MM + # returns an array of multiple space separated int values + @cache + def get_multiple_int_param(self, param, default="0"): + params = self.get_param(param, default).split(" ") + try: + params = [int(param) for param in params] + except (TypeError, ValueError): + return [default] + return params + def set_param(self, name, value): # Sets a param on the node backing this element. Used by params dialog. # After calling, this element is invalid due to caching and must be re-created to use the new value. diff --git a/lib/elements/fill_stitch.py b/lib/elements/fill_stitch.py index f4a21f90..7de293cb 100644 --- a/lib/elements/fill_stitch.py +++ b/lib/elements/fill_stitch.py @@ -405,7 +405,7 @@ class FillStitch(EmbroideryElement): @property @param('fill_underlay_angle', _('Fill angle'), - tooltip=_('Default: fill angle + 90 deg. Insert comma-seperated list for multiple layers.'), + tooltip=_('Default: fill angle + 90 deg. Insert a list for multiple layers separated by a space.'), unit='deg', group=_('Fill Underlay'), type='float') @@ -414,7 +414,9 @@ class FillStitch(EmbroideryElement): underlay_angles = self.get_param('fill_underlay_angle', None) default_value = [self.angle + math.pi / 2.0] if underlay_angles is not None: - underlay_angles = underlay_angles.strip().split(',') + underlay_angles = underlay_angles.strip().split(' ') + # remove comma separator for backward compatibility + underlay_angles = [angle[:-1] if angle.endswith(',') else angle for angle in underlay_angles] try: underlay_angles = [math.radians( float(angle)) for angle in underlay_angles] diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py index a95edf70..73973bf7 100644 --- a/lib/elements/stroke.py +++ b/lib/elements/stroke.py @@ -112,12 +112,13 @@ class Stroke(EmbroideryElement): _('Bean stitch number of repeats'), tooltip=_('Backtrack each stitch this many times. ' 'A value of 1 would triple each stitch (forward, back, forward). ' - 'A value of 2 would quintuple each stitch, etc.'), - type='int', + 'A value of 2 would quintuple each stitch, etc.\n\n' + 'A pattern with various repeats can be created with a list of values separated by a space.'), + type='str', default=0, sort_index=3) def bean_stitch_repeats(self): - return self.get_int_param("bean_stitch_repeats", 0) + return self.get_multiple_int_param("bean_stitch_repeats", "0") @property @param('running_stitch_length_mm', @@ -463,7 +464,7 @@ class Stroke(EmbroideryElement): if self.stroke_method == 1: patch = self.ripple_stitch() if patch: - if self.bean_stitch_repeats > 0: + if any(self.bean_stitch_repeats): patch.stitches = self.do_bean_repeats(patch.stitches) patches.append(patch) else: @@ -475,7 +476,8 @@ class Stroke(EmbroideryElement): # running stitch elif self.is_running_stitch(): patch = self.running_stitch(path, self.running_stitch_length, self.running_stitch_tolerance) - if self.bean_stitch_repeats > 0: + # bean stitch + if any(self.bean_stitch_repeats): patch.stitches = self.do_bean_repeats(patch.stitches) # simple satin else: |
