FindNodePlacement should find a placement for the node, but not creating

a new node.
This commit is contained in:
Diego Prado Gesto 2018-06-13 11:28:20 +02:00
parent b0b4f78cf2
commit 981eed313c
3 changed files with 14 additions and 12 deletions

View file

@ -1,10 +1,12 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from typing import List
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
from UM.Logger import Logger from UM.Logger import Logger
from UM.Math.Polygon import Polygon from UM.Math.Polygon import Polygon
from UM.Math.Vector import Vector from UM.Math.Vector import Vector
from UM.Scene.SceneNode import SceneNode
from cura.Arranging.ShapeArray import ShapeArray from cura.Arranging.ShapeArray import ShapeArray
from cura.Scene import ZOffsetDecorator from cura.Scene import ZOffsetDecorator
@ -85,8 +87,7 @@ class Arrange:
# \param node # \param node
# \param offset_shape_arr ShapeArray with offset, for placing the shape # \param offset_shape_arr ShapeArray with offset, for placing the shape
# \param hull_shape_arr ShapeArray without offset, used to find location # \param hull_shape_arr ShapeArray without offset, used to find location
def findNodePlacement(self, node, offset_shape_arr, hull_shape_arr, step = 1): def findNodePlacement(self, node: SceneNode, offset_shape_arr: ShapeArray, hull_shape_arr: ShapeArray, step = 1):
new_node = node
best_spot = self.bestSpot( best_spot = self.bestSpot(
hull_shape_arr, start_prio = self._last_priority, step = step) hull_shape_arr, start_prio = self._last_priority, step = step)
x, y = best_spot.x, best_spot.y x, y = best_spot.x, best_spot.y
@ -95,21 +96,21 @@ class Arrange:
self._last_priority = best_spot.priority self._last_priority = best_spot.priority
# Ensure that the object is above the build platform # Ensure that the object is above the build platform
new_node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator) node.removeDecorator(ZOffsetDecorator.ZOffsetDecorator)
if new_node.getBoundingBox(): if node.getBoundingBox():
center_y = new_node.getWorldPosition().y - new_node.getBoundingBox().bottom center_y = node.getWorldPosition().y - node.getBoundingBox().bottom
else: else:
center_y = 0 center_y = 0
if x is not None: # We could find a place 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 found_spot = True
self.place(x, y, offset_shape_arr) # place the object in arranger self.place(x, y, offset_shape_arr) # place the object in arranger
else: else:
Logger.log("d", "Could not find spot!"), Logger.log("d", "Could not find spot!"),
found_spot = False found_spot = False
new_node.setPosition(Vector(200, center_y, 100)) node.setPosition(Vector(200, center_y, 100))
return new_node, found_spot return found_spot
## Fill priority, center is best. Lower value is better ## Fill priority, center is best. Lower value is better
# This is a strategy for the arranger. # This is a strategy for the arranger.

View file

@ -1675,7 +1675,7 @@ class CuraApplication(QtApplication):
return return
# Step is for skipping tests to make it a lot faster. it also makes the outcome somewhat rougher # 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 # 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 # of BuildPlateDecorator produces one that's associated with build plate -1. So, here we need to check if

View file

@ -64,10 +64,11 @@ class MultiplyObjectsJob(Job):
arranger.resetLastPriority() arranger.resetLastPriority()
for i in range(self._count): for i in range(self._count):
# We do place the nodes one by one, as we want to yield in between. # 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: if not node_too_big:
new_node, solution_found = arranger.findNodePlacement(current_node, offset_shape_arr, hull_shape_arr) solution_found = arranger.findNodePlacement(new_node, offset_shape_arr, hull_shape_arr)
else:
new_node = copy.deepcopy(node)
if node_too_big or not solution_found: if node_too_big or not solution_found:
found_solution_for_all = False found_solution_for_all = False
new_location = new_node.getPosition() new_location = new_node.getPosition()