25 m_UndoController(nullptr),
26 m_StateMachineContainer(nullptr),
27 m_CurrentState(nullptr),
28 m_MouseCursorSet(false)
43 if (m_StateMachineContainer !=
nullptr)
45 m_StateMachineContainer->Delete();
49 if (m_StateMachineContainer->
LoadBehavior(filename, module))
53 for (
auto i = m_ConditionDelegatesMap.begin(); i != m_ConditionDelegatesMap.end();
58 m_ConditionDelegatesMap.clear();
61 for (
auto i = m_ActionFunctionsMap.begin();
62 i != m_ActionFunctionsMap.end();
67 m_ActionFunctionsMap.clear();
68 for (
auto i = m_ActionDelegatesMap.begin(); i != m_ActionDelegatesMap.end(); ++i)
72 m_ActionDelegatesMap.clear();
79 MITK_WARN <<
"Unable to load StateMachine from file: " << filename;
86 if (m_StateMachineContainer !=
nullptr)
88 m_StateMachineContainer->Delete();
97 delete m_ActionFunctionsMap[action];
98 auto i = m_ActionDelegatesMap.find(action);
99 if (i != m_ActionDelegatesMap.end())
102 m_ActionDelegatesMap.erase(i);
104 m_ActionFunctionsMap[action] = functor;
109 auto i = m_ActionFunctionsMap.find(action);
110 if (i != m_ActionFunctionsMap.end())
113 m_ActionFunctionsMap.erase(i);
116 delete m_ActionDelegatesMap[action];
117 m_ActionDelegatesMap[action] = delegate.
Clone();
123 m_ConditionDelegatesMap[condition] = delegate.
Clone();
140 if (transition.IsNotNull())
143 m_CurrentState = transition->GetNextState();
147 for (
auto it = actions.cbegin(); it != actions.cend(); ++it)
153 catch (
const std::exception &e)
155 MITK_ERROR <<
"Unhandled excaption caught in ExecuteAction(): " << e.what();
160 MITK_ERROR <<
"Unhandled excaption caught in ExecuteAction()";
172 MITK_WARN <<
"ConnectActionsAndFunctions in DataInteractor not implemented.\n DataInteractor will not be able to " 173 "process any events.";
179 ConditionDelegatesMapType::const_iterator delegateIter = m_ConditionDelegatesMap.find(condition.
GetConditionName());
180 if (delegateIter != m_ConditionDelegatesMap.cend())
182 retVal = delegateIter->second->Execute(event);
194 if (action ==
nullptr)
200 ActionDelegatesMapType::const_iterator delegateIter = m_ActionDelegatesMap.find(action->
GetActionName());
201 if (delegateIter != m_ActionDelegatesMap.cend())
203 delegateIter->second->Execute(action, event);
208 std::map<std::string, TActionFunctor *>::const_iterator functionIter =
210 if (functionIter != m_ActionFunctionsMap.cend())
212 functionIter->second->DoAction(action, event);
223 return m_CurrentState.GetPointer();
228 if (dataNode ==
nullptr)
230 MITK_WARN <<
"EventStateMachine: Empty DataNode received along with this Event " << interactionEvent;
233 bool visible =
false;
245 std::map<std::string, bool> conditionsMap;
249 m_CurrentState->GetTransitionList(event->GetNameOfClass(),
MapToEventVariant(event));
252 if (transitionList.empty())
257 StateMachineState::TransitionVector::const_iterator transitionIter;
258 ConditionVectorType::const_iterator conditionIter;
259 for (transitionIter = transitionList.cbegin(); transitionIter != transitionList.cend(); ++transitionIter)
261 bool allConditionsFulfilled(
true);
265 for (conditionIter = conditions.cbegin(); conditionIter != conditions.cend(); ++conditionIter)
267 bool currentConditionFulfilled(
false);
270 const std::string conditionName = (*conditionIter).GetConditionName();
273 if (conditionsMap.find(conditionName) == conditionsMap.cend())
279 currentConditionFulfilled =
CheckCondition((*conditionIter), event);
280 conditionsMap.insert(std::pair<std::string, bool>(conditionName, currentConditionFulfilled));
282 catch (
const std::exception &e)
284 MITK_ERROR <<
"Unhandled excaption caught in CheckCondition(): " << e.what();
285 currentConditionFulfilled =
false;
290 MITK_ERROR <<
"Unhandled excaption caught in CheckCondition()";
291 currentConditionFulfilled =
false;
298 currentConditionFulfilled = conditionsMap[conditionName];
303 if (currentConditionFulfilled == (*conditionIter).IsInverted())
305 allConditionsFulfilled =
false;
311 if (allConditionsFulfilled)
313 return (*transitionIter);
329 if (m_MouseCursorSet)
335 m_MouseCursorSet =
true;
340 if (m_MouseCursorSet)
343 m_MouseCursorSet =
false;
bool LoadBehavior(const std::string &fileName, const us::Module *module)
Loads XML resource.
virtual MessageAbstractDelegate1 * Clone() const =0
StateMachineTransition * GetExecutableTransition(InteractionEvent *event)
Returns the executable transition for the given event.
std::vector< mitk::StateMachineAction::Pointer > ActionVectorType
std::string GetConditionName() const
Returns the String-Id of this action.
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 LoadStateMachine(const std::string &filename, const us::Module *module=nullptr)
Loads XML resource.
void PopCursor()
Restore the previous cursor.
virtual void ConnectActionsAndFunctions()
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
void AddActionFunction(const std::string &action, TActionFunctor *functor)
BaseRenderer * GetSender() const
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...
~EventStateMachine() override
StateMachineState * GetCurrentState() const
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
StateMachineState::Pointer GetStartState() const
Returns the StartState of the StateMachine.
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)
std::string GetActionName() const
Returns the String-Id of this action.
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
std::vector< StateMachineTransition::Pointer > TransitionVector
std::string MapToEventVariant(InteractionEvent *interactionEvent)
Class for nodes of the DataTree.
std::vector< StateMachineCondition > ConditionVectorType