Add jump to stroke extension (#1947)

pull/1955/head
Kaalleen 2022-12-11 09:44:42 +01:00 zatwierdzone przez GitHub
rodzic 815b3c6035
commit f74f427cae
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 76 dodań i 1 usunięć

Wyświetl plik

@ -25,6 +25,7 @@ from .gradient_blocks import GradientBlocks
from .input import Input
from .install import Install
from .install_custom_palette import InstallCustomPalette
from .jump_to_stroke import JumpToStroke
from .layer_commands import LayerCommands
from .lettering import Lettering
from .lettering_custom_font_dir import LetteringCustomFontDir
@ -69,6 +70,7 @@ __all__ = extensions = [StitchPlanPreview,
CommandsScaleSymbols,
ConvertToSatin,
ConvertToStroke,
JumpToStroke,
CutSatin,
AutoSatin,
AutoRun,

Wyświetl plik

@ -0,0 +1,56 @@
# 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 DirectedLineSegment, PathElement, errormsg
from ..i18n import _
from ..svg import PIXELS_PER_MM, get_correction_transform
from .base import InkstitchExtension
class JumpToStroke(InkstitchExtension):
"""Adds a running stitch as a connection between two (or more) selected elements.
The elements must have the same color and a minimum distance (collapse_len)."""
def effect(self):
if not self.svg.selection or not self.get_elements() or len(self.elements) < 2:
errormsg(_("Please select at least two elements to convert the jump stitch to a running stitch."))
return
last_stitch_group = None
last_color = None
for element in self.elements:
stitch_group = element.to_stitch_groups(last_stitch_group)
end = stitch_group[-1].stitches[-1]
if last_stitch_group is not None and element.color == last_color:
start = last_stitch_group.stitches[-1]
self.generate_stroke(element, start, end)
last_stitch_group = stitch_group[-1]
last_color = element.color
def generate_stroke(self, element, start, end):
node = element.node
parent = node.getparent()
index = parent.index(node)
# do not add a running stitch if the distance is smaller than the collapse setting
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm'] or 3.0
collapse_len *= PIXELS_PER_MM
line = DirectedLineSegment((start.x, start.y), (end.x, end.y))
if collapse_len > line.length:
return
path = f'M {start.x}, {start.y} L {end.x}, {end.y}'
color = element.color
style = f'stroke:{color};stroke-width:1px;stroke-dasharray:3, 1;fill:none;'
line = PathElement(d=path, style=style, transform=get_correction_transform(node))
parent.insert(index, line)
if __name__ == '__main__':
JumpToStroke().run()

Wyświetl plik

@ -10,7 +10,7 @@
<object-type>all</object-type>
<effects-menu>
<submenu name="Ink/Stitch" translatable="no">
<submenu name="Tools: Satin" />
<submenu name="Tools: Stroke" />
</submenu>
</effects-menu>
</effect>

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>Jump Stitch to Stroke</name>
<id>org.inkstitch.jump_to_stroke</id>
<param name="extension" type="string" gui-hidden="true">jump_to_stroke</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Ink/Stitch" translatable="no">
<submenu name="Tools: Stroke" />
</submenu>
</effects-menu>
</effect>
<script>
{{ command_tag | safe }}
</script>
</inkscape-extension>