diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-08-17 16:21:58 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-17 16:21:58 -0400 |
| commit | f0bd1404ad078a71eb3bca1a9fef7858e709ec0c (patch) | |
| tree | 2075fc0292038b4a2e92fc018b503805cf30fdec /lib/extensions/base.py | |
| parent | ece81d0c91c8b96f7da2c0339f6807a47d57112e (diff) | |
| parent | 0e4c3a3f1b76c1b655ec2788017335e87eff29da (diff) | |
Merge pull request #243 from inkstitch/lexelby-no-embroider-command
"ignore" command
Diffstat (limited to 'lib/extensions/base.py')
| -rw-r--r-- | lib/extensions/base.py | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/lib/extensions/base.py b/lib/extensions/base.py index d230f1b0..571e3c2d 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -7,7 +7,7 @@ from collections import MutableMapping from ..svg.tags import * from ..elements import AutoFill, Fill, Stroke, SatinColumn, Polyline, EmbroideryElement from ..utils import cache -from ..commands import is_command +from ..commands import is_command, layer_commands SVG_METADATA_TAG = inkex.addNS("metadata", "svg") @@ -110,39 +110,40 @@ class InkstitchExtension(inkex.Effect): inkex.errormsg(_("No embroiderable paths found in document.")) inkex.errormsg(_("Tip: use Path -> Object to Path to convert non-paths.")) - def descendants(self, node): + def descendants(self, node, selected=False): nodes = [] element = EmbroideryElement(node) + if element.has_command('ignore_object'): + return [] + + if node.tag == SVG_GROUP_TAG and node.get(INKSCAPE_GROUPMODE) == "layer": + if layer_commands(node, "ignore_layer"): + return [] + if element.has_style('display') and element.get_style('display') is None: return [] if node.tag == SVG_DEFS_TAG: return [] + if self.selected: + if node.get("id") in self.selected: + selected = True + else: + # if the user didn't select anything that means we process everything + selected = True + for child in node: - nodes.extend(self.descendants(child)) + nodes.extend(self.descendants(child, selected)) - if node.tag in EMBROIDERABLE_TAGS: + if selected and node.tag in EMBROIDERABLE_TAGS: nodes.append(node) return nodes def get_nodes(self): - """Get all XML nodes, or just those selected - - effect is an instance of a subclass of inkex.Effect. - """ - - if self.selected: - nodes = [] - for node in self.document.getroot().iter(): - if node.get("id") in self.selected: - nodes.extend(self.descendants(node)) - else: - nodes = self.descendants(self.document.getroot()) - - return nodes + return self.descendants(self.document.getroot()) def detect_classes(self, node): if node.tag == SVG_POLYLINE_TAG: |
