hpgl.py 2.6 KB

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