kopia lustrzana https://github.com/inkstitch/inkstitch
Add Transfer Params Extension (#1096)
rodzic
f787121080
commit
354759b6ca
|
@ -10,6 +10,7 @@ from .break_apart import BreakApart
|
|||
from .cleanup import Cleanup
|
||||
from .convert_to_satin import ConvertToSatin
|
||||
from .cut_satin import CutSatin
|
||||
from .embroider_settings import EmbroiderSettings
|
||||
from .flip import Flip
|
||||
from .global_commands import GlobalCommands
|
||||
from .import_threadlist import ImportThreadlist
|
||||
|
@ -17,6 +18,9 @@ from .input import Input
|
|||
from .install import Install
|
||||
from .layer_commands import LayerCommands
|
||||
from .lettering import Lettering
|
||||
from .lettering_custom_font_dir import LetteringCustomFontDir
|
||||
from .lettering_generate_json import LetteringGenerateJson
|
||||
from .lettering_remove_kerning import LetteringRemoveKerning
|
||||
from .object_commands import ObjectCommands
|
||||
from .output import Output
|
||||
from .params import Params
|
||||
|
@ -25,11 +29,8 @@ from .remove_embroidery_settings import RemoveEmbroiderySettings
|
|||
from .reorder import Reorder
|
||||
from .simulator import Simulator
|
||||
from .stitch_plan_preview import StitchPlanPreview
|
||||
from .transfer_params import TransferParams
|
||||
from .zip import Zip
|
||||
from .lettering_generate_json import LetteringGenerateJson
|
||||
from .lettering_remove_kerning import LetteringRemoveKerning
|
||||
from .lettering_custom_font_dir import LetteringCustomFontDir
|
||||
from .embroider_settings import EmbroiderSettings
|
||||
|
||||
__all__ = extensions = [StitchPlanPreview,
|
||||
Install,
|
||||
|
@ -56,4 +57,5 @@ __all__ = extensions = [StitchPlanPreview,
|
|||
ImportThreadlist,
|
||||
Simulator,
|
||||
Reorder,
|
||||
TransferParams,
|
||||
EmbroiderSettings]
|
||||
|
|
|
@ -188,6 +188,14 @@ class InkstitchExtension(inkex.Effect):
|
|||
self.no_elements_error()
|
||||
return False
|
||||
|
||||
def get_selected_in_order(self):
|
||||
selected = []
|
||||
for i in self.options.ids:
|
||||
path = '//*[@id="%s"]' % i
|
||||
for node in self.document.xpath(path, namespaces=inkex.NSS):
|
||||
selected.append(node)
|
||||
return selected
|
||||
|
||||
def elements_to_patches(self, elements):
|
||||
patches = []
|
||||
for element in elements:
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
# Copyright (c) 2010 Authors
|
||||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||
|
||||
import inkex
|
||||
|
||||
from .base import InkstitchExtension
|
||||
|
||||
|
||||
|
@ -12,16 +10,6 @@ class Reorder(InkstitchExtension):
|
|||
# Remove selected objects from the document and readd them in the order they
|
||||
# were selected.
|
||||
|
||||
def get_selected_in_order(self):
|
||||
selected = []
|
||||
|
||||
for i in self.options.ids:
|
||||
path = '//*[@id="%s"]' % i
|
||||
for node in self.document.xpath(path, namespaces=inkex.NSS):
|
||||
selected.append(node)
|
||||
|
||||
return selected
|
||||
|
||||
def effect(self):
|
||||
objects = self.get_selected_in_order()
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
# Authors: see git history
|
||||
#
|
||||
# Copyright (c) 2021 Authors
|
||||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||
|
||||
import inkex
|
||||
|
||||
from ..i18n import _
|
||||
from ..svg.tags import EMBROIDERABLE_TAGS, SVG_GROUP_TAG
|
||||
from .base import InkstitchExtension
|
||||
|
||||
|
||||
class TransferParams(InkstitchExtension):
|
||||
# Transfer inkstitch namespaced attributes from the first selected element to the rest of selection
|
||||
|
||||
def effect(self):
|
||||
objects = self.get_selected_in_order()
|
||||
if len(objects) < 2:
|
||||
inkex.errormsg(_("This function transfers Ink/Stitch parameters from the first selected element to the rest of the selection. "
|
||||
"Please select at least two elements."))
|
||||
return
|
||||
|
||||
copy_from = objects[0]
|
||||
copy_from_attribs = self.get_inkstitch_attributes(copy_from)
|
||||
|
||||
copy_to_selection = objects[1:]
|
||||
self.copy_to = []
|
||||
|
||||
# extract copy_to group elements
|
||||
for element in copy_to_selection:
|
||||
if element.tag == SVG_GROUP_TAG:
|
||||
for descendant in element.iterdescendants(EMBROIDERABLE_TAGS):
|
||||
self.copy_to.append(descendant)
|
||||
elif element.tag in EMBROIDERABLE_TAGS:
|
||||
self.copy_to.append(element)
|
||||
|
||||
# remove inkstitch params from copy_to elements
|
||||
for element in self.copy_to:
|
||||
copy_to_attribs = self.get_inkstitch_attributes(element)
|
||||
for attrib in copy_to_attribs:
|
||||
element.pop(attrib)
|
||||
|
||||
# paste inkstitch params from copy_from element to copy_to elements
|
||||
for attrib in copy_from_attribs:
|
||||
for element in self.copy_to:
|
||||
element.attrib[attrib] = copy_from_attribs[attrib]
|
||||
|
||||
def get_inkstitch_attributes(self, node):
|
||||
return {k: v for k, v in node.attrib.iteritems() if inkex.NSS['inkstitch'] in k}
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>{% trans %}Transfer Params{% endtrans %}</name>
|
||||
<id>org.inkstitch.transfer_params.{{ locale }}</id>
|
||||
<param name="extension" type="string" gui-hidden="true">transfer_params</param>
|
||||
<effect>
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="Ink/Stitch" />
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
{{ command_tag | safe }}
|
||||
</script>
|
||||
</inkscape-extension>
|
Ładowanie…
Reference in New Issue