This commit is contained in:
Marius Stanciu
2022-05-09 14:18:49 +03:00
committed by Marius
parent 411a9320e5
commit 9dc6c94a45
3 changed files with 34 additions and 7 deletions

View File

@@ -186,10 +186,38 @@ def path2shapely(path, object_type, res=1.0, units='MM', factor=1.0):
geo_element = Polygon(rings.geoms[0]) geo_element = Polygon(rings.geoms[0])
else: else:
geo_element = LineString(rings.geoms[0]) geo_element = LineString(rings.geoms[0])
geometry.append(geo_element)
else: else:
try: try:
geo_element = Polygon(rings.geoms[0], rings.geoms[1:]) poly_list = [Polygon(line.coords) for line in rings.geoms]
except Exception: # 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 = [] coords = []
for line in rings.geoms: for line in rings.geoms:
coords.append(line.coords[0]) 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) geo_element = Polygon(coords)
except Exception: except Exception:
geo_element = LineString(coords) geo_element = LineString(coords)
geometry.append(geo_element) geometry.append(geo_element)
return geometry return geometry

View File

@@ -1976,9 +1976,7 @@ class ToolPaint(AppTool, Gerber):
total_geometry += list(x.get_objects()) total_geometry += list(x.get_objects())
# clean the geometry # clean the geometry
new_geo = [g for g in total_geometry if g and not g.is_empty] total_geometry = [g for g in total_geometry if g and not g.is_empty]
total_geometry = new_geo
final_solid_geometry += total_geometry
except grace: except grace:
return "fail" return "fail"
except Exception as e: except Exception as e:
@@ -1992,6 +1990,7 @@ class ToolPaint(AppTool, Gerber):
# dictionary and then reset the temporary list that stored that solid_geometry # 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]['solid_geometry'] = deepcopy(total_geometry)
tools_storage[current_uid]['data']['name'] = name tools_storage[current_uid]['data']['name'] = name
final_solid_geometry += total_geometry
# clean the progressive plotted shapes if it was used # clean the progressive plotted shapes if it was used
if self.app.options["tools_paint_plotting"] == 'progressive': if self.app.options["tools_paint_plotting"] == 'progressive':

View File

@@ -1265,7 +1265,7 @@ class Geometry(object):
geos.append(ml) geos.append(ml)
except TypeError: except TypeError:
geos.append(merged_lines) geos.append(merged_lines)
# Add to object # Add to object
if self.solid_geometry is None: if self.solid_geometry is None:
self.solid_geometry = [] self.solid_geometry = []