From 1949d315e360d715925146e96c05a48e9c407aac Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 19 Oct 2023 16:02:08 +0200 Subject: [PATCH 1/4] Minor auto-arrange improvements CURA-10403 --- cura/Arranging/Nest2DArrange.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cura/Arranging/Nest2DArrange.py b/cura/Arranging/Nest2DArrange.py index 68ab5f75da..38b38d77df 100644 --- a/cura/Arranging/Nest2DArrange.py +++ b/cura/Arranging/Nest2DArrange.py @@ -49,8 +49,9 @@ class Nest2DArrange(Arranger): def findNodePlacement(self) -> Tuple[bool, List[Item]]: spacing = int(1.5 * self._factor) # 1.5mm spacing. - machine_width = self._build_volume.getWidth() - machine_depth = self._build_volume.getDepth() + edge_disallowed_size = self._build_volume.getEdgeDisallowedSize() + machine_width = self._build_volume.getWidth() - (edge_disallowed_size * 2) + machine_depth = self._build_volume.getDepth() - (edge_disallowed_size * 2) build_plate_bounding_box = Box(int(machine_width * self._factor), int(machine_depth * self._factor)) if self._fixed_nodes is None: @@ -112,7 +113,7 @@ class Nest2DArrange(Arranger): config = NfpConfig() config.accuracy = 1.0 - config.alignment = NfpConfig.Alignment.DONT_ALIGN + config.alignment = NfpConfig.Alignment.CENTER if self._lock_rotation: config.rotations = [0.0] From 1509e2798387c1d2ac6c3dfc0d4a41a9132426c0 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 19 Oct 2023 16:03:14 +0200 Subject: [PATCH 2/4] Removed unused variable CURA-10403 --- cura/Arranging/Nest2DArrange.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/cura/Arranging/Nest2DArrange.py b/cura/Arranging/Nest2DArrange.py index 38b38d77df..089d0171cd 100644 --- a/cura/Arranging/Nest2DArrange.py +++ b/cura/Arranging/Nest2DArrange.py @@ -81,7 +81,6 @@ class Nest2DArrange(Arranger): ], numpy.float32)) disallowed_areas = self._build_volume.getDisallowedAreas() - num_disallowed_areas_added = 0 for area in disallowed_areas: converted_points = [] @@ -96,7 +95,6 @@ class Nest2DArrange(Arranger): disallowed_area = Item(converted_points) disallowed_area.markAsDisallowedAreaInBin(0) node_items.append(disallowed_area) - num_disallowed_areas_added += 1 for node in self._fixed_nodes: converted_points = [] @@ -109,7 +107,6 @@ class Nest2DArrange(Arranger): item = Item(converted_points) item.markAsFixedInBin(0) node_items.append(item) - num_disallowed_areas_added += 1 config = NfpConfig() config.accuracy = 1.0 From 0d0375d5e0bf49bbdc5b11617212fe6b124bbc25 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Thu, 19 Oct 2023 16:36:19 +0200 Subject: [PATCH 3/4] Retry auto-arrange with a few different strategies CURA-10403 --- cura/Arranging/Nest2DArrange.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/cura/Arranging/Nest2DArrange.py b/cura/Arranging/Nest2DArrange.py index 089d0171cd..aa6f2af319 100644 --- a/cura/Arranging/Nest2DArrange.py +++ b/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 From 1b9ad841152ee2e71fde68f3099289cfd6f3ba5d Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Fri, 20 Oct 2023 12:05:19 +0200 Subject: [PATCH 4/4] Improve code readability CURA-10403 --- cura/Arranging/Nest2DArrange.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cura/Arranging/Nest2DArrange.py b/cura/Arranging/Nest2DArrange.py index aa6f2af319..968522d5a3 100644 --- a/cura/Arranging/Nest2DArrange.py +++ b/cura/Arranging/Nest2DArrange.py @@ -108,14 +108,14 @@ class Nest2DArrange(Arranger): item.markAsFixedInBin(0) node_items.append(item) - tried_strategies = [NfpConfig.Alignment.CENTER] * 3 + [NfpConfig.Alignment.BOTTOM_LEFT] * 3 + 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: + while not found_solution_for_all and len(strategies) > 0: config = NfpConfig() config.accuracy = 1.0 config.alignment = NfpConfig.Alignment.CENTER - config.starting_point = tried_strategies[0] - tried_strategies = tried_strategies[1:] + config.starting_point = strategies[0] + strategies = strategies[1:] if self._lock_rotation: config.rotations = [0.0]