- Thieving Plugin: fixed errors due of changes in the Shapely module

This commit is contained in:
Marius Stanciu
2023-05-17 22:48:39 +03:00
parent dea367b185
commit 761b61668a
2 changed files with 41 additions and 71 deletions

View File

@@ -7,6 +7,10 @@ CHANGELOG for FlatCAM Evo beta
================================================= =================================================
17.05.2023
- Thieving Plugin: fixed errors due of changes in the Shapely module
16.05.2023 16.05.2023
- NCC Plugin: fixed the Standard method of copper clearing (both normal and with Rest machining) - NCC Plugin: fixed the Standard method of copper clearing (both normal and with Rest machining)

View File

@@ -722,7 +722,7 @@ class ToolCopperThieving(AppTool):
# ######################################################################################################### # #########################################################################################################
# Generate solid filling geometry. Effectively it's a NEGATIVE of the source object # Generate solid filling geometry. Effectively it's a NEGATIVE of the source object
# ######################################################################################################### # #########################################################################################################
tool_obj.thief_solid_geometry = bounding_box.difference(clearance_geometry) tool_obj.thief_solid_geometry = flatten_shapely_geometry(bounding_box.difference(clearance_geometry))
temp_geo = [] temp_geo = []
try: try:
@@ -803,47 +803,31 @@ class ToolCopperThieving(AppTool):
# create a thick polygon-line that surrounds the copper features # create a thick polygon-line that surrounds the copper features
outline_geometry = [] outline_geometry = []
try: gerb_geometry = flatten_shapely_geometry(tool_obj.grb_object.solid_geometry)
for pol in tool_obj.grb_object.solid_geometry: for pol in gerb_geometry:
if tool_obj.app.abort_flag: if tool_obj.app.abort_flag:
# graceful abort requested by the user # graceful abort requested by the user
raise grace raise grace
outline_geometry.append(
pol.buffer(c_val+half_thick_line, int(int(tool_obj.geo_steps_per_circle) / 4))
)
pol_nr += 1
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
if old_disp_number < disp_number <= 100:
msg = ' %s ... %d%%' % (_("Buffering"), int(disp_number))
tool_obj.app.proc_container.update_view_text(msg)
old_disp_number = disp_number
except TypeError:
# taking care of the case when the self.solid_geometry is just a single Polygon, not a list or a
# MultiPolygon (not an iterable)
outline_geometry.append( outline_geometry.append(
tool_obj.grb_object.solid_geometry.buffer( pol.buffer(c_val + half_thick_line, int(int(tool_obj.geo_steps_per_circle) / 4))
c_val+half_thick_line,
int(int(tool_obj.geo_steps_per_circle) / 4)
)
) )
pol_nr += 1
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
if old_disp_number < disp_number <= 100:
msg = ' %s ... %d%%' % (_("Buffering"), int(disp_number))
tool_obj.app.proc_container.update_view_text(msg)
old_disp_number = disp_number
tool_obj.app.proc_container.update_view_text(' %s' % _("Buffering")) tool_obj.app.proc_container.update_view_text(' %s' % _("Buffering"))
outline_geometry = unary_union(outline_geometry)
outline_line = [] outline_line = []
try: outline_geometry = flatten_shapely_geometry(unary_union(outline_geometry))
for geo_o in outline_geometry: for geo_o in outline_geometry:
outline_line.append(
geo_o.exterior.buffer(
half_thick_line, resolution=int(int(tool_obj.geo_steps_per_circle) / 4)
)
)
except TypeError:
outline_line.append( outline_line.append(
outline_geometry.exterior.buffer( geo_o.exterior.buffer(
half_thick_line, resolution=int(int(tool_obj.geo_steps_per_circle) / 4) half_thick_line, resolution=int(int(tool_obj.geo_steps_per_circle) / 4)
) )
) )
@@ -888,9 +872,10 @@ class ToolCopperThieving(AppTool):
tool_obj.app.proc_container.update_view_text(' %s' % _("Append geometry")) tool_obj.app.proc_container.update_view_text(' %s' % _("Append geometry"))
# create a list of the source geometry # create a list of the source geometry
geo_list = deepcopy(tool_obj.grb_object.solid_geometry) # geo_list = deepcopy(tool_obj.grb_object.solid_geometry)
if isinstance(tool_obj.grb_object.solid_geometry, MultiPolygon): # if isinstance(tool_obj.grb_object.solid_geometry, MultiPolygon):
geo_list = list(geo_list.geoms) # geo_list = list(geo_list.geoms)
geo_list = flatten_shapely_geometry(tool_obj.grb_object.solid_geometry)
# create a new dictionary to hold the source object apertures allowing us to tamper with without altering # create a new dictionary to hold the source object apertures allowing us to tamper with without altering
# the original source object's apertures # the original source object's apertures
@@ -903,20 +888,13 @@ class ToolCopperThieving(AppTool):
} }
# add the thieving geometry in the 0 aperture of the new_apertures dict # add the thieving geometry in the 0 aperture of the new_apertures dict
try: t_geometry = flatten_shapely_geometry(tool_obj.thief_solid_geometry)
for poly in tool_obj.thief_solid_geometry: for poly in t_geometry:
# append to the new solid geometry
geo_list.append(poly)
# append into the 0 aperture
geo_elem = {'solid': poly, 'follow': poly.exterior}
new_apertures[0]['geometry'].append(deepcopy(geo_elem))
except TypeError:
# append to the new solid geometry # append to the new solid geometry
geo_list.append(tool_obj.thief_solid_geometry) geo_list.append(poly)
# append into the 0 aperture # append into the 0 aperture
geo_elem = {'solid': tool_obj.thief_solid_geometry, 'follow': tool_obj.thief_solid_geometry.exterior} geo_elem = {'solid': poly, 'follow': poly.exterior}
new_apertures[0]['geometry'].append(deepcopy(geo_elem)) new_apertures[0]['geometry'].append(deepcopy(geo_elem))
# prepare also the solid_geometry for the new object having the thieving geometry # prepare also the solid_geometry for the new object having the thieving geometry
@@ -934,7 +912,7 @@ class ToolCopperThieving(AppTool):
grb_obj.multigeo = False grb_obj.multigeo = False
grb_obj.follow = deepcopy(self.grb_object.follow) grb_obj.follow = deepcopy(self.grb_object.follow)
grb_obj.tools = new_apertures grb_obj.tools = new_apertures
grb_obj.solid_geometry = deepcopy(new_solid_geo) grb_obj.solid_geometry = deepcopy(flatten_shapely_geometry(new_solid_geo))
grb_obj.follow_geometry = deepcopy(self.grb_object.follow_geometry) grb_obj.follow_geometry = deepcopy(self.grb_object.follow_geometry)
app_obj.proc_container.update_view_text(' %s' % _("Append source file")) app_obj.proc_container.update_view_text(' %s' % _("Append source file"))
@@ -1039,12 +1017,12 @@ class ToolCopperThieving(AppTool):
for geo in geo_list: for geo in geo_list:
plated_area += geo.area plated_area += geo.area
thieving_solid_geo = deepcopy(self.thief_solid_geometry) thieving_solid_geo = deepcopy(flatten_shapely_geometry(self.thief_solid_geometry))
robber_solid_geo = deepcopy(self.robber_geo) robber_solid_geo = deepcopy(flatten_shapely_geometry(self.robber_geo))
robber_line = deepcopy(self.robber_line) robber_line = deepcopy(flatten_shapely_geometry(self.robber_line))
# store here the chosen follow geometry # store here the chosen follow geometry
new_follow_geo = deepcopy(self.sm_object.follow_geometry) new_follow_geo = deepcopy(flatten_shapely_geometry(self.sm_object.follow_geometry))
# if we have copper thieving geometry, add it # if we have copper thieving geometry, add it
if thieving_solid_geo and geo_choice in [0, 1]: # ['b', 't'] if thieving_solid_geo and geo_choice in [0, 1]: # ['b', 't']
@@ -1059,28 +1037,16 @@ class ToolCopperThieving(AppTool):
'geometry': [] 'geometry': []
} }
try: for poly in thieving_solid_geo:
for poly in thieving_solid_geo: poly_b = poly.buffer(ppm_clearance)
poly_b = poly.buffer(ppm_clearance)
# append to the new solid geometry
geo_list.append(poly_b)
# append into the 0 aperture
geo_elem = {
'solid': poly_b,
'follow': poly_b.exterior
}
new_apertures[0]['geometry'].append(deepcopy(geo_elem))
except TypeError:
# append to the new solid geometry # append to the new solid geometry
assert isinstance(thieving_solid_geo, Polygon) geo_list.append(poly_b)
geo_list.append(thieving_solid_geo.buffer(ppm_clearance))
# append into the 0 aperture # append into the 0 aperture
geo_elem = { geo_elem = {
'solid': thieving_solid_geo.buffer(ppm_clearance), 'solid': poly_b,
'follow': thieving_solid_geo.buffer(ppm_clearance).exterior 'follow': poly_b.exterior
} }
new_apertures[0]['geometry'].append(deepcopy(geo_elem)) new_apertures[0]['geometry'].append(deepcopy(geo_elem))
@@ -1143,7 +1109,7 @@ class ToolCopperThieving(AppTool):
grb_obj.follow = False grb_obj.follow = False
grb_obj.follow_geometry = deepcopy(new_follow_geo) grb_obj.follow_geometry = deepcopy(new_follow_geo)
grb_obj.tools = deepcopy(new_apertures) grb_obj.tools = deepcopy(new_apertures)
grb_obj.solid_geometry = deepcopy(new_solid_geometry) grb_obj.solid_geometry = deepcopy(flatten_shapely_geometry(new_solid_geometry))
app_obj.proc_container.update_view_text(' %s' % _("Append source file")) app_obj.proc_container.update_view_text(' %s' % _("Append source file"))
# update the source file with the new geometry: # update the source file with the new geometry: