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. coordinate_format = "%.*f"
  13. def start_code(self, p):
  14. gcode = 'IN;'
  15. return gcode
  16. def startz_code(self, p):
  17. return ''
  18. def lift_code(self, p):
  19. gcode = 'PU;' + '\n'
  20. return gcode
  21. def down_code(self, p):
  22. gcode = 'PD;' + '\n'
  23. return gcode
  24. def toolchange_code(self, p):
  25. return 'SP%d;' % int(p.tool)
  26. def up_to_zero_code(self, p):
  27. return ''
  28. def position_code(self, p):
  29. units = str(p['units']).lower()
  30. # we work only with METRIC units because HPGL mention only metric units so if FlatCAM units are INCH we
  31. # transform them in METRIC
  32. if units == 'in':
  33. x = p.x * 25.4
  34. y = p.y * 25.4
  35. else:
  36. x = p.x
  37. y = p.y
  38. # we need to have the coordinates as multiples of 0.025mm
  39. x = round(x / 0.025) * 25 / 1000
  40. y = round(y / 0.025) * 25 / 1000
  41. return ('PA' + self.coordinate_format + ',' + self.coordinate_format + ';') % \
  42. (p.coords_decimals, x, p.coords_decimals, y)
  43. def rapid_code(self, p):
  44. return self.position_code(p).format(**p)
  45. def linear_code(self, p):
  46. return self.position_code(p).format(**p)
  47. def end_code(self, p):
  48. gcode = self.position_code(p).format(**p)
  49. return gcode
  50. def feedrate_code(self, p):
  51. return ''
  52. def z_feedrate_code(self, p):
  53. return ''
  54. def feedrate_rapid_code(self, p):
  55. return ''
  56. def spindle_code(self, p):
  57. return ''
  58. def dwell_code(self, p):
  59. return ''
  60. def spindle_stop_code(self,p):
  61. return ''