diff options
author | Jaime van Kessel <nallath@gmail.com> | 2016-04-28 18:21:09 +0300 |
---|---|---|
committer | Jaime van Kessel <nallath@gmail.com> | 2016-04-28 18:21:09 +0300 |
commit | 633d14d92585e67749b736b0f400af3d1066472d (patch) | |
tree | 952248600f2a766d55fb9113a544bd626aec4f44 /cura/MachineActionManager.py | |
parent | 9009fb9d3de9e0223d500702f603d2145e6b0f1f (diff) |
Added first stubs of MachineActions
CURA-1385
Diffstat (limited to 'cura/MachineActionManager.py')
-rw-r--r-- | cura/MachineActionManager.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/cura/MachineActionManager.py b/cura/MachineActionManager.py new file mode 100644 index 0000000000..b8d1c4f9b2 --- /dev/null +++ b/cura/MachineActionManager.py @@ -0,0 +1,53 @@ +from UM.Logger import Logger + + +class MachineActionManager: + def __init__(self): + ## Dict of all known machine actions + self._machine_actions = {} + + ## Dict of all required actions by machine reference. + self._required_actions = {} + + ## Dict of all supported actions by machine reference + self._supported_actions = {} + + ## Dict of all actions that need to be done when first added by machine reference. + self._first_start_actions = {} + + ## Add a required action + def addRequiredAction(self, machine, action_key): + if action_key in self._machine_actions: + if machine in self._required_actions: + self._required_actions[machine].append(action_key) + else: + self._required_actions[machine] = set(action_key) + else: + # Todo: define specific Exception types (instead of general type) + raise Exception("Action %s, which is required for %s is not known." % (action_key, machine.getKey())) + + ## Add a (unique) MachineAction + # if the Key of the action is not unique, an exception is raised. + def addMachineAction(self, action): + if action.getKey() not in self._machine_action: + self._machine_action[action.getKey()] = action + else: + # Todo: define specific Exception types (instead of general type) + raise Exception("MachineAction with key %s was already added. Actions must have unique keys.", action.getKey()) + + ## Remove Machine action from manager + # \param action to remove + def removeMachineAction(self, action): + try: + del self._machine_actions[action.getKey()] + except KeyError: + Logger.log("w", "Trying to remove MachineAction (%s) that was already removed", action.getKey()) + + ## Get MachineAction by key + # \param key String of key to select + # \return Machine action if found, None otherwise + def getMachineAction(self, key): + if key in self._machine_actions: + return self._machine_actions[key] + else: + return None
\ No newline at end of file |