Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkEventStateMachine.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkEventStateMachine_h
14 #define mitkEventStateMachine_h
15 
16 #include "itkObject.h"
17 #include "mitkCommon.h"
19 #include "mitkMessage.h"
20 
21 #include <MitkCoreExports.h>
22 #include <string>
23 
29 #define CONNECT_FUNCTION(a, f) \
30  ::mitk::EventStateMachine::AddActionFunction( \
31  a, \
32  ::mitk::MessageDelegate2<Self, ::mitk::StateMachineAction *, ::mitk::InteractionEvent *, void>(this, &Self::f));
33 
34 #define CONNECT_CONDITION(a, f) \
35  ::mitk::EventStateMachine::AddConditionFunction( \
36  a, ::mitk::MessageDelegate1<Self, const ::mitk::InteractionEvent *, bool>(this, &Self::f));
37 
38 namespace us
39 {
40  class Module;
41 }
42 
43 namespace mitk
44 {
45  class StateMachineTransition;
46  class StateMachineContainer;
47  class StateMachineAction;
48  class StateMachineCondition;
49  class InteractionEvent;
50  class StateMachineState;
51  class DataNode;
52  class UndoController;
53 
61  {
62  public:
64  virtual ~TActionFunctor() {}
65  };
66 
68  // * \class TSpecificActionFunctor
69  // * Specific implementation of ActionFunctor class, implements a reference to the function which is to be executed.
70  // It
71  // takes two arguments:
72  // * StateMachineAction - the action by which the function call is invoked, InteractionEvent - the event that caused
73  // the
74  // transition.
75  // */
76  // template<class T>
77  // class DEPRECATED() TSpecificActionFunctor : public TActionFunctor
78  //{
79  // public:
80 
81  // TSpecificActionFunctor(T* object, bool (T::*memberFunctionPointer)(StateMachineAction*, InteractionEvent*)) :
82  // m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
83  // {
84  // }
85 
86  // virtual ~TSpecificActionFunctor()
87  // {
88  // }
89  // virtual bool DoAction(StateMachineAction* action, InteractionEvent* event) override
90  // {
91  // return (*m_Object.*m_MemberFunctionPointer)(action, event);// executes member function
92  // }
93 
94  // private:
95  // T* m_Object;
96  // bool (T::*m_MemberFunctionPointer)(StateMachineAction*, InteractionEvent*);
97  //};
98 
112  {
113  public:
115 
116  typedef std::map<std::string, TActionFunctor *> DEPRECATED(ActionFunctionsMapType);
117 
119 
127  bool LoadStateMachine(const std::string &filename, const us::Module *module = nullptr);
142  bool HandleEvent(InteractionEvent *event, DataNode *dataNode);
143 
147  void EnableUndo(bool enable) { m_UndoEnabled = enable; }
151  void EnableInteraction(bool enable) { m_IsActive = enable; }
152  protected:
154  ~EventStateMachine() override;
155 
158 
163  DEPRECATED(void AddActionFunction(const std::string &action, TActionFunctor *functor));
164 
165  void AddActionFunction(const std::string &action, const ActionFunctionDelegate &delegate);
166 
167  void AddConditionFunction(const std::string &condition, const ConditionFunctionDelegate &delegate);
168 
170 
176 
184 
185  virtual bool CheckCondition(const StateMachineCondition &condition, const InteractionEvent *interactionEvent);
186 
191  virtual void ExecuteAction(StateMachineAction *action, InteractionEvent *interactionEvent);
192 
210  virtual bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode);
211 
216  void SetMouseCursor(const char *xpm[], int hotspotX, int hotspotY);
217 
223 
241 
242  // Determines if state machine reacts to events
244  // Undo/Redo
247 
248  private:
249  typedef std::map<std::string, ActionFunctionDelegate *> ActionDelegatesMapType;
250  typedef std::map<std::string, ConditionFunctionDelegate *> ConditionDelegatesMapType;
251 
253  *m_StateMachineContainer; // storage of all states, action, transitions on which the statemachine operates.
254  std::map<std::string, TActionFunctor *> m_ActionFunctionsMap; // stores association between action string
255  ActionDelegatesMapType m_ActionDelegatesMap;
256  ConditionDelegatesMapType m_ConditionDelegatesMap;
257  StateMachineStateType m_CurrentState;
258 
259  bool m_MouseCursorSet;
260  };
261 
262 } /* namespace mitk */
263 #endif
#define MITKCORE_EXPORT
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
bool LoadStateMachine(const std::string &filename, const us::Module *module=nullptr)
Loads XML resource.
bool HandleEvent(InteractionEvent *event, DataNode *dataNode)
void ResetToStartState()
ResetToStartState Reset state machine to it initial starting state.
void EnableInteraction(bool enable)
Enables/disables the state machine. In un-enabled state it won't react to any events.
StateMachineState * GetCurrentState() const
void EnableUndo(bool enable)
Enables or disabled Undo.
itk::SmartPointer< StateMachineState > StateMachineStateType
std::map< std::string, TActionFunctor * > ActionFunctionsMapType
virtual void ExecuteAction(StateMachineAction *action, InteractionEvent *interactionEvent)
~EventStateMachine() override
void AddConditionFunction(const std::string &condition, const ConditionFunctionDelegate &delegate)
void AddActionFunction(const std::string &action, const ActionFunctionDelegate &delegate)
virtual bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode)
virtual bool CheckCondition(const StateMachineCondition &condition, const InteractionEvent *interactionEvent)
void ResetMouseCursor()
Resets the mouse cursor to its original state.
StateMachineTransition * GetExecutableTransition(InteractionEvent *event)
Returns the executable transition for the given event.
MessageAbstractDelegate1< const InteractionEvent *, bool > ConditionFunctionDelegate
void SetMouseCursor(const char *xpm[], int hotspotX, int hotspotY)
Sets the specified mouse cursor.
virtual void ConnectActionsAndFunctions()
void AddActionFunction(const std::string &action, TActionFunctor *functor)
MessageAbstractDelegate2< StateMachineAction *, InteractionEvent *, void > ActionFunctionDelegate
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
Connects two states, and holds references to corresponding actions and conditions.
Base class of ActionFunctors, to provide an easy to connect actions with functions.
virtual bool DoAction(StateMachineAction *, InteractionEvent *)=0
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
#define DEPRECATED(func)
Definition: mitkCommon.h:175
Find image slices visible on a given plane.