hpgl.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # ########################################################## ##
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Marius Adrian Stanciu (c) #
  5. # Date: 3/10/2019 #
  6. # MIT Licence #
  7. # ########################################################## ##
  8. from FlatCAMPostProc import *
  9. # for Roland Preprocessors it is mandatory for the preprocessor name (python file and class name, both of them must be
  10. # the same) to contain the following keyword, case-sensitive: 'Roland' without the quotes.
  11. class hpgl(FlatCAMPostProc):
  12. include_header = True
  13. coordinate_format = "%.*f"
  14. def start_code(self, p):
  15. gcode = 'IN;'
  16. return gcode
  17. def startz_code(self, p):
  18. return ''
  19. def lift_code(self, p):
  20. gcode = 'PU;' + '\n'
  21. return gcode
  22. def down_code(self, p):
  23. gcode = 'PD;' + '\n'
  24. return gcode
  25. def toolchange_code(self, p):
  26. return 'SP%d;' % int(p.tool)
  27. def up_to_zero_code(self, p):
  28. return ''
  29. def position_code(self, p):
  30. units = str(p['units']).lower()
  31. # we work only with METRIC units because HPGL mention only metric units so if FlatCAM units are INCH we
  32. # transform them in METRIC
  33. if units == 'in':
  34. x = p.x * 25.4
  35. y = p.y * 25.4
  36. else:
  37. x = p.x
  38. y = p.y
  39. # we need to have the coordinates as multiples of 0.025mm
  40. x = round(x / 0.025) * 25 / 1000
  41. y = round(y / 0.025) * 25 / 1000
  42. return ('PA' + self.coordinate_format + ',' + self.coordinate_format + ';') % \
  43. (p.coords_decimals, x, p.coords_decimals, y)
  44. def rapid_code(self, p):
  45. return self.position_code(p).format(**p)
  46. def linear_code(self, p):
  47. return self.position_code(p).format(**p)
  48. def end_code(self, p):
  49. gcode = self.position_code(p).format(**p)
  50. return gcode
  51. def feedrate_code(self, p):
  52. return ''
  53. def z_feedrate_code(self, p):
  54. return ''
  55. def feedrate_rapid_code(self, p):
  56. return ''
  57. def spindle_code(self, p):
  58. return ''
  59. def dwell_code(self, p):
  60. return ''
  61. def spindle_stop_code(self,p):
  62. return ''