From 9dc6c94a45834397798ab9bb49268787407f8d45 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 9 May 2022 14:18:49 +0300 Subject: [PATCH] - 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 = []