diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-03-22 06:44:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-22 06:44:45 +0100 |
| commit | ee14e4e28aed2abcfefe05980f7f35ace8634a1c (patch) | |
| tree | ef17268ace07a6cff91d1d5c144c005721e8ca04 | |
| parent | ca74233f2db7ec781a531a0089e93e7453afa146 (diff) | |
auto_satin: remove commands also when a single satin has been routed (and not keep originals is enabled) (#3596)
| -rw-r--r-- | lib/stitches/auto_satin.py | 46 | ||||
| -rw-r--r-- | 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 cb74bb3a..1495891e 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 0e7d11fa..0ae6bd7c 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): |
