From af8469ebc907fbc902ef1ae39f16a8b85e14d9e4 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 27 Oct 2021 19:21:08 +0300 Subject: [PATCH] - fixed the offseting feature in the Isolation Plugin such that the interiors of the isolated polygons are offset correctly --- CHANGELOG.md | 4 ++++ camlib.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 262d4e49..bb1b4443 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM beta ================================================= +27.10.2021 + +- fixed the offseting feature in the Isolation Plugin such that the interiors of the isolated polygons are offset correctly + 25.10.2021 - updated the PlotCanvas3d diff --git a/camlib.py b/camlib.py index fea4c83f..4a35223b 100644 --- a/camlib.py +++ b/camlib.py @@ -977,6 +977,37 @@ class Geometry(object): return self.flat_geometry + def flatten_exterior_interiors(self, geometry=None): + """ + Creates a list of non-iterable linear geometry objects. + Polygons are expanded into its exterior and interiors. + + + :param geometry: Shapely type or list or list of list of such. + """ + + flat_geo_ext = [] + flat_geo_ints = [] + + if geometry is None: + geometry = self.solid_geometry + # ## If iterable, expand recursively. + try: + for geo in geometry: + if geo is not None: + ext, ints = self.flatten_exterior_interiors(geo) + flat_geo_ext += ext + flat_geo_ints += ints + # ## Not iterable, do the actual indexing and add. + except TypeError: + if type(geometry) == Polygon: + flat_geo_ext.append(geometry.exterior) + flat_geo_ints += geometry.interiors + elif isinstance(geometry, (LineString, LinearRing)): + flat_geo_ext.append(geometry) + + return flat_geo_ext, flat_geo_ints + # def make2Dstorage(self): # # self.flatten() @@ -3545,15 +3576,10 @@ class CNCjob(Geometry): # The Geometry from which we create GCode geometry = tools[tool]['solid_geometry'] - # ## Flatten the geometry. Only linear elements (no polygons) remain. - flat_geometry = self.flatten(geometry, reset=True, pathonly=True) - log.debug("%d paths" % len(flat_geometry)) - # ######################################################################################################### # ######################################################################################################### # ############# PARAMETERS used in PREPROCESSORS so they need to be updated ############################### # ######################################################################################################### - # ######################################################################################################### self.tool = str(tool) tool_dict = tools[tool]['data'] # this is the tool diameter, it is used as such to accommodate the preprocessor who need the tool diameter @@ -3593,13 +3619,34 @@ class CNCjob(Geometry): else: tool_offset = 0.0 + # ############################################################################################################# + # ## Flatten the geometry. Only linear elements (no polygons) remain. + # ############################################################################################################# + flat_ext_geo, flat_ints_geo = self.flatten_exterior_interiors(geometry) + flat_geometry = flat_ext_geo + flat_ints_geo + # flat_geometry = self.flatten(geometry, reset=True, pathonly=True) + log.debug("%d paths" % len(flat_geometry)) if tool_offset != 0.0: - for it in flat_geometry: + # for it in flat_geometry: + # # if the geometry is a closed shape then create a Polygon out of it + # if isinstance(it, LineString): + # if it.is_ring: + # it = Polygon(it) + # temp_solid_geometry.append(it.buffer(tool_offset, join_style=2)) + for it in flat_ext_geo: # if the geometry is a closed shape then create a Polygon out of it if isinstance(it, LineString): if it.is_ring: it = Polygon(it) temp_solid_geometry.append(it.buffer(tool_offset, join_style=2)) + + for it in flat_ints_geo: + # if the geometry is a closed shape then create a Polygon out of it + if isinstance(it, (LineString, LinearRing)): + if it.is_ring: + it = Polygon(it) + temp_solid_geometry.append(it.buffer(-tool_offset, join_style=2)) + temp_solid_geometry = self.flatten(temp_solid_geometry, reset=True, pathonly=True) else: temp_solid_geometry = flat_geometry