summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/base.py65
1 files changed, 8 insertions, 57 deletions
diff --git a/lib/extensions/base.py b/lib/extensions/base.py
index 4d5aacfe..5f840417 100644
--- a/lib/extensions/base.py
+++ b/lib/extensions/base.py
@@ -6,18 +6,12 @@
import os
import inkex
-from lxml.etree import Comment
-from ..commands import is_command, layer_commands
-from ..elements import EmbroideryElement, nodes_to_elements
-from ..elements.clone import is_clone
from ..i18n import _
-from ..marker import has_marker
from ..metadata import InkStitchMetadata
from ..svg import generate_unique_id
-from ..svg.tags import (CONNECTOR_TYPE, EMBROIDERABLE_TAGS, INKSCAPE_GROUPMODE,
- NOT_EMBROIDERABLE_TAGS, SVG_CLIPPATH_TAG, SVG_DEFS_TAG,
- SVG_GROUP_TAG, SVG_MASK_TAG)
+from ..svg.tags import INKSCAPE_GROUPMODE, SVG_GROUP_TAG
+from ..elements.utils import iterate_nodes, nodes_to_elements
from ..update import update_inkstitch_document
@@ -62,58 +56,15 @@ class InkstitchExtension(inkex.EffectExtension):
inkex.errormsg(_("Tip: Run Extensions > Ink/Stitch > Troubleshoot > Troubleshoot Objects") + "\n")
- def descendants(self, node, selected=False, troubleshoot=False): # noqa: C901
- nodes = []
-
- if node.tag == Comment:
- return []
-
- element = EmbroideryElement(node)
-
- if element.has_command('ignore_object'):
- return []
-
- if node.tag == SVG_GROUP_TAG and node.get(INKSCAPE_GROUPMODE) == "layer":
- if len(list(layer_commands(node, "ignore_layer"))):
- return []
-
- if (node.tag in EMBROIDERABLE_TAGS or node.tag == SVG_GROUP_TAG) and element.get_style('display', 'inline') is None:
- return []
-
- # defs, masks and clippaths can contain embroiderable elements
- # but should never be rendered directly.
- if node.tag in [SVG_DEFS_TAG, SVG_MASK_TAG, SVG_CLIPPATH_TAG]:
- return []
-
- # command connectors with a fill color set, will glitch into the elements list
- if is_command(node) or node.get(CONNECTOR_TYPE):
- return []
-
- if self.svg.selection:
- if node in list(self.svg.selection):
- 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, selected, troubleshoot))
-
- if selected:
- if node.tag == SVG_GROUP_TAG:
- pass
- elif (node.tag in EMBROIDERABLE_TAGS or is_clone(node)) and not has_marker(node):
- nodes.append(node)
- # add images, text and elements with a marker for the troubleshoot extension
- elif troubleshoot and (node.tag in NOT_EMBROIDERABLE_TAGS or has_marker(node)):
- nodes.append(node)
-
- return nodes
-
def get_nodes(self, troubleshoot=False):
# Postorder traversal of selected nodes and their descendants.
# Returns all nodes if there is no selection.
- return self.descendants(self.document.getroot(), troubleshoot=troubleshoot)
+ if self.svg.selection:
+ selection = list(self.svg.selection)
+ else:
+ selection = None
+
+ return iterate_nodes(self.document.getroot(), selection=selection, troubleshoot=troubleshoot)
def get_elements(self, troubleshoot=False):
self.elements = nodes_to_elements(self.get_nodes(troubleshoot))