Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjen Hiemstra <ahiemstra@heimr.nl>2017-04-20 18:25:05 +0300
committerArjen Hiemstra <ahiemstra@heimr.nl>2017-04-20 18:41:53 +0300
commit905e59354b314db9806374111616c8ba775d3136 (patch)
treeb6cf9a0185c43db6e261ba94c1d0c2dc9bd60c4a /cura/MultiplyObjectsJob.py
parent97fd35c21d2d8e90c0f078f4e9529b03383760e8 (diff)
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
Diffstat (limited to 'cura/MultiplyObjectsJob.py')
-rw-r--r--cura/MultiplyObjectsJob.py58
1 files changed, 31 insertions, 27 deletions
diff --git a/cura/MultiplyObjectsJob.py b/cura/MultiplyObjectsJob.py
index 40dbc221d6..a795e0bc10 100644
--- a/cura/MultiplyObjectsJob.py
+++ b/cura/MultiplyObjectsJob.py
@@ -24,9 +24,9 @@ from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
class MultiplyObjectsJob(Job):
- def __init__(self, object_id, count, min_offset = 8):
+ def __init__(self, objects, count, min_offset = 8):
super().__init__()
- self._object_id = object_id
+ self._objects = objects
self._count = count
self._min_offset = min_offset
@@ -35,38 +35,42 @@ class MultiplyObjectsJob(Job):
dismissable=False, progress=0)
status_message.show()
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
- node = Selection.getSelectedObject(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()
+ total_progress = len(self._objects) * self._count
+ current_progress = 0
root = scene.getRoot()
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 = []
- 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)
+ for node in self._objects:
+ # 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()
+
+ 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
+
+ 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()
- status_message.setProgress((i + 1) / self._count * 100)
if nodes:
op = GroupedOperation()