From c37ac02bf32f3b8f725d166dcc5b2600ce95043b Mon Sep 17 00:00:00 2001 From: Kaalleen Date: Fri, 21 Mar 2025 09:00:45 +0100 Subject: [PATCH] auto_satin: remove commands also when a single satin has been routed (and not keep originals is enabled) --- lib/stitches/auto_satin.py | 46 +++++++++++++++++++-------------- lib/stitches/utils/autoroute.py | 5 ++-- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/stitches/auto_satin.py b/lib/stitches/auto_satin.py index cb74bb3aa..1495891eb 100644 --- a/lib/stitches/auto_satin.py +++ b/lib/stitches/auto_satin.py @@ -359,26 +359,7 @@ def auto_satin(elements, preserve_order=False, starting_point=None, ending_point """ if len(elements) == 1 and ending_point is None and starting_point is not None: - # they just used this method to lazily create running stitch to start the satin - # generate a line from starting point to the actual start of the satin - satin = elements[0] - parent = satin.node.getparent() - index = parent.index(satin.node) - - project = satin.center_line.project(ShapelyPoint(starting_point)) - path = substring(satin.center_line, project, 0) - - run = RunningStitch(path, satin) - run_element = run.to_element() - - transform = get_correction_transform(satin.node, False) - run_element.node.set('transform', transform) - run_element.node.apply_transform() - - stroke_width = convert_stroke_width(satin) - run_element.node.style['stroke-width'] = stroke_width - - parent.insert(index, run_element.node) + _route_single_satin(elements, starting_point, keep_originals) return # save these for create_new_group() call below @@ -423,6 +404,31 @@ def auto_satin(elements, preserve_order=False, starting_point=None, ending_point return new_elements +def _route_single_satin(elements, starting_point, keep_originals): + # they just used this method to lazily create running stitch to start the satin + # generate a line from starting point to the actual start of the satin + satin = elements[0] + parent = satin.node.getparent() + index = parent.index(satin.node) + + project = satin.center_line.project(ShapelyPoint(starting_point)) + path = substring(satin.center_line, project, 0) + + run = RunningStitch(path, satin) + run_element = run.to_element() + + transform = get_correction_transform(satin.node, False) + run_element.node.set('transform', transform) + run_element.node.apply_transform() + + stroke_width = convert_stroke_width(satin) + run_element.node.style['stroke-width'] = stroke_width + + parent.insert(index, run_element.node) + if not keep_originals: + remove_original_elements([satin], True) + + def convert_stroke_width(element): document_unit = element.node.getroottree().getroot().document_unit stroke_width = convert_unit(element.stroke_width, document_unit) diff --git a/lib/stitches/utils/autoroute.py b/lib/stitches/utils/autoroute.py index 0e7d11fa1..0ae6bd7c3 100644 --- a/lib/stitches/utils/autoroute.py +++ b/lib/stitches/utils/autoroute.py @@ -241,7 +241,7 @@ def get_nodes_on_element(graph, element): return nodes -def remove_original_elements(elements): +def remove_original_elements(elements, commands_only=False): for element in elements: for command in element.commands: command_group = command.use.getparent() @@ -250,7 +250,8 @@ def remove_original_elements(elements): else: remove_from_parent(command.connector) remove_from_parent(command.use) - remove_from_parent(element.node) + if not commands_only: + remove_from_parent(element.node) def remove_from_parent(node):