Medical Imaging Interaction Toolkit  2026.06.00
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 
75  {
76  public:
78 
80 
92  bool LoadStateMachine(const std::string &filename, const us::Module *module = nullptr);
93 
108  bool HandleEvent(InteractionEvent *event, DataNode *dataNode);
109 
114  void EnableUndo(bool enable) { m_UndoEnabled = enable; }
115 
123  void EnableInteraction(bool enable) { m_IsActive = enable; }
124  protected:
126  ~EventStateMachine() override;
127 
130 
135  void AddActionFunction(const std::string &action, const ActionFunctionDelegate &delegate);
136 
137  void AddConditionFunction(const std::string &condition, const ConditionFunctionDelegate &delegate);
138 
140 
146 
154 
155  virtual bool CheckCondition(const StateMachineCondition &condition, const InteractionEvent *interactionEvent);
156 
161  virtual void ExecuteAction(StateMachineAction *action, InteractionEvent *interactionEvent);
162 
180  virtual bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode);
181 
186  void SetMouseCursor(const char *xpm[], int hotspotX, int hotspotY);
187 
193 
211 
212  // Determines if state machine reacts to events
214  // Undo/Redo
217 
218  private:
219  typedef std::map<std::string, ActionFunctionDelegate *> ActionDelegatesMapType;
220  typedef std::map<std::string, ConditionFunctionDelegate *> ConditionDelegatesMapType;
221 
223  *m_StateMachineContainer; // storage of all states, action, transitions on which the statemachine operates.
224  ActionDelegatesMapType m_ActionDelegatesMap;
225  ConditionDelegatesMapType m_ConditionDelegatesMap;
226  StateMachineStateType m_CurrentState;
227 
228  bool m_MouseCursorSet;
229  };
230 
231 } /* namespace mitk */
232 #endif
#define MITKCORE_EXPORT
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Provides state machine functionality for DataInteractors.
bool LoadStateMachine(const std::string &filename, const us::Module *module=nullptr)
Load a state machine pattern from an XML resource file.
bool HandleEvent(InteractionEvent *event, DataNode *dataNode)
Process an incoming interaction event.
void ResetToStartState()
ResetToStartState Reset state machine to it initial starting state.
void EnableInteraction(bool enable)
Enable or disable the state machine.
StateMachineState * GetCurrentState() const
mitkClassMacro(EventStateMachine, InteractionEventHandler)
void EnableUndo(bool enable)
Enable or disable the undo mechanism for this state machine.
itk::SmartPointer< StateMachineState > StateMachineStateType
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()
MessageAbstractDelegate2< StateMachineAction *, InteractionEvent *, void > ActionFunctionDelegate
Base class for all objects that handle mitk::InteractionEvents.
Base class for all interaction events in MITK.
Abstract base class for message delegates with one parameter.
Definition: mitkMessage.h:101
Abstract base class for message delegates with two parameters.
Definition: mitkMessage.h:116
Represents an action that is executed after a certain event in the state machine mechanism.
Represents a condition, that has to be fulfilled in order to execute a state machine transition after...
Parses XML state machine descriptions and builds the state machine structure.
Represents a state of a state machine pattern.
Connects two states, and holds references to corresponding actions and conditions.
Controller that manages undo/redo operations by delegating to an UndoModel.
Represents a CppMicroServices module.
Definition: usModule.h:70
Find image slices visible on a given plane.