29 m_UndoController(NULL),
30 m_StateMachineContainer(NULL),
32 m_MouseCursorSet(false)
47 if (m_StateMachineContainer != NULL)
49 m_StateMachineContainer->Delete();
53 if (m_StateMachineContainer->LoadBehavior(filename, module))
55 m_CurrentState = m_StateMachineContainer->GetStartState();
57 for (ConditionDelegatesMapType::iterator i = m_ConditionDelegatesMap.begin(); i != m_ConditionDelegatesMap.end();
62 m_ConditionDelegatesMap.clear();
65 for (std::map<std::string, TActionFunctor *>::iterator i = m_ActionFunctionsMap.begin();
66 i != m_ActionFunctionsMap.end();
71 m_ActionFunctionsMap.clear();
72 for (ActionDelegatesMapType::iterator i = m_ActionDelegatesMap.begin(); i != m_ActionDelegatesMap.end(); ++i)
76 m_ActionDelegatesMap.clear();
90 if (m_StateMachineContainer != NULL)
92 m_StateMachineContainer->Delete();
101 delete m_ActionFunctionsMap[action];
102 ActionDelegatesMapType::iterator i = m_ActionDelegatesMap.find(action);
103 if (i != m_ActionDelegatesMap.end())
106 m_ActionDelegatesMap.erase(i);
108 m_ActionFunctionsMap[action] = functor;
113 std::map<std::string, TActionFunctor *>::iterator i = m_ActionFunctionsMap.find(action);
114 if (i != m_ActionFunctionsMap.end())
117 m_ActionFunctionsMap.erase(i);
120 delete m_ActionDelegatesMap[action];
121 m_ActionDelegatesMap[action] = delegate.
Clone();
127 m_ConditionDelegatesMap[condition] = delegate.
Clone();
135 if (!FilterEvents(event, dataNode))
144 if (transition.IsNotNull())
147 m_CurrentState = transition->GetNextState();
151 for (ActionVectorType::const_iterator it = actions.cbegin(); it != actions.cend(); ++it)
155 ExecuteAction(*it, event);
157 catch (
const std::exception &e)
159 MITK_ERROR <<
"Unhandled excaption caught in ExecuteAction(): " << e.what();
164 MITK_ERROR <<
"Unhandled excaption caught in ExecuteAction()";
176 MITK_WARN <<
"ConnectActionsAndFunctions in DataInteractor not implemented.\n DataInteractor will not be able to "
177 "process any events.";
183 ConditionDelegatesMapType::const_iterator delegateIter = m_ConditionDelegatesMap.find(condition.
GetConditionName());
184 if (delegateIter != m_ConditionDelegatesMap.cend())
186 retVal = delegateIter->second->Execute(event);
204 ActionDelegatesMapType::const_iterator delegateIter = m_ActionDelegatesMap.find(action->
GetActionName());
205 if (delegateIter != m_ActionDelegatesMap.cend())
207 delegateIter->second->Execute(action, event);
212 std::map<std::string, TActionFunctor *>::const_iterator functionIter =
214 if (functionIter != m_ActionFunctionsMap.cend())
216 functionIter->second->DoAction(action, event);
227 return m_CurrentState.GetPointer();
232 if (dataNode == NULL)
234 MITK_WARN <<
"EventStateMachine: Empty DataNode received along with this Event " << interactionEvent;
237 bool visible =
false;
249 std::map<std::string, bool> conditionsMap;
253 m_CurrentState->GetTransitionList(event->GetNameOfClass(), MapToEventVariant(event));
256 if (transitionList.empty())
261 StateMachineState::TransitionVector::const_iterator transitionIter;
262 ConditionVectorType::const_iterator conditionIter;
263 for (transitionIter = transitionList.cbegin(); transitionIter != transitionList.cend(); ++transitionIter)
265 bool allConditionsFulfilled(
true);
269 for (conditionIter = conditions.cbegin(); conditionIter != conditions.cend(); ++conditionIter)
271 bool currentConditionFulfilled(
false);
274 const std::string conditionName = (*conditionIter).GetConditionName();
277 if (conditionsMap.find(conditionName) == conditionsMap.cend())
283 currentConditionFulfilled = CheckCondition((*conditionIter), event);
284 conditionsMap.insert(std::pair<std::string, bool>(conditionName, currentConditionFulfilled));
286 catch (
const std::exception &e)
288 MITK_ERROR <<
"Unhandled excaption caught in CheckCondition(): " << e.what();
289 currentConditionFulfilled =
false;
294 MITK_ERROR <<
"Unhandled excaption caught in CheckCondition()";
295 currentConditionFulfilled =
false;
302 currentConditionFulfilled = conditionsMap[conditionName];
307 if (currentConditionFulfilled == (*conditionIter).IsInverted())
309 allConditionsFulfilled =
false;
315 if (allConditionsFulfilled)
317 return (*transitionIter);
327 m_CurrentState = m_StateMachineContainer->GetStartState();
333 if (m_MouseCursorSet)
339 m_MouseCursorSet =
true;
344 if (m_MouseCursorSet)
347 m_MouseCursorSet =
false;
virtual ~EventStateMachine()
BaseRenderer * GetSender() const
virtual MessageAbstractDelegate1 * Clone() const =0
StateMachineTransition * GetExecutableTransition(InteractionEvent *event)
Returns the executable transition for the given event.
std::vector< mitk::StateMachineAction::Pointer > ActionVectorType
Base class of ActionFunctors, to provide an easy to connect actions with functions.
bool HandleEvent(InteractionEvent *event, DataNode *dataNode)
virtual bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode)
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
bool LoadStateMachine(const std::string &filename, const us::Module *module=nullptr)
Loads XML resource.
void PopCursor()
Restore the previous cursor.
virtual void ConnectActionsAndFunctions()
void AddActionFunction(const std::string &action, TActionFunctor *functor)
StateMachineState * GetCurrentState() const
std::string GetConditionName() const
Returns the String-Id of this action.
void AddConditionFunction(const std::string &condition, const ConditionFunctionDelegate &delegate)
static ApplicationCursor * GetInstance()
This class is a singleton.
static StateMachineContainer * New()
virtual void ExecuteAction(StateMachineAction *action, InteractionEvent *interactionEvent)
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
std::string GetActionName() const
Returns the String-Id of this action.
static const std::string filename
virtual void ConnectActionsAndFunctions() override
void ResetMouseCursor()
Resets the mouse cursor (if modified by the SlicesCoordinator) to its original state.
Connects two states, and holds references to corresponding actions and conditions.
void ResetToStartState()
ResetToStartState Reset state machine to it initial starting state.
void PushCursor(const char *XPM[], int hotspotX=-1, int hotspotY=-1)
Change the current application cursor.
UndoController * m_UndoController
void SetMouseCursor(const char *xpm[], int hotspotX, int hotspotY)
Sets the specified mouse cursor.
virtual MessageAbstractDelegate2 * Clone() const =0
virtual bool CheckCondition(const StateMachineCondition &condition, const InteractionEvent *interactionEvent)
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
std::vector< StateMachineTransition::Pointer > TransitionVector
Class for nodes of the DataTree.
std::vector< StateMachineCondition > ConditionVectorType