- Gerber Editor: some more changes in processing LPC polygons

This commit is contained in:
Marius Stanciu 2019-04-14 01:03:42 +03:00
parent 0fdd2e4f7c
commit 4100e98ebe
2 changed files with 36 additions and 2 deletions

View File

@ -3183,10 +3183,10 @@ class Gerber (Geometry):
temp_geo = []
for apid in self.apertures:
if 'clear_geometry' in self.apertures[apid]:
clear_geo = cascaded_union(self.apertures[apid]['clear_geometry'])
clear_geo = MultiPolygon(self.apertures[apid]['clear_geometry'])
for solid_geo in self.apertures[apid]['solid_geometry']:
if clear_geo.intersects(solid_geo):
res_geo = clear_geo.symmetric_difference(solid_geo)
res_geo = solid_geo.difference(clear_geo)
temp_geo.append(res_geo)
else:
temp_geo.append(solid_geo)

View File

@ -1292,6 +1292,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
# this var will store the state of the toolbar before starting the editor
self.toolbar_old_state = False
# holds flattened geometry
self.flat_geometry = []
# Init GUI
self.apdim_lbl.hide()
self.apdim_entry.hide()
@ -1927,6 +1930,37 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.shapes.clear(update=True)
self.tool_shape.clear(update=True)
def flatten(self, geometry=None, reset=True, pathonly=False):
"""
Creates a list of non-iterable linear geometry objects.
Polygons are expanded into its exterior pathonly param if specified.
Results are placed in flat_geometry
:param geometry: Shapely type or list or list of list of such.
:param reset: Clears the contents of self.flat_geometry.
:param pathonly: Expands polygons into linear elements from the exterior attribute.
"""
if reset:
self.flat_geometry = []
## If iterable, expand recursively.
try:
for geo in geometry:
if geo is not None:
self.flatten(geometry=geo, reset=False, pathonly=pathonly)
## Not iterable, do the actual indexing and add.
except TypeError:
if pathonly and type(geometry) == Polygon:
self.flat_geometry.append(geometry.exterior)
self.flatten(geometry=geometry.interiors,
reset=False,
pathonly=True)
else:
self.flat_geometry.append(geometry)
return self.flat_geometry
def edit_fcgerber(self, orig_grb_obj):
"""
Imports the geometry found in self.apertures from the given FlatCAM Gerber object