From 6c2d628c6c963f3322e871964a7bda7e68942228 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 16 Dec 2019 14:52:58 +0200 Subject: [PATCH] - fixed the Defaults upgrade overwrting the new version number with the old one - fixed issue with clear_polygon3() - the one who makes 'lines' and fixed the NCC Tool --- FlatCAMApp.py | 6 +- README.md | 2 + camlib.py | 117 +++++++++++++++++------------ flatcamTools/ToolNonCopperClear.py | 69 +++++++++++------ 4 files changed, 119 insertions(+), 75 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 3d35fccc..57b290bd 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -140,8 +140,8 @@ class App(QtCore.QObject): # ########################################################################## # ################## Version and VERSION DATE ############################## # ########################################################################## - version = 8.99 - version_date = "2019/12/15" + version = 8.991 + version_date = "2019/12/30" beta = True engine = '3D' @@ -3813,7 +3813,7 @@ class App(QtCore.QObject): if 'version' not in defaults or defaults['version'] != self.defaults['version']: for k, v in defaults.items(): - if k in self.defaults: + if k in self.defaults and k != 'version': self.defaults[k] = v # delete old factory defaults diff --git a/README.md b/README.md index dbdccc80..d88b2339 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ CAD program, and create G-Code for Isolation routing. - in Geometry Editor added support for Jump To function such as that it works within the Editor Tools themselves. For now it works only in absolute jumps - modified the Jump To method such that now allows relative jump from the current mouse location +- fixed the Defaults upgrade overwrting the new version number with the old one +- fixed issue with clear_polygon3() - the one who makes 'lines' and fixed the NCC Tool 15.12.2019 diff --git a/camlib.py b/camlib.py index b11b3d67..7d3dc52d 100644 --- a/camlib.py +++ b/camlib.py @@ -1381,9 +1381,10 @@ class Geometry(object): inner_edges.append(y) # geoms += outer_edges + inner_edges for g in outer_edges + inner_edges: - geoms.insert(g) - if prog_plot: - self.plot_temp_shapes(g) + if g and not g.is_empty: + geoms.insert(g) + if prog_plot: + self.plot_temp_shapes(g) if prog_plot: self.temp_shapes.redraw() @@ -1395,7 +1396,9 @@ class Geometry(object): # Optimization: Reduce lifts if connect: # log.debug("Reducing tool lifts...") - geoms = Geometry.paint_connect(geoms, polygon_to_clear, tooldia, steps_per_circle) + geoms_conn = Geometry.paint_connect(geoms, polygon_to_clear, tooldia, steps_per_circle) + if geoms_conn: + return geoms_conn return geoms @@ -1419,6 +1422,9 @@ class Geometry(object): """ # log.debug("camlib.clear_polygon3()") + if not isinstance(polygon, Polygon): + log.debug("camlib.Geometry.clear_polygon3() --> Not a Polygon but %s" % str(type(polygon))) + return None # ## The toolpaths # Index first and last points in paths @@ -1433,41 +1439,43 @@ class Geometry(object): # Bounding box left, bot, right, top = polygon.bounds - margin_poly = polygon.buffer(-tooldia / 1.99999999, (int(steps_per_circle))) + try: + margin_poly = polygon.buffer(-tooldia / 1.99999999, (int(steps_per_circle))) + except Exception as e: + log.debug("camlib.Geometry.clear_polygon3() --> Could not buffer the Polygon") + return None # First line - y = top - tooldia / 1.99999999 - while y > bot + tooldia / 1.999999999: - if self.app.abort_flag: - # graceful abort requested by the user - raise FlatCAMApp.GracefulException + try: + y = top - tooldia / 1.99999999 + while y > bot + tooldia / 1.999999999: + if self.app.abort_flag: + # graceful abort requested by the user + raise FlatCAMApp.GracefulException - # provide the app with a way to process the GUI events when in a blocking loop - QtWidgets.QApplication.processEvents() + # provide the app with a way to process the GUI events when in a blocking loop + QtWidgets.QApplication.processEvents() + line = LineString([(left, y), (right, y)]) + line = line.intersection(margin_poly) + lines_trimmed.append(line) + y -= tooldia * (1 - overlap) + if prog_plot: + self.plot_temp_shapes(line) + self.temp_shapes.redraw() + + # Last line + y = bot + tooldia / 2 line = LineString([(left, y), (right, y)]) line = line.intersection(margin_poly) - lines_trimmed.append(line) - y -= tooldia * (1 - overlap) - if prog_plot: - self.plot_temp_shapes(line) - self.temp_shapes.redraw() - # Last line - y = bot + tooldia / 2 - line = LineString([(left, y), (right, y)]) - line = line.intersection(margin_poly) - for ll in line: - lines_trimmed.append(ll) - if prog_plot: - self.plot_temp_shapes(line) - - # Combine - # linesgeo = unary_union(lines) - - # Trim to the polygon - # margin_poly = polygon.buffer(-tooldia / 1.99999999, (int(steps_per_circle))) - # lines_trimmed = linesgeo.intersection(margin_poly) + for ll in line: + lines_trimmed.append(ll) + if prog_plot: + self.plot_temp_shapes(line) + except Exception as e: + log.debug('camlib.Geometry.clear_polygon3() Processing poly --> %s' % str(e)) + return None if prog_plot: self.temp_shapes.redraw() @@ -1477,27 +1485,33 @@ class Geometry(object): # Add lines to storage try: for line in lines_trimmed: - geoms.insert(line) + if isinstance(line, LineString) or isinstance(line, LinearRing): + geoms.insert(line) + else: + log.debug("camlib.Geometry.clear_polygon3(). Not a line: %s" % str(type(line))) except TypeError: # in case lines_trimmed are not iterable (Linestring, LinearRing) geoms.insert(lines_trimmed) # Add margin (contour) to storage if contour: - if isinstance(margin_poly, Polygon): - geoms.insert(margin_poly.exterior) - if prog_plot: - self.plot_temp_shapes(margin_poly.exterior) - for ints in margin_poly.interiors: - geoms.insert(ints) - if prog_plot: - self.plot_temp_shapes(ints) - elif isinstance(margin_poly, MultiPolygon): + try: for poly in margin_poly: - geoms.insert(poly.exterior) + if isinstance(poly, Polygon) and not poly.is_empty: + geoms.insert(poly.exterior) + if prog_plot: + self.plot_temp_shapes(poly.exterior) + for ints in poly.interiors: + geoms.insert(ints) + if prog_plot: + self.plot_temp_shapes(ints) + except TypeError: + if isinstance(margin_poly, Polygon) and not margin_poly.is_empty: + marg_ext = margin_poly.exterior + geoms.insert(marg_ext) if prog_plot: - self.plot_temp_shapes(poly.exterior) - for ints in poly.interiors: + self.plot_temp_shapes(margin_poly.exterior) + for ints in margin_poly.interiors: geoms.insert(ints) if prog_plot: self.plot_temp_shapes(ints) @@ -1508,7 +1522,9 @@ class Geometry(object): # Optimization: Reduce lifts if connect: # log.debug("Reducing tool lifts...") - geoms = Geometry.paint_connect(geoms, polygon, tooldia, steps_per_circle) + geoms_conn = Geometry.paint_connect(geoms, polygon, tooldia, steps_per_circle) + if geoms_conn: + return geoms_conn return geoms @@ -1581,8 +1597,14 @@ class Geometry(object): optimized_paths.get_points = get_pts path_count = 0 current_pt = (0, 0) - pt, geo = storage.nearest(current_pt) + try: + pt, geo = storage.nearest(current_pt) + except StopIteration: + log.debug("camlib.Geometry.paint_connect(). Storage empty") + return None + storage.remove(geo) + geo = LineString(geo) current_pt = geo.coords[-1] try: @@ -1592,6 +1614,7 @@ class Geometry(object): pt, candidate = storage.nearest(current_pt) storage.remove(candidate) + candidate = LineString(candidate) # If last point in geometry is the nearest diff --git a/flatcamTools/ToolNonCopperClear.py b/flatcamTools/ToolNonCopperClear.py index f443e931..07c99879 100644 --- a/flatcamTools/ToolNonCopperClear.py +++ b/flatcamTools/ToolNonCopperClear.py @@ -1811,7 +1811,38 @@ class NonCopperClear(FlatCAMTool, Gerber): # graceful abort requested by the user raise FlatCAMApp.GracefulException if p is not None: + poly_processed = list() try: + for pol in p: + if pol is not None and isinstance(pol, Polygon): + if ncc_method == 'standard': + cp = self.clear_polygon(pol, tool, + self.grb_circle_steps, + overlap=overlap, contour=contour, + connect=connect, + prog_plot=prog_plot) + elif ncc_method == 'seed': + cp = self.clear_polygon2(pol, tool, + self.grb_circle_steps, + overlap=overlap, contour=contour, + connect=connect, + prog_plot=prog_plot) + else: + cp = self.clear_polygon3(pol, tool, + self.grb_circle_steps, + overlap=overlap, contour=contour, + connect=connect, + prog_plot=prog_plot) + if cp: + cleared_geo += list(cp.get_objects()) + poly_processed.append(True) + else: + poly_processed.append(False) + log.warning("Polygon in MultiPolygon can not be cleared.") + else: + log.warning("Geo in Iterable can not be cleared beacuse it is not Polygon. " + "It is: %s" % str(type(pol))) + except TypeError: if isinstance(p, Polygon): if ncc_method == 'standard': cp = self.clear_polygon(p, tool, self.grb_circle_steps, @@ -1827,32 +1858,20 @@ class NonCopperClear(FlatCAMTool, Gerber): prog_plot=prog_plot) if cp: cleared_geo += list(cp.get_objects()) - elif isinstance(p, MultiPolygon): - for pol in p: - if pol is not None: - if ncc_method == 'standard': - cp = self.clear_polygon(pol, tool, - self.grb_circle_steps, - overlap=overlap, contour=contour, - connect=connect, - prog_plot=prog_plot) - elif ncc_method == 'seed': - cp = self.clear_polygon2(pol, tool, - self.grb_circle_steps, - overlap=overlap, contour=contour, - connect=connect, - prog_plot=prog_plot) - else: - cp = self.clear_polygon3(pol, tool, - self.grb_circle_steps, - overlap=overlap, contour=contour, - connect=connect, - prog_plot=prog_plot) - if cp: - cleared_geo += list(cp.get_objects()) - except Exception as e: - log.warning("Polygon can not be cleared. %s" % str(e)) + poly_processed.append(True) + else: + poly_processed.append(False) + log.warning("Polygon can not be cleared.") + else: + 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) + + if p_not_cleared: app_obj.poly_not_cleared = True + + if p_cleared == 0: continue pol_nr += 1