hpgl.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 * 40)
  41. y = round(y * 40)
  42. # constrain the x and y values within the domain of valid values: [-32767 ... 32768]
  43. if x <= -32767:
  44. x = -32767
  45. if x >= 32768:
  46. x = 32768
  47. if y <= -32767:
  48. y = -32767
  49. if y >= 32768:
  50. y = 32768
  51. return ('PA' + self.coordinate_format + ',' + self.coordinate_format + ';') % \
  52. (p.coords_decimals, x, p.coords_decimals, y)
  53. def rapid_code(self, p):
  54. return self.position_code(p).format(**p)
  55. def linear_code(self, p):
  56. return self.position_code(p).format(**p)
  57. def end_code(self, p):
  58. gcode = self.position_code(p).format(**p)
  59. return gcode
  60. def feedrate_code(self, p):
  61. return ''
  62. def z_feedrate_code(self, p):
  63. return ''
  64. def feedrate_rapid_code(self, p):
  65. return ''
  66. def spindle_code(self, p):
  67. return ''
  68. def dwell_code(self, p):
  69. return ''
  70. def spindle_stop_code(self, p):
  71. return ''