diff --git a/CHANGELOG.md b/CHANGELOG.md index 35fb9566..83aaa54d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG for FlatCAM Evo beta - Gerber Parser: minor changes, cleaning up the KiCAD junk lines if the Gerber file is made by KiCAD - Allowed the opening of certain types of damaged Gerber files (apertures not defines but used) but WARNINGS +- NCC Plugin - fixed a minor bug that crashed the NCC Tcl Command; reported by @Aldin Halilovic on bitbucket 7.06.2023 diff --git a/appPlugins/ToolNCC.py b/appPlugins/ToolNCC.py index 5419fbb5..84c78b9b 100644 --- a/appPlugins/ToolNCC.py +++ b/appPlugins/ToolNCC.py @@ -3228,85 +3228,87 @@ class NonCopperClear(AppTool, Gerber): old_disp_number = 0 self.app.log.warning("Total number of polygons to be cleared. %s" % str(geo_len)) - if area.geoms: - pol_nr = 0 - for p in area: - # provide the app with a way to process the GUI events when in a blocking loop - QtWidgets.QApplication.processEvents() + if not area: + continue - if self.app.abort_flag: - # graceful abort requested by the user - raise grace + pol_nr = 0 + for p in area: + # provide the app with a way to process the GUI events when in a blocking loop + QtWidgets.QApplication.processEvents() - # clean the polygon - p = p.buffer(0) + if self.app.abort_flag: + # graceful abort requested by the user + raise grace - if p and p.is_valid: - poly_processed = [] - if isinstance(p, Polygon): - if ncc_method == 0: # standard - cp = self.clear_polygon(p, tool, self.circle_steps, - overlap=overlap, contour=contour, connect=connect, - prog_plot=False) - elif ncc_method == 1: # seed - cp = self.clear_polygon2(p, tool, self.circle_steps, - overlap=overlap, contour=contour, connect=connect, - prog_plot=False) - else: - cp = self.clear_polygon3(p, tool, self.circle_steps, - overlap=overlap, contour=contour, connect=connect, - prog_plot=False) - if cp: - cleared_geo += list(cp.get_objects()) - poly_processed.append(True) - else: - poly_processed.append(False) - self.app.log.warning("Polygon can not be cleared.") + # clean the polygon + p = p.buffer(0) + + if p and p.is_valid: + poly_processed = [] + if isinstance(p, Polygon): + if ncc_method == 0: # standard + cp = self.clear_polygon(p, tool, self.circle_steps, + overlap=overlap, contour=contour, connect=connect, + prog_plot=False) + elif ncc_method == 1: # seed + cp = self.clear_polygon2(p, tool, self.circle_steps, + overlap=overlap, contour=contour, connect=connect, + prog_plot=False) else: - self.app.log.warning("Geo can not be cleared because it is: %s" % str(type(p))) + cp = self.clear_polygon3(p, tool, self.circle_steps, + overlap=overlap, contour=contour, connect=connect, + prog_plot=False) + if cp: + cleared_geo += list(cp.get_objects()) + poly_processed.append(True) + else: + poly_processed.append(False) + self.app.log.warning("Polygon can not be cleared.") + else: + self.app.log.warning("Geo can not be cleared because it is: %s" % str(type(p))) - p_cleared = poly_processed.count(True) - p_not_cleared = poly_processed.count(False) + p_cleared = poly_processed.count(True) + p_not_cleared = poly_processed.count(False) - if p_not_cleared: - app_obj.poly_not_cleared = True + if p_not_cleared: + app_obj.poly_not_cleared = True - if p_cleared == 0: - continue + if p_cleared == 0: + continue - pol_nr += 1 - disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100])) - # log.debug("Polygons cleared: %d" % pol_nr) + pol_nr += 1 + disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100])) + # log.debug("Polygons cleared: %d" % pol_nr) - if old_disp_number < disp_number <= 100: - self.app.proc_container.update_view_text(' %d%%' % disp_number) - old_disp_number = disp_number - # log.debug("Polygons cleared: %d. Percentage done: %d%%" % (pol_nr, disp_number)) + if old_disp_number < disp_number <= 100: + self.app.proc_container.update_view_text(' %d%%' % disp_number) + old_disp_number = disp_number + # log.debug("Polygons cleared: %d. Percentage done: %d%%" % (pol_nr, disp_number)) - # check if there is a geometry at all in the cleared geometry - if cleared_geo: - # Overall cleared area - cleared = empty.buffer(-offset_a * (1 + overlap)).buffer(-tool / 1.999999).buffer( - tool / 1.999999) + # check if there is a geometry at all in the cleared geometry + if cleared_geo: + # Overall cleared area + cleared = empty.buffer(-offset_a * (1 + overlap)).buffer(-tool / 1.999999).buffer( + tool / 1.999999) - # clean-up cleared geo - cleared = cleared.buffer(0) + # clean-up cleared geo + cleared = cleared.buffer(0) - # find the tooluid associated with the current tool_dia so we know where to add the tool - # solid_geometry - for k, v in tools_storage.items(): - if float('%.*f' % (self.decimals, v['tooldia'])) == float('%.*f' % (self.decimals, - tool)): - current_uid = int(k) + # find the tooluid associated with the current tool_dia so we know where to add the tool + # solid_geometry + for k, v in tools_storage.items(): + if float('%.*f' % (self.decimals, v['tooldia'])) == float('%.*f' % (self.decimals, + tool)): + current_uid = int(k) - # add the solid_geometry to the current too in self.paint_tools dictionary - # and then reset the temporary list that stored that solid_geometry - v['solid_geometry'] = flatten_shapely_geometry(cleared_geo) - v['data']['name'] = name - break - geo_obj.tools[current_uid] = dict(tools_storage[current_uid]) - else: - app_obj.log.debug("There are no geometries in the cleared polygon.") + # add the solid_geometry to the current too in self.paint_tools dictionary + # and then reset the temporary list that stored that solid_geometry + v['solid_geometry'] = flatten_shapely_geometry(cleared_geo) + v['data']['name'] = name + break + geo_obj.tools[current_uid] = dict(tools_storage[current_uid]) + else: + app_obj.log.debug("There are no geometries in the cleared polygon.") # delete tools with empty geometry # look for keys in the tools_storage dict that have 'solid_geometry' values empty