appPreProcessor.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 logging
  14. log = logging.getLogger('base')
  15. preprocessors = {}
  16. class ABCPreProcRegister(ABCMeta):
  17. # handles preprocessors registration on instantiation
  18. def __new__(cls, clsname, bases, attrs):
  19. newclass = super(ABCPreProcRegister, cls).__new__(cls, clsname, bases, attrs)
  20. if object not in bases:
  21. if newclass.__name__ in preprocessors:
  22. log.warning('Preprocessor %s has been overriden' % newclass.__name__)
  23. preprocessors[newclass.__name__] = newclass() # here is your register function
  24. return newclass
  25. class PreProc(object, metaclass=ABCPreProcRegister):
  26. @abstractmethod
  27. def start_code(self, p):
  28. pass
  29. @abstractmethod
  30. def lift_code(self, p):
  31. pass
  32. @abstractmethod
  33. def down_code(self, p):
  34. pass
  35. @abstractmethod
  36. def toolchange_code(self, p):
  37. pass
  38. @abstractmethod
  39. def up_to_zero_code(self, p):
  40. pass
  41. @abstractmethod
  42. def rapid_code(self, p):
  43. pass
  44. @abstractmethod
  45. def linear_code(self, p):
  46. pass
  47. @abstractmethod
  48. def end_code(self, p):
  49. pass
  50. @abstractmethod
  51. def feedrate_code(self, p):
  52. pass
  53. @abstractmethod
  54. def spindle_code(self, p):
  55. pass
  56. @abstractmethod
  57. def spindle_stop_code(self, p):
  58. pass
  59. class AppPreProcTools(object, metaclass=ABCPreProcRegister):
  60. @abstractmethod
  61. def start_code(self, p):
  62. pass
  63. @abstractmethod
  64. def lift_code(self, p):
  65. pass
  66. @abstractmethod
  67. def down_z_start_code(self, p):
  68. pass
  69. @abstractmethod
  70. def lift_z_dispense_code(self, p):
  71. pass
  72. @abstractmethod
  73. def down_z_stop_code(self, p):
  74. pass
  75. @abstractmethod
  76. def toolchange_code(self, p):
  77. pass
  78. @abstractmethod
  79. def rapid_code(self, p):
  80. pass
  81. @abstractmethod
  82. def linear_code(self, p):
  83. pass
  84. @abstractmethod
  85. def end_code(self, p):
  86. pass
  87. @abstractmethod
  88. def feedrate_xy_code(self, p):
  89. pass
  90. @abstractmethod
  91. def z_feedrate_code(self, p):
  92. pass
  93. @abstractmethod
  94. def feedrate_z_dispense_code(self, p):
  95. pass
  96. @abstractmethod
  97. def spindle_fwd_code(self, p):
  98. pass
  99. @abstractmethod
  100. def spindle_rev_code(self, p):
  101. pass
  102. @abstractmethod
  103. def spindle_off_code(self, p):
  104. pass
  105. @abstractmethod
  106. def dwell_fwd_code(self, p):
  107. pass
  108. @abstractmethod
  109. def dwell_rev_code(self, p):
  110. pass
  111. def load_preprocessors(app):
  112. preprocessors_path_search = [
  113. os.path.join(app.data_path, 'preprocessors', '*.py'),
  114. os.path.join('preprocessors', '*.py')
  115. ]
  116. import glob
  117. for path_search in preprocessors_path_search:
  118. for file in glob.glob(path_search):
  119. try:
  120. SourceFileLoader('FlatCAMPostProcessor', file).load_module()
  121. except Exception as e:
  122. app.log.error(str(e))
  123. return preprocessors