浏览代码

- in NCC Tool I've added a warning so the user is warned that the NCC margin has to have a value of at least the tool diameter that is doing an iso_op job in the Tool Table

Marius Stanciu 6 年之前
父节点
当前提交
a738ed7305
共有 3 个文件被更改,包括 105 次插入69 次删除
  1. 1 1
      README.md
  2. 104 67
      flatcamTools/ToolNonCopperClear.py
  3. 0 1
      tclCommands/TclCommandDrillcncjob.py

+ 1 - 1
README.md

@@ -14,7 +14,7 @@ CAD program, and create G-Code for Isolation routing.
 - fixed bug in NCC Tool: after trying to add a tool already in the Tool Table when trying to change the Tool Type the GUI does not change
 - fixed bug in NCC Tool: after trying to add a tool already in the Tool Table when trying to change the Tool Type the GUI does not change
 - final fix for app not quiting when running a script as argument, script that has the quit_flatcam Tcl command; fixed issue #360
 - final fix for app not quiting when running a script as argument, script that has the quit_flatcam Tcl command; fixed issue #360
 - fixed issue #363. The Tcl command drillcncjob does not create tool cut, does not allow creation of gcode, it forces the usage of dwell and dwelltime parameters
 - fixed issue #363. The Tcl command drillcncjob does not create tool cut, does not allow creation of gcode, it forces the usage of dwell and dwelltime parameters
-
+- in NCC Tool I've added a warning so the user is warned that the NCC margin has to have a value of at least the tool diameter that is doing an iso_op job in the Tool Table
 
 
 30.12.2019
 30.12.2019
 
 

+ 104 - 67
flatcamTools/ToolNonCopperClear.py

@@ -1626,6 +1626,11 @@ class NonCopperClear(FlatCAMTool, Gerber):
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 if empty == 'fail':
                 if empty == 'fail':
                     return 'fail'
                     return 'fail'
+
+                if empty.is_empty:
+                    app_obj.inform.emit('[ERROR_NOTCL] %s' %
+                                        _("Could not get the extent of the area to be non copper cleared."))
+                    return 'fail'
             elif isinstance(ncc_obj, FlatCAMGerber) and isotooldia:
             elif isinstance(ncc_obj, FlatCAMGerber) and isotooldia:
                 isolated_geo = []
                 isolated_geo = []
 
 
@@ -1650,6 +1655,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
                     if isolated_geo == 'fail':
                     if isolated_geo == 'fail':
                         app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
                         app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
                     else:
                     else:
+                        if ncc_margin < tool_iso:
+                            app_obj.inform.emit('[WARNING_NOTCL] %s' % _("Isolation geometry is broken. Margin is less "
+                                                                         "than isolation tool diameter."))
                         try:
                         try:
                             for geo_elem in isolated_geo:
                             for geo_elem in isolated_geo:
                                 # provide the app with a way to process the GUI events when in a blocking loop
                                 # provide the app with a way to process the GUI events when in a blocking loop
@@ -1723,26 +1731,28 @@ class NonCopperClear(FlatCAMTool, Gerber):
                 if empty == 'fail':
                 if empty == 'fail':
                     return 'fail'
                     return 'fail'
 
 
+                if empty.is_empty:
+                    app_obj.inform.emit('[ERROR_NOTCL] %s' %
+                                        _("Isolation geometry is broken. Margin is less than isolation tool diameter."))
+                    return 'fail'
+
             elif isinstance(ncc_obj, FlatCAMGeometry):
             elif isinstance(ncc_obj, FlatCAMGeometry):
                 sol_geo = cascaded_union(ncc_obj.solid_geometry)
                 sol_geo = cascaded_union(ncc_obj.solid_geometry)
                 if has_offset is True:
                 if has_offset is True:
-                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' %
-                                        _("Buffering"))
+                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' % _("Buffering"))
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
-                    app_obj.inform.emit('[success] %s ...' %
-                                        _("Buffering finished"))
+                    app_obj.inform.emit('[success] %s ...' %  _("Buffering finished"))
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 if empty == 'fail':
                 if empty == 'fail':
                     return 'fail'
                     return 'fail'
 
 
-            else:
-                app_obj.inform.emit('[ERROR_NOTCL] %s' %
-                                    _('The selected object is not suitable for copper clearing.'))
-                return
+                if empty.is_empty:
+                    app_obj.inform.emit('[ERROR_NOTCL] %s' %
+                                        _("Could not get the extent of the area to be non copper cleared."))
+                    return 'fail'
 
 
-            if empty.is_empty:
-                app_obj.inform.emit('[ERROR_NOTCL] %s' %
-                                    _("Could not get the extent of the area to be non copper cleared."))
+            else:
+                app_obj.inform.emit('[ERROR_NOTCL] %s' %  _('The selected object is not suitable for copper clearing.'))
                 return 'fail'
                 return 'fail'
 
 
             if type(empty) is Polygon:
             if type(empty) is Polygon:
