summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2023-05-01 12:03:44 +0200
committerGitHub <noreply@github.com>2023-05-01 12:03:44 +0200
commitac688331eb3c961281812cd824e3734796ac321d (patch)
tree1a018eed3baa590d99786990421dde29dd8d360a
parent2542f124eb4e741687ebc7e0d69b27e2291310c6 (diff)
Add svg updater extension (#2252)
* add updater extension * update legacy underlay_fill_angle: comma to space
-rw-r--r--lib/extensions/__init__.py4
-rw-r--r--lib/extensions/update_svg.py39
-rw-r--r--lib/update.py33
-rw-r--r--templates/update_svg.xml24
4 files changed, 87 insertions, 13 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index cc47f151..25d3214c 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -33,7 +33,6 @@ from .lettering_force_lock_stitches import LetteringForceLockStitches
from .lettering_generate_json import LetteringGenerateJson
from .lettering_remove_kerning import LetteringRemoveKerning
from .letters_to_font import LettersToFont
-from .zigzag_line_to_satin import ZigzagLineToSatin
from .object_commands import ObjectCommands
from .object_commands_toggle_visibility import ObjectCommandsToggleVisibility
from .output import Output
@@ -51,6 +50,8 @@ from .simulator import Simulator
from .stitch_plan_preview import StitchPlanPreview
from .stitch_plan_preview_undo import StitchPlanPreviewUndo
from .stroke_to_lpe_satin import StrokeToLpeSatin
+from .update_svg import UpdateSvg
+from .zigzag_line_to_satin import ZigzagLineToSatin
from .zip import Zip
from.lettering_along_path import LetteringAlongPath
@@ -91,6 +92,7 @@ __all__ = extensions = [StitchPlanPreview,
Troubleshoot,
RemoveEmbroiderySettings,
Cleanup,
+ UpdateSvg,
BreakApart,
GradientBlocks,
ApplyThreadlist,
diff --git a/lib/extensions/update_svg.py b/lib/extensions/update_svg.py
new file mode 100644
index 00000000..51960cb2
--- /dev/null
+++ b/lib/extensions/update_svg.py
@@ -0,0 +1,39 @@
+# 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 errormsg
+
+from ..i18n import _
+from ..update import update_inkstitch_document
+from .base import InkstitchExtension
+
+
+class UpdateSvg(InkstitchExtension):
+
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ # TODO: When there are more legacy versions than only one, this can be transformed in a user input
+ # inkstitch_svg_version history: 1 -> v2.3.0
+ self.update_from = 0
+
+ def effect(self):
+ if not self.svg.selection:
+ errormsg(_('Please select at least one element to update. '
+ 'This extension is designed to help you update copy and pasted elements from old designs.'))
+
+ # set the file version to the update_from value, so that the updater knows where to start from
+ # the updater will then reset it to the current version after the update has finished
+ metadata = self.get_inkstitch_metadata()
+ metadata['inkstitch_svg_version'] = self.update_from
+
+ update_inkstitch_document(self.document, self.get_selection())
+
+ def get_selection(self):
+ selection = []
+ for element in self.svg.selection:
+ selection.append(element)
+ for descendant in element.iterdescendants():
+ selection.append(descendant)
+ return selection
diff --git a/lib/update.py b/lib/update.py
index f8e6740c..6287a77c 100644
--- a/lib/update.py
+++ b/lib/update.py
@@ -4,12 +4,12 @@ from .elements import EmbroideryElement
from .i18n import _
from .metadata import InkStitchMetadata
from .svg import PIXELS_PER_MM
-from .svg.tags import INKSTITCH_ATTRIBS
+from .svg.tags import EMBROIDERABLE_TAGS, INKSTITCH_ATTRIBS
INKSTITCH_SVG_VERSION = 1
-def update_inkstitch_document(svg):
+def update_inkstitch_document(svg, selection=None):
document = svg.getroot()
# get the inkstitch svg version from the document
search_string = "//*[local-name()='inkstitch_svg_version']//text()"
@@ -41,10 +41,15 @@ def update_inkstitch_document(svg):
return
# update elements
- for element in document.iterdescendants():
- # We are just checking for params and update them.
- # No need to check for specific stitch types at this point
- update_legacy_params(EmbroideryElement(element), file_version, INKSTITCH_SVG_VERSION)
+ if selection:
+ # this comes from the updater extension where we only update selected elements
+ for element in selection:
+ update_legacy_params(EmbroideryElement(element), file_version, INKSTITCH_SVG_VERSION)
+ else:
+ # this is the automatic update when a legacy inkstitch svg version was recognized
+ for element in document.iterdescendants():
+ if element.tag in EMBROIDERABLE_TAGS:
+ update_legacy_params(EmbroideryElement(element), file_version, INKSTITCH_SVG_VERSION)
_update_inkstitch_svg_version(svg)
@@ -90,17 +95,26 @@ def _update_to_one(element): # noqa: C901
elif legacy_fill_method == 3:
element.set_param('fill_method', 'legacy_fill')
+ underlay_angle = element.get_param('fill_underlay_angle', None)
+ if underlay_angle and ',' in underlay_angle:
+ element.set_param('fill_underlay_angle', underlay_angle.replace(',', ' '))
+
# legacy satin method
if element.get_boolean_param('e_stitch', False) is True:
element.remove_param('e_stitch')
element.set_param('satin_method', 'e_stitch')
+ if element.get_boolean_param('satin_column', False):
+ # reverse_rails defaults to Automatic, but we should never reverse an
+ # old satin automatically, only new ones
+ element.set_param('reverse_rails', 'none')
+
# default setting for fill_underlay has changed
if legacy_attribs and not element.get_param('fill_underlay', ""):
element.set_param('fill_underlay', False)
# convert legacy stroke_method
- if element.get_style("stroke"):
+ if element.get_style("stroke") and not element.node.get('inkscape:connection-start', None):
# manual stitch
legacy_manual_stitch = element.get_boolean_param('manual_stitch', False)
if legacy_manual_stitch is True:
@@ -124,11 +138,6 @@ def _update_to_one(element): # noqa: C901
element.set_param('grid_size_mm', size)
element.remove_param('grid_size')
- if element.get_boolean_param('satin_column', False):
- # reverse_rails defaults to Automatic, but we should never reverse an
- # old satin automatically, only new ones
- element.set_param('reverse_rails', 'none')
-
def _replace_legacy_embroider_param(element, param):
# remove "embroider_" prefix
diff --git a/templates/update_svg.xml b/templates/update_svg.xml
new file mode 100644
index 00000000..4de56e03
--- /dev/null
+++ b/templates/update_svg.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension translationdomain="inkstitch" xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+ <name>Update inkstitch svg</name>
+ <id>org.inkstitch.update_svg</id>
+ <param name="extension" type="string" gui-hidden="true">update_svg</param>
+ <effect needs-live-preview="false">
+ <object-type>all</object-type>
+ <effects-menu>
+ <submenu name="Ink/Stitch" translatable="no">
+ <submenu name="Troubleshoot" />
+ </submenu>
+ </effects-menu>
+ </effect>
+ <label appearance="header">Usually there is no need to run this extension: Ink/Stitch automatically updates old designs once.</label>
+ <spacer />
+ <label>However, when you copy and paste parts from old files into a new design, you may see for example, that a former contour fill renders as a standard fill, etc.</label>
+ <spacer />
+ <label>Tipp: You can prevent inserting legacy designs into new files by running any Ink/Stitch extension before you copy the design parts (for example open and re-apply parameters on a single element in the document).</label>
+ <spacer />
+ <label appearance="header">This extension only updates selected elements.</label>
+ <script>
+ {{ command_tag | safe }}
+ </script>
+</inkscape-extension>