From 61983b615b202bb95c21d7a5021af3373615e839 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 30 Jun 2018 14:16:56 -0400 Subject: add has_command() --- lib/elements/element.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/elements') diff --git a/lib/elements/element.py b/lib/elements/element.py index 3c31f1b0..f0b7ea6f 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -214,6 +214,10 @@ class EmbroideryElement(object): def get_commands(self, command): 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) -- cgit v1.2.3 From 3893d13b52b2755ea134ec4d3a215ee807dbbc2e Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 30 Jun 2018 14:18:45 -0400 Subject: add support for trim/stop commands --- lib/elements/element.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/elements') diff --git a/lib/elements/element.py b/lib/elements/element.py index f0b7ea6f..1c67d123 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -268,8 +268,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 -- cgit v1.2.3 From aa86dc56ad5cb9166ab1c9cda036d9521855ad29 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 30 Jun 2018 14:19:28 -0400 Subject: remove 'TRIM after' and 'STOP after' from Params dialog --- lib/elements/element.py | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'lib/elements') diff --git a/lib/elements/element.py b/lib/elements/element.py index 1c67d123..62e9745d 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -242,22 +242,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) -- cgit v1.2.3 From 62ef2850a2f57d64d0e65fbfc055b85e3c940031 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Wed, 4 Jul 2018 21:17:20 -0400 Subject: generalize Element.shape and implement in all element types --- lib/elements/element.py | 4 ++++ lib/elements/polyline.py | 7 +++++++ lib/elements/satin_column.py | 11 +++++++++++ lib/elements/stroke.py | 7 +++++++ 4 files changed, 29 insertions(+) (limited to 'lib/elements') diff --git a/lib/elements/element.py b/lib/elements/element.py index 62e9745d..ebca90a4 100644 --- a/lib/elements/element.py +++ b/lib/elements/element.py @@ -205,6 +205,10 @@ class EmbroideryElement(object): def parse_path(self): 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): 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 @@ -27,6 +29,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 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 @@ -87,6 +87,17 @@ class SatinColumn(EmbroideryElement): # the edges of the satin column. return self.get_float_param("zigzag_underlay_inset_mm") or self.contour_underlay_inset / 2.0 + @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): 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 _ @@ -50,6 +51,12 @@ class Stroke(EmbroideryElement): else: 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): -- cgit v1.2.3