From 9dc6c94a45834397798ab9bb49268787407f8d45 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 9 May 2022 14:18:49 +0300 Subject: [PATCH 1/2] - wip --- appParsers/ParseSVG.py | 34 +++++++++++++++++++++++++++++++--- appPlugins/ToolPaint.py | 5 ++--- camlib.py | 2 +- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/appParsers/ParseSVG.py b/appParsers/ParseSVG.py index 3c3bafa7..a704f62f 100644 --- a/appParsers/ParseSVG.py +++ b/appParsers/ParseSVG.py @@ -186,10 +186,38 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0): geo_element = Polygon(rings.geoms[0]) else: geo_element = LineString(rings.geoms[0]) + geometry.append(geo_element) else: try: - geo_element = Polygon(rings.geoms[0], rings.geoms[1:]) - except Exception: + poly_list = [Polygon(line.coords) for line in rings.geoms] + # if len(poly_list) == 2: + # if poly_list[0].contains(poly_list[1]): + # geo_element = Polygon(rings.geoms[0], rings.geoms[1:]) + # geometry.append(geo_element) + # else: + # geometry = poly_list + # else: + # geo_element = Polygon(rings.geoms[0], rings.geoms[1:]) + # geometry.append(geo_element) + contained = [] + not_contained = [] + if len(poly_list) > 1: + for p in poly_list[1:-1]: + if poly_list[0].contains(p): + contained.append(p) + else: + not_contained.append(p) + else: + not_contained = poly_list + + if not_contained: + geometry += [poly_list[0]] + geometry += not_contained + + if contained: + geo_element = Polygon(poly_list[0].exterior, [p.exterior for p in contained]) + geometry.append(geo_element) + except Exception as err: coords = [] for line in rings.geoms: coords.append(line.coords[0]) @@ -198,7 +226,7 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0): geo_element = Polygon(coords) except Exception: geo_element = LineString(coords) - geometry.append(geo_element) + geometry.append(geo_element) return geometry diff --git a/appPlugins/ToolPaint.py b/appPlugins/ToolPaint.py index d87fd415..621c6e52 100644 --- a/appPlugins/ToolPaint.py +++ b/appPlugins/ToolPaint.py @@ -1976,9 +1976,7 @@ class ToolPaint(AppTool, Gerber): total_geometry += list(x.get_objects()) # clean the geometry - new_geo = [g for g in total_geometry if g and not g.is_empty] - total_geometry = new_geo - final_solid_geometry += total_geometry + total_geometry = [g for g in total_geometry if g and not g.is_empty] except grace: return "fail" except Exception as e: @@ -1992,6 +1990,7 @@ class ToolPaint(AppTool, Gerber): # dictionary and then reset the temporary list that stored that solid_geometry tools_storage[current_uid]['solid_geometry'] = deepcopy(total_geometry) tools_storage[current_uid]['data']['name'] = name + final_solid_geometry += total_geometry # clean the progressive plotted shapes if it was used if self.app.options["tools_paint_plotting"] == 'progressive': diff --git a/camlib.py b/camlib.py index f1835f7f..a0cbecb9 100644 --- a/camlib.py +++ b/camlib.py @@ -1265,7 +1265,7 @@ class Geometry(object): geos.append(ml) except TypeError: geos.append(merged_lines) - + # Add to object if self.solid_geometry is None: self.solid_geometry = [] From ba7fafb6dec2c5c363bf520613e5606989464c70 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 9 May 2022 16:12:12 +0300 Subject: [PATCH 2/2] - fixed an issue in the SVG parser where when parsing a path and getting multiple polygons will generate an invalid compound polygon (the polygons other than the first are seen as interiors even if they are not inside the first) --- CHANGELOG.md | 1 + appParsers/ParseSVG.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7167bd27..bac377d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG for FlatCAM Evo beta 9.05.2022 - fixed an issue in the Paint Plugin where some polygons are discarded in a Geometry object made out of an imported SVG +- fixed an issue in the SVG parser where when parsing a path and getting multiple polygons will generate an invalid compound polygon (the polygons other than the first are seen as interiors even if they are not inside the first) 6.05.2022 diff --git a/appParsers/ParseSVG.py b/appParsers/ParseSVG.py index a704f62f..c38ddef2 100644 --- a/appParsers/ParseSVG.py +++ b/appParsers/ParseSVG.py @@ -202,7 +202,7 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0): contained = [] not_contained = [] if len(poly_list) > 1: - for p in poly_list[1:-1]: + for p in poly_list[1:]: if poly_list[0].contains(p): contained.append(p) else: @@ -217,7 +217,7 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0): if contained: geo_element = Polygon(poly_list[0].exterior, [p.exterior for p in contained]) geometry.append(geo_element) - except Exception as err: + except Exception: coords = [] for line in rings.geoms: coords.append(line.coords[0])