From 4285a6fb7f230547d0c70032c346f6f30956e167 Mon Sep 17 00:00:00 2001 From: Claudine Date: Sun, 6 Nov 2022 10:49:25 -0500 Subject: add pull_compensation_percent --- lib/elements/satin_column.py | 57 ++++++++++++++++++++++++++++++++++++++------ lib/svg/tags.py | 2 ++ 2 files changed, 52 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 08f76bd5..772d1454 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -132,6 +132,18 @@ class SatinColumn(EmbroideryElement): # peak-to-peak distance between zigzags return max(self.get_float_param("zigzag_spacing_mm", 0.4), 0.01) + @property + @param( + 'pull_compensation_percent', + _('Pull compensation percentage'), + tooltip=_('pull compensation in percentage'), + unit='%', + type='int', + default=0) + def pull_compensation_percent(self): + # pull compensation as a percentage of the width + return max(self.get_int_param("pull_compensation_percent", 0), 0) + @property @param( 'pull_compensation_mm', @@ -147,6 +159,18 @@ class SatinColumn(EmbroideryElement): # wider than we desire the column to end up. return self.get_float_param("pull_compensation_mm", 0) + @property + @param( + 'pull_compensation_rails', + _('Apply pull compensation to '), + tooltip=_('decide wether the pull compensations should be applied to both side or only to a given one'), + type='dropdown', + options=[_("Both rails"), _("First rail only"), _("Second rail only")], + default=0) + def pull_compensation_rails(self): + # 0=Both | 1 = First Rail | 2 = Second Rail + return self.get_int_param("pull_compensation_rails", 0) + @property @param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay')) def contour_underlay(self): @@ -619,11 +643,16 @@ class SatinColumn(EmbroideryElement): center_walk, _ = self.plot_points_on_rails(self.zigzag_spacing, -100000) return shgeo.LineString(center_walk) - def offset_points(self, pos1, pos2, offset_px): + def offset_points(self, pos1, pos2, offset, offset_percent=0, offset_rails=0): # Expand or contract two points about their midpoint. This is # useful for pull compensation and insetting underlay. distance = (pos1 - pos2).length() + offset_px = 0 + if offset: + offset_px += offset + if offset_percent: + offset_px += ((offset_percent / 100) * distance) if distance < 0.0001: # if they're the same point, we don't know which direction @@ -634,8 +663,21 @@ class SatinColumn(EmbroideryElement): if offset_px < -distance / 2.0: offset_px = -distance / 2.0 - pos1 = pos1 + (pos1 - pos2).unit() * offset_px - pos2 = pos2 + (pos2 - pos1).unit() * offset_px + # chose how to apply on the rails + + coeff1 = 1 + coeff2 = 1 + + if offset_rails == 1: + coeff1 = 2 + coeff2 = 0 + + if offset_rails == 2: + coeff1 = 0 + coeff2 = 2 + + pos1 = pos1 + (pos1 - pos2).unit() * offset_px * coeff1 + pos2 = pos2 + (pos2 - pos1).unit() * offset_px * coeff2 return pos1, pos2 @@ -672,13 +714,13 @@ class SatinColumn(EmbroideryElement): distance_remaining -= segment_length pos = segment_end - def plot_points_on_rails(self, spacing, offset): + def plot_points_on_rails(self, spacing, offset, offset_percent=0, offset_rails=0): # Take a section from each rail in turn, and plot out an equal number # of points on both rails. Return the points plotted. The points will # be contracted or expanded by offset using self.offset_points(). def add_pair(pos0, pos1): - pos0, pos1 = self.offset_points(pos0, pos1, offset) + pos0, pos1 = self.offset_points(pos0, pos1, offset, offset_percent, offset_rails) points[0].append(pos0) points[1].append(pos1) @@ -836,7 +878,8 @@ class SatinColumn(EmbroideryElement): # print >> dbg, "satin", self.zigzag_spacing, self.pull_compensation patch = StitchGroup(color=self.color) - sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation) + sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent, + self.pull_compensation_rails) if self.max_stitch_length: return self.do_split_stitch(patch, sides) @@ -866,7 +909,7 @@ class SatinColumn(EmbroideryElement): patch = StitchGroup(color=self.color) - sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation) + sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent, self.pull_compensation_rails) # "left" and "right" here are kind of arbitrary designations meaning # a point from the first and second rail respectively diff --git a/lib/svg/tags.py b/lib/svg/tags.py index d113bb6d..06c402dc 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -116,6 +116,8 @@ inkstitch_attribs = [ 'zigzag_underlay_max_stitch_length_mm', 'e_stitch', 'pull_compensation_mm', + 'pull_compensation_percent', + 'pull_compensation_rails', 'stroke_first', # stitch_plan 'invisible_layers', -- cgit v1.2.3 From 3aa92ba7b7c1bcc2fb04ecddea9e096d2620196d Mon Sep 17 00:00:00 2001 From: George Steel Date: Sun, 6 Nov 2022 20:23:21 -0500 Subject: change pull_compensation_rails to a continuous balance and fix some edge cases. --- lib/elements/satin_column.py | 72 +++++++++++++++++++------------------------- lib/svg/tags.py | 2 +- 2 files changed, 32 insertions(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 772d1454..480c56c6 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -136,14 +136,13 @@ class SatinColumn(EmbroideryElement): @param( 'pull_compensation_percent', _('Pull compensation percentage'), - tooltip=_('pull compensation in percentage'), + tooltip=_('Additional pull compensation which varries as a percentage of stitch width.'), unit='%', - type='int', + type='float', default=0) def pull_compensation_percent(self): # pull compensation as a percentage of the width - return max(self.get_int_param("pull_compensation_percent", 0), 0) - + return self.get_float_param("pull_compensation_percent", 0) @property @param( 'pull_compensation_mm', @@ -161,15 +160,14 @@ class SatinColumn(EmbroideryElement): @property @param( - 'pull_compensation_rails', - _('Apply pull compensation to '), - tooltip=_('decide wether the pull compensations should be applied to both side or only to a given one'), - type='dropdown', - options=[_("Both rails"), _("First rail only"), _("Second rail only")], - default=0) - def pull_compensation_rails(self): - # 0=Both | 1 = First Rail | 2 = Second Rail - return self.get_int_param("pull_compensation_rails", 0) + 'pull_compensation_balance', + _('Pull compensation balance'), + tooltip=_('Percentage of pull compensation which gets applied to second rail (50% is centered).'), + unit='%', + type='float', + default=50) + def pull_compensation_balance(self): + return min(100, max(0, self.get_float_param("pull_compensation_balance", 50))) @property @param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay')) @@ -643,41 +641,31 @@ class SatinColumn(EmbroideryElement): center_walk, _ = self.plot_points_on_rails(self.zigzag_spacing, -100000) return shgeo.LineString(center_walk) - def offset_points(self, pos1, pos2, offset, offset_percent=0, offset_rails=0): + def offset_points(self, pos1, pos2, offset_px, offset_prop=0, offset_balance=0.5): # Expand or contract two points about their midpoint. This is # useful for pull compensation and insetting underlay. distance = (pos1 - pos2).length() - offset_px = 0 - if offset: - offset_px += offset - if offset_percent: - offset_px += ((offset_percent / 100) * distance) if distance < 0.0001: # if they're the same point, we don't know which direction # to offset in, so we have to just return the points return pos1, pos2 - # don't contract beyond the midpoint, or we'll start expanding - if offset_px < -distance / 2.0: - offset_px = -distance / 2.0 + # calculate the offset for each side + offset_total = offset_px + (offset_prop * distance) + inv_offset_balance = 1 - offset_balance + offset1 = offset_total * inv_offset_balance + offset2 = offset_total * offset_balance - # chose how to apply on the rails - - coeff1 = 1 - coeff2 = 1 - - if offset_rails == 1: - coeff1 = 2 - coeff2 = 0 - - if offset_rails == 2: - coeff1 = 0 - coeff2 = 2 + # don't contract beyond the midpoint, or we'll start expanding + if offset1 < -distance * inv_offset_balance: + offset1 = -distance * inv_offset_balance + if offset2 < -distance * offset_balance: + offset2 = -distance * offset_balance - pos1 = pos1 + (pos1 - pos2).unit() * offset_px * coeff1 - pos2 = pos2 + (pos2 - pos1).unit() * offset_px * coeff2 + pos1 = pos1 + (pos1 - pos2).unit() * offset1 + pos2 = pos2 + (pos2 - pos1).unit() * offset2 return pos1, pos2 @@ -714,13 +702,13 @@ class SatinColumn(EmbroideryElement): distance_remaining -= segment_length pos = segment_end - def plot_points_on_rails(self, spacing, offset, offset_percent=0, offset_rails=0): + def plot_points_on_rails(self, spacing, offset_px=0, offset_prop=0, offset_balance=0.5): # Take a section from each rail in turn, and plot out an equal number # of points on both rails. Return the points plotted. The points will # be contracted or expanded by offset using self.offset_points(). def add_pair(pos0, pos1): - pos0, pos1 = self.offset_points(pos0, pos1, offset, offset_percent, offset_rails) + pos0, pos1 = self.offset_points(pos0, pos1, offset_px, offset_prop, offset_balance) points[0].append(pos0) points[1].append(pos1) @@ -878,8 +866,10 @@ class SatinColumn(EmbroideryElement): # print >> dbg, "satin", self.zigzag_spacing, self.pull_compensation patch = StitchGroup(color=self.color) - sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent, - self.pull_compensation_rails) + + # pull compensation is automatically converted from mm to pixels by get_float_param + sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent/100, + self.pull_compensation_balance/100) if self.max_stitch_length: return self.do_split_stitch(patch, sides) @@ -909,7 +899,7 @@ class SatinColumn(EmbroideryElement): patch = StitchGroup(color=self.color) - sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent, self.pull_compensation_rails) + sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent/100, self.pull_compensation_balance/100) # "left" and "right" here are kind of arbitrary designations meaning # a point from the first and second rail respectively diff --git a/lib/svg/tags.py b/lib/svg/tags.py index 06c402dc..90a815d7 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -117,7 +117,7 @@ inkstitch_attribs = [ 'e_stitch', 'pull_compensation_mm', 'pull_compensation_percent', - 'pull_compensation_rails', + 'pull_compensation_balance', 'stroke_first', # stitch_plan 'invisible_layers', -- cgit v1.2.3 From 8728e8d7b2dc291129f708c9bb9a50fc4b71de45 Mon Sep 17 00:00:00 2001 From: George Steel Date: Sun, 6 Nov 2022 22:23:25 -0500 Subject: Add proportional inset and balance properties to underlay. --- lib/elements/satin_column.py | 61 ++++++++++++++++++++++++++++++++++++-------- lib/svg/tags.py | 3 +++ 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 480c56c6..6aa3e193 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -148,7 +148,7 @@ class SatinColumn(EmbroideryElement): 'pull_compensation_mm', _('Pull compensation'), tooltip=_('Satin stitches pull the fabric together, resulting in a column narrower than you draw in Inkscape. ' - 'This setting expands each pair of needle penetrations outward from the center of the satin column.'), + 'This setting expands each pair of needle penetrations outward from the center of the satin column by a fixed length.'), unit='mm', type='float', default=0) @@ -162,7 +162,7 @@ class SatinColumn(EmbroideryElement): @param( 'pull_compensation_balance', _('Pull compensation balance'), - tooltip=_('Percentage of pull compensation which gets applied to second rail (50% is centered).'), + tooltip=_('Percentage of pull compensation which applies to second rail (50% is centered).'), unit='%', type='float', default=50) @@ -183,16 +183,37 @@ class SatinColumn(EmbroideryElement): @property @param('contour_underlay_inset_mm', - _('Contour underlay inset amount'), - tooltip=_('Shrink the outline, to prevent the underlay from showing around the outside of the satin column.'), - unit='mm', + _('Inset distance'), + tooltip=_('Shrink the outlineby a fixed length, to prevent the underlay from showing around the outside of the satin column.'), group=_('Contour Underlay'), - type='float', - default=0.4) + unit='mm', type='float', default=0.4, + sort_index=2) def contour_underlay_inset(self): # how far inside the edge of the column to stitch the underlay return self.get_float_param("contour_underlay_inset_mm", 0.4) + @property + @param('contour_underlay_inset_percent', + _('Inset distance'), + tooltip=_('Shrink the outlineby a proportion of the width, to prevent the underlay from showing around the outside of the satin column.'), + group=_('Contour Underlay'), + unit='%', type='float', default=0, + sort_index=3) + def contour_underlay_inset_percent(self): + # how far inside the edge of the column to stitch the underlay + return min(100, max(0, self.get_float_param("contour_underlay_inset_percent", 0))) + + @property + @param('contour_underlay_inset_balance', + _('Inset distance'), + tooltip=_('Proportion of the inset which applies to second rail (50% is centered). This can be useful for asymmetric designs.'), + group=_('Contour Underlay'), + unit='%', type='float', default=50, + sort_index=4) + def contour_underlay_inset_balance(self): + # how far inside the edge of the column to stitch the underlay + return min(100, max(0, self.get_float_param("contour_underlay_inset_balance", 50))) + @property @param('center_walk_underlay', _('Center-walk underlay'), type='toggle', group=_('Center-Walk Underlay')) def center_walk_underlay(self): @@ -206,10 +227,25 @@ class SatinColumn(EmbroideryElement): return max(self.get_float_param("center_walk_underlay_stitch_length_mm", 1.5), 0.01) @property - @param('center_walk_underlay_repeats', _('Repeats'), group=_('Center-Walk Underlay'), type='int', default=2, sort_index=2) + @param('center_walk_underlay_repeats', + _('Repeats'), + tooltip=_('for an odd number of repeats, this will reverse the direction the satin column is stitched, causing stitching to both begin and end at the start point.'), + group=_('Center-Walk Underlay'), + type='int', default=2, + sort_index=2) def center_walk_underlay_repeats(self): return max(self.get_int_param("center_walk_underlay_repeats", 2), 1) + @property + @param('center_walk_underlay_position', + _('Position'), + tooltip=_('Position of underlay from between the rails (50% is centered), consistent with the Balance parameter for contour underlay.'), + group=_('Center-Walk Underlay'), + type='float', unit='%', default=50, + sort_index=3) + def center_walk_underlay_position(self): + return min(100, max(0, self.get_float_param("center_walk_underlay_position", 50))) + @property @param('zigzag_underlay', _('Zig-zag underlay'), type='toggle', group=_('Zig-zag Underlay')) def zigzag_underlay(self): @@ -788,7 +824,10 @@ class SatinColumn(EmbroideryElement): def do_contour_underlay(self): # "contour walk" underlay: do stitches up one side and down the # other. - forward, back = self.plot_points_on_rails(self.contour_underlay_stitch_length, -self.contour_underlay_inset) + forward, back = self.plot_points_on_rails( + self.contour_underlay_stitch_length, + -self.contour_underlay_inset, -self.contour_underlay_inset_percent/100, + self.contour_underlay_inset_balance/100) stitches = (forward + list(reversed(back))) if self._center_walk_is_odd(): stitches = (list(reversed(back)) + forward) @@ -803,7 +842,9 @@ class SatinColumn(EmbroideryElement): # center line between the bezier curves. # Do it like contour underlay, but inset all the way to the center. - forward, back = self.plot_points_on_rails(self.center_walk_underlay_stitch_length, -100000) + forward, back = self.plot_points_on_rails( + self.center_walk_underlay_stitch_length, + 0, -1, self.center_walk_underlay_position/100) stitches = [] for i in range(self.center_walk_underlay_repeats): diff --git a/lib/svg/tags.py b/lib/svg/tags.py index 90a815d7..c359f9e5 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -106,9 +106,12 @@ inkstitch_attribs = [ 'center_walk_underlay', 'center_walk_underlay_stitch_length_mm', 'center_walk_underlay_repeats', + 'center_walk_underlay_position', 'contour_underlay', 'contour_underlay_stitch_length_mm', 'contour_underlay_inset_mm', + 'contour_underlay_inset_percent', + 'contour_underlay_inset_balance', 'zigzag_underlay', 'zigzag_spacing_mm', 'zigzag_underlay_inset_mm', -- cgit v1.2.3 From e1d9677ea0467ddec5e5faa0b1edff9f9e6f7dea Mon Sep 17 00:00:00 2001 From: George Steel Date: Tue, 8 Nov 2022 22:53:55 -0500 Subject: fix typos --- lib/elements/satin_column.py | 22 +++++++++++----------- lib/svg/tags.py | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 6aa3e193..1d86d254 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -183,8 +183,8 @@ class SatinColumn(EmbroideryElement): @property @param('contour_underlay_inset_mm', - _('Inset distance'), - tooltip=_('Shrink the outlineby a fixed length, to prevent the underlay from showing around the outside of the satin column.'), + _('Inset distance (fixed)'), + tooltip=_('Shrink the outline by a fixed length, to prevent the underlay from showing around the outside of the satin column.'), group=_('Contour Underlay'), unit='mm', type='float', default=0.4, sort_index=2) @@ -194,8 +194,8 @@ class SatinColumn(EmbroideryElement): @property @param('contour_underlay_inset_percent', - _('Inset distance'), - tooltip=_('Shrink the outlineby a proportion of the width, to prevent the underlay from showing around the outside of the satin column.'), + _('Inset distance (proportional)'), + tooltip=_('Shrink the outline by a proportion of the column width, to prevent the underlay from showing around the outside of the satin column.'), group=_('Contour Underlay'), unit='%', type='float', default=0, sort_index=3) @@ -205,7 +205,7 @@ class SatinColumn(EmbroideryElement): @property @param('contour_underlay_inset_balance', - _('Inset distance'), + _('Inset balance'), tooltip=_('Proportion of the inset which applies to second rail (50% is centered). This can be useful for asymmetric designs.'), group=_('Contour Underlay'), unit='%', type='float', default=50, @@ -229,7 +229,7 @@ class SatinColumn(EmbroideryElement): @property @param('center_walk_underlay_repeats', _('Repeats'), - tooltip=_('for an odd number of repeats, this will reverse the direction the satin column is stitched, causing stitching to both begin and end at the start point.'), + tooltip=_('For an odd number of repeats, this will reverse the direction the satin column is stitched, causing stitching to both begin and end at the start point.'), group=_('Center-Walk Underlay'), type='int', default=2, sort_index=2) @@ -237,14 +237,14 @@ class SatinColumn(EmbroideryElement): return max(self.get_int_param("center_walk_underlay_repeats", 2), 1) @property - @param('center_walk_underlay_position', - _('Position'), + @param('center_walk_underlay_balance', + _('Balance'), tooltip=_('Position of underlay from between the rails (50% is centered), consistent with the Balance parameter for contour underlay.'), group=_('Center-Walk Underlay'), type='float', unit='%', default=50, sort_index=3) - def center_walk_underlay_position(self): - return min(100, max(0, self.get_float_param("center_walk_underlay_position", 50))) + def center_walk_underlay_balance(self): + return min(100, max(0, self.get_float_param("center_walk_underlay_balance", 50))) @property @param('zigzag_underlay', _('Zig-zag underlay'), type='toggle', group=_('Zig-zag Underlay')) @@ -844,7 +844,7 @@ class SatinColumn(EmbroideryElement): # Do it like contour underlay, but inset all the way to the center. forward, back = self.plot_points_on_rails( self.center_walk_underlay_stitch_length, - 0, -1, self.center_walk_underlay_position/100) + 0, -1, self.center_walk_underlay_balance/100) stitches = [] for i in range(self.center_walk_underlay_repeats): diff --git a/lib/svg/tags.py b/lib/svg/tags.py index c359f9e5..21aee22b 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -106,7 +106,7 @@ inkstitch_attribs = [ 'center_walk_underlay', 'center_walk_underlay_stitch_length_mm', 'center_walk_underlay_repeats', - 'center_walk_underlay_position', + 'center_walk_underlay_balance', 'contour_underlay', 'contour_underlay_stitch_length_mm', 'contour_underlay_inset_mm', -- cgit v1.2.3 From 9237d19f0c5f0720a93451abf12057acd7583af0 Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 11 Nov 2022 00:20:59 -0500 Subject: fix code formatting --- lib/elements/satin_column.py | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 1d86d254..a96e8bf9 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -143,6 +143,7 @@ class SatinColumn(EmbroideryElement): def pull_compensation_percent(self): # pull compensation as a percentage of the width return self.get_float_param("pull_compensation_percent", 0) + @property @param( 'pull_compensation_mm', @@ -195,14 +196,15 @@ class SatinColumn(EmbroideryElement): @property @param('contour_underlay_inset_percent', _('Inset distance (proportional)'), - tooltip=_('Shrink the outline by a proportion of the column width, to prevent the underlay from showing around the outside of the satin column.'), + tooltip=_('Shrink the outline by a proportion of the column width, ' + 'to prevent the underlay from showing around the outside of the satin column.'), group=_('Contour Underlay'), unit='%', type='float', default=0, sort_index=3) def contour_underlay_inset_percent(self): # how far inside the edge of the column to stitch the underlay return min(100, max(0, self.get_float_param("contour_underlay_inset_percent", 0))) - + @property @param('contour_underlay_inset_balance', _('Inset balance'), @@ -228,21 +230,22 @@ class SatinColumn(EmbroideryElement): @property @param('center_walk_underlay_repeats', - _('Repeats'), - tooltip=_('For an odd number of repeats, this will reverse the direction the satin column is stitched, causing stitching to both begin and end at the start point.'), - group=_('Center-Walk Underlay'), - type='int', default=2, - sort_index=2) + _('Repeats'), + tooltip=_('For an odd number of repeats, this will reverse the direction the satin column is stitched, ' + 'causing stitching to both begin and end at the start point.'), + group=_('Center-Walk Underlay'), + type='int', default=2, + sort_index=2) def center_walk_underlay_repeats(self): return max(self.get_int_param("center_walk_underlay_repeats", 2), 1) @property @param('center_walk_underlay_balance', - _('Balance'), - tooltip=_('Position of underlay from between the rails (50% is centered), consistent with the Balance parameter for contour underlay.'), - group=_('Center-Walk Underlay'), - type='float', unit='%', default=50, - sort_index=3) + _('Balance'), + tooltip=_('Position of underlay from between the rails (50% is centered), consistent with the Balance parameter for contour underlay.'), + group=_('Center-Walk Underlay'), + type='float', unit='%', default=50, + sort_index=3) def center_walk_underlay_balance(self): return min(100, max(0, self.get_float_param("center_walk_underlay_balance", 50))) @@ -909,8 +912,12 @@ class SatinColumn(EmbroideryElement): patch = StitchGroup(color=self.color) # pull compensation is automatically converted from mm to pixels by get_float_param - sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent/100, - self.pull_compensation_balance/100) + sides = self.plot_points_on_rails( + self.zigzag_spacing, + self.pull_compensation, + self.pull_compensation_percent/100, + self.pull_compensation_balance/100 + ) if self.max_stitch_length: return self.do_split_stitch(patch, sides) @@ -940,7 +947,12 @@ class SatinColumn(EmbroideryElement): patch = StitchGroup(color=self.color) - sides = self.plot_points_on_rails(self.zigzag_spacing, self.pull_compensation, self.pull_compensation_percent/100, self.pull_compensation_balance/100) + sides = self.plot_points_on_rails( + self.zigzag_spacing, + self.pull_compensation, + self.pull_compensation_percent/100, + self.pull_compensation_balance/100 + ) # "left" and "right" here are kind of arbitrary designations meaning # a point from the first and second rail respectively -- cgit v1.2.3 From e2ab19d92fbad798ff8a785646ce7aaddc36abaa Mon Sep 17 00:00:00 2001 From: George Steel Date: Fri, 11 Nov 2022 00:26:59 -0500 Subject: fix shadowing bug leading to division by zero --- lib/elements/satin_column.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index a96e8bf9..f9c5495d 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -703,10 +703,10 @@ class SatinColumn(EmbroideryElement): if offset2 < -distance * offset_balance: offset2 = -distance * offset_balance - pos1 = pos1 + (pos1 - pos2).unit() * offset1 - pos2 = pos2 + (pos2 - pos1).unit() * offset2 + out1 = pos1 + (pos1 - pos2).unit() * offset1 + out2 = pos2 + (pos2 - pos1).unit() * offset2 - return pos1, pos2 + return out1, out2 def walk(self, path, start_pos, start_index, distance): # Move pixels along , which is a sequence of line -- cgit v1.2.3 From 08581d7eae58f08af6bc57fdc9a69e47f1f8768b Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 17 Nov 2022 01:51:33 -0500 Subject: Make pull-compensation and insets per-side --- lib/elements/element.py | 27 ++++++++ lib/elements/satin_column.py | 139 ++++++++++++++++++++---------------------- lib/stitches/ripple_stitch.py | 2 +- lib/svg/tags.py | 5 +- 4 files changed, 96 insertions(+), 77 deletions(-) (limited to 'lib') diff --git a/lib/elements/element.py b/lib/elements/element.py index 75d22580..8ff821e2 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -5,6 +5,7 @@ import sys from copy import deepcopy +import numpy as np import inkex from inkex import bezier @@ -135,6 +136,32 @@ class EmbroideryElement(object): return value + # returns 2 float values as a numpy array + # if a single number is given in the param, it will apply to both returned values. + # Not cached the cache will crash if the default is a numpy array. + # The ppoperty calling this will need to cache itself and can safely do so since it has no parameters + def get_lr_float_param(self, param, default=(0, 0)): + default = np.array(default) # type coersion in case the default is a tuple + + raw = self.get_param(param, "") + parts = raw.split() + try: + if len(parts) == 0: + return default + elif len(parts) == 1: + a = float(parts[0]) + return np.array([a, a]) + else: + a = float(parts[0]) + b = float(parts[1]) + return np.array([a, b]) + except (TypeError, ValueError): + return default + + # not cached + def get_lr_mm_param_as_px(self, param, default): + return self.get_lr_float_param(param, default) * PIXELS_PER_MM + def set_param(self, name, value): param = INKSTITCH_ATTRIBS[name] self.node.set(param, str(value)) diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index f9c5495d..400f60d8 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -5,6 +5,7 @@ from copy import deepcopy from itertools import chain +import numpy as np from shapely import affinity as shaffinity from shapely import geometry as shgeo @@ -16,7 +17,7 @@ from ..i18n import _ from ..stitch_plan import StitchGroup from ..svg import line_strings_to_csp, point_lists_to_csp from ..utils import Point, cache, collapse_duplicate_point, cut -from .element import EmbroideryElement, param +from .element import EmbroideryElement, param, PIXELS_PER_MM from .validation import ValidationError, ValidationWarning @@ -124,8 +125,8 @@ class SatinColumn(EmbroideryElement): @property @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), - tooltip=_('Peak-to-peak distance between zig-zags.'), - unit='mm', + tooltip=_('Peak-to-peak distance between zig-zags. This is double the mm/stitch measurement used by most mechanichal machines.'), + unit='mm/cycle', type='float', default=0.4) def zigzag_spacing(self): @@ -136,39 +137,30 @@ class SatinColumn(EmbroideryElement): @param( 'pull_compensation_percent', _('Pull compensation percentage'), - tooltip=_('Additional pull compensation which varries as a percentage of stitch width.'), - unit='%', + tooltip=_('Additional pull compensation which varries as a percentage of stitch width. ' + 'Two values separated by a space may be used for an aysmmetric effect.'), + unit='% (each side)', type='float', default=0) def pull_compensation_percent(self): # pull compensation as a percentage of the width - return self.get_float_param("pull_compensation_percent", 0) + return self.get_lr_float_param("pull_compensation_percent", (0, 0)) @property @param( 'pull_compensation_mm', _('Pull compensation'), - tooltip=_('Satin stitches pull the fabric together, resulting in a column narrower than you draw in Inkscape. ' - 'This setting expands each pair of needle penetrations outward from the center of the satin column by a fixed length.'), - unit='mm', + tooltip=_('Satin stitches pull the fabric together, resulting in a column narrower than you draw in Inkscape. ' + 'This setting expands each pair of needle penetrations outward from the center of the satin column by a fixed length. ' + 'Two values separated by a space may be used for an aysmmetric effect.'), + unit='mm (each side)', type='float', default=0) - def pull_compensation(self): + def pull_compensation_px(self): # In satin stitch, the stitches have a tendency to pull together and # narrow the entire column. We can compensate for this by stitching # wider than we desire the column to end up. - return self.get_float_param("pull_compensation_mm", 0) - - @property - @param( - 'pull_compensation_balance', - _('Pull compensation balance'), - tooltip=_('Percentage of pull compensation which applies to second rail (50% is centered).'), - unit='%', - type='float', - default=50) - def pull_compensation_balance(self): - return min(100, max(0, self.get_float_param("pull_compensation_balance", 50))) + return self.get_lr_mm_param_as_px("pull_compensation_mm", (0, 0)) @property @param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay')) @@ -187,11 +179,11 @@ class SatinColumn(EmbroideryElement): _('Inset distance (fixed)'), tooltip=_('Shrink the outline by a fixed length, to prevent the underlay from showing around the outside of the satin column.'), group=_('Contour Underlay'), - unit='mm', type='float', default=0.4, + unit='mm (each side)', type='float', default=0.4, sort_index=2) - def contour_underlay_inset(self): + def contour_underlay_inset_px(self): # how far inside the edge of the column to stitch the underlay - return self.get_float_param("contour_underlay_inset_mm", 0.4) + return self.get_lr_mm_param_as_px("contour_underlay_inset_mm", (0.4, 0.4)) @property @param('contour_underlay_inset_percent', @@ -199,22 +191,11 @@ class SatinColumn(EmbroideryElement): tooltip=_('Shrink the outline by a proportion of the column width, ' 'to prevent the underlay from showing around the outside of the satin column.'), group=_('Contour Underlay'), - unit='%', type='float', default=0, + unit='% (each side)', type='float', default=0, sort_index=3) def contour_underlay_inset_percent(self): # how far inside the edge of the column to stitch the underlay - return min(100, max(0, self.get_float_param("contour_underlay_inset_percent", 0))) - - @property - @param('contour_underlay_inset_balance', - _('Inset balance'), - tooltip=_('Proportion of the inset which applies to second rail (50% is centered). This can be useful for asymmetric designs.'), - group=_('Contour Underlay'), - unit='%', type='float', default=50, - sort_index=4) - def contour_underlay_inset_balance(self): - # how far inside the edge of the column to stitch the underlay - return min(100, max(0, self.get_float_param("contour_underlay_inset_balance", 50))) + return self.get_lr_float_param("contour_underlay_inset_percent", (0, 0)) @property @param('center_walk_underlay', _('Center-walk underlay'), type='toggle', group=_('Center-Walk Underlay')) @@ -240,14 +221,14 @@ class SatinColumn(EmbroideryElement): return max(self.get_int_param("center_walk_underlay_repeats", 2), 1) @property - @param('center_walk_underlay_balance', - _('Balance'), - tooltip=_('Position of underlay from between the rails (50% is centered), consistent with the Balance parameter for contour underlay.'), + @param('center_walk_underlay_position', + _('Position'), + tooltip=_('Position of underlay from between the rails. 0% is along the first rail, 50% is centered, 100% is along the second rail.'), group=_('Center-Walk Underlay'), type='float', unit='%', default=50, sort_index=3) - def center_walk_underlay_balance(self): - return min(100, max(0, self.get_float_param("center_walk_underlay_balance", 50))) + def center_walk_underlay_position(self): + return min(100, max(0, self.get_float_param("center_walk_underlay_position", 50))) @property @param('zigzag_underlay', _('Zig-zag underlay'), type='toggle', group=_('Zig-zag Underlay')) @@ -267,13 +248,13 @@ class SatinColumn(EmbroideryElement): @property @param('zigzag_underlay_inset_mm', - _('Inset amount'), + _('Inset amount (fixed)'), tooltip=_('default: half of contour underlay inset'), - unit='mm', + unit='mm (each side)', group=_('Zig-zag Underlay'), type='float', default="") - def zigzag_underlay_inset(self): + def zigzag_underlay_inset_px(self): # how far in from the edge of the satin the points in the zigzags # should be @@ -281,7 +262,21 @@ class SatinColumn(EmbroideryElement): # doing both contour underlay and zigzag underlay, make sure the # points of the zigzag fall outside the contour underlay but inside # the edges of the satin column. - return self.get_float_param("zigzag_underlay_inset_mm") or self.contour_underlay_inset / 2.0 + default = self.contour_underlay_inset_px * 0.5 / PIXELS_PER_MM + x = self.get_lr_mm_param_as_px("zigzag_underlay_inset_mm", default) + return x + + @property + @param('zigzag_underlay_inset_percent', + _('Inset amount (proportional)'), + tooltip=_('default: half of contour underlay inset'), + unit='% (each side)', + group=_('Zig-zag Underlay'), + type='float', + default="") + def zigzag_underlay_inset_percent(self): + default = self.contour_underlay_inset_percent * 0.5 + return self.get_lr_float_param("zigzag_underlay_inset_percent", default) @property @param('zigzag_underlay_max_stitch_length_mm', @@ -375,7 +370,7 @@ class SatinColumn(EmbroideryElement): # intersect with the rails even with floating point inaccuracy. start = Point(*start) end = Point(*end) - start, end = self.offset_points(start, end, 0.01) + start, end = self.offset_points(start, end, (0.01, 0.01), (0, 0)) start = list(start) end = list(end) @@ -585,7 +580,7 @@ class SatinColumn(EmbroideryElement): """ # like in do_satin() - points = list(chain.from_iterable(zip(*self.plot_points_on_rails(self.zigzag_spacing, 0)))) + points = list(chain.from_iterable(zip(*self.plot_points_on_rails(self.zigzag_spacing)))) if isinstance(split_point, float): index_of_closest_stitch = int(round(len(points) * split_point)) @@ -677,10 +672,10 @@ class SatinColumn(EmbroideryElement): @cache def center_line(self): # similar technique to do_center_walk() - center_walk, _ = self.plot_points_on_rails(self.zigzag_spacing, -100000) + center_walk, _ = self.plot_points_on_rails(self.zigzag_spacing, (0, 0), (-0.5, -0.5)) return shgeo.LineString(center_walk) - def offset_points(self, pos1, pos2, offset_px, offset_prop=0, offset_balance=0.5): + def offset_points(self, pos1, pos2, offset_px, offset_prop): # Expand or contract two points about their midpoint. This is # useful for pull compensation and insetting underlay. @@ -692,19 +687,18 @@ class SatinColumn(EmbroideryElement): return pos1, pos2 # calculate the offset for each side - offset_total = offset_px + (offset_prop * distance) - inv_offset_balance = 1 - offset_balance - offset1 = offset_total * inv_offset_balance - offset2 = offset_total * offset_balance + offset_a = offset_px[0] + (distance * offset_prop[0]) + offset_b = offset_px[1] + (distance * offset_prop[1]) + offset_total = offset_a + offset_b # don't contract beyond the midpoint, or we'll start expanding - if offset1 < -distance * inv_offset_balance: - offset1 = -distance * inv_offset_balance - if offset2 < -distance * offset_balance: - offset2 = -distance * offset_balance + if offset_total < -distance: + scale = distance / offset_total + offset_a = offset_a * scale + offset_b = offset_b * scale - out1 = pos1 + (pos1 - pos2).unit() * offset1 - out2 = pos2 + (pos2 - pos1).unit() * offset2 + out1 = pos1 + (pos1 - pos2).unit() * offset_a + out2 = pos2 + (pos2 - pos1).unit() * offset_b return out1, out2 @@ -741,13 +735,13 @@ class SatinColumn(EmbroideryElement): distance_remaining -= segment_length pos = segment_end - def plot_points_on_rails(self, spacing, offset_px=0, offset_prop=0, offset_balance=0.5): + def plot_points_on_rails(self, spacing, offset_px=(0, 0), offset_prop=(0, 0)): # Take a section from each rail in turn, and plot out an equal number # of points on both rails. Return the points plotted. The points will # be contracted or expanded by offset using self.offset_points(). def add_pair(pos0, pos1): - pos0, pos1 = self.offset_points(pos0, pos1, offset_px, offset_prop, offset_balance) + pos0, pos1 = self.offset_points(pos0, pos1, offset_px, offset_prop) points[0].append(pos0) points[1].append(pos1) @@ -829,8 +823,7 @@ class SatinColumn(EmbroideryElement): # other. forward, back = self.plot_points_on_rails( self.contour_underlay_stitch_length, - -self.contour_underlay_inset, -self.contour_underlay_inset_percent/100, - self.contour_underlay_inset_balance/100) + -self.contour_underlay_inset_px, -self.contour_underlay_inset_percent/100) stitches = (forward + list(reversed(back))) if self._center_walk_is_odd(): stitches = (list(reversed(back)) + forward) @@ -844,10 +837,11 @@ class SatinColumn(EmbroideryElement): # Center walk underlay is just a running stitch down and back on the # center line between the bezier curves. + inset_prop = -np.array([self.center_walk_underlay_position, 100-self.center_walk_underlay_position]) / 100 # Do it like contour underlay, but inset all the way to the center. forward, back = self.plot_points_on_rails( self.center_walk_underlay_stitch_length, - 0, -1, self.center_walk_underlay_balance/100) + (0, 0), inset_prop) stitches = [] for i in range(self.center_walk_underlay_repeats): @@ -875,7 +869,8 @@ class SatinColumn(EmbroideryElement): patch = StitchGroup(color=self.color) sides = self.plot_points_on_rails(self.zigzag_underlay_spacing / 2.0, - -self.zigzag_underlay_inset) + -self.zigzag_underlay_inset_px, + -self.zigzag_underlay_inset_percent/100) if self._center_walk_is_odd(): sides = [list(reversed(sides[0])), list(reversed(sides[1]))] @@ -914,9 +909,8 @@ class SatinColumn(EmbroideryElement): # pull compensation is automatically converted from mm to pixels by get_float_param sides = self.plot_points_on_rails( self.zigzag_spacing, - self.pull_compensation, - self.pull_compensation_percent/100, - self.pull_compensation_balance/100 + self.pull_compensation_px, + self.pull_compensation_percent/100 ) if self.max_stitch_length: @@ -949,9 +943,8 @@ class SatinColumn(EmbroideryElement): sides = self.plot_points_on_rails( self.zigzag_spacing, - self.pull_compensation, - self.pull_compensation_percent/100, - self.pull_compensation_balance/100 + self.pull_compensation_px, + self.pull_compensation_percent/100 ) # "left" and "right" here are kind of arbitrary designations meaning diff --git a/lib/stitches/ripple_stitch.py b/lib/stitches/ripple_stitch.py index 6a0ef7f0..67362f12 100644 --- a/lib/stitches/ripple_stitch.py +++ b/lib/stitches/ripple_stitch.py @@ -74,7 +74,7 @@ def _get_satin_ripple_helper_lines(stroke): length = stroke.grid_size or stroke.running_stitch_length # use satin column points for satin like build ripple stitches - rail_points = SatinColumn(stroke.node).plot_points_on_rails(length, 0) + rail_points = SatinColumn(stroke.node).plot_points_on_rails(length) steps = _get_steps(stroke.get_line_count(), exponent=stroke.exponent, flip=stroke.flip_exponent) diff --git a/lib/svg/tags.py b/lib/svg/tags.py index 21aee22b..219a9b56 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -106,21 +106,20 @@ inkstitch_attribs = [ 'center_walk_underlay', 'center_walk_underlay_stitch_length_mm', 'center_walk_underlay_repeats', - 'center_walk_underlay_balance', + 'center_walk_underlay_position', 'contour_underlay', 'contour_underlay_stitch_length_mm', 'contour_underlay_inset_mm', 'contour_underlay_inset_percent', - 'contour_underlay_inset_balance', 'zigzag_underlay', 'zigzag_spacing_mm', 'zigzag_underlay_inset_mm', + 'zigzag_underlay_inset_percent', 'zigzag_underlay_spacing_mm', 'zigzag_underlay_max_stitch_length_mm', 'e_stitch', 'pull_compensation_mm', 'pull_compensation_percent', - 'pull_compensation_balance', 'stroke_first', # stitch_plan 'invisible_layers', -- cgit v1.2.3 From 7cef2c9a094abe61282ac9bdc6bbfdc1e3e1d8c6 Mon Sep 17 00:00:00 2001 From: George Steel Date: Wed, 23 Nov 2022 21:58:39 -0500 Subject: typo fixes --- lib/elements/element.py | 6 +++--- lib/elements/satin_column.py | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/elements/element.py b/lib/elements/element.py index 8ff821e2..96949ca3 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -140,7 +140,7 @@ class EmbroideryElement(object): # if a single number is given in the param, it will apply to both returned values. # Not cached the cache will crash if the default is a numpy array. # The ppoperty calling this will need to cache itself and can safely do so since it has no parameters - def get_lr_float_param(self, param, default=(0, 0)): + def get_split_float_param(self, param, default=(0, 0)): default = np.array(default) # type coersion in case the default is a tuple raw = self.get_param(param, "") @@ -159,8 +159,8 @@ class EmbroideryElement(object): return default # not cached - def get_lr_mm_param_as_px(self, param, default): - return self.get_lr_float_param(param, default) * PIXELS_PER_MM + def get_split_mm_param_as_px(self, param, default): + return self.get_split_float_param(param, default) * PIXELS_PER_MM def set_param(self, name, value): param = INKSTITCH_ATTRIBS[name] diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 400f60d8..2cb0529d 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -125,7 +125,7 @@ class SatinColumn(EmbroideryElement): @property @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), - tooltip=_('Peak-to-peak distance between zig-zags. This is double the mm/stitch measurement used by most mechanichal machines.'), + tooltip=_('Peak-to-peak distance between zig-zags. This is double the mm/stitch measurement used by most mechanical machines.'), unit='mm/cycle', type='float', default=0.4) @@ -144,7 +144,7 @@ class SatinColumn(EmbroideryElement): default=0) def pull_compensation_percent(self): # pull compensation as a percentage of the width - return self.get_lr_float_param("pull_compensation_percent", (0, 0)) + return self.get_split_float_param("pull_compensation_percent", (0, 0)) @property @param( @@ -160,7 +160,7 @@ class SatinColumn(EmbroideryElement): # In satin stitch, the stitches have a tendency to pull together and # narrow the entire column. We can compensate for this by stitching # wider than we desire the column to end up. - return self.get_lr_mm_param_as_px("pull_compensation_mm", (0, 0)) + return self.get_split_mm_param_as_px("pull_compensation_mm", (0, 0)) @property @param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay')) @@ -183,7 +183,7 @@ class SatinColumn(EmbroideryElement): sort_index=2) def contour_underlay_inset_px(self): # how far inside the edge of the column to stitch the underlay - return self.get_lr_mm_param_as_px("contour_underlay_inset_mm", (0.4, 0.4)) + return self.get_split_mm_param_as_px("contour_underlay_inset_mm", (0.4, 0.4)) @property @param('contour_underlay_inset_percent', @@ -195,7 +195,7 @@ class SatinColumn(EmbroideryElement): sort_index=3) def contour_underlay_inset_percent(self): # how far inside the edge of the column to stitch the underlay - return self.get_lr_float_param("contour_underlay_inset_percent", (0, 0)) + return self.get_split_float_param("contour_underlay_inset_percent", (0, 0)) @property @param('center_walk_underlay', _('Center-walk underlay'), type='toggle', group=_('Center-Walk Underlay')) @@ -263,7 +263,7 @@ class SatinColumn(EmbroideryElement): # points of the zigzag fall outside the contour underlay but inside # the edges of the satin column. default = self.contour_underlay_inset_px * 0.5 / PIXELS_PER_MM - x = self.get_lr_mm_param_as_px("zigzag_underlay_inset_mm", default) + x = self.get_split_mm_param_as_px("zigzag_underlay_inset_mm", default) return x @property @@ -276,7 +276,7 @@ class SatinColumn(EmbroideryElement): default="") def zigzag_underlay_inset_percent(self): default = self.contour_underlay_inset_percent * 0.5 - return self.get_lr_float_param("zigzag_underlay_inset_percent", default) + return self.get_split_float_param("zigzag_underlay_inset_percent", default) @property @param('zigzag_underlay_max_stitch_length_mm', -- cgit v1.2.3 From 739e2b96705de45d4c662a2ba969ff2dd360944a Mon Sep 17 00:00:00 2001 From: George Steel Date: Wed, 23 Nov 2022 23:09:57 -0500 Subject: add option to swap rails --- lib/elements/satin_column.py | 22 +++++++++++++++++++++- lib/svg/tags.py | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 2cb0529d..1c236055 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -142,6 +142,7 @@ class SatinColumn(EmbroideryElement): unit='% (each side)', type='float', default=0) + @cache def pull_compensation_percent(self): # pull compensation as a percentage of the width return self.get_split_float_param("pull_compensation_percent", (0, 0)) @@ -156,12 +157,24 @@ class SatinColumn(EmbroideryElement): unit='mm (each side)', type='float', default=0) + @cache def pull_compensation_px(self): # In satin stitch, the stitches have a tendency to pull together and # narrow the entire column. We can compensate for this by stitching # wider than we desire the column to end up. return self.get_split_mm_param_as_px("pull_compensation_mm", (0, 0)) + @property + @param( + 'swap_satin_rails', + _('Swap rails'), + tooltip=_('Swaps the first and second rails of the satin column, ' + 'effecting which side the thread finished on as well as any sided properties'), + type='boolean', + default='false') + def swap_rails(self): + return self.get_boolean_param('swap_satin_rails', False) + @property @param('contour_underlay', _('Contour underlay'), type='toggle', group=_('Contour Underlay')) def contour_underlay(self): @@ -181,6 +194,7 @@ class SatinColumn(EmbroideryElement): group=_('Contour Underlay'), unit='mm (each side)', type='float', default=0.4, sort_index=2) + @cache def contour_underlay_inset_px(self): # how far inside the edge of the column to stitch the underlay return self.get_split_mm_param_as_px("contour_underlay_inset_mm", (0.4, 0.4)) @@ -193,6 +207,7 @@ class SatinColumn(EmbroideryElement): group=_('Contour Underlay'), unit='% (each side)', type='float', default=0, sort_index=3) + @cache def contour_underlay_inset_percent(self): # how far inside the edge of the column to stitch the underlay return self.get_split_float_param("contour_underlay_inset_percent", (0, 0)) @@ -274,6 +289,7 @@ class SatinColumn(EmbroideryElement): group=_('Zig-zag Underlay'), type='float', default="") + @cache def zigzag_underlay_inset_percent(self): default = self.contour_underlay_inset_percent * 0.5 return self.get_split_float_param("zigzag_underlay_inset_percent", default) @@ -306,7 +322,11 @@ class SatinColumn(EmbroideryElement): @cache def rails(self): """The rails in order, as point lists""" - return [subpath for i, subpath in enumerate(self.csp) if i in self.rail_indices] + rails = [subpath for i, subpath in enumerate(self.csp) if i in self.rail_indices] + if len(rails) == 2 and self.swap_rails: + return [rails[1], rails[0]] + else: + return rails @property @cache diff --git a/lib/svg/tags.py b/lib/svg/tags.py index 06424dc2..850256ee 100644 --- a/lib/svg/tags.py +++ b/lib/svg/tags.py @@ -104,6 +104,7 @@ inkstitch_attribs = [ 'short_stitch_distance_mm', 'short_stitch_inset', 'running_stitch_length_mm', + 'swap_satin_rails', 'center_walk_underlay', 'center_walk_underlay_stitch_length_mm', 'center_walk_underlay_repeats', -- cgit v1.2.3 From 81168fd299c27b1f6a7c5ed62a3a5ca3ff95acbb Mon Sep 17 00:00:00 2001 From: George Steel Date: Thu, 24 Nov 2022 21:10:14 -0500 Subject: typo fixes --- lib/elements/satin_column.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 1c236055..e4d69361 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -169,7 +169,7 @@ class SatinColumn(EmbroideryElement): 'swap_satin_rails', _('Swap rails'), tooltip=_('Swaps the first and second rails of the satin column, ' - 'effecting which side the thread finished on as well as any sided properties'), + 'affecting which side the thread finished on as well as any sided properties'), type='boolean', default='false') def swap_rails(self): @@ -695,7 +695,7 @@ class SatinColumn(EmbroideryElement): center_walk, _ = self.plot_points_on_rails(self.zigzag_spacing, (0, 0), (-0.5, -0.5)) return shgeo.LineString(center_walk) - def offset_points(self, pos1, pos2, offset_px, offset_prop): + def offset_points(self, pos1, pos2, offset_px, offset_proportional): # Expand or contract two points about their midpoint. This is # useful for pull compensation and insetting underlay. @@ -707,8 +707,8 @@ class SatinColumn(EmbroideryElement): return pos1, pos2 # calculate the offset for each side - offset_a = offset_px[0] + (distance * offset_prop[0]) - offset_b = offset_px[1] + (distance * offset_prop[1]) + offset_a = offset_px[0] + (distance * offset_proportional[0]) + offset_b = offset_px[1] + (distance * offset_proportional[1]) offset_total = offset_a + offset_b # don't contract beyond the midpoint, or we'll start expanding @@ -755,13 +755,13 @@ class SatinColumn(EmbroideryElement): distance_remaining -= segment_length pos = segment_end - def plot_points_on_rails(self, spacing, offset_px=(0, 0), offset_prop=(0, 0)): + def plot_points_on_rails(self, spacing, offset_px=(0, 0), offset_proportional=(0, 0)): # Take a section from each rail in turn, and plot out an equal number # of points on both rails. Return the points plotted. The points will # be contracted or expanded by offset using self.offset_points(). def add_pair(pos0, pos1): - pos0, pos1 = self.offset_points(pos0, pos1, offset_px, offset_prop) + pos0, pos1 = self.offset_points(pos0, pos1, offset_px, offset_proportional) points[0].append(pos0) points[1].append(pos1) -- cgit v1.2.3