summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2022-04-10 10:21:59 +0200
committerGitHub <noreply@github.com>2022-04-10 10:21:59 +0200
commit7ecfa7a2e6b2c971f35d8264c35b3efdae212489 (patch)
tree195e932b557e9d34ace426cac0d8a599479da654 /lib
parentc575aeda96d389de29389c9e6e46395e1b938244 (diff)
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
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/__init__.py4
-rw-r--r--lib/extensions/commands_scale_symbols.py23
-rw-r--r--lib/extensions/cutwork_segmentation.py7
-rw-r--r--lib/extensions/object_commands_toggle_visibility.py24
-rw-r--r--lib/extensions/remove_embroidery_settings.py15
-rw-r--r--lib/stitch_plan/stitch_plan.py4
6 files changed, 65 insertions, 12 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
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index a501391d..74caa54a 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -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)
# 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:
if (len(color_block) and
((stitch_group.stitches[0] - color_block.stitches[-1]).length() > collapse_len or
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,
force_lock_stitches=stitch_group.force_lock_stitches, no_ties=stitch_group.stitch_as_is)