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.py11
-rw-r--r--lib/elements/stroke.py7
4 files changed, 35 insertions, 14 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..2ceb38de 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -89,6 +89,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()
diff --git a/lib/elements/stroke.py b/lib/elements/stroke.py
index eca9e0ba..e8eb4783 100644
--- a/lib/elements/stroke.py
+++ b/lib/elements/stroke.py
@@ -1,4 +1,5 @@
import sys
+import shapely.geometry
from .element import param, EmbroideryElement, Patch
from ..i18n import _
@@ -51,6 +52,12 @@ class Stroke(EmbroideryElement):
return self.flatten(path)
@property
+ @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)
def manual_stitch_mode(self):
return self.get_boolean_param('manual_stitch')