@@ -1762,11 +1772,8 @@ class NonCopperClear(FlatCAMTool, Gerber):
                 # provide the app with a way to process the GUI events when in a blocking loop
                 # provide the app with a way to process the GUI events when in a blocking loop
                 QtWidgets.QApplication.processEvents()
                 QtWidgets.QApplication.processEvents()
 
 
-                app_obj.inform.emit(
-                    '[success] %s %s%s %s' % (_('NCC Tool clearing with tool diameter = '),
-                                              str(tool),
-                                              units.lower(),
-                                              _('started.'))
+                app_obj.inform.emit('[success] %s = %s%s %s' % (
+                    _('NCC Tool clearing with tool diameter'), str(tool), units.lower(), _('started.'))
                 )
                 )
                 app_obj.proc_container.update_view_text(' %d%%' % 0)
                 app_obj.proc_container.update_view_text(' %d%%' % 0)
 
 
@@ -1836,7 +1843,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
                                                 poly_processed.append(False)
                                                 poly_processed.append(False)
                                                 log.warning("Polygon in MultiPolygon can not be cleared.")
                                                 log.warning("Polygon in MultiPolygon can not be cleared.")
                                         else:
                                         else:
-                                            log.warning("Geo in Iterable can not be cleared beacuse it is not Polygon. "
+                                            log.warning("Geo in Iterable can not be cleared because it is not Polygon. "
                                                         "It is: %s" % str(type(pol)))
                                                         "It is: %s" % str(type(pol)))
                                 except TypeError:
                                 except TypeError:
                                     if isinstance(p, Polygon):
                                     if isinstance(p, Polygon):
@@ -1942,32 +1949,59 @@ class NonCopperClear(FlatCAMTool, Gerber):
                 if geo_obj.tools[tooluid]['solid_geometry']:
                 if geo_obj.tools[tooluid]['solid_geometry']:
                     has_solid_geo += 1
                     has_solid_geo += 1
             if has_solid_geo == 0:
             if has_solid_geo == 0:
-                app_obj.inform.emit('[ERROR] %s' % _("There is no NCC Geometry in the file.\n"
-                                                     "Usually it means that the tool diameter is too big "
-                                                     "for the painted geometry.\n"
-                                                     "Change the painting parameters and try again."))
-                return
+                app_obj.inform.emit('[ERROR] %s' %
+                                    _("There is no NCC Geometry in the file.\n"
+                                      "Usually it means that the tool diameter is too big for the painted geometry.\n"
+                                      "Change the painting parameters and try again."))
+                return 'fail'
 
 
-            # create the solid_geometry
-            geo_obj.solid_geometry = list()
-            for tooluid in geo_obj.tools:
-                if geo_obj.tools[tooluid]['solid_geometry']:
-                    try:
-                        for geo in geo_obj.tools[tooluid]['solid_geometry']:
-                            geo_obj.solid_geometry.append(geo)
-                    except TypeError:
-                        geo_obj.solid_geometry.append(geo_obj.tools[tooluid]['solid_geometry'])
-
-            # Experimental...
-            # print("Indexing...", end=' ')
-            # geo_obj.make_index()
-            if warning_flag == 0:
-                self.app.inform.emit('[success] %s' % _("NCC Tool clear all done."))
+            # check to see if geo_obj.tools is empty
+            # it will be updated only if there is a solid_geometry for tools
+            if geo_obj.tools:
+                if warning_flag == 0:
+                    self.app.inform.emit('[success] %s' % _("NCC Tool clear all done."))
+                else:
+                    self.app.inform.emit('[WARNING] %s: %s %s.' % (
+                        _("NCC Tool clear all done but the copper features isolation is broken for"),
+                        str(warning_flag),
+                        _("tools")))
+                    return
+
+                # create the solid_geometry
+                geo_obj.solid_geometry = list()
+                for tooluid in geo_obj.tools:
+                    if geo_obj.tools[tooluid]['solid_geometry']:
+                        try:
+                            for geo in geo_obj.tools[tooluid]['solid_geometry']:
+                                geo_obj.solid_geometry.append(geo)
+                        except TypeError:
+                            geo_obj.solid_geometry.append(geo_obj.tools[tooluid]['solid_geometry'])
             else:
             else:
