diff --git a/cura/Arranging/GridArrange.py b/cura/Arranging/GridArrange.py index 13778e9de9..659f3b36e1 100644 --- a/cura/Arranging/GridArrange.py +++ b/cura/Arranging/GridArrange.py @@ -80,6 +80,116 @@ class GridArrange(Arranger): self._allowed_grid_idx = self._build_plate_grid_ids.difference(self._fixed_nodes_grid_ids) + self._drawDebugSvg() + + def _drawDebugSvg(self): + with open("Builvolume_test.svg", "w") as f: + build_volume_bounding_box = self._build_volume.getBoundingBox() + + f.write( + f"""""") + + if self._build_volume.getShape() == "elliptic": + f.write( + f""" + + """) + else: + f.write( + f""" + + """) + + for grid_x in range(-2, 20): + for grid_y in range(-2, 20): + if (grid_x, grid_y) in self._allowed_grid_idx: + fill_color = "rgba(0, 255, 0, 0.5)" + elif (grid_x, grid_y) in self._build_plate_grid_ids: + fill_color = "rgba(255, 165, 0, 0.5)" + else: + fill_color = "rgba(255, 0, 0, 0.5)" + + f.write(self._polygonToSvgPath(self._gridIdToPolygon(grid_x, grid_y), fill_color=fill_color, + stroke="black", stroke_width=0.1)) + coord_grid_x, coord_grid_y = self._gridSpaceToCoordSpace(grid_x, grid_y) + f.write(f""" + + {grid_x},{grid_y} + + """) + for node in self._fixed_nodes: + bounding_box = node.getBoundingBox() + f.write(f""" + + """) + + for polygon in self._build_volume.getDisallowedAreas(): + # Extract individual points and convert them to tuples + f.write(self._polygonToSvgPath(polygon, stroke="black", fill_color="rgba(0,0,0,0.5)")) + + for polygon in self._fixed_nodes: + adhesion_polygon = polygon.callDecoration("getAdhesionArea") + if adhesion_polygon is not None: + f.write(self._polygonToSvgPath(adhesion_polygon, stroke="black", fill_color="rgba(0,255,0,0.5)")) + + convex_hull = polygon.callDecoration("getConvexHull") + if convex_hull is not None: + f.write(self._polygonToSvgPath(convex_hull, stroke="black", fill_color="rgba(0,0,255,0.5)")) + + # coord_build_plate_center_x = self._build_volume.getBoundingBox().width * 0.5 + self._build_volume.getBoundingBox().left + # coord_build_plate_center_y = self._build_volume.getBoundingBox().depth * 0.5 + self._build_volume.getBoundingBox().back + # f.write(f""" + # """) + + f.write(f"") + + @staticmethod + def _polygonToSvgPath(polygon: Polygon, stroke: str = "none", fill_color: str = "none", + stroke_width: float = 1.0) -> str: + return f""" + + """ + + def _gridIdToPolygon(self, grid_x: int, grid_y: int) -> Polygon: + min_x, min_y = self._gridSpaceToCoordSpace(grid_x, grid_y) + max_x, max_y = self._gridSpaceToCoordSpace(grid_x + 1, grid_y + 1) + return Polygon([(min_x, min_y), (max_x, min_y), (max_x, max_y), (min_x, max_y)]) + def createGroupOperationForArrange(self, add_new_nodes_in_scene: bool = False) -> Tuple[GroupedOperation, int]: # Find the sequence in which items are placed coord_build_plate_center_x = self._build_volume_bounding_box.width * 0.5 + self._build_volume_bounding_box.left