Medical Imaging Interaction Toolkit  2024.06.99-60d9b802
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:
63  virtual bool DoAction(StateMachineAction *, InteractionEvent *) = 0;
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 
169  StateMachineState *GetCurrentState() const;
170 
175  void ResetToStartState();
176 
183  virtual void ConnectActionsAndFunctions();
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 
222  void ResetMouseCursor();
223 
240  StateMachineTransition *GetExecutableTransition(InteractionEvent *event);
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
mitk::InteractionEventHandler
Definition: mitkInteractionEventHandler.h:40
mitk::TActionFunctor::DoAction
virtual bool DoAction(StateMachineAction *, InteractionEvent *)=0
mitk::InteractionEvent
Definition: mitkInteractionEvent.h:26
mitk::EventStateMachine::ConditionFunctionDelegate
MessageAbstractDelegate1< const InteractionEvent *, bool > ConditionFunctionDelegate
Definition: mitkEventStateMachine.h:157
mitk::EventStateMachine::m_IsActive
bool m_IsActive
Definition: mitkEventStateMachine.h:243
mitk::StateMachineState
Definition: mitkStateMachineState.h:30
us
Definition: mitkAbstractFileReader.h:29
mitk::TActionFunctor::~TActionFunctor
virtual ~TActionFunctor()
Definition: mitkEventStateMachine.h:64
DEPRECATED
#define DEPRECATED(func)
Definition: mitkCommon.h:175
mitk::EventStateMachine::EnableUndo
void EnableUndo(bool enable)
Enables or disabled Undo.
Definition: mitkEventStateMachine.h:147
itk::SmartPointer< StateMachineState >
mitk::StateMachineCondition
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
Definition: mitkStateMachineCondition.h:47
mitk::StateMachineContainer
Definition: mitkStateMachineContainer.h:39
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkInteractionEventHandler.h
mitk::EventStateMachine
‍**
Definition: mitkEventStateMachine.h:111
mitk::EventStateMachine::StateMachineStateType
itk::SmartPointer< StateMachineState > StateMachineStateType
Definition: mitkEventStateMachine.h:118
mitk::EventStateMachine::m_UndoController
UndoController * m_UndoController
Definition: mitkEventStateMachine.h:245
MitkCoreExports.h
mitkMessage.h
mitk::MessageAbstractDelegate1
Definition: mitkMessage.h:93
us::Module
Definition: usModule.h:78
mitk::EventStateMachine::m_UndoEnabled
bool m_UndoEnabled
Definition: mitkEventStateMachine.h:246
mitkCommon.h
mitk::StateMachineTransition
Connects two states, and holds references to corresponding actions and conditions.
Definition: mitkStateMachineTransition.h:44
mitk::EventStateMachine::ActionFunctionsMapType
std::map< std::string, TActionFunctor * > ActionFunctionsMapType
Definition: mitkEventStateMachine.h:114
mitk::MessageAbstractDelegate2
Definition: mitkMessage.h:103
mitk::StateMachineAction
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
Definition: mitkStateMachineAction.h:30
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::EventStateMachine::EnableInteraction
void EnableInteraction(bool enable)
Enables/disables the state machine. In un-enabled state it won't react to any events.
Definition: mitkEventStateMachine.h:151
mitk::UndoController
Definition: mitkUndoController.h:24
mitk::EventStateMachine::ActionFunctionDelegate
MessageAbstractDelegate2< StateMachineAction *, InteractionEvent *, void > ActionFunctionDelegate
Definition: mitkEventStateMachine.h:156
MITKCORE_EXPORT
#define MITKCORE_EXPORT
Definition: MitkCoreExports.h:15
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
mitk::TActionFunctor
Base class of ActionFunctors, to provide an easy to connect actions with functions.
Definition: mitkEventStateMachine.h:60