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 3c3bafa7..c38ddef2 100644 --- a/appParsers/ParseSVG.py +++ b/appParsers/ParseSVG.py @@ -186,9 +186,37 @@ 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:]) + 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:]: + 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: coords = [] for line in rings.geoms: @@ -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 4f683ee0..395de21e 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 = []