From 981eed313c841dcdbc2f9cfc1d4869b99c774846 Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Wed, 13 Jun 2018 11:28:20 +0200 Subject: [PATCH] FindNodePlacement should find a placement for the node, but not creating a new node. --- cura/Arranging/Arrange.py | 17 +++++++++-------- cura/CuraApplication.py | 2 +- cura/MultiplyObjectsJob.py | 7 ++++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cura/Arranging/Arrange.py b/cura/Arranging/Arrange.py index 4005f436be..ee5db3f1fb 100644 --- a/cura/Arranging/Arrange.py +++ b/cura/Arranging/Arrange.py @@ -1,10 +1,12 @@ # Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +from typing import List from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Logger import Logger from UM.Math.Polygon import Polygon from UM.Math.Vector import Vector +from UM.Scene.SceneNode import SceneNode from cura.Arranging.ShapeArray import ShapeArray from cura.Scene import ZOffsetDecorator @@ -85,8 +87,7 @@ class Arrange: # \param node # \param offset_shape_arr ShapeArray with offset, for placing the shape # \param hull_shape_arr ShapeArray without offset, used to find location - def findNodePlacement(self, node, offset_shape_arr, hull_shape_arr, step = 1): - new_node = node + def findNodePlacement(self, node: SceneNode, offset_shape_arr: ShapeArray, hull_shape_arr: ShapeArray, step = 1): best_spot = self.bestSpot( hull_shape_arr, start_prio = self._last_priority, step = step) x, y = best_spot.x, best_spot.y @@ -95,21 +96,21 @@ class Arrange: self._last_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 + node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) + if node.getBoundingBox(): + center_y = node.getWorldPosition().y - 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)) + node.setPosition(Vector(x, center_y, y)) found_spot = True self.place(x, y, offset_shape_arr) # place the object in arranger else: Logger.log("d", "Could not find spot!"), found_spot = False - new_node.setPosition(Vector(200, center_y, 100)) - return new_node, found_spot + node.setPosition(Vector(200, center_y, 100)) + return found_spot ## 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 e651ef5413..9db53c0836 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1675,7 +1675,7 @@ class CuraApplication(QtApplication): return # 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) + arranger.findNodePlacement(node, offset_shape_arr, hull_shape_arr, step = 10) # This node is deep copied from some other node which already has a BuildPlateDecorator, but the deepcopy # of BuildPlateDecorator produces one that's associated with build plate -1. So, here we need to check if diff --git a/cura/MultiplyObjectsJob.py b/cura/MultiplyObjectsJob.py index 57db7734e7..3cbf795952 100644 --- a/cura/MultiplyObjectsJob.py +++ b/cura/MultiplyObjectsJob.py @@ -64,10 +64,11 @@ class MultiplyObjectsJob(Job): arranger.resetLastPriority() for i in range(self._count): # We do place the nodes one by one, as we want to yield in between. + new_node = copy.deepcopy(node) + solution_found = False if not node_too_big: - new_node, solution_found = arranger.findNodePlacement(current_node, offset_shape_arr, hull_shape_arr) - else: - new_node = copy.deepcopy(node) + solution_found = arranger.findNodePlacement(new_node, offset_shape_arr, hull_shape_arr) + if node_too_big or not solution_found: found_solution_for_all = False new_location = new_node.getPosition()