2019-12-16 17:24:50 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# http://flatcam.org #
|
|
|
|
# File Author: Marius Adrian Stanciu (c) #
|
|
|
|
# Date: 3/10/2019 #
|
|
|
|
# MIT Licence #
|
2019-12-16 17:24:50 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
|
2020-05-18 13:02:41 +00:00
|
|
|
from AppPreProcessor import *
|
2019-01-19 00:31:47 +00:00
|
|
|
|
|
|
|
|
2019-12-06 21:00:43 +00:00
|
|
|
# for Roland Preprocessors it is mandatory for the preprocessor name (python file and class name, both of them must be
|
2019-01-19 00:31:47 +00:00
|
|
|
# the same) to contain the following keyword, case-sensitive: 'Roland' without the quotes.
|
|
|
|
class hpgl(FlatCAMPostProc):
|
2019-12-15 22:12:04 +00:00
|
|
|
include_header = True
|
2019-01-19 00:31:47 +00:00
|
|
|
coordinate_format = "%.*f"
|
|
|
|
|
|
|
|
def start_code(self, p):
|
2019-12-16 18:32:00 +00:00
|
|
|
gcode = 'IN;\n'
|
|
|
|
gcode += 'PU;'
|
2019-01-19 00:31:47 +00:00
|
|
|
return gcode
|
|
|
|
|
|
|
|
def startz_code(self, p):
|
2019-01-19 00:38:44 +00:00
|
|
|
return ''
|
2019-01-19 00:31:47 +00:00
|
|
|
|
|
|
|
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):
|
2019-01-19 00:38:44 +00:00
|
|
|
return 'SP%d;' % int(p.tool)
|
2019-01-19 00:31:47 +00:00
|
|
|
|
|
|
|
def up_to_zero_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def position_code(self, p):
|
2019-01-20 02:11:34 +00:00
|
|
|
units = str(p['units']).lower()
|
|
|
|
|
|
|
|
# we work only with METRIC units because HPGL mention only metric units so if FlatCAM units are INCH we
|
|
|
|
# transform them in METRIC
|
|
|
|
if units == 'in':
|
|
|
|
x = p.x * 25.4
|
|
|
|
y = p.y * 25.4
|
|
|
|
else:
|
|
|
|
x = p.x
|
|
|
|
y = p.y
|
|
|
|
|
|
|
|
# we need to have the coordinates as multiples of 0.025mm
|
2019-12-16 17:56:24 +00:00
|
|
|
x = round(x * 40)
|
|
|
|
y = round(y * 40)
|
|
|
|
|
|
|
|
# constrain the x and y values within the domain of valid values: [-32767 ... 32768]
|
|
|
|
if x <= -32767:
|
|
|
|
x = -32767
|
|
|
|
if x >= 32768:
|
|
|
|
x = 32768
|
|
|
|
|
|
|
|
if y <= -32767:
|
|
|
|
y = -32767
|
|
|
|
if y >= 32768:
|
|
|
|
y = 32768
|
2019-01-20 02:11:34 +00:00
|
|
|
|
2019-01-19 00:38:44 +00:00
|
|
|
return ('PA' + self.coordinate_format + ',' + self.coordinate_format + ';') % \
|
2019-01-20 02:11:34 +00:00
|
|
|
(p.coords_decimals, x, p.coords_decimals, y)
|
2019-01-19 00:31:47 +00:00
|
|
|
|
|
|
|
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 ''
|
|
|
|
|
2019-02-28 16:02:29 +00:00
|
|
|
def z_feedrate_code(self, p):
|
2019-01-19 00:31:47 +00:00
|
|
|
return ''
|
|
|
|
|
|
|
|
def feedrate_rapid_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def spindle_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def dwell_code(self, p):
|
|
|
|
return ''
|
|
|
|
|
2019-12-16 17:24:50 +00:00
|
|
|
def spindle_stop_code(self, p):
|
2019-01-19 00:31:47 +00:00
|
|
|
return ''
|