Browse Source

Merge pull request #5298 from Ultimaker/CURA-6120_arrange_child_nodes_fix

Arrange child-nodes (like blocker) with parents. [CURA-6120]
Lipu Fei 6 years ago
parent
commit
45af26879f
2 changed files with 25 additions and 3 deletions
  1. 9 2
      cura/Arranging/ArrangeObjectsJob.py
  2. 16 1
      cura/Arranging/ShapeArray.py

+ 9 - 2
cura/Arranging/ArrangeObjectsJob.py

@@ -1,4 +1,4 @@
-# Copyright (c) 2017 Ultimaker B.V.
+# Copyright (c) 2019 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
 from UM.Application import Application
@@ -39,10 +39,17 @@ class ArrangeObjectsJob(Job):
 
         arranger = Arrange.create(x = machine_width, y = machine_depth, fixed_nodes = self._fixed_nodes, min_offset = self._min_offset)
 
+        # Build set to exclude children (those get arranged together with the parents).
+        included_as_child = set()
+        for node in self._nodes:
+            included_as_child.update(node.getAllChildren())
+
         # Collect nodes to be placed
         nodes_arr = []  # fill with (size, node, offset_shape_arr, hull_shape_arr)
         for node in self._nodes:
-            offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(node, min_offset = self._min_offset)
+            if node in included_as_child:
+                continue
+            offset_shape_arr, hull_shape_arr = ShapeArray.fromNode(node, min_offset = self._min_offset, include_children = True)
             if offset_shape_arr is None:
                 Logger.log("w", "Node [%s] could not be converted to an array for arranging...", str(node))
                 continue

+ 16 - 1
cura/Arranging/ShapeArray.py

@@ -42,7 +42,7 @@ class ShapeArray:
     #   \param min_offset offset for the offset ShapeArray
     #   \param scale scale the coordinates
     @classmethod
-    def fromNode(cls, node, min_offset, scale = 0.5):
+    def fromNode(cls, node, min_offset, scale = 0.5, include_children = False):
         transform = node._transformation
         transform_x = transform._data[0][3]
         transform_y = transform._data[2][3]
@@ -52,6 +52,21 @@ class ShapeArray:
             return None, None
         # For one_at_a_time printing you need the convex hull head.
         hull_head_verts = node.callDecoration("getConvexHullHead") or hull_verts
+        if hull_head_verts is None:
+            hull_head_verts = Polygon()
+
+        # If the child-nodes are included, adjust convex hulls as well:
+        if include_children:
+            children = node.getAllChildren()
+            if not children is None:
+                for child in children:
+                    # 'Inefficient' combination of convex hulls through known code rather than mess it up:
+                    child_hull = child.callDecoration("getConvexHull")
+                    if not child_hull is None:
+                        hull_verts = hull_verts.unionConvexHulls(child_hull)
+                    child_hull_head = child.callDecoration("getConvexHullHead") or child_hull
+                    if not child_hull_head is None:
+                        hull_head_verts = hull_head_verts.unionConvexHulls(child_hull_head)
 
         offset_verts = hull_head_verts.getMinkowskiHull(Polygon.approximatedCircle(min_offset))
         offset_points = copy.deepcopy(offset_verts._points)  # x, y