Scale and toggle commands (etc) (#1611)

* scale and toggle commands
* fix tie in when first stitch is a jump stitch
* set tie modus to 3 for cutwork objects
* cutwork set stitch length
* fix bug in remove embroidery settings
pull/1620/head
Kaalleen 2022-04-10 10:21:59 +02:00 zatwierdzone przez GitHub
rodzic c575aeda96
commit 7ecfa7a2e6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
8 zmienionych plików z 100 dodań i 12 usunięć

Wyświetl plik

@ -8,6 +8,7 @@ from lib.extensions.troubleshoot import Troubleshoot
from .auto_satin import AutoSatin from .auto_satin import AutoSatin
from .break_apart import BreakApart from .break_apart import BreakApart
from .cleanup import Cleanup from .cleanup import Cleanup
from .commands_scale_symbols import CommandsScaleSymbols
from .convert_to_satin import ConvertToSatin from .convert_to_satin import ConvertToSatin
from .convert_to_stroke import ConvertToStroke from .convert_to_stroke import ConvertToStroke
from .cut_satin import CutSatin from .cut_satin import CutSatin
@ -29,6 +30,7 @@ from .lettering_generate_json import LetteringGenerateJson
from .lettering_remove_kerning import LetteringRemoveKerning from .lettering_remove_kerning import LetteringRemoveKerning
from .letters_to_font import LettersToFont from .letters_to_font import LettersToFont
from .object_commands import ObjectCommands from .object_commands import ObjectCommands
from .object_commands_toggle_visibility import ObjectCommandsToggleVisibility
from .output import Output from .output import Output
from .palette_split_text import PaletteSplitText from .palette_split_text import PaletteSplitText
from .palette_to_text import PaletteToText from .palette_to_text import PaletteToText
@ -51,8 +53,10 @@ __all__ = extensions = [StitchPlanPreview,
Flip, Flip,
SelectionToPattern, SelectionToPattern,
ObjectCommands, ObjectCommands,
ObjectCommandsToggleVisibility,
LayerCommands, LayerCommands,
GlobalCommands, GlobalCommands,
CommandsScaleSymbols,
ConvertToSatin, ConvertToSatin,
ConvertToStroke, ConvertToStroke,
CutSatin, CutSatin,

Wyświetl plik

@ -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))

Wyświetl plik

@ -5,14 +5,15 @@
from math import atan2, degrees from math import atan2, degrees
import inkex
from lxml import etree from lxml import etree
from shapely.geometry import LineString, Point from shapely.geometry import LineString, Point
import inkex
from ..elements import Stroke from ..elements import Stroke
from ..i18n import _ from ..i18n import _
from ..svg import get_correction_transform 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 from .base import InkstitchExtension
@ -141,6 +142,8 @@ class CutworkSegmentation(InkstitchExtension):
{ {
"style": color, "style": color,
"transform": get_correction_transform(element.node), "transform": get_correction_transform(element.node),
INKSTITCH_ATTRIBS["ties"]: "3",
INKSTITCH_ATTRIBS["running_stitch_length_mm"]: "1",
"d": d "d": d
}) })
self.new_elements.append([stroke_element, sector['id']]) self.new_elements.append([stroke_element, sector['id']])

Wyświetl plik

@ -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

Wyświetl plik

@ -46,22 +46,21 @@ class RemoveEmbroiderySettings(InkstitchExtension):
def remove_commands(self): def remove_commands(self):
if not self.svg.selected: if not self.svg.selected:
# we are not able to grab commands by a specific id # remove intact command groups
# so let's move through every object instead and see if it has a command xpath = ".//svg:g[starts-with(@id,'command_group')]"
xpath = ".//svg:path|.//svg:circle|.//svg:rect|.//svg:ellipse" groups = find_elements(self.svg, xpath)
elements = find_elements(self.svg, xpath) for group in groups:
group.getparent().remove(group)
else: else:
elements = self.get_selected_elements() elements = self.get_selected_elements()
if elements:
for element in elements: for element in elements:
for command in find_commands(element): for command in find_commands(element):
group = command.connector.getparent() group = command.connector.getparent()
group.getparent().remove(group) group.getparent().remove(group)
if not self.svg.selected: if not self.svg.selected:
# remove standalone commands # remove standalone commands and ungrouped object commands
standalone_commands = ".//svg:use[starts-with(@xlink:href, '#inkstitch_')]" standalone_commands = ".//svg:use[starts-with(@xlink:href, '#inkstitch_')]|.//svg:path[starts-with(@id, 'command_connector')]"
self.remove_elements(standalone_commands) self.remove_elements(standalone_commands)
# let's remove the symbols (defs), we won't need them in the document # let's remove the symbols (defs), we won't need them in the document

Wyświetl plik

@ -40,12 +40,12 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties=
color_block = stitch_plan.new_color_block(color=stitch_group.color) color_block = stitch_plan.new_color_block(color=stitch_group.color)
# always start a color with a JUMP to the first stitch position # always start a color with a JUMP to the first stitch position
color_block.add_stitch(stitch_group.stitches[0], jump=True) color_block.add_stitch(stitch_group.stitches[0], jump=True, tie_modus=stitch_group.tie_modus)
else: else:
if (len(color_block) and if (len(color_block) and
((stitch_group.stitches[0] - color_block.stitches[-1]).length() > collapse_len or ((stitch_group.stitches[0] - color_block.stitches[-1]).length() > collapse_len or
color_block.stitches[-1].force_lock_stitches)): color_block.stitches[-1].force_lock_stitches)):
color_block.add_stitch(stitch_group.stitches[0], jump=True) color_block.add_stitch(stitch_group.stitches[0], jump=True, tie_modus=stitch_group.tie_modus)
color_block.add_stitches(stitches=stitch_group.stitches, tie_modus=stitch_group.tie_modus, color_block.add_stitches(stitches=stitch_group.stitches, tie_modus=stitch_group.tie_modus,
force_lock_stitches=stitch_group.force_lock_stitches, no_ties=stitch_group.stitch_as_is) force_lock_stitches=stitch_group.force_lock_stitches, no_ties=stitch_group.stitch_as_is)

Wyświetl plik

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension translationdomain="inkstitch" xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Scale Command Symbols</name>
<id>org.inkstitch.commands_scale_symbols</id>
<param name="extension" type="string" gui-hidden="true">commands_scale_symbols</param>
<param name="size" type="float" precision="1" min="0" max="2" gui-text="Size" appearance="full">1.0</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Ink/Stitch" translatable="no">
<submenu name="Commands" />
</submenu>
</effects-menu>
</effect>
<script>
{{ command_tag | safe }}
</script>
</inkscape-extension>

Wyświetl plik

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension translationdomain="inkstitch" xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Display|Hide Object Commands</name>
<id>org.inkstitch.object_commands_toggle_visibility</id>
<param name="extension" type="string" gui-hidden="true">object_commands_toggle_visibility</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Ink/Stitch" translatable="no">
<submenu name="Commands" />
</submenu>
</effects-menu>
</effect>
<script>
{{ command_tag | safe }}
</script>
</inkscape-extension>