FlatCAMPostProc.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # File Author: Matthieu Berthomé #
  5. # Date: 5/26/2017 #
  6. # MIT Licence #
  7. # ##########################################################
  8. from importlib.machinery import SourceFileLoader
  9. import os
  10. from abc import ABCMeta, abstractmethod
  11. import math
  12. # module-root dictionary of preprocessors
  13. import FlatCAMApp
  14. preprocessors = {}
  15. class ABCPostProcRegister(ABCMeta):
  16. # handles preprocessors registration on instantiation
  17. def __new__(cls, clsname, bases, attrs):
  18. newclass = super(ABCPostProcRegister, cls).__new__(cls, clsname, bases, attrs)
  19. if object not in bases:
  20. if newclass.__name__ in preprocessors:
  21. FlatCAMApp.App.log.warning('Preprocessor %s has been overriden' % newclass.__name__)
  22. preprocessors[newclass.__name__] = newclass() # here is your register function
  23. return newclass
  24. class FlatCAMPostProc(object, metaclass=ABCPostProcRegister):
  25. @abstractmethod
  26. def start_code(self, p):
  27. pass
  28. @abstractmethod
  29. def lift_code(self, p):
  30. pass
  31. @abstractmethod
  32. def down_code(self, p):
  33. pass
  34. @abstractmethod
  35. def toolchange_code(self, p):
  36. pass
  37. @abstractmethod
  38. def up_to_zero_code(self, p):
  39. pass
  40. @abstractmethod
  41. def rapid_code(self, p):
  42. pass
  43. @abstractmethod
  44. def linear_code(self, p):
  45. pass
  46. @abstractmethod
  47. def end_code(self, p):
  48. pass
  49. @abstractmethod
  50. def feedrate_code(self, p):
  51. pass
  52. @abstractmethod
  53. def spindle_code(self, p):
  54. pass
  55. @abstractmethod
  56. def spindle_stop_code(self, p):
  57. pass
  58. class FlatCAMPostProc_Tools(object, metaclass=ABCPostProcRegister):
  59. @abstractmethod
  60. def start_code(self, p):
  61. pass
  62. @abstractmethod
  63. def lift_code(self, p):
  64. pass
  65. @abstractmethod
  66. def down_z_start_code(self, p):
  67. pass
  68. @abstractmethod
  69. def lift_z_dispense_code(self, p):
  70. pass
  71. @abstractmethod
  72. def down_z_stop_code(self, p):
  73. pass
  74. @abstractmethod
  75. def toolchange_code(self, p):
  76. pass
  77. @abstractmethod
  78. def rapid_code(self, p):
  79. pass
  80. @abstractmethod
  81. def linear_code(self, p):
  82. pass
  83. @abstractmethod
  84. def end_code(self, p):
  85. pass
  86. @abstractmethod
  87. def feedrate_xy_code(self, p):
  88. pass
  89. @abstractmethod
  90. def z_feedrate_code(self, p):
  91. pass
  92. @abstractmethod
  93. def feedrate_z_dispense_code(self, p):
  94. pass
  95. @abstractmethod
  96. def spindle_fwd_code(self, p):
  97. pass
  98. @abstractmethod
  99. def spindle_rev_code(self, p):
  100. pass
  101. @abstractmethod
  102. def spindle_off_code(self, p):
  103. pass
  104. @abstractmethod
  105. def dwell_fwd_code(self, p):
  106. pass
  107. @abstractmethod
  108. def dwell_rev_code(self, p):
  109. pass
  110. def load_preprocessors(app):
  111. preprocessors_path_search = [os.path.join(app.data_path, 'preprocessors', '*.py'),
  112. os.path.join('preprocessors', '*.py')]
  113. import glob
  114. for path_search in preprocessors_path_search:
  115. for file in glob.glob(path_search):
  116. try:
  117. SourceFileLoader('FlatCAMPostProcessor', file).load_module()
  118. except Exception as e:
  119. app.log.error(str(e))
  120. return preprocessors