summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/extensions/auto_satin.py11
-rw-r--r--lib/stitches/auto_satin.py15
2 files changed, 20 insertions, 6 deletions
diff --git a/lib/extensions/auto_satin.py b/lib/extensions/auto_satin.py
index d5456bcb..a5e6ab3f 100644
--- a/lib/extensions/auto_satin.py
+++ b/lib/extensions/auto_satin.py
@@ -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)
diff --git a/lib/stitches/auto_satin.py b/lib/stitches/auto_satin.py
index 7d3cb05e..1ef224c8 100644
--- a/lib/stitches/auto_satin.py
+++ b/lib/stitches/auto_satin.py
@@ -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)