From 805cf75e85867ee58aab874452e7036f1bb03d54 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 26 Jan 2022 13:49:48 +0200 Subject: [PATCH] - modified the bounding box utility feature in the Gerber Object UI to work with negative margin values --- CHANGELOG.md | 3 ++- appObjects/FlatCAMGerber.py | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b637c36b..7cf34388 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,11 @@ CHANGELOG for FlatCAM beta - fixed the Cutout plugin not working with Geometry objects that are made out of a LineString or LinearRing geometric elements - fixed the Cutout plugin for the rectangular cutout: the name of the resulting object is now correct if there is no extension in the source file -- modified the bounding box utility feature in the Gerber Object UI to work with buffer value of 0.0 and rounded corners +- modified the bounding box utility feature in the Gerber Object UI to work with margin value of 0.0 and rounded corners - in Cutout plugin added the ability to create Manual Geometries with negative tool diameters - fix the Transform plugin, buffer functionality for Geometry objects such that the buffer with negative values will work by crating a buffer toward the interior of that geometry - minor changes +- modified the bounding box utility feature in the Gerber Object UI to work with negative margin values 25.01.2022 diff --git a/appObjects/FlatCAMGerber.py b/appObjects/FlatCAMGerber.py index a2ed9b6a..02fdb50c 100644 --- a/appObjects/FlatCAMGerber.py +++ b/appObjects/FlatCAMGerber.py @@ -482,16 +482,31 @@ class GerberObject(FlatCAMObj, Gerber): except Exception: self.solid_geometry = unary_union(self.solid_geometry) + distance = float(self.options["bboxmargin"]) + # Bounding box with rounded corners - if isinstance(self.solid_geometry, Polygon): - bounding_box = self.solid_geometry.buffer(float(self.options["bboxmargin"])).exterior - elif isinstance(self.solid_geometry, MultiPolygon): - try: - bounding_box = self.solid_geometry.buffer(float(self.options["bboxmargin"])).exterior - except Exception: - bounding_box = self.solid_geometry.envelope.buffer(float(self.options["bboxmargin"])) + if distance >= 0: + if isinstance(self.solid_geometry, Polygon): + bounding_box = self.solid_geometry.buffer(distance).exterior + elif isinstance(self.solid_geometry, MultiPolygon): + try: + bounding_box = self.solid_geometry.buffer(distance).exterior + except Exception: + bounding_box = self.solid_geometry.envelope.buffer(distance) + else: + bounding_box = self.solid_geometry.envelope.buffer(distance) else: - bounding_box = self.solid_geometry.envelope.buffer(float(self.options["bboxmargin"])) + if isinstance(self.solid_geometry, Polygon): + bounding_box = self.solid_geometry.buffer(abs(distance*2)).interiors + elif isinstance(self.solid_geometry, MultiPolygon): + try: + bounding_box = self.solid_geometry.buffer(abs(distance*2)).interiors + except Exception: + bounding_box = self.solid_geometry.envelope.buffer(abs(distance*2)).interiors + else: + bounding_box = self.solid_geometry.envelope.buffer(abs(distance*2)).interiors + bounding_box = unary_union(bounding_box).buffer(-distance).exterior + if not self.options["bboxrounded"]: # Remove rounded corners bounding_box = bounding_box.envelope