-                self.app.inform.emit('[WARNING] %s: %s %s.' % (_("NCC Tool clear all done but the copper features "
-                                                                 "isolation is broken for"),
-                                                               str(warning_flag),
-                                                               _("tools")))
+                # I will use this variable for this purpose although it was meant for something else
+                # signal that we have no geo in the object therefore don't create it
+                app_obj.poly_not_cleared = False
+                return "fail"
+
+            # create the solid_geometry
+            # geo_obj.solid_geometry = list()
+            # for tooluid in geo_obj.tools:
+            #     if geo_obj.tools[tooluid]['solid_geometry']:
+            #         try:
+            #             for geo in geo_obj.tools[tooluid]['solid_geometry']:
+            #                 geo_obj.solid_geometry.append(geo)
+            #         except TypeError:
+            #             geo_obj.solid_geometry.append(geo_obj.tools[tooluid]['solid_geometry'])
+            #
+            # # Experimental...
+            # # print("Indexing...", end=' ')
+            # # geo_obj.make_index()
+            # if warning_flag == 0:
+            #     self.app.inform.emit('[success] %s' % _("NCC Tool clear all done."))
+            # else:
+            #     self.app.inform.emit('[WARNING] %s: %s %s.' % (
+            #         _("NCC Tool clear all done but the copper features isolation is broken for"),
+            #         str(warning_flag),
+            #         _("tools")))
 
 
         # ###########################################################################################
         # ###########################################################################################
         # Initializes the new geometry object for the case of the rest-machining ####################
         # Initializes the new geometry object for the case of the rest-machining ####################
@@ -2009,15 +2043,17 @@ class NonCopperClear(FlatCAMTool, Gerber):
             if isinstance(ncc_obj, FlatCAMGerber) and not isotooldia:
             if isinstance(ncc_obj, FlatCAMGerber) and not isotooldia:
                 sol_geo = ncc_obj.solid_geometry
                 sol_geo = ncc_obj.solid_geometry
                 if has_offset is True:
                 if has_offset is True:
-                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' %
-                                        _("Buffering"))
+                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' % _("Buffering"))
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
-                    app_obj.inform.emit('[success] %s ...' %
-                                        _("Buffering finished"))
+                    app_obj.inform.emit('[success] %s ...' %  _("Buffering finished"))
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 if empty == 'fail':
                 if empty == 'fail':
                     return 'fail'
                     return 'fail'
 
 
+                if empty.is_empty:
+                    app_obj.inform.emit('[ERROR_NOTCL] %s' %
+                                        _("Could not get the extent of the area to be non copper cleared."))
+                    return 'fail'
             elif isinstance(ncc_obj, FlatCAMGerber) and isotooldia:
             elif isinstance(ncc_obj, FlatCAMGerber) and isotooldia:
                 isolated_geo = []
                 isolated_geo = []
                 self.solid_geometry = ncc_obj.solid_geometry
                 self.solid_geometry = ncc_obj.solid_geometry
@@ -2036,6 +2072,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
                     if isolated_geo == 'fail':
                     if isolated_geo == 'fail':
                         app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
                         app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
                     else:
                     else:
+                        app_obj.inform.emit('[WARNING_NOTCL] %s' % _("Isolation geometry is broken. Margin is less "
+                                                                     "than isolation tool diameter."))
+
                         try:
                         try:
                             for geo_elem in isolated_geo:
                             for geo_elem in isolated_geo:
                                 # provide the app with a way to process the GUI events when in a blocking loop
                                 # provide the app with a way to process the GUI events when in a blocking loop
@@ -2105,36 +2144,36 @@ class NonCopperClear(FlatCAMTool, Gerber):
 
 
                 sol_geo = cascaded_union(isolated_geo)
                 sol_geo = cascaded_union(isolated_geo)
                 if has_offset is True:
                 if has_offset is True:
-                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' %
-                                        _("Buffering"))
+                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' % _("Buffering"))
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
-                    app_obj.inform.emit('[success] %s ...' %
-                                        _("Buffering finished"))
+                    app_obj.inform.emit('[success] %s ...' % _("Buffering finished"))
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 if empty == 'fail':
                 if empty == 'fail':
                     return 'fail'
                     return 'fail'
 
 
+                if empty.is_empty:
+                    app_obj.inform.emit('[ERROR_NOTCL] %s' %
+                                        _("Isolation geometry is broken. Margin is less than isolation tool diameter."))
+                    return 'fail'
+
             elif isinstance(ncc_obj, FlatCAMGeometry):
             elif isinstance(ncc_obj, FlatCAMGeometry):
                 sol_geo = cascaded_union(ncc_obj.solid_geometry)
                 sol_geo = cascaded_union(ncc_obj.solid_geometry)
                 if has_offset is True:
                 if has_offset is True:
