Change MultiplyObjectsJob to work on a list of objects

This makes MultiplyObjectsJob able to handle a list of objects instead
of a single object ID.

Contributes to CURA-3609
This commit is contained in:
Arjen Hiemstra 2017-04-20 17:25:05 +02:00
parent 97fd35c21d
commit 905e59354b
2 changed files with 39 additions and 28 deletions

View file

@ -855,7 +855,14 @@ class CuraApplication(QtApplication):
# \param min_offset minimum offset to other objects. # \param min_offset minimum offset to other objects.
@pyqtSlot("quint64", int) @pyqtSlot("quint64", int)
def multiplyObject(self, object_id, count, min_offset = 8): def multiplyObject(self, object_id, count, min_offset = 8):
job = MultiplyObjectsJob(object_id, count, min_offset) node = self.getController().getScene().findObject(object_id)
if not node:
node = Selection.getSelectedObject(0)
while node.getParent() and node.getParent().callDecoration("isGroup"):
node = node.getParent()
job = MultiplyObjectsJob([node], count, min_offset)
job.start() job.start()
return return

View file

@ -24,9 +24,9 @@ from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
class MultiplyObjectsJob(Job): class MultiplyObjectsJob(Job):
def __init__(self, object_id, count, min_offset = 8): def __init__(self, objects, count, min_offset = 8):
super().__init__() super().__init__()
self._object_id = object_id self._objects = objects
self._count = count self._count = count
self._min_offset = min_offset self._min_offset = min_offset
@ -35,38 +35,42 @@ class MultiplyObjectsJob(Job):
dismissable=False, progress=0) dismissable=False, progress=0)
status_message.show() status_message.show()
scene = Application.getInstance().getController().getScene() scene = Application.getInstance().getController().getScene()
node = scene.findObject(self._object_id)
if not node and self._object_id != 0: # Workaround for tool handles overlapping the selected object total_progress = len(self._objects) * self._count
node = Selection.getSelectedObject(0) current_progress = 0
# If object is part of a group, multiply group
current_node = node
while current_node.getParent() and current_node.getParent().callDecoration("isGroup"):
current_node = current_node.getParent()
root = scene.getRoot() root = scene.getRoot()
arranger = Arrange.create(scene_root=root) arranger = Arrange.create(scene_root=root)
node_too_big = False
if node.getBoundingBox().width < 300 or node.getBoundingBox().depth < 300:
offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(current_node, min_offset=self._min_offset)
else:
node_too_big = True
nodes = [] nodes = []
found_solution_for_all = True for node in self._objects:
for i in range(self._count): # If object is part of a group, multiply group
# We do place the nodes one by one, as we want to yield in between. current_node = node
if not node_too_big: while current_node.getParent() and current_node.getParent().callDecoration("isGroup"):
node, solution_found = arranger.findNodePlacement(current_node, offset_shape_arr, hull_shape_arr) current_node = current_node.getParent()
if node_too_big or not solution_found:
found_solution_for_all = False node_too_big = False
new_location = node.getPosition() if node.getBoundingBox().width < 300 or node.getBoundingBox().depth < 300:
new_location = new_location.set(z = 100 - i * 20) offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(current_node, min_offset=self._min_offset)
node.setPosition(new_location) else:
node_too_big = True
found_solution_for_all = True
for i in range(self._count):
# We do place the nodes one by one, as we want to yield in between.
if not node_too_big:
node, solution_found = arranger.findNodePlacement(current_node, offset_shape_arr, hull_shape_arr)
if node_too_big or not solution_found:
found_solution_for_all = False
new_location = node.getPosition()
new_location = new_location.set(z = 100 - i * 20)
node.setPosition(new_location)
nodes.append(node)
current_progress += 1
status_message.setProgress((current_progress / total_progress) * 100)
Job.yieldThread()
nodes.append(node)
Job.yieldThread() Job.yieldThread()
status_message.setProgress((i + 1) / self._count * 100)
if nodes: if nodes:
op = GroupedOperation() op = GroupedOperation()