Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
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 
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 
223  void ResetMouseCursor();
224 
241  StateMachineTransition *GetExecutableTransition(InteractionEvent *event);
242 
243  // Determines if state machine reacts to events
245  // Undo/Redo
248 
249  private:
250  typedef std::map<std::string, ActionFunctionDelegate *> ActionDelegatesMapType;
251  typedef std::map<std::string, ConditionFunctionDelegate *> ConditionDelegatesMapType;
252 
254  *m_StateMachineContainer; // storage of all states, action, transitions on which the statemachine operates.
255  std::map<std::string, TActionFunctor *> m_ActionFunctionsMap; // stores association between action string
256  ActionDelegatesMapType m_ActionDelegatesMap;
257  ConditionDelegatesMapType m_ConditionDelegatesMap;
258  StateMachineStateType m_CurrentState;
259 
260  bool m_MouseCursorSet;
261  };
262 
263 } /* namespace mitk */
264 #endif /* MITKEVENTSTATEMACHINE_H_ */
#define MITKCORE_EXPORT
Base class of ActionFunctors, to provide an easy to connect actions with functions.
MessageAbstractDelegate2< StateMachineAction *, InteractionEvent *, void > ActionFunctionDelegate
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
#define DEPRECATED(func)
Definition: mitkCommon.h:179
void EnableInteraction(bool enable)
Enables/disables the state machine. In un-enabled state it won&#39;t react to any events.
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:40
std::map< std::string, TActionFunctor * > ActionFunctionsMapType
Connects two states, and holds references to corresponding actions and conditions.
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
MessageAbstractDelegate1< const InteractionEvent *, bool > ConditionFunctionDelegate
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Super-class that provides the functionality of a StateMachine to DataInteractors. ...