summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudine <claudine@MacBook-Pro-2.local>2022-11-06 10:49:25 -0500
committerGeorge Steel <george.steel@gmail.com>2022-11-06 10:49:25 -0500
commit4285a6fb7f230547d0c70032c346f6f30956e167 (patch)
treeb814c80613be62f895fe9864ef496df5941c77bf
parentea13c429973e50ef55ee4bf4403a0618cb9b26d8 (diff)
add pull_compensation_percent
-rw-r--r--lib/elements/satin_column.py57
-rw-r--r--lib/svg/tags.py2
2 files changed, 52 insertions, 7 deletions
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
@@ -134,6 +134,18 @@ class SatinColumn(EmbroideryElement):
@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',
_('Pull compensation'),
tooltip=_('Satin stitches pull the fabric together, resulting in a column narrower than you draw in Inkscape. '
@@ -148,6 +160,18 @@ class SatinColumn(EmbroideryElement):
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):
# "Contour underlay" is stitching just inside the rectangular shape
@@ -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',