Browse Source

Retry auto-arrange with a few different strategies

CURA-10403
Erwan MATHIEU 1 year ago
parent
commit
0d0375d5e0
1 changed files with 15 additions and 9 deletions
  1. 15 9
      cura/Arranging/Nest2DArrange.py

+ 15 - 9
cura/Arranging/Nest2DArrange.py

@@ -108,18 +108,24 @@ class Nest2DArrange(Arranger):
                 item.markAsFixedInBin(0)
                 node_items.append(item)
 
-        config = NfpConfig()
-        config.accuracy = 1.0
-        config.alignment = NfpConfig.Alignment.CENTER
-        if self._lock_rotation:
-            config.rotations = [0.0]
+        tried_strategies = [NfpConfig.Alignment.CENTER] * 3 + [NfpConfig.Alignment.BOTTOM_LEFT] * 3
+        found_solution_for_all = False
+        while not found_solution_for_all and len(tried_strategies) > 0:
+            config = NfpConfig()
+            config.accuracy = 1.0
+            config.alignment = NfpConfig.Alignment.CENTER
+            config.starting_point = tried_strategies[0]
+            tried_strategies = tried_strategies[1:]
 
-        num_bins = nest(node_items, build_plate_bounding_box, spacing, config)
+            if self._lock_rotation:
+                config.rotations = [0.0]
 
-        # Strip the fixed items (previously placed) and the disallowed areas from the results again.
-        node_items = list(filter(lambda item: not item.isFixed(), node_items))
+            num_bins = nest(node_items, build_plate_bounding_box, spacing, config)
 
-        found_solution_for_all = num_bins == 1
+            # Strip the fixed items (previously placed) and the disallowed areas from the results again.
+            node_items = list(filter(lambda item: not item.isFixed(), node_items))
+
+            found_solution_for_all = num_bins == 1
 
         return found_solution_for_all, node_items