diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2022-05-18 16:02:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-18 16:02:07 +0200 |
| commit | bc4f3b4699555f48c571be9a22a6768635c38cd0 (patch) | |
| tree | 6a0bcd47bd19742857d0a7ed6bc034b22a4621a6 /lib/extensions | |
| parent | bb0f3b8168ea2c889935b96b532188b79d7f952e (diff) | |
Auto route for running stitch (#1638)
* add auto route for running stitch
* introduce free motion commands
Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/__init__.py | 2 | ||||
| -rw-r--r-- | lib/extensions/auto_run.py | 65 | ||||
| -rw-r--r-- | lib/extensions/base.py | 8 | ||||
| -rw-r--r-- | lib/extensions/reorder.py | 2 |
4 files changed, 72 insertions, 5 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index b6e0d1d1..d0cfa911 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -6,6 +6,7 @@ from lib.extensions.troubleshoot import Troubleshoot from .apply_threadlist import ApplyThreadlist +from .auto_run import AutoRun from .auto_satin import AutoSatin from .break_apart import BreakApart from .cleanup import Cleanup @@ -61,6 +62,7 @@ __all__ = extensions = [StitchPlanPreview, ConvertToStroke, CutSatin, AutoSatin, + AutoRun, Lettering, LetteringGenerateJson, LetteringRemoveKerning, diff --git a/lib/extensions/auto_run.py b/lib/extensions/auto_run.py new file mode 100644 index 00000000..02997fd0 --- /dev/null +++ b/lib/extensions/auto_run.py @@ -0,0 +1,65 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import inkex + +from ..elements import Stroke +from ..i18n import _ +from ..stitches.auto_run import autorun +from .commands import CommandsExtension + + +class AutoRun(CommandsExtension): + COMMANDS = ["trim"] + + def __init__(self, *args, **kwargs): + CommandsExtension.__init__(self, *args, **kwargs) + + self.arg_parser.add_argument("-b", "--break_up", dest="break_up", type=inkex.Boolean, default=True) + self.arg_parser.add_argument("-p", "--preserve_order", dest="preserve_order", type=inkex.Boolean, default=False) + self.arg_parser.add_argument("-o", "--options", dest="options", type=str, default="") + self.arg_parser.add_argument("-i", "--info", dest="help", type=str, default="") + + def effect(self): + elements = self.check_selection() + if not elements: + return + + starting_point = self.get_starting_point() + ending_point = self.get_ending_point() + + break_up = self.options.break_up + + autorun(elements, self.options.preserve_order, break_up, starting_point, ending_point, self.options.trim) + + def get_starting_point(self): + return self.get_command_point("run_start") + + def get_ending_point(self): + return self.get_command_point("run_end") + + def get_command_point(self, command_type): + command = None + for stroke in self.elements: + command = stroke.get_command(command_type) + # return the first occurence directly + if command: + return command.target_point + + def check_selection(self): + if not self.get_elements(): + return + + if not self.svg.selection: + # L10N auto-route running stitch columns extension + inkex.errormsg(_("Please select one or more stroke elements.")) + return False + + elements = [element for element in self.elements if isinstance(element, Stroke)] + if len(elements) == 0: + inkex.errormsg(_("Please select at least one stroke element.")) + return False + + return elements diff --git a/lib/extensions/base.py b/lib/extensions/base.py index 75a07c5a..a5f1209a 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -17,7 +17,7 @@ from ..commands import is_command, layer_commands from ..elements import EmbroideryElement, nodes_to_elements from ..elements.clone import is_clone from ..i18n import _ -from ..patterns import is_pattern +from ..marker import has_marker 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, @@ -169,10 +169,10 @@ class InkstitchExtension(inkex.Effect): if selected: if node.tag == SVG_GROUP_TAG: pass - elif (node.tag in EMBROIDERABLE_TAGS or is_clone(node)) and not is_pattern(node): + elif (node.tag in EMBROIDERABLE_TAGS or is_clone(node)) and not has_marker(node): nodes.append(node) - # add images, text and patterns for the troubleshoot extension - elif troubleshoot and (node.tag in NOT_EMBROIDERABLE_TAGS or is_pattern(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 diff --git a/lib/extensions/reorder.py b/lib/extensions/reorder.py index 83ecfe26..956c0615 100644 --- a/lib/extensions/reorder.py +++ b/lib/extensions/reorder.py @@ -17,7 +17,7 @@ class Reorder(InkstitchExtension): objects = self.svg.selection if not objects: - errormsg(_("Please select at least to elements to reorder.")) + errormsg(_("Please select at least two elements to reorder.")) return for obj in objects: |
