diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/commands.py | 79 | ||||
| -rw-r--r-- | lib/extensions/base.py | 3 | ||||
| -rw-r--r-- | lib/extensions/commands.py | 2 |
3 files changed, 61 insertions, 23 deletions
diff --git a/lib/commands.py b/lib/commands.py index 02c13b25..74cf32b8 100644 --- a/lib/commands.py +++ b/lib/commands.py @@ -5,28 +5,33 @@ from .svg import apply_transforms from .svg.tags import SVG_USE_TAG, SVG_SYMBOL_TAG, CONNECTION_START, CONNECTION_END, XLINK_HREF -class Command(object): - def __init__(self, connector): - self.connector = connector - self.svg = self.connector.getroottree().getroot() +class CommandParseError(Exception): + pass - self.parse_command() - def get_node_by_url(self, url): - # url will be #path12345. Find the object at the other end. +def get_node_by_url(svg, url): + # url will be #path12345. Find the object at the other end. - if url is None: - raise ValueError("url is None") + if url is None: + raise CommandParseError("url is None") - if not url.startswith('#'): - raise ValueError("invalid connection url: %s" % url) + if not url.startswith('#'): + raise CommandParseError("invalid connection url: %s" % url) - id = url[1:] + id = url[1:] - try: - return self.svg.xpath(".//*[@id='%s']" % id)[0] - except (IndexError, AttributeError): - raise ValueError("could not find node by url %s" % id) + try: + return svg.xpath(".//*[@id='%s']" % id)[0] + except (IndexError, AttributeError): + raise CommandParseError("could not find node by url %s" % id) + + +class Command(object): + def __init__(self, connector): + self.connector = connector + self.svg = self.connector.getroottree().getroot() + + self.parse_command() def parse_connector_path(self): path = cubicsuperpath.parsePath(self.connector.get('d')) @@ -36,27 +41,27 @@ class Command(object): path = self.parse_connector_path() neighbors = [ - (self.get_node_by_url(self.connector.get(CONNECTION_START)), path[0][0][1]), - (self.get_node_by_url(self.connector.get(CONNECTION_END)), path[0][-1][1]) + (get_node_by_url(self.svg, self.connector.get(CONNECTION_START)), path[0][0][1]), + (get_node_by_url(self.svg, self.connector.get(CONNECTION_END)), path[0][-1][1]) ] if neighbors[0][0].tag != SVG_USE_TAG: neighbors.reverse() if neighbors[0][0].tag != SVG_USE_TAG: - raise ValueError("connector does not point to a use tag") + raise CommandParseError("connector does not point to a use tag") - self.symbol = self.get_node_by_url(neighbors[0][0].get(XLINK_HREF)) + self.symbol = self.get_node_by_url(self.svg, neighbors[0][0].get(XLINK_HREF)) if self.symbol.tag != SVG_SYMBOL_TAG: - raise ValueError("use points to non-symbol") + raise CommandParseError("use points to non-symbol") self.command = self.symbol.get('id') if self.command.startswith('inkstitch_'): self.command = self.command[10:] else: - raise ValueError("symbol is not an Ink/Stitch command") + raise CommandParseError("symbol is not an Ink/Stitch command") self.target = neighbors[1][0] self.target_point = neighbors[1][1] @@ -64,6 +69,17 @@ class Command(object): def __repr__(self): return "Command('%s', %s)" % (self.command, self.target_point) +class StandaloneCommand(object): + def __init__(self, symbol): + self.symbol = symbol + self.svg = self.connector.getroottree().getroot() + + self.parse_command() + + def parse_command(self): + pass + + def find_commands(node): """Find the symbols this node is connected to and return them as Commands""" @@ -82,5 +98,24 @@ def find_commands(node): return commands +def layer_commands(layer, command): + """Find standalone (unconnected) command symbols in this layer.""" + pass + +def global_commands(svg): + """Find all unconnected command symbols in the SVG.""" + + xpath = ".//svg:use[starts-with(@xlink:href, '#inkstitch_')]" + symbols = svg.xpath(xpath, namespace=inkex.NSS) + + commands = [] + for symbol in symbols: + try: + commands.append(StandaloneCommand(symbol)) + except CommandParseError: + pass + + return commands + def is_command(node): return CONNECTION_START in node.attrib or CONNECTION_END in node.attrib diff --git a/lib/extensions/base.py b/lib/extensions/base.py index d230f1b0..41ed8093 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -114,6 +114,9 @@ class InkstitchExtension(inkex.Effect): nodes = [] element = EmbroideryElement(node) + if element.has_command('ignore_object'): + return [] + if element.has_style('display') and element.get_style('display') is None: return [] diff --git a/lib/extensions/commands.py b/lib/extensions/commands.py index 353c9874..0924845c 100644 --- a/lib/extensions/commands.py +++ b/lib/extensions/commands.py @@ -16,7 +16,7 @@ from ..svg import get_correction_transform class Commands(InkstitchExtension): - COMMANDS = ["fill_start", "fill_end", "stop", "trim"] + COMMANDS = ["fill_start", "fill_end", "stop", "trim", "ignore"] def __init__(self, *args, **kwargs): InkstitchExtension.__init__(self, *args, **kwargs) |