-                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' %
-                                        _("Buffering"))
+                    app_obj.inform.emit('[WARNING_NOTCL] %s ...' % _("Buffering"))
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
                     sol_geo = sol_geo.buffer(distance=ncc_offset)
-                    app_obj.inform.emit('[success] %s ...' %
-                                        _("Buffering finished"))
+                    app_obj.inform.emit('[success] %s ...' % _("Buffering finished"))
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 empty = self.get_ncc_empty_area(target=sol_geo, boundary=bounding_box)
                 if empty == 'fail':
                 if empty == 'fail':
                     return 'fail'
                     return 'fail'
+
+                if empty.is_empty:
+                    app_obj.inform.emit('[ERROR_NOTCL] %s' %
+                                        _("Could not get the extent of the area to be non copper cleared."))
+                    return 'fail'
             else:
             else:
-                app_obj.inform.emit('[ERROR_NOTCL] %s' %
-                                    _('The selected object is not suitable for copper clearing.'))
+                app_obj.inform.emit('[ERROR_NOTCL] %s' % _('The selected object is not suitable for copper clearing.'))
                 return
                 return
 
 
-            if empty.is_empty:
-                app_obj.inform.emit('[ERROR_NOTCL] %s' %
-                                    _("Could not get the extent of the area to be non copper cleared."))
-                return 'fail'
-
             if self.app.abort_flag:
             if self.app.abort_flag:
                 # graceful abort requested by the user
                 # graceful abort requested by the user
                 raise FlatCAMApp.GracefulException
                 raise FlatCAMApp.GracefulException
@@ -2156,11 +2195,8 @@ class NonCopperClear(FlatCAMTool, Gerber):
                 tool = sorted_tools.pop(0)
                 tool = sorted_tools.pop(0)
                 log.debug("Starting geometry processing for tool: %s" % str(tool))
                 log.debug("Starting geometry processing for tool: %s" % str(tool))
 
 
-                app_obj.inform.emit(
-                    '[success] %s %s%s %s' % (_('NCC Tool clearing with tool diameter = '),
-                                              str(tool),
-                                              units.lower(),
-                                              _('started.'))
+                app_obj.inform.emit('[success] %s = %s%s %s' % (
+                    _('NCC Tool clearing with tool diameter'), str(tool), units.lower(), _('started.'))
                 )
                 )
                 app_obj.proc_container.update_view_text(' %d%%' % 0)
                 app_obj.proc_container.update_view_text(' %d%%' % 0)
 
 
@@ -2240,7 +2276,8 @@ class NonCopperClear(FlatCAMTool, Gerber):
                                 elif isinstance(p, MultiPolygon):
                                 elif isinstance(p, MultiPolygon):
                                     for poly in p:
                                     for poly in p:
                                         if poly is not None:
                                         if poly is not None:
-                                            # provide the app with a way to process the GUI events when in a blocking loop
+                                            # provide the app with a way to process the GUI events when
+                                            # in a blocking loop
                                             QtWidgets.QApplication.processEvents()
                                             QtWidgets.QApplication.processEvents()
 
 
                                             try:
                                             try:
@@ -2337,7 +2374,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
                     self.app.inform.emit(
                     self.app.inform.emit(
                         '[WARNING] %s: %s %s.' % (_("NCC Tool Rest Machining clear all done but the copper features "
                         '[WARNING] %s: %s %s.' % (_("NCC Tool Rest Machining clear all done but the copper features "
                                                     "isolation is broken for"), str(warning_flag), _("tools")))
                                                     "isolation is broken for"), str(warning_flag), _("tools")))
-                return
+                    return
 
 
                 # create the solid_geometry
                 # create the solid_geometry
                 geo_obj.solid_geometry = list()
                 geo_obj.solid_geometry = list()

+ 0 - 1
tclCommands/TclCommandDrillcncjob.py

@@ -221,7 +221,6 @@ class TclCommandDrillcncjob(TclCommandSignaled):
                 # for now there is no tool offset support in this Tcl Command so we write the 0.0 value here
                 # for now there is no tool offset support in this Tcl Command so we write the 0.0 value here
                 job_obj.tool_offset[t_item] = 0.0
                 job_obj.tool_offset[t_item] = 0.0
 
 
-            print(job_obj.tool_offset)
             job_obj.origin_kind = 'excellon'
             job_obj.origin_kind = 'excellon'
 
 
             job_obj.gcode_parse()
             job_obj.gcode_parse()