Преглед изворни кода

- 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

Marius Stanciu пре 6 година
родитељ
комит
6c2d628c6c
4 измењених фајлова са 120 додато и 76 уклоњено
  1. 3 3
      FlatCAMApp.py
  2. 2 0
      README.md
  3. 71 48
      camlib.py
  4. 44 25
      flatcamTools/ToolNonCopperClear.py

+ 3 - 3
FlatCAMApp.py

@@ -140,8 +140,8 @@ class App(QtCore.QObject):
     # ##########################################################################
     # ##########################################################################
     # ################## Version and VERSION DATE ##############################
     # ################## Version and VERSION DATE ##############################
     # ##########################################################################
     # ##########################################################################
-    version = 8.99
-    version_date = "2019/12/15"
+    version = 8.991
+    version_date = "2019/12/30"
     beta = True
     beta = True
     engine = '3D'
     engine = '3D'
 
 
@@ -3813,7 +3813,7 @@ class App(QtCore.QObject):
 
 
         if 'version' not in defaults or defaults['version'] != self.defaults['version']:
         if 'version' not in defaults or defaults['version'] != self.defaults['version']:
             for k, v in defaults.items():
             for k, v in defaults.items():
-                if k in self.defaults:
+                if k in self.defaults and k != 'version':
                     self.defaults[k] = v
                     self.defaults[k] = v
 
 
             # delete old factory defaults
             # delete old factory defaults

+ 2 - 0
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
 - 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
 - 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
 15.12.2019
 
 

+ 71 - 48
camlib.py

@@ -1381,9 +1381,10 @@ class Geometry(object):
                     inner_edges.append(y)
                     inner_edges.append(y)
             # geoms += outer_edges + inner_edges
             # geoms += outer_edges + inner_edges
             for g in 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:
         if prog_plot:
             self.temp_shapes.redraw()
             self.temp_shapes.redraw()
@@ -1395,7 +1396,9 @@ class Geometry(object):
         # Optimization: Reduce lifts
         # Optimization: Reduce lifts
         if connect:
         if connect:
             # log.debug("Reducing tool lifts...")
             # 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
         return geoms
 
 
@@ -1419,6 +1422,9 @@ class Geometry(object):
         """
         """
 
 
         # log.debug("camlib.clear_polygon3()")
         # 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
         # ## The toolpaths
         # Index first and last points in paths
         # Index first and last points in paths
@@ -1433,41 +1439,43 @@ class Geometry(object):
         # Bounding box
         # Bounding box
         left, bot, right, top = polygon.bounds
         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
         # 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 = LineString([(left, y), (right, y)])
             line = line.intersection(margin_poly)
             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:
         if prog_plot:
             self.temp_shapes.redraw()
             self.temp_shapes.redraw()
@@ -1477,27 +1485,33 @@ class Geometry(object):
         # Add lines to storage
         # Add lines to storage
         try:
         try:
             for line in lines_trimmed:
             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:
         except TypeError:
             # in case lines_trimmed are not iterable (Linestring, LinearRing)
             # in case lines_trimmed are not iterable (Linestring, LinearRing)
             geoms.insert(lines_trimmed)
             geoms.insert(lines_trimmed)
 
 
         # Add margin (contour) to storage
         # Add margin (contour) to storage
         if contour:
         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:
                 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:
                     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)
                         geoms.insert(ints)
                         if prog_plot:
                         if prog_plot:
                             self.plot_temp_shapes(ints)
                             self.plot_temp_shapes(ints)
@@ -1508,7 +1522,9 @@ class Geometry(object):
         # Optimization: Reduce lifts
         # Optimization: Reduce lifts
         if connect:
         if connect:
             # log.debug("Reducing tool lifts...")
             # 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
         return geoms
 
 
@@ -1581,8 +1597,14 @@ class Geometry(object):
         optimized_paths.get_points = get_pts
         optimized_paths.get_points = get_pts
         path_count = 0
         path_count = 0
         current_pt = (0, 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)
         storage.remove(geo)
+
         geo = LineString(geo)
         geo = LineString(geo)
         current_pt = geo.coords[-1]
         current_pt = geo.coords[-1]
         try:
         try:
@@ -1592,6 +1614,7 @@ class Geometry(object):
 
 
                 pt, candidate = storage.nearest(current_pt)
                 pt, candidate = storage.nearest(current_pt)
                 storage.remove(candidate)
                 storage.remove(candidate)
+
                 candidate = LineString(candidate)
                 candidate = LineString(candidate)
 
 
                 # If last point in geometry is the nearest
                 # If last point in geometry is the nearest

+ 44 - 25
flatcamTools/ToolNonCopperClear.py

@@ -1811,7 +1811,38 @@ class NonCopperClear(FlatCAMTool, Gerber):
                                 # graceful abort requested by the user
                                 # graceful abort requested by the user
                                 raise FlatCAMApp.GracefulException
                                 raise FlatCAMApp.GracefulException
                             if p is not None:
                             if p is not None:
+                                poly_processed = list()
                                 try:
                                 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 isinstance(p, Polygon):
                                         if ncc_method == 'standard':
                                         if ncc_method == 'standard':
                                             cp = self.clear_polygon(p, tool, self.grb_circle_steps,
                                             cp = self.clear_polygon(p, tool, self.grb_circle_steps,
@@ -1827,32 +1858,20 @@ class NonCopperClear(FlatCAMTool, Gerber):
                                                                      prog_plot=prog_plot)
                                                                      prog_plot=prog_plot)
                                         if cp:
                                         if cp:
                                             cleared_geo += list(cp.get_objects())
                                             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
                                     app_obj.poly_not_cleared = True
+
+                                if p_cleared == 0:
                                     continue
                                     continue
 
 
                                 pol_nr += 1
                                 pol_nr += 1