فهرست منبع

- modified the export_gcode() method and the preprocessors such that the preprocessors now have the information if to include the gcode header
- RELEASE 8.99

Marius Stanciu 6 سال پیش
والد
کامیت
7ad091e163

+ 144 - 75
FlatCAMObj.py

@@ -6621,10 +6621,12 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         :param to_file: if False then no actual file is saved but the app will know that a file was created
         :return: None
         """
-        gcode = ''
-        roland = False
-        hpgl = False
-        isel_icp = False
+        # gcode = ''
+        # roland = False
+        # hpgl = False
+        # isel_icp = False
+
+        include_header = True
 
         try:
             if self.special_group:
@@ -6636,86 +6638,153 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         except AttributeError:
             pass
 
-        # detect if using Roland preprocessor
-        try:
-            for key in self.cnc_tools:
-                if self.cnc_tools[key]['data']['ppname_g'] == 'Roland_MDX_20':
-                    roland = True
-                    break
-        except Exception:
-            try:
-                for key in self.cnc_tools:
-                    if self.cnc_tools[key]['data']['ppname_e'] == 'Roland_MDX_20':
-                        roland = True
-                        break
-            except Exception:
-                pass
+        # if this dict is not empty then the object is a Geometry object
+        if self.cnc_tools:
+            first_key = next(iter(self.cnc_tools))
+            include_header = self.app.preprocessors[self.cnc_tools[first_key]['data']['ppname_g']].include_header
 
-        # detect if using HPGL preprocessor
-        try:
-            for key in self.cnc_tools:
-                if self.cnc_tools[key]['data']['ppname_g'] == 'hpgl':
-                    hpgl = True
-                    break
-        except Exception:
-            try:
-                for key in self.cnc_tools:
-                    if self.cnc_tools[key]['data']['ppname_e'] == 'hpgl':
-                        hpgl = True
-                        break
-            except Exception:
-                pass
+        # if this dict is not empty then the object is an Excellon object
+        if self.exc_cnc_tools:
+            first_key = next(iter(self.exc_cnc_tools))
+            include_header = self.app.preprocessors[self.exc_cnc_tools[first_key]['data']['ppname_e']].include_header
 
-        # detect if using ISEL_ICP_CNC preprocessor
-        try:
-            for key in self.cnc_tools:
-                if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_g'].upper():
-                    isel_icp = True
-                    break
-        except Exception:
-            try:
-                for key in self.cnc_tools:
-                    if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_e'].upper():
-                        isel_icp = True
-                        break
-            except Exception:
-                pass
+        # # detect if using Roland preprocessor
+        # try:
+        #     for key in self.cnc_tools:
+        #         if self.cnc_tools[key]['data']['ppname_g'] == 'Roland_MDX_20':
+        #             roland = True
+        #             break
+        # except Exception:
+        #     try:
+        #         for key in self.cnc_tools:
+        #             if self.cnc_tools[key]['data']['ppname_e'] == 'Roland_MDX_20':
+        #                 roland = True
+        #                 break
+        #     except Exception:
+        #         pass
+        #
+        # # detect if using HPGL preprocessor
+        # try:
+        #     for key in self.cnc_tools:
+        #         if self.cnc_tools[key]['data']['ppname_g'] == 'hpgl':
+        #             hpgl = True
+        #             break
+        # except Exception:
+        #     try:
+        #         for key in self.cnc_tools:
+        #             if self.cnc_tools[key]['data']['ppname_e'] == 'hpgl':
+        #                 hpgl = True
+        #                 break
+        #     except Exception:
+        #         pass
+        #
+        # # detect if using ISEL_ICP_CNC preprocessor
+        # try:
+        #     for key in self.cnc_tools:
+        #         if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_g'].upper():
+        #             isel_icp = True
+        #             break
+        # except Exception:
+        #     try:
+        #         for key in self.cnc_tools:
+        #             if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_e'].upper():
+        #                 isel_icp = True
+        #                 break
+        #     except Exception:
+        #         pass
 
         # do not add gcode_header when using the Roland preprocessor, add it for every other preprocessor
-        if roland is False and hpgl is False and isel_icp is False:
-            gcode = self.gcode_header()
-
-        # detect if using multi-tool and make the Gcode summation correctly for each case
-        if self.multitool is True:
-            for tooluid_key in self.cnc_tools:
-                for key, value in self.cnc_tools[tooluid_key].items():
-                    if key == 'gcode':
-                        gcode += value
-                        break
-        else:
-            gcode += self.gcode
+        # if roland is False and hpgl is False and isel_icp is False:
+        #     gcode = self.gcode_header()
 
-        if roland is True:
-            g = preamble + gcode + postamble
-        elif hpgl is True:
-            g = self.gcode_header() + preamble + gcode + postamble
+        # do not add gcode_header when using the Roland, HPGL or ISEP_ICP_CNC preprocessor (or any other preprocessor
+        # that has the include_header attribute set as False, add it for every other preprocessor
+        # if include_header:
+        #     gcode = self.gcode_header()
+        # else:
+        #     gcode = ''
+
+        # # detect if using multi-tool and make the Gcode summation correctly for each case
+        # if self.multitool is True:
+        #     for tooluid_key in self.cnc_tools:
+        #         for key, value in self.cnc_tools[tooluid_key].items():
+        #             if key == 'gcode':
+        #                 gcode += value
+        #                 break
+        # else:
+        #     gcode += self.gcode
+
+        # if roland is True:
+        #     g = preamble + gcode + postamble
+        # elif hpgl is True:
+        #     g = self.gcode_header() + preamble + gcode + postamble
+        # else:
+        #     # fix so the preamble gets inserted in between the comments header and the actual start of GCODE
+        #     g_idx = gcode.rfind('G20')
+        #
+        #     # if it did not find 'G20' then search for 'G21'
+        #     if g_idx == -1:
+        #         g_idx = gcode.rfind('G21')
+        #
+        #     # if it did not find 'G20' and it did not find 'G21' then there is an error and return
+        #     # but only when the preprocessor is not ISEL_ICP who is allowed not to have the G20/G21 command
+        #     if g_idx == -1 and isel_icp is False:
+        #         self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
+        #         return
+        #
+        #     footer = self.app.defaults['cncjob_footer']
+        #     end_gcode = self.gcode_footer() if footer is True else ''
+        #     g = gcode[:g_idx] + preamble + '\n' + gcode[g_idx:] + postamble + end_gcode
+
+        gcode = ''
+        if include_header is False:
+            g = preamble
+            # detect if using multi-tool and make the Gcode summation correctly for each case
+            if self.multitool is True:
+                for tooluid_key in self.cnc_tools:
+                    for key, value in self.cnc_tools[tooluid_key].items():
+                        if key == 'gcode':
+                            gcode += value
+                            break
+            else:
+                gcode += self.gcode
+
+            g = g + gcode + postamble
         else:
+            # search for the GCode beginning which is usually a G20 or G21
             # fix so the preamble gets inserted in between the comments header and the actual start of GCODE
-            g_idx = gcode.rfind('G20')
-
-            # if it did not find 'G20' then search for 'G21'
-            if g_idx == -1:
-                g_idx = gcode.rfind('G21')
+            # g_idx = gcode.rfind('G20')
+            #
+            # # if it did not find 'G20' then search for 'G21'
+            # if g_idx == -1:
+            #     g_idx = gcode.rfind('G21')
+            #
+            # # if it did not find 'G20' and it did not find 'G21' then there is an error and return
+            # if g_idx == -1:
+            #     self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
+            #     return
+
+            # detect if using multi-tool and make the Gcode summation correctly for each case
+            if self.multitool is True:
+                for tooluid_key in self.cnc_tools:
+                    for key, value in self.cnc_tools[tooluid_key].items():
+                        if key == 'gcode':
+                            gcode += value
+                            break
+            else:
+                gcode += self.gcode
 
-            # if it did not find 'G20' and it did not find 'G21' then there is an error and return
-            # but only when the preprocessor is not ISEL_ICP who is allowed not to have the G20/G21 command
-            if g_idx == -1 and isel_icp is False:
-                self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
-                return
+            end_gcode = self.gcode_footer() if self.app.defaults['cncjob_footer'] is True else ''
 
-            footer = self.app.defaults['cncjob_footer']
-            end_gcode = self.gcode_footer() if footer is True else ''
-            g = gcode[:g_idx] + preamble + '\n' + gcode[g_idx:] + postamble + end_gcode
+            try:
+                g_idx = gcode.index('G94')
+                g = self.gcode_header() + gcode[:g_idx + 3] + '\n\n' + preamble + '\n' + \
+                    gcode[(g_idx + 3):] + postamble + end_gcode
+            except ValueError:
+                self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                     _("G-code does not have a G94 code and we will not include the code in the "
+                                       "'Prepend to GCode' text box"))
+                g = self.gcode_header() + '\n' + gcode + postamble + end_gcode
 
         # if toolchange custom is used, replace M6 code with the code from the Toolchange Custom Text box
         if self.ui.toolchange_cb.get_value() is True:

+ 1 - 0
README.md

@@ -19,6 +19,7 @@ CAD program, and create G-Code for Isolation routing.
 - fixed layout on first launch of the app
 - fixed some issues with the recent preparation for dark icons resource usage
 - added a new preprocessor file contributed by Daniel Friderich and added fixes for it
+- modified the export_gcode() method and the preprocessors such that the preprocessors now have the information if to include the gcode header
 - RELEASE 8.99
 
 14.12.2019

+ 6 - 0
camlib.py

@@ -2448,11 +2448,17 @@ class CNCjob(Geometry):
                     except KeyError:
                         z_off = 0
 
+                    default_data = dict()
+                    for k, v in list(self.options.items()):
+                        default_data[k] = deepcopy(v)
+
                     self.exc_cnc_tools[it[1]] = dict()
                     self.exc_cnc_tools[it[1]]['tool'] = it[0]
                     self.exc_cnc_tools[it[1]]['nr_drills'] = drill_no
                     self.exc_cnc_tools[it[1]]['nr_slots'] = slot_no
                     self.exc_cnc_tools[it[1]]['offset_z'] = z_off
+                    self.exc_cnc_tools[it[1]]['data'] = default_data
+
                     self.exc_cnc_tools[it[1]]['solid_geometry'] = deepcopy(sol_geo)
 
         self.app.inform.emit(_("Creating a list of points to drill..."))

+ 6 - 3
preprocessors/Berta_CNC.py

@@ -14,6 +14,8 @@ from FlatCAMPostProc import *
 
 
 class Berta_CNC(FlatCAMPostProc):
+
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 
@@ -66,18 +68,19 @@ class Berta_CNC(FlatCAMPostProc):
 
         gcode += '(Spindle Speed: %s RPM)\n' % str(p['spindlespeed'])
 
-        gcode += '(Berta)\n'
-        gcode += 'G90 G94 G17 G91.1'
         gcode += (
             # This line allow you to sets the machine to METRIC / INCH in the GUI
-            'G20\n' if p.units.upper() == 'IN' else 'G21\n')
+            'G20\n' if p.units.upper() == 'IN' else 'G21\n') + '\n'
         #        gcode += 'G21\n' # This line sets the machine to METRIC ONLY
         #        gcode += 'G20\n' # This line sets the machine to INCH ONLY
+
+        gcode += 'G90 G17 G91.1\n'
         gcode += 'G64 P0.03\n'
         gcode += 'M110\n'
         gcode += 'G54\n'
         gcode += 'G0\n'
         gcode += '(Berta)\n'
+        gcode += 'G94\n'
 
         return gcode
 

+ 1 - 1
preprocessors/ISEL_CNC.py

@@ -10,7 +10,7 @@ from FlatCAMPostProc import *
 
 
 class ISEL_CNC(FlatCAMPostProc):
-
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 

+ 4 - 1
preprocessors/ISEL_ICP_CNC.py

@@ -9,7 +9,10 @@
 from FlatCAMPostProc import *
 
 
-class ISEL_ICP_CNC(FlatCAMPostProc):    
+class ISEL_ICP_CNC(FlatCAMPostProc):
+
+    include_header = False
+
     def start_code(self, p):
         units = ' ' + str(p['units']).lower()
         coords_xy = p['xy_toolchange']

+ 1 - 0
preprocessors/Paste_1.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class Paste_1(FlatCAMPostProc_Tools):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 

+ 2 - 0
preprocessors/Repetier.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class Repetier(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
     feedrate_rapid_format = feedrate_format
@@ -66,6 +67,7 @@ class Repetier(FlatCAMPostProc):
 
         gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
         gcode += 'G90\n'
+        gcode += 'G94\n'
 
         return gcode
 

+ 1 - 0
preprocessors/Roland_MDX_20.py

@@ -13,6 +13,7 @@ from FlatCAMPostProc import *
 # the same) to contain the following keyword, case-sensitive: 'Roland' without the quotes.
 class Roland_MDX_20(FlatCAMPostProc):
 
+    include_header = False
     coordinate_format = "%.1f"
     feedrate_format = '%.1f'
     feedrate_rapid_format = '%.1f'

+ 1 - 0
preprocessors/Toolchange_Custom.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class Toolchange_Custom(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 

+ 5 - 4
preprocessors/Toolchange_Probe_MACH3.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class Toolchange_Probe_MACH3(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 
@@ -69,14 +70,14 @@ class Toolchange_Probe_MACH3(FlatCAMPostProc):
         gcode += 'G90\n'
         gcode += 'G17\n'
         gcode += 'G94\n'
-        gcode += '(MSG, WARNING: Make sure you do zero on all axis. ' \
-                 'For Z axis, since it will be probed, make a rough estimate and do a zero.)\n'
-        gcode += 'M0'
 
         return gcode
 
     def startz_code(self, p):
-        return ''
+        g = '(MSG, WARNING: Make sure you do zero on all axis. ' \
+            'For Z axis, since it will be probed, make a rough estimate and do a zero.)\n'
+        g += 'M0'
+        return g
 
     def lift_code(self, p):
         return 'G00 Z' + self.coordinate_format%(p.coords_decimals, p.z_move)

+ 1 - 0
preprocessors/Toolchange_manual.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class Toolchange_manual(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 

+ 1 - 0
preprocessors/default.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class default(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 

+ 2 - 1
preprocessors/grbl_11.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class grbl_11(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 
@@ -63,8 +64,8 @@ class grbl_11(FlatCAMPostProc):
 
         gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
         gcode += 'G90\n'
-        gcode += 'G94\n'
         gcode += 'G17\n'
+        gcode += 'G94\n'
 
         return gcode
 

+ 4 - 3
preprocessors/grbl_laser.py

@@ -14,6 +14,7 @@ from FlatCAMPostProc import *
 
 class grbl_laser(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 
@@ -34,15 +35,15 @@ class grbl_laser(FlatCAMPostProc):
         if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
             gcode += '(Preprocessor Excellon: ' + str(p['pp_excellon_name']) + ')\n'
         else:
-            gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n'
-        gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n" + '\n'
+            gcode += '(Preprocessor Geometry: ' + str(p['pp_geometry_name']) + ')\n' + '\n'
 
         gcode += '(X range: ' + '{: >9s}'.format(xmin) + ' ... ' + '{: >9s}'.format(xmax) + ' ' + units + ')\n'
         gcode += '(Y range: ' + '{: >9s}'.format(ymin) + ' ... ' + '{: >9s}'.format(ymax) + ' ' + units + ')\n\n'
 
+        gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
         gcode += 'G90\n'
-        gcode += 'G94\n'
         gcode += 'G17\n'
+        gcode += 'G94\n'
 
         return gcode
 

+ 1 - 1
preprocessors/hpgl.py

@@ -12,7 +12,7 @@ from FlatCAMPostProc import *
 # for Roland Preprocessors it is mandatory for the preprocessor name (python file and class name, both of them must be
 # the same) to contain the following keyword, case-sensitive: 'Roland' without the quotes.
 class hpgl(FlatCAMPostProc):
-
+    include_header = True
     coordinate_format = "%.*f"
 
     def start_code(self, p):

+ 1 - 0
preprocessors/line_xyz.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class line_xyz(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
 

+ 2 - 0
preprocessors/marlin.py

@@ -11,6 +11,7 @@ from FlatCAMPostProc import *
 
 class marlin(FlatCAMPostProc):
 
+    include_header = True
     coordinate_format = "%.*f"
     feedrate_format = '%.*f'
     feedrate_rapid_format = feedrate_format
@@ -66,6 +67,7 @@ class marlin(FlatCAMPostProc):
 
         gcode += ('G20' if p.units.upper() == 'IN' else 'G21') + "\n"
         gcode += 'G90\n'
+        gcode += 'G94\n'
 
         return gcode