Browse Source

Let autoplacement also take the existing nodes into account

CURA-7440
Jaime van Kessel 4 years ago
parent
commit
30966beed2
2 changed files with 22 additions and 1 deletions
  1. 15 0
      cura/Arranging/Nest2DArrange.py
  2. 7 1
      cura/CuraApplication.py

+ 15 - 0
cura/Arranging/Nest2DArrange.py

@@ -15,6 +15,9 @@ def findNodePlacement(nodes_to_arrange, build_volume, fixed_nodes = None, factor
     machine_depth = build_volume.getDepth()
     build_plate_bounding_box = Box(machine_width * factor, machine_depth * factor)
 
+    if fixed_nodes is None:
+        fixed_nodes = []
+
     # Add all the items we want to arrange
     node_items = []
     for node in nodes_to_arrange:
@@ -51,6 +54,18 @@ def findNodePlacement(nodes_to_arrange, build_volume, fixed_nodes = None, factor
         node_items.append(disallowed_area)
         num_disallowed_areas_added += 1
 
+    for node in fixed_nodes:
+        converted_points = []
+        hull_polygon = node.callDecoration("getConvexHull")
+        
+        for point in hull_polygon.getPoints():
+            converted_points.append(Point(point[0] * factor, point[1] * factor))
+        item = Item(converted_points)
+        node_items.append(item)
+        item.markAsFixedInBin(0)
+        node_items.append(item)
+        num_disallowed_areas_added += 1
+
     config = NfpConfig()
     config.accuracy = 1.0
 

+ 7 - 1
cura/CuraApplication.py

@@ -1823,6 +1823,12 @@ class CuraApplication(QtApplication):
         select_models_on_load = self.getPreferences().getValue("cura/select_models_on_load")
 
         nodes_to_arrange = []  # type: List[CuraSceneNode]
+        
+        fixed_nodes = []
+        for node_ in DepthFirstIterator(self.getController().getScene().getRoot()):
+            # Only count sliceable objects
+            if node_.callDecoration("isSliceable"):
+                fixed_nodes.append(node_)
 
         for original_node in nodes:
             # Create a CuraSceneNode just if the original node is not that type
@@ -1892,7 +1898,7 @@ class CuraApplication(QtApplication):
             if select_models_on_load:
                 Selection.add(node)
 
-        arrange(nodes_to_arrange, self.getBuildVolume())
+        arrange(nodes_to_arrange, self.getBuildVolume(), fixed_nodes)
 
         self.fileCompleted.emit(file_name)