diff --git a/cura/Arrange.py b/cura/Arrange.py index 1508a6618d..5ea1e1c12d 100755 --- a/cura/Arrange.py +++ b/cura/Arrange.py @@ -58,8 +58,10 @@ class Arrange: for i in range(count): new_node = copy.deepcopy(node) - x, y = self.bestSpot( + best_spot = self.bestSpot( offset_shape_arr, start_prio = start_prio, step = step) + x, y = best_spot.x, best_spot.y + start_prio = best_spot.priority transformation = new_node._transformation if x is not None: # We could find a place transformation._data[0][3] = x diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index e788b175e4..10cbb52629 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1031,20 +1031,24 @@ class CuraApplication(QtApplication): min_offset = 8 arranger = Arrange.create(fixed_nodes = fixed_nodes) + + # Collect nodes to be placed nodes_arr = [] # fill with (size, node, offset_shape_arr, hull_shape_arr) for node in nodes: offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(node, min_offset = min_offset) nodes_arr.append((offset_shape_arr.arr.shape[0] * offset_shape_arr.arr.shape[1], node, offset_shape_arr, hull_shape_arr)) + # Sort nodes biggest area first nodes_arr.sort(key = lambda item: item[0]) nodes_arr.reverse() + # Place nodes one at a time start_prio = 0 for size, node, offset_shape_arr, hull_shape_arr in nodes_arr: - # we assume that when a location does not fit, it will also not fit for the next - # object (while what can be untrue). That saves a lot of time. - best_spot = arranger.bestSpot( - offset_shape_arr, start_prio = start_prio) + # For performance reasons, we assume that when a location does not fit, + # it will also not fit for the next object (while what can be untrue). + # We also skip possibilities by slicing through the possibilities (step = 10) + best_spot = arranger.bestSpot(offset_shape_arr, start_prio = start_prio, step = 10) x, y = best_spot.x, best_spot.y start_prio = best_spot.priority if x is not None: # We could find a place diff --git a/cura/ShapeArray.py b/cura/ShapeArray.py index e6ddff7a94..6d310b7be8 100755 --- a/cura/ShapeArray.py +++ b/cura/ShapeArray.py @@ -31,10 +31,9 @@ class ShapeArray: arr = cls.arrayFromPolygon(shape, flip_vertices) return cls(arr, offset_x, offset_y) - ## Return an offset and hull ShapeArray from a scenenode. + ## Return an offset and hull ShapeArray from a scene node. @classmethod def fromNode(cls, node, min_offset, scale = 0.5): - # hacky way to undo transformation transform = node._transformation transform_x = transform._data[0][3] transform_y = transform._data[2][3]