diff options
Diffstat (limited to 'lib/elements')
| -rw-r--r-- | lib/elements/satin_column.py | 72 |
1 files changed, 31 insertions, 41 deletions
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 |
