auto satin: add option to keep original path elements (#3332)

pull/3344/head
Kaalleen 2024-12-14 16:49:42 +01:00 zatwierdzone przez GitHub
rodzic 1abd305132
commit 1f3f15efde
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 27 dodań i 9 usunięć

Wyświetl plik

@ -20,6 +20,7 @@ class AutoSatin(CommandsExtension):
CommandsExtension.__init__(self, *args, **kwargs)
self.arg_parser.add_argument("--notebook")
self.arg_parser.add_argument("-p", "--preserve_order", dest="preserve_order", type=inkex.Boolean, default=False)
self.arg_parser.add_argument("-k", "--keep_originals", dest="keep_originals", type=inkex.Boolean, default=False)
def get_starting_point(self):
return self.get_point("autoroute_start")
@ -56,6 +57,13 @@ class AutoSatin(CommandsExtension):
return True
def _get_parent_and_index(self):
last_element = self.svg.selection[-1]
if last_element.TAG == 'g':
parent = last_element.getparent()
return parent, parent.index(last_element) + 1
return None, None
def effect(self):
if not self.check_selection():
return
@ -71,4 +79,5 @@ class AutoSatin(CommandsExtension):
if not elements:
return
auto_satin(elements, self.options.preserve_order, starting_point, ending_point, self.options.trim)
parent, index = self._get_parent_and_index()
auto_satin(elements, self.options.preserve_order, starting_point, ending_point, self.options.trim, self.options.keep_originals, parent, index)

Wyświetl plik

@ -293,7 +293,7 @@ class RunningStitch(object):
return RunningStitch(new_path, self.original_element)
def auto_satin(elements, preserve_order=False, starting_point=None, ending_point=None, trim=False):
def auto_satin(elements, preserve_order=False, starting_point=None, ending_point=None, trim=False, keep_originals=False, parent=None, index=None):
"""Find an optimal order to stitch a list of SatinColumns.
Add running stitch and jump stitches as necessary to construct a stitch
@ -340,8 +340,10 @@ def auto_satin(elements, preserve_order=False, starting_point=None, ending_point
"""
# save these for create_new_group() call below
parent = elements[0].node.getparent()
index = parent.index(elements[0].node)
if parent is None:
parent = elements[-1].node.getparent()
if index is None:
index = parent.index(elements[-1].node) + 1
# apply live path effects
# It would be nice if we could preserve them, but this could have unwanted side effects
@ -360,12 +362,15 @@ def auto_satin(elements, preserve_order=False, starting_point=None, ending_point
operations = collapse_sequential_segments(operations)
new_elements, trims, original_parents = operations_to_elements_and_trims(operations, preserve_order)
remove_original_elements(elements)
if not keep_originals:
remove_original_elements(elements)
if preserve_order:
if preserve_order and not keep_originals:
preserve_original_groups(new_elements, original_parents)
else:
group = create_new_group(parent, index, _("Auto-Route"))
if keep_originals and parent.TAG == "svg":
group.set('inkscape:groupmode', "layer")
add_elements_to_group(new_elements, group)
name_elements(new_elements, preserve_order)

Wyświetl plik

@ -5,9 +5,13 @@
<param name="notebook" type="notebook">
<page name="options" gui-text="Options">
<param name="trim" type="boolean" gui-text="Trim jump stitches">true</param>
<param name="preserve_order" type="boolean" gui-text="Preserve order of satin columns">false</param>
<param name="extension" type="string" gui-hidden="true">auto_satin</param>
<param name="trim" type="boolean" gui-text="Trim jump stitches">true</param>
<param name="preserve_order" type="boolean" gui-text="Preserve order of satin columns">false</param>
<param name="extension" type="string" gui-hidden="true">auto_satin</param>
<spacer />
<separator />
<spacer />
<param name="keep_originals" type="boolean" gui-text="Keep original paths">false</param>
</page>
<page name="info" gui-text="Help">
<label>This extension tries to create a single stitch path through all selected satin columns.</label>