summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/elements/auto_fill.py33
-rw-r--r--lib/elements/element.py5
-rw-r--r--lib/elements/stroke.py81
3 files changed, 70 insertions, 49 deletions
diff --git a/lib/elements/auto_fill.py b/lib/elements/auto_fill.py
index 08ae67f7..504bae2a 100644
--- a/lib/elements/auto_fill.py
+++ b/lib/elements/auto_fill.py
@@ -63,20 +63,43 @@ class AutoFill(Fill):
return self.get_float_param("fill_underlay_max_stitch_length_mm") or self.max_stitch_length
@property
- @param('fill_underlay_inset_mm', _('Inset'), unit='mm', group=_('AutoFill Underlay'), type='float', default=0)
+ @param('fill_underlay_inset_mm',
+ _('Inset'),
+ tooltip='Shrink the shape before doing underlay, to prevent underlay from showing around the outside of the fill.',
+ unit='mm',
+ group=_('AutoFill Underlay'),
+ type='float',
+ default=0)
def fill_underlay_inset(self):
return self.get_float_param('fill_underlay_inset_mm', 0)
@property
- def underlay_shape(self):
- if self.fill_underlay_inset:
- shape = self.shape.buffer(-self.fill_underlay_inset)
+ @param('expand_mm',
+ _('Expand'),
+ tooltip='Expand the shape before fill stitching, to compensate for gaps between shapes.',
+ unit='mm',
+ type='float',
+ default=0)
+ def expand(self):
+ return self.get_float_param('expand_mm', 0)
+
+ def shrink_or_grow_shape(self, amount):
+ if amount:
+ shape = self.shape.buffer(amount)
if not isinstance(shape, shgeo.MultiPolygon):
shape = shgeo.MultiPolygon([shape])
return shape
else:
return self.shape
+ @property
+ def underlay_shape(self):
+ return self.shrink_or_grow_shape(-self.fill_underlay_inset)
+
+ @property
+ def fill_shape(self):
+ return self.shrink_or_grow_shape(self.expand)
+
def to_patches(self, last_patch):
stitches = []
@@ -96,7 +119,7 @@ class AutoFill(Fill):
starting_point))
starting_point = stitches[-1]
- stitches.extend(auto_fill(self.shape,
+ stitches.extend(auto_fill(self.fill_shape,
self.angle,
self.row_spacing,
self.end_row_spacing,
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 300136dd..42f6c470 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -29,6 +29,10 @@ class Patch:
else:
raise TypeError("Patch can only be added to another Patch")
+ def __len__(self):
+ # This method allows `len(patch)` and `if patch:
+ return len(self.stitches)
+
def add_stitch(self, stitch):
self.stitches.append(stitch)
@@ -36,7 +40,6 @@ class Patch:
return Patch(self.color, self.stitches[::-1])
-
class Param(object):
def __init__(self, name, description, unit=None, values=[], type=None, group=None, inverse=False, default=None, tooltip=None, sort_index=0):
self.name = name
diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py
index 48662b6d..d3054132 100644
--- a/lib/elements/stroke.py
+++ b/lib/elements/stroke.py
@@ -3,7 +3,7 @@ import sys
from .element import param, EmbroideryElement, Patch
from ..i18n import _
from ..utils import cache, Point
-
+from ..stitches import running_stitch
warned_about_legacy_running_stitch = False
@@ -93,56 +93,50 @@ class Stroke(EmbroideryElement):
else:
return False
- def stroke_points(self, emb_point_list, zigzag_spacing, stroke_width):
- # TODO: use inkstitch.stitches.running_stitch
+ def simple_satin(self, path, zigzag_spacing, stroke_width):
+ "zig-zag along the path at the specified spacing and wdith"
- patch = Patch(color=self.color)
- p0 = emb_point_list[0]
- rho = 0.0
- side = 1
- last_segment_direction = None
+ # `self.zigzag_spacing` is the length for a zig and a zag
+ # together (a V shape). Start with running stitch at half
+ # that length:
+ patch = self.running_stitch(path, zigzag_spacing / 2.0)
- for repeat in xrange(self.repeats):
- if repeat % 2 == 0:
- order = range(1, len(emb_point_list))
- else:
- order = range(-2, -len(emb_point_list) - 1, -1)
+ # Now move the points left and right. Consider each pair
+ # of points in turn, and move perpendicular to them,
+ # alternating left and right.
- for segi in order:
- p1 = emb_point_list[segi]
+ offset = stroke_width / 2.0
- # how far we have to go along segment
- seg_len = (p1 - p0).length()
- if (seg_len == 0):
- continue
+ for i in xrange(len(patch) - 1):
+ start = patch.stitches[i]
+ end = patch.stitches[i + 1]
+ segment_direction = (end - start).unit()
+ zigzag_direction = segment_direction.rotate_left()
- # vector pointing along segment
- along = (p1 - p0).unit()
+ if i % 2 == 1:
+ zigzag_direction *= -1
- # vector pointing to edge of stroke width
- perp = along.rotate_left() * (stroke_width * 0.5)
+ patch.stitches[i] += zigzag_direction * offset
- if stroke_width == 0.0 and last_segment_direction is not None:
- if abs(1.0 - along * last_segment_direction) > 0.5:
- # if greater than 45 degree angle, stitch the corner
- rho = zigzag_spacing
- patch.add_stitch(p0)
+ return patch
- # iteration variable: how far we are along segment
- while (rho <= seg_len):
- left_pt = p0 + along * rho + perp * side
- patch.add_stitch(left_pt)
- rho += zigzag_spacing
- side = -side
+ def running_stitch(self, path, stitch_length):
+ repeated_path = []
- p0 = p1
- last_segment_direction = along
- rho -= seg_len
+ # go back and forth along the path as specified by self.repeats
+ for i in xrange(self.repeats):
+ if i % 2 == 1:
+ # reverse every other pass
+ this_path = path[::-1]
+ else:
+ this_path = path[:]
- if (p0 - patch.stitches[-1]).length() > 0.1:
- patch.add_stitch(p0)
+ repeated_path.extend(this_path)
+
+ stitches = running_stitch(repeated_path, stitch_length)
+
+ return Patch(self.color, stitches)
- return patch
def to_patches(self, last_patch):
patches = []
@@ -152,10 +146,11 @@ class Stroke(EmbroideryElement):
if self.manual_stitch_mode:
patch = Patch(color=self.color, stitches=path, stitch_as_is=True)
elif self.is_running_stitch():
- patch = self.stroke_points(path, self.running_stitch_length, stroke_width=0.0)
+ patch = self.running_stitch(path, self.running_stitch_length)
else:
- patch = self.stroke_points(path, self.zigzag_spacing / 2.0, stroke_width=self.stroke_width)
+ patch = self.simple_satin(path, self.zigzag_spacing, self.stroke_width)
- patches.append(patch)
+ if patch:
+ patches.append(patch)
return patches