flatcam/appPreProcessor.py

162 lines
3.5 KiB
Python
Raw Normal View History

2019-07-16 17:51:09 +00:00
# ##########################################################
# FlatCAM: 2D Post-processing for Manufacturing #
# http://flatcam.org #
# File Author: Matthieu Berthomé #
# Date: 5/26/2017 #
# MIT Licence #
2019-07-16 17:51:09 +00:00
# ##########################################################
2019-01-03 19:25:08 +00:00
from importlib.machinery import SourceFileLoader
import os
from abc import ABCMeta, abstractmethod
import math
2019-01-03 19:25:08 +00:00
# module-root dictionary of preprocessors
2019-01-03 19:25:08 +00:00
import logging
log = logging.getLogger('base')
preprocessors = {}
2019-01-03 19:25:08 +00:00
2020-06-02 15:29:45 +00:00
class ABCPreProcRegister(ABCMeta):
# handles preprocessors registration on instantiation
2019-01-03 19:25:08 +00:00
def __new__(cls, clsname, bases, attrs):
2020-06-02 15:29:45 +00:00
newclass = super(ABCPreProcRegister, cls).__new__(cls, clsname, bases, attrs)
2019-01-03 19:25:08 +00:00
if object not in bases:
if newclass.__name__ in preprocessors:
log.warning('Preprocessor %s has been overriden' % newclass.__name__)
preprocessors[newclass.__name__] = newclass() # here is your register function
2019-01-03 19:25:08 +00:00
return newclass
2019-02-21 21:48:13 +00:00
2020-06-02 15:29:45 +00:00
class PreProc(object, metaclass=ABCPreProcRegister):
2019-01-03 19:25:08 +00:00
@abstractmethod
def start_code(self, p):
pass
@abstractmethod
def lift_code(self, p):
pass
@abstractmethod
def down_code(self, p):
pass
@abstractmethod
def toolchange_code(self, p):
pass
@abstractmethod
def up_to_zero_code(self, p):
pass
@abstractmethod
def rapid_code(self, p):
pass
@abstractmethod
def linear_code(self, p):
pass
@abstractmethod
def end_code(self, p):
pass
@abstractmethod
def feedrate_code(self, p):
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def spindle_code(self, p):
2019-01-03 19:25:08 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def spindle_stop_code(self, p):
2019-01-03 19:25:08 +00:00
pass
2019-02-21 21:48:13 +00:00
2020-06-02 15:29:45 +00:00
class AppPreProcTools(object, metaclass=ABCPreProcRegister):
2019-02-21 21:48:13 +00:00
@abstractmethod
def start_code(self, p):
pass
@abstractmethod
def lift_code(self, p):
pass
@abstractmethod
def down_z_start_code(self, p):
pass
@abstractmethod
def lift_z_dispense_code(self, p):
pass
@abstractmethod
def down_z_stop_code(self, p):
pass
@abstractmethod
def toolchange_code(self, p):
pass
@abstractmethod
def rapid_code(self, p):
pass
@abstractmethod
def linear_code(self, p):
pass
@abstractmethod
def end_code(self, p):
pass
@abstractmethod
def feedrate_xy_code(self, p):
pass
@abstractmethod
def z_feedrate_code(self, p):
2019-02-21 21:48:13 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def feedrate_z_dispense_code(self, p):
2019-02-21 21:48:13 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def spindle_fwd_code(self, p):
2019-02-21 21:48:13 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def spindle_rev_code(self, p):
2019-02-21 21:48:13 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def spindle_off_code(self, p):
2019-02-21 21:48:13 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def dwell_fwd_code(self, p):
2019-02-21 21:48:13 +00:00
pass
@abstractmethod
2019-07-16 17:51:09 +00:00
def dwell_rev_code(self, p):
2019-02-21 21:48:13 +00:00
pass
def load_preprocessors(app):
preprocessors_path_search = [
os.path.join(app.data_path, 'preprocessors', '*.py'),
os.path.join('preprocessors', '*.py')
]
2019-01-03 19:25:08 +00:00
import glob
for path_search in preprocessors_path_search:
2019-01-03 19:25:08 +00:00
for file in glob.glob(path_search):
try:
SourceFileLoader('FlatCAMPostProcessor', file).load_module()
except Exception as e:
app.log.error(str(e))
return preprocessors