diff options
Diffstat (limited to 'lib/extensions')
| -rw-r--r-- | lib/extensions/__init__.py | 4 | ||||
| -rw-r--r-- | lib/extensions/commands_scale_symbols.py | 23 | ||||
| -rw-r--r-- | lib/extensions/cutwork_segmentation.py | 7 | ||||
| -rw-r--r-- | lib/extensions/object_commands_toggle_visibility.py | 24 | ||||
| -rw-r--r-- | lib/extensions/remove_embroidery_settings.py | 15 |
5 files changed, 63 insertions, 10 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index 8a41c22c..4c5e1a71 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -8,6 +8,7 @@ from lib.extensions.troubleshoot import Troubleshoot from .auto_satin import AutoSatin from .break_apart import BreakApart from .cleanup import Cleanup +from .commands_scale_symbols import CommandsScaleSymbols from .convert_to_satin import ConvertToSatin from .convert_to_stroke import ConvertToStroke from .cut_satin import CutSatin @@ -29,6 +30,7 @@ from .lettering_generate_json import LetteringGenerateJson from .lettering_remove_kerning import LetteringRemoveKerning from .letters_to_font import LettersToFont from .object_commands import ObjectCommands +from .object_commands_toggle_visibility import ObjectCommandsToggleVisibility from .output import Output from .palette_split_text import PaletteSplitText from .palette_to_text import PaletteToText @@ -51,8 +53,10 @@ __all__ = extensions = [StitchPlanPreview, Flip, SelectionToPattern, ObjectCommands, + ObjectCommandsToggleVisibility, LayerCommands, GlobalCommands, + CommandsScaleSymbols, ConvertToSatin, ConvertToStroke, CutSatin, diff --git a/lib/extensions/commands_scale_symbols.py b/lib/extensions/commands_scale_symbols.py new file mode 100644 index 00000000..2e025000 --- /dev/null +++ b/lib/extensions/commands_scale_symbols.py @@ -0,0 +1,23 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from inkex import NSS, Transform + +from .base import InkstitchExtension + + +class CommandsScaleSymbols(InkstitchExtension): + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) + self.arg_parser.add_argument("-s", "--size", dest="size", type=float, default=1) + + def effect(self): + size = self.options.size + + svg = self.document.getroot() + command_symbols = svg.xpath(".//svg:symbol[starts-with(@id,'inkstitch_')]", namespaces=NSS) + for symbol in command_symbols: + transform = Transform(symbol.get('transform')).add_scale(size) + symbol.set('transform', str(transform)) diff --git a/lib/extensions/cutwork_segmentation.py b/lib/extensions/cutwork_segmentation.py index d17cfd76..1b0c568e 100644 --- a/lib/extensions/cutwork_segmentation.py +++ b/lib/extensions/cutwork_segmentation.py @@ -5,14 +5,15 @@ from math import atan2, degrees -import inkex from lxml import etree from shapely.geometry import LineString, Point +import inkex + from ..elements import Stroke from ..i18n import _ from ..svg import get_correction_transform -from ..svg.tags import INKSCAPE_LABEL, SVG_PATH_TAG +from ..svg.tags import INKSCAPE_LABEL, INKSTITCH_ATTRIBS, SVG_PATH_TAG from .base import InkstitchExtension @@ -141,6 +142,8 @@ class CutworkSegmentation(InkstitchExtension): { "style": color, "transform": get_correction_transform(element.node), + INKSTITCH_ATTRIBS["ties"]: "3", + INKSTITCH_ATTRIBS["running_stitch_length_mm"]: "1", "d": d }) self.new_elements.append([stroke_element, sector['id']]) diff --git a/lib/extensions/object_commands_toggle_visibility.py b/lib/extensions/object_commands_toggle_visibility.py new file mode 100644 index 00000000..569f4305 --- /dev/null +++ b/lib/extensions/object_commands_toggle_visibility.py @@ -0,0 +1,24 @@ +# Authors: see git history +# +# Copyright (c) 2022 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +from inkex import NSS + +from .base import InkstitchExtension + + +class ObjectCommandsToggleVisibility(InkstitchExtension): + + def effect(self): + svg = self.document.getroot() + # toggle object commands (in fact it's display or hide all of them) + command_groups = svg.xpath(".//svg:g[starts-with(@id,'command_group')]", namespaces=NSS) + display = "none" + first_iteration = True + for command_group in command_groups: + if first_iteration: + first_iteration = False + if not command_group.is_visible(): + display = "inline" + command_group.style['display'] = display diff --git a/lib/extensions/remove_embroidery_settings.py b/lib/extensions/remove_embroidery_settings.py index 223e4811..31c15cd9 100644 --- a/lib/extensions/remove_embroidery_settings.py +++ b/lib/extensions/remove_embroidery_settings.py @@ -46,22 +46,21 @@ class RemoveEmbroiderySettings(InkstitchExtension): def remove_commands(self): if not self.svg.selected: - # we are not able to grab commands by a specific id - # so let's move through every object instead and see if it has a command - xpath = ".//svg:path|.//svg:circle|.//svg:rect|.//svg:ellipse" - elements = find_elements(self.svg, xpath) + # remove intact command groups + xpath = ".//svg:g[starts-with(@id,'command_group')]" + groups = find_elements(self.svg, xpath) + for group in groups: + group.getparent().remove(group) else: elements = self.get_selected_elements() - - if elements: for element in elements: for command in find_commands(element): group = command.connector.getparent() group.getparent().remove(group) if not self.svg.selected: - # remove standalone commands - standalone_commands = ".//svg:use[starts-with(@xlink:href, '#inkstitch_')]" + # remove standalone commands and ungrouped object commands + standalone_commands = ".//svg:use[starts-with(@xlink:href, '#inkstitch_')]|.//svg:path[starts-with(@id, 'command_connector')]" self.remove_elements(standalone_commands) # let's remove the symbols (defs), we won't need them in the document |
