diff options
Diffstat (limited to 'lib/extensions/base.py')
| -rw-r--r-- | lib/extensions/base.py | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/lib/extensions/base.py b/lib/extensions/base.py index 440a5413..310dd873 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -1,18 +1,20 @@ -from collections import MutableMapping -from copy import deepcopy import json import os import re +from collections import MutableMapping +from copy import deepcopy -import inkex from stringcase import snakecase -from ..commands import layer_commands +import inkex + +from ..commands import is_command, layer_commands from ..elements import EmbroideryElement, nodes_to_elements +from ..elements.clone import is_clone, is_embroiderable_clone from ..i18n import _ from ..svg import generate_unique_id -from ..svg.tags import SVG_GROUP_TAG, INKSCAPE_GROUPMODE, SVG_DEFS_TAG, EMBROIDERABLE_TAGS - +from ..svg.tags import (CONNECTOR_TYPE, EMBROIDERABLE_TAGS, INKSCAPE_GROUPMODE, + NOT_EMBROIDERABLE_TAGS, SVG_DEFS_TAG, SVG_GROUP_TAG) SVG_METADATA_TAG = inkex.addNS("metadata", "svg") @@ -128,10 +130,9 @@ class InkstitchExtension(inkex.Effect): else: inkex.errormsg(_("There are no objects in the entire document that Ink/Stitch knows how to work with.") + "\n") - inkex.errormsg(_("Ink/Stitch only knows how to work with paths. It can't work with objects like text, rectangles, or circles.") + "\n") - inkex.errormsg(_("Tip: select some objects and use Path -> Object to Path to convert them to paths.") + "\n") + inkex.errormsg(_("Tip: Select some objects and use Path -> Object to Path to convert them to paths.") + "\n") - def descendants(self, node, selected=False): + def descendants(self, node, selected=False, troubleshoot=False): # noqa: C901 nodes = [] element = EmbroideryElement(node) @@ -148,6 +149,10 @@ class InkstitchExtension(inkex.Effect): if node.tag == SVG_DEFS_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.selected: if node.get("id") in self.selected: selected = True @@ -156,23 +161,26 @@ class InkstitchExtension(inkex.Effect): selected = True for child in node: - nodes.extend(self.descendants(child, selected)) + nodes.extend(self.descendants(child, selected, troubleshoot)) - if selected and node.tag in EMBROIDERABLE_TAGS: - nodes.append(node) + if selected: + if node.tag in EMBROIDERABLE_TAGS or is_embroiderable_clone(node): + nodes.append(node) + elif troubleshoot and (node.tag in NOT_EMBROIDERABLE_TAGS or is_clone(node)): + nodes.append(node) return nodes - def get_nodes(self): - return self.descendants(self.document.getroot()) + def get_nodes(self, troubleshoot=False): + return self.descendants(self.document.getroot(), troubleshoot=troubleshoot) - def get_elements(self): - self.elements = nodes_to_elements(self.get_nodes()) + def get_elements(self, troubleshoot=False): + self.elements = nodes_to_elements(self.get_nodes(troubleshoot)) if self.elements: return True - else: + if not troubleshoot: self.no_elements_error() - return False + return False def elements_to_patches(self, elements): patches = [] |
