summaryrefslogtreecommitdiff
path: root/lib/extensions/base.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2020-05-16 23:01:00 +0200
committerGitHub <noreply@github.com>2020-05-16 23:01:00 +0200
commita308db7ae152626c84ade069e307864a7e7e6213 (patch)
tree3af8a13562021796743378d16a1e7cc725ac75e4 /lib/extensions/base.py
parent4e950332419743dcbaf661fdda1f7c7970241d93 (diff)
support svg objects (#643)
Diffstat (limited to 'lib/extensions/base.py')
-rw-r--r--lib/extensions/base.py44
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 = []