Parcourir la source

- added initial implementation of HPGL postprocessor

Marius Stanciu il y a 7 ans
Parent
commit
4b6df74c2e
3 fichiers modifiés avec 101 ajouts et 12 suppressions
  1. 34 12
      FlatCAMObj.py
  2. 4 0
      README.md
  3. 63 0
      postprocessors/hpgl.py

+ 34 - 12
FlatCAMObj.py

@@ -3819,11 +3819,16 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         log.debug("FlatCAMCNCJob.gcode_header()")
         time_str = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
         marlin = False
+        hpgl = False
+
         try:
             for key in self.cnc_tools:
                 if self.cnc_tools[key]['data']['ppname_g'] == 'marlin':
                     marlin = True
                     break
+                if self.cnc_tools[key]['data']['ppname_g'] == 'hpgl':
+                    hpgl = True
+                    break
         except Exception as e:
             log.debug("FlatCAMCNCJob.gcode_header() error: --> %s" % str(e))
             try:
@@ -3834,37 +3839,49 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
             except:
                 pass
 
-        if marlin is False:
-            gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
+        if marlin is True:
+            gcode = ';Marlin G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date:    %s\n' % \
                     (str(self.app.version), str(self.app.version_date)) + '\n'
 
-            gcode += '(Name: ' + str(self.options['name']) + ')\n'
-            gcode += '(Type: ' + "G-code from " + str(self.options['type']) + ')\n'
+            gcode += ';Name: ' + str(self.options['name']) + '\n'
+            gcode += ';Type: ' + "G-code from " + str(self.options['type']) + '\n'
 
             # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
             #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
 
-            gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
-            gcode += '(Created on ' + time_str + ')\n' + '\n'
+            gcode += ';Units: ' + self.units.upper() + '\n' + "\n"
+            gcode += ';Created on ' + time_str + '\n' + '\n'
+        elif hpgl is True:
+            gcode = 'CO "HPGL CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date:    %s' % \
+                    (str(self.app.version), str(self.app.version_date)) + '";\n'
+
+            gcode += 'CO "Name: ' + str(self.options['name']) + '";\n'
+            gcode += 'CO "Type: ' + "G-code from " + str(self.options['type']) + '";\n'
 
+            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
+            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
+
+            gcode += 'CO "Units: ' + self.units.upper() + '";\n'
+            gcode += 'CO "Created on ' + time_str + '";\n'
         else:
-            gcode = ';G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s\n' % \
+            gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
                     (str(self.app.version), str(self.app.version_date)) + '\n'
 
-            gcode += ';Name: ' + str(self.options['name']) + '\n'
-            gcode += ';Type: ' + "G-code from " + str(self.options['type']) + '\n'
+            gcode += '(Name: ' + str(self.options['name']) + ')\n'
+            gcode += '(Type: ' + "G-code from " + str(self.options['type']) + ')\n'
 
             # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
             #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
 
-            gcode += ';Units: ' + self.units.upper() + '\n' + "\n"
-            gcode += ';Created on ' + time_str + '\n' + '\n'
+            gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
+            gcode += '(Created on ' + time_str + ')\n' + '\n'
 
         return gcode
 
     def export_gcode(self, filename=None, preamble='', postamble='', to_file=False):
         gcode = ''
         roland = False
+        hpgl = False
 
         # detect if using Roland postprocessor
         try:
@@ -3872,6 +3889,9 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
                 if self.cnc_tools[key]['data']['ppname_g'] == 'Roland_MDX_20':
                     roland = True
                     break
+                if self.cnc_tools[key]['data']['ppname_g'] == 'hpgl':
+                    hpgl = True
+                    break
         except:
             try:
                 for key in self.cnc_tools:
@@ -3882,7 +3902,7 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
                 pass
 
         # do not add gcode_header when using the Roland postprocessor, add it for every other postprocessor
-        if roland is False:
+        if roland is False and hpgl is False:
             gcode = self.gcode_header()
 
         # detect if using multi-tool and make the Gcode summation correctly for each case
@@ -3897,6 +3917,8 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
 
         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')

+ 4 - 0
README.md

@@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing.
 
 =================================================
 
+19.01.2019
+
+- added initial implementation of HPGL postprocessor
+
 11.01.2019
 
 - added a status message for font parsing

+ 63 - 0
postprocessors/hpgl.py

@@ -0,0 +1,63 @@
+from FlatCAMPostProc import *
+
+
+# for Roland Postprocessors it is mandatory for the postprocessor 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):
+
+    coordinate_format = "%.*f"
+    feedrate_format = '%.1f'
+    feedrate_rapid_format = '%.1f'
+
+    def start_code(self, p):
+        gcode = 'IN;'
+        return gcode
+
+    def startz_code(self, p):
+        return 'SP%d' % int(p.tool)
+
+    def lift_code(self, p):
+        gcode = 'PU;' + '\n'
+        return gcode
+
+    def down_code(self, p):
+        gcode = 'PD;' + '\n'
+        return gcode
+
+    def toolchange_code(self, p):
+        return ''
+
+    def up_to_zero_code(self, p):
+        return ''
+
+    def position_code(self, p):
+        return ('PA' + self.coordinate_format + ',' + self.coordinate_format) % \
+               (p.coords_decimals, p.x, p.coords_decimals, p.y)
+
+    def rapid_code(self, p):
+        return self.position_code(p).format(**p)
+
+    def linear_code(self, p):
+        return self.position_code(p).format(**p)
+
+    def end_code(self, p):
+        gcode = self.position_code(p).format(**p)
+        return gcode
+
+    def feedrate_code(self, p):
+        return ''
+
+    def feedrate_z_code(self, p):
+        return ''
+
+    def feedrate_rapid_code(self, p):
+        return ''
+
+    def spindle_code(self, p):
+        return ''
+
+    def dwell_code(self, p):
+        return ''
+
+    def spindle_stop_code(self,p):
+        return ''