Merge pull request #17036 from Ultimaker/CURA-10403_revisit_auto_arrange_strategy

Cura 10403 revisit auto arrange strategy
This commit is contained in:
Casper Lamboo 2023-10-20 17:04:43 +02:00 committed by GitHub
commit f035c42f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,8 +49,9 @@ class Nest2DArrange(Arranger):
def findNodePlacement(self) -> Tuple[bool, List[Item]]: def findNodePlacement(self) -> Tuple[bool, List[Item]]:
spacing = int(1.5 * self._factor) # 1.5mm spacing. spacing = int(1.5 * self._factor) # 1.5mm spacing.
machine_width = self._build_volume.getWidth() edge_disallowed_size = self._build_volume.getEdgeDisallowedSize()
machine_depth = self._build_volume.getDepth() 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)) build_plate_bounding_box = Box(int(machine_width * self._factor), int(machine_depth * self._factor))
if self._fixed_nodes is None: if self._fixed_nodes is None:
@ -80,7 +81,6 @@ class Nest2DArrange(Arranger):
], numpy.float32)) ], numpy.float32))
disallowed_areas = self._build_volume.getDisallowedAreas() disallowed_areas = self._build_volume.getDisallowedAreas()
num_disallowed_areas_added = 0
for area in disallowed_areas: for area in disallowed_areas:
converted_points = [] converted_points = []
@ -95,7 +95,6 @@ class Nest2DArrange(Arranger):
disallowed_area = Item(converted_points) disallowed_area = Item(converted_points)
disallowed_area.markAsDisallowedAreaInBin(0) disallowed_area.markAsDisallowedAreaInBin(0)
node_items.append(disallowed_area) node_items.append(disallowed_area)
num_disallowed_areas_added += 1
for node in self._fixed_nodes: for node in self._fixed_nodes:
converted_points = [] converted_points = []
@ -108,20 +107,25 @@ class Nest2DArrange(Arranger):
item = Item(converted_points) item = Item(converted_points)
item.markAsFixedInBin(0) item.markAsFixedInBin(0)
node_items.append(item) node_items.append(item)
num_disallowed_areas_added += 1
config = NfpConfig() strategies = [NfpConfig.Alignment.CENTER] * 3 + [NfpConfig.Alignment.BOTTOM_LEFT] * 3
config.accuracy = 1.0 found_solution_for_all = False
config.alignment = NfpConfig.Alignment.DONT_ALIGN while not found_solution_for_all and len(strategies) > 0:
if self._lock_rotation: config = NfpConfig()
config.rotations = [0.0] config.accuracy = 1.0
config.alignment = NfpConfig.Alignment.CENTER
config.starting_point = strategies[0]
strategies = 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. num_bins = nest(node_items, build_plate_bounding_box, spacing, config)
node_items = list(filter(lambda item: not item.isFixed(), node_items))
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 return found_solution_for_all, node_items