- added initial implementation of HPGL postprocessor

This commit is contained in:
Marius Stanciu
2019-01-19 02:31:47 +02:00
committed by Marius S
parent 18de843fc1
commit 4b6df74c2e
3 changed files with 104 additions and 15 deletions

View File

@@ -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,7 +3839,31 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
except:
pass
if marlin is False:
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'
# 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'
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' % \
(str(self.app.version), str(self.app.version_date)) + '\n'
@@ -3847,24 +3876,12 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
gcode += '(Created on ' + time_str + ')\n' + '\n'
else:
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'
# 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'
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')