Medical Imaging Interaction Toolkit  2016.11.0
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,
6  Division of Medical and Biological Informatics.
7  All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without
10  even the implied warranty of MERCHANTABILITY or FITNESS FOR
11  A PARTICULAR PURPOSE.
12 
13  See LICENSE.txt or http://www.mitk.org for details.
14 
15  ===================================================================*/
16 
17 #ifndef MITKEVENTSTATEMACHINE_H_
18 #define MITKEVENTSTATEMACHINE_H_
19 
20 #include "itkObject.h"
21 #include "mitkCommon.h"
23 #include "mitkMessage.h"
24 
25 #include <MitkCoreExports.h>
26 #include <string>
27 
33 #define CONNECT_FUNCTION(a, f) \
34  ::mitk::EventStateMachine::AddActionFunction( \
35  a, \
36  ::mitk::MessageDelegate2<Self, ::mitk::StateMachineAction *, ::mitk::InteractionEvent *, void>(this, &Self::f));
37 
38 #define CONNECT_CONDITION(a, f) \
39  ::mitk::EventStateMachine::AddConditionFunction( \
40  a, ::mitk::MessageDelegate1<Self, const ::mitk::InteractionEvent *, bool>(this, &Self::f));
41 
42 namespace us
43 {
44  class Module;
45 }
46 
47 namespace mitk
48 {
49  class StateMachineTransition;
50  class StateMachineContainer;
51  class StateMachineAction;
52  class StateMachineCondition;
53  class InteractionEvent;
54  class StateMachineState;
55  class DataNode;
56  class UndoController;
57 
65  {
66  public:
67  virtual bool DoAction(StateMachineAction *, InteractionEvent *) = 0;
68  virtual ~TActionFunctor() {}
69  };
70 
72  // * \class TSpecificActionFunctor
73  // * Specific implementation of ActionFunctor class, implements a reference to the function which is to be executed.
74  // It
75  // takes two arguments:
76  // * StateMachineAction - the action by which the function call is invoked, InteractionEvent - the event that caused
77  // the
78  // transition.
79  // */
80  // template<class T>
81  // class DEPRECATED() TSpecificActionFunctor : public TActionFunctor
82  //{
83  // public:
84 
85  // TSpecificActionFunctor(T* object, bool (T::*memberFunctionPointer)(StateMachineAction*, InteractionEvent*)) :
86  // m_Object(object), m_MemberFunctionPointer(memberFunctionPointer)
87  // {
88  // }
89 
90  // virtual ~TSpecificActionFunctor()
91  // {
92  // }
93  // virtual bool DoAction(StateMachineAction* action, InteractionEvent* event) override
94  // {
95  // return (*m_Object.*m_MemberFunctionPointer)(action, event);// executes member function
96  // }
97 
98  // private:
99  // T* m_Object;
100  // bool (T::*m_MemberFunctionPointer)(StateMachineAction*, InteractionEvent*);
101  //};
102 
116  {
117  public:
119 
121 
123 
131  bool LoadStateMachine(const std::string &filename, const us::Module *module = nullptr);
146  bool HandleEvent(InteractionEvent *event, DataNode *dataNode);
147 
151  void EnableUndo(bool enable) { m_UndoEnabled = enable; }
155  void EnableInteraction(bool enable) { m_IsActive = enable; }
156  protected:
158  virtual ~EventStateMachine();
159 
162 
167  DEPRECATED(void AddActionFunction(const std::string &action, TActionFunctor *functor));
168 
169  void AddActionFunction(const std::string &action, const ActionFunctionDelegate &delegate);
170 
171  void AddConditionFunction(const std::string &condition, const ConditionFunctionDelegate &delegate);
172 
173  StateMachineState *GetCurrentState() const;
174 
179  void ResetToStartState();
180 
187  virtual void ConnectActionsAndFunctions();
188 
189  virtual bool CheckCondition(const StateMachineCondition &condition, const InteractionEvent *interactionEvent);
190 
195  virtual void ExecuteAction(StateMachineAction *action, InteractionEvent *interactionEvent);
196 
214  virtual bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode);
215 
220  void SetMouseCursor(const char *xpm[], int hotspotX, int hotspotY);
221 
227  void ResetMouseCursor();
228 
245  StateMachineTransition *GetExecutableTransition(InteractionEvent *event);
246 
247  // Determines if state machine reacts to events
249  // Undo/Redo
252 
253  private:
254  typedef std::map<std::string, ActionFunctionDelegate *> ActionDelegatesMapType;
255  typedef std::map<std::string, ConditionFunctionDelegate *> ConditionDelegatesMapType;
256 
258  *m_StateMachineContainer; // storage of all states, action, transitions on which the statemachine operates.
259  std::map<std::string, TActionFunctor *> m_ActionFunctionsMap; // stores association between action string
260  ActionDelegatesMapType m_ActionDelegatesMap;
261  ConditionDelegatesMapType m_ConditionDelegatesMap;
262  StateMachineStateType m_CurrentState;
263 
264  bool m_MouseCursorSet;
265  };
266 
267 } /* namespace mitk */
268 #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:183
void EnableInteraction(bool enable)
Enables/disables the state machine. In un-enabled state it won't react to any events.
virtual bool DoAction(StateMachineAction *, InteractionEvent *)=0
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
static const std::string filename
virtual void ConnectActionsAndFunctions() override
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
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:66
Super-class that provides the functionality of a StateMachine to DataInteractors. ...