Do not move objects if auto-arrange fails

CURA-12169
When doing an explicit auto-arrange that can not find a complete solution, it is better not to move the objects because they will probably end up in a weird position
This commit is contained in:
Erwan MATHIEU 2025-03-06 10:58:54 +01:00
parent 36b5a40563
commit e19f5ee330
3 changed files with 9 additions and 4 deletions

View File

@ -40,7 +40,7 @@ class ArrangeObjectsJob(Job):
found_solution_for_all = False found_solution_for_all = False
try: try:
found_solution_for_all = arranger.arrange() found_solution_for_all = arranger.arrange(only_if_full_success = True)
except: # If the thread crashes, the message should still close except: # If the thread crashes, the message should still close
Logger.logException("e", Logger.logException("e",
"Unable to arrange the objects on the buildplate. The arrange algorithm has crashed.") "Unable to arrange the objects on the buildplate. The arrange algorithm has crashed.")

View File

@ -16,12 +16,16 @@ class Arranger:
""" """
raise NotImplementedError raise NotImplementedError
def arrange(self, add_new_nodes_in_scene: bool = False) -> bool: def arrange(self, add_new_nodes_in_scene: bool = False, only_if_full_success: bool = False) -> bool:
""" """
Find placement for a set of scene nodes, and move them by using a single grouped operation. Find placement for a set of scene nodes, and move them by using a single grouped operation.
:param add_new_nodes_in_scene: Whether to create new scene nodes before applying the transformations and rotations :param add_new_nodes_in_scene: Whether to create new scene nodes before applying the transformations and rotations
:return: found_solution_for_all: Whether the algorithm found a place on the buildplate for all the objects :return: found_solution_for_all: Whether the algorithm found a place on the buildplate for all the objects
""" """
grouped_operation, not_fit_count = self.createGroupOperationForArrange(add_new_nodes_in_scene) grouped_operation, not_fit_count = self.createGroupOperationForArrange(add_new_nodes_in_scene)
grouped_operation.push() full_success = not_fit_count == 0
return not_fit_count == 0
if full_success or not only_if_full_success:
grouped_operation.push()
return full_success

View File

@ -84,6 +84,7 @@ class MultiplyObjectsJob(Job):
arranger = Nest2DArrange(nodes, Application.getInstance().getBuildVolume(), fixed_nodes, factor=1000) arranger = Nest2DArrange(nodes, Application.getInstance().getBuildVolume(), fixed_nodes, factor=1000)
group_operation, not_fit_count = arranger.createGroupOperationForArrange(add_new_nodes_in_scene=True) group_operation, not_fit_count = arranger.createGroupOperationForArrange(add_new_nodes_in_scene=True)
found_solution_for_all = not_fit_count == 0
if nodes_to_add_without_arrange: if nodes_to_add_without_arrange:
for nested_node in nodes_to_add_without_arrange: for nested_node in nodes_to_add_without_arrange: