summaryrefslogtreecommitdiff
path: root/lib/elements
diff options
context:
space:
mode:
Diffstat (limited to 'lib/elements')
-rw-r--r--lib/elements/element.py24
-rw-r--r--lib/elements/polyline.py7
-rw-r--r--lib/elements/satin_column.py48
-rw-r--r--lib/elements/stroke.py31
4 files changed, 88 insertions, 22 deletions
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 3c31f1b0..ebca90a4 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -206,6 +206,10 @@ class EmbroideryElement(object):
return apply_transforms(self.path, self.node)
@property
+ def shape(self):
+ raise NotImplementedError("INTERNAL ERROR: %s must implement shape()", self.__class__)
+
+ @property
@cache
def commands(self):
return find_commands(self.node)
@@ -215,6 +219,10 @@ class EmbroideryElement(object):
return [c for c in self.commands if c.command == command]
@cache
+ def has_command(self, command):
+ return len(self.get_commands(command)) > 0
+
+ @cache
def get_command(self, command):
commands = self.get_commands(command)
@@ -238,22 +246,10 @@ class EmbroideryElement(object):
return [self.strip_control_points(subpath) for subpath in path]
@property
- @param('trim_after',
- _('TRIM after'),
- tooltip=_('Trim thread after this object (for supported machines and file formats)'),
- type='boolean',
- default=False,
- sort_index=1000)
def trim_after(self):
return self.get_boolean_param('trim_after', False)
@property
- @param('stop_after',
- _('STOP after'),
- tooltip=_('Add STOP instruction after this object (for supported machines and file formats)'),
- type='boolean',
- default=False,
- sort_index=1000)
def stop_after(self):
return self.get_boolean_param('stop_after', False)
@@ -264,8 +260,8 @@ class EmbroideryElement(object):
patches = self.to_patches(last_patch)
if patches:
- patches[-1].trim_after = self.trim_after
- patches[-1].stop_after = self.stop_after
+ patches[-1].trim_after = self.has_command("trim") or self.trim_after
+ patches[-1].stop_after = self.has_command("stop") or self.stop_after
return patches
diff --git a/lib/elements/polyline.py b/lib/elements/polyline.py
index 5c474237..b9ffdc0b 100644
--- a/lib/elements/polyline.py
+++ b/lib/elements/polyline.py
@@ -1,3 +1,5 @@
+from shapely import geometry as shgeo
+
from .element import param, EmbroideryElement, Patch
from ..i18n import _
from ..utils.geometry import Point
@@ -28,6 +30,11 @@ class Polyline(EmbroideryElement):
return points
@property
+ @cache
+ def shape(self):
+ return shgeo.LineString(self.points)
+
+ @property
def path(self):
# A polyline is a series of connected line segments described by their
# points. In order to make use of the existing logic for incorporating
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index 1d13c5e0..78275745 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -17,6 +17,12 @@ class SatinColumn(EmbroideryElement):
def satin_column(self):
return self.get_boolean_param("satin_column")
+ # I18N: "E" stitch is so named because it looks like the letter E.
+ @property
+ @param('e_stitch', _('"E" stitch'), type='boolean', default='false')
+ def e_stitch(self):
+ return self.get_boolean_param("e_stitch")
+
@property
def color(self):
return self.get_style("stroke")
@@ -28,7 +34,7 @@ class SatinColumn(EmbroideryElement):
return max(self.get_float_param("zigzag_spacing_mm", 0.4), 0.01)
@property
- @param('pull_compensation_mm', _('Pull compensation'), unit='mm', type='float')
+ @param('pull_compensation_mm', _('Pull compensation'), unit='mm', type='float', default=0)
def pull_compensation(self):
# In satin stitch, the stitches have a tendency to pull together and
# narrow the entire column. We can compensate for this by stitching
@@ -76,7 +82,7 @@ class SatinColumn(EmbroideryElement):
return max(self.get_float_param("zigzag_underlay_spacing_mm", 3), 0.01)
@property
- @param('zigzag_underlay_inset_mm', _('Inset amount (default: half of contour underlay inset)'), unit='mm', group=_('Zig-zag Underlay'), type='float')
+ @param('zigzag_underlay_inset_mm', _('Inset amount (default: half of contour underlay inset)'), unit='mm', group=_('Zig-zag Underlay'), type='float', default="")
def zigzag_underlay_inset(self):
# how far in from the edge of the satin the points in the zigzags
# should be
@@ -89,6 +95,17 @@ class SatinColumn(EmbroideryElement):
@property
@cache
+ def shape(self):
+ # This isn't used for satins at all, but other parts of the code
+ # may need to know the general shape of a satin column.
+
+ flattened = self.flatten(self.parse_path())
+ line_strings = [shgeo.LineString(path) for path in flattened]
+
+ return shgeo.MultiLineString(line_strings)
+
+ @property
+ @cache
def csp(self):
return self.parse_path()
@@ -377,6 +394,28 @@ class SatinColumn(EmbroideryElement):
return patch
+ def do_e_stitch(self):
+ # e stitch: do a pattern that looks like the letter "E". It looks like
+ # this:
+ #
+ # _|_|_|_|_|_|_|_|_|_|_|_|
+
+ # print >> dbg, "satin", self.zigzag_spacing, self.pull_compensation
+
+ patch = Patch(color=self.color)
+
+ sides = self.walk_paths(self.zigzag_spacing, self.pull_compensation)
+
+ # "left" and "right" here are kind of arbitrary designations meaning
+ # a point from the first and second rail repectively
+ for left, right in izip(*sides):
+ patch.add_stitch(left)
+ patch.add_stitch(right)
+ patch.add_stitch(left)
+
+ return patch
+
+
def to_patches(self, last_patch):
# Stitch a variable-width satin column, zig-zagging between two paths.
@@ -400,6 +439,9 @@ class SatinColumn(EmbroideryElement):
# zigzags sit on the contour walk underlay like rail ties on rails.
patches.append(self.do_zigzag_underlay())
- patches.append(self.do_satin())
+ if self.e_stitch:
+ patches.append(self.do_e_stitch())
+ else:
+ patches.append(self.do_satin())
return patches
diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py
index eca9e0ba..bc2ee54c 100644
--- a/lib/elements/stroke.py
+++ b/lib/elements/stroke.py
@@ -1,9 +1,10 @@
import sys
+import shapely.geometry
from .element import param, EmbroideryElement, Patch
from ..i18n import _
from ..utils import cache, Point
-from ..stitches import running_stitch
+from ..stitches import running_stitch, bean_stitch
from ..svg import parse_length_with_units
warned_about_legacy_running_stitch = False
@@ -26,18 +27,28 @@ class Stroke(EmbroideryElement):
return self.get_style("stroke-dasharray") is not None
@property
- @param('running_stitch_length_mm', _('Running stitch length'), unit='mm', type='float', default=1.5)
+ @param('running_stitch_length_mm', _('Running stitch length'), unit='mm', type='float', default=1.5, sort_index=3)
def running_stitch_length(self):
return max(self.get_float_param("running_stitch_length_mm", 1.5), 0.01)
@property
- @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), unit='mm', type='float', default=0.4)
+ @param('bean_stitch_repeats',
+ _('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. Only applies to running stitch.'),
+ type='int',
+ default=0,
+ sort_index=2)
+ def bean_stitch_repeats(self):
+ return self.get_int_param("bean_stitch_repeats", 0)
+
+ @property
+ @param('zigzag_spacing_mm', _('Zig-zag spacing (peak-to-peak)'), unit='mm', type='float', default=0.4, sort_index=3)
@cache
def zigzag_spacing(self):
return max(self.get_float_param("zigzag_spacing_mm", 0.4), 0.01)
@property
- @param('repeats', _('Repeats'), type='int', default="1")
+ @param('repeats', _('Repeats'), type='int', default="1", sort_index=1)
def repeats(self):
return self.get_int_param("repeats", 1)
@@ -51,7 +62,13 @@ class Stroke(EmbroideryElement):
return self.flatten(path)
@property
- @param('manual_stitch', _('Manual stitch placement'), tooltip=_("Stitch every node in the path. Stitch length and zig-zag spacing are ignored."), type='boolean', default=False)
+ @cache
+ def shape(self):
+ line_strings = [shapely.geometry.LineString(path) for path in self.paths]
+ return shapely.geometry.MultiLineString(line_strings)
+
+ @property
+ @param('manual_stitch', _('Manual stitch placement'), tooltip=_("Stitch every node in the path. Stitch length and zig-zag spacing are ignored."), type='boolean', default=False, sort_index=0)
def manual_stitch_mode(self):
return self.get_boolean_param('manual_stitch')
@@ -145,6 +162,10 @@ class Stroke(EmbroideryElement):
patch = Patch(color=self.color, stitches=path, stitch_as_is=True)
elif self.is_running_stitch():
patch = self.running_stitch(path, self.running_stitch_length)
+
+ if self.bean_stitch_repeats > 0:
+ patch.stitches = bean_stitch(patch.stitches, self.bean_stitch_repeats)
+
else:
patch = self.simple_satin(path, self.zigzag_spacing, self.stroke_width)