From f42efcb7e03f683bedd6d17108fab488db9a2b0d Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Fri, 7 Apr 2017 16:16:38 +0200 Subject: [PATCH] Removed count from findNodePlacement CURA-3239 --- cura/Arrange.py | 43 +++++++++++++++++--------------------- cura/CuraApplication.py | 14 +++++-------- cura/MultiplyObjectsJob.py | 2 +- 3 files changed, 25 insertions(+), 34 deletions(-) diff --git a/cura/Arrange.py b/cura/Arrange.py index 9ba1f67396..225e512c2f 100755 --- a/cura/Arrange.py +++ b/cura/Arrange.py @@ -69,31 +69,26 @@ class Arrange: # \param node # \param offset_shape_arr ShapeArray with offset, used to find location # \param hull_shape_arr ShapeArray without offset, for placing the shape - # \param count Number of objects - def findNodePlacements(self, node, offset_shape_arr, hull_shape_arr, count = 1, step = 1): - nodes = [] - for i in range(count): - new_node = copy.deepcopy(node) - best_spot = self.bestSpot( - offset_shape_arr, start_prio = self._start_priority, step = step) - x, y = best_spot.x, best_spot.y - self._start_priority = best_spot.priority - # Ensure that the object is above the build platform - new_node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) - if new_node.getBoundingBox(): - center_y = new_node.getWorldPosition().y - new_node.getBoundingBox().bottom - else: - center_y = 0 + def findNodePlacement(self, node, offset_shape_arr, hull_shape_arr, step = 1): + new_node = copy.deepcopy(node) + best_spot = self.bestSpot( + offset_shape_arr, start_prio = self._start_priority, step = step) + x, y = best_spot.x, best_spot.y + self._start_priority = best_spot.priority + # Ensure that the object is above the build platform + new_node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) + if new_node.getBoundingBox(): + center_y = new_node.getWorldPosition().y - new_node.getBoundingBox().bottom + else: + center_y = 0 - if x is not None: # We could find a place - new_node.setPosition(Vector(x, center_y, y)) - self.place(x, y, hull_shape_arr) # place the object in arranger - else: - Logger.log("d", "Could not find spot!") - new_node.setPosition(Vector(200, center_y, 100 - i * 20)) - - nodes.append(new_node) - return nodes + if x is not None: # We could find a place + new_node.setPosition(Vector(x, center_y, y)) + self.place(x, y, hull_shape_arr) # place the object in arranger + else: + Logger.log("d", "Could not find spot!") + new_node.setPosition(Vector(200, center_y, 100)) + return new_node ## Fill priority, center is best. Lower value is better # This is a strategy for the arranger. diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 9996935f80..30c0d06932 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1280,18 +1280,14 @@ class CuraApplication(QtApplication): node.addDecorator(ConvexHullDecorator()) if node.callDecoration("isSliceable"): - # find node location + # Find node location offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(node, min_offset = min_offset) - # step is for skipping tests to make it a lot faster. it also makes the outcome somewhat rougher - nodes = arranger.findNodePlacements(node, offset_shape_arr, hull_shape_arr, count = 1, step = 10) - for new_node in nodes: - op = AddSceneNodeOperation(new_node, scene.getRoot()) - op.push() - else: - op = AddSceneNodeOperation(node, scene.getRoot()) - op.push() + # Step is for skipping tests to make it a lot faster. it also makes the outcome somewhat rougher + node = arranger.findNodePlacement(node, offset_shape_arr, hull_shape_arr, step = 10) + op = AddSceneNodeOperation(node, scene.getRoot()) + op.push() scene.sceneChanged.emit(node) def addNonSliceableExtension(self, extension): diff --git a/cura/MultiplyObjectsJob.py b/cura/MultiplyObjectsJob.py index 184dd8a07e..f7bb3cf0fb 100644 --- a/cura/MultiplyObjectsJob.py +++ b/cura/MultiplyObjectsJob.py @@ -52,7 +52,7 @@ class MultiplyObjectsJob(Job): for i in range(self._count): # We do place the nodes one by one, as we want to yield in between. - nodes.extend(arranger.findNodePlacements(current_node, offset_shape_arr, hull_shape_arr, count = 1)) + nodes.append(arranger.findNodePlacement(current_node, offset_shape_arr, hull_shape_arr)) Job.yieldThread() status_message.setProgress((i + 1) / self._count * 100)