auto_satin: remove commands also when a single satin has been routed (and not keep originals is enabled)

pull/3596/head
Kaalleen 2025-03-21 09:00:45 +01:00
rodzic de7d86e526
commit c37ac02bf3
2 zmienionych plików z 29 dodań i 22 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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):