Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::EventStateMachine Class Reference

Provides state machine functionality for DataInteractors. More...

#include <mitkEventStateMachine.h>

Inheritance diagram for mitk::EventStateMachine:
Collaboration diagram for mitk::EventStateMachine:

Public Types

typedef itk::SmartPointer< StateMachineState > StateMachineStateType
 

Public Member Functions

 mitkClassMacro (EventStateMachine, InteractionEventHandler)
 
bool LoadStateMachine (const std::string &filename, const us::Module *module=nullptr)
 Load a state machine pattern from an XML resource file. More...
 
bool HandleEvent (InteractionEvent *event, DataNode *dataNode)
 Process an incoming interaction event. More...
 
void EnableUndo (bool enable)
 Enable or disable the undo mechanism for this state machine. More...
 
void EnableInteraction (bool enable)
 Enable or disable the state machine. More...
 
- Public Member Functions inherited from mitk::InteractionEventHandler
 mitkClassMacroItkParent (InteractionEventHandler, itk::Object)
 
bool SetEventConfig (const std::string &filename, const us::Module *module=nullptr)
 Loads a configuration from an XML resource. More...
 
bool SetEventConfig (const EventConfig &config)
 Loads a configuration from an EventConfig object. More...
 
EventConfig GetEventConfig () const
 Returns the current configuration. More...
 
bool AddEventConfig (const std::string &filename, const us::Module *module=nullptr)
 This method extends the configuration. More...
 
bool AddEventConfig (const EventConfig &config)
 This method extends the configuration. The configuration from the EventConfig object is loaded and only the ones conflicting are replaced by the new one. This way several configurations can be combined. More...
 

Protected Types

typedef MessageAbstractDelegate2< StateMachineAction *, InteractionEvent *, void > ActionFunctionDelegate
 
typedef MessageAbstractDelegate1< const InteractionEvent *, bool > ConditionFunctionDelegate
 

Protected Member Functions

 EventStateMachine ()
 
 ~EventStateMachine () override
 
void AddActionFunction (const std::string &action, const ActionFunctionDelegate &delegate)
 
void AddConditionFunction (const std::string &condition, const ConditionFunctionDelegate &delegate)
 
StateMachineState * GetCurrentState () const
 
void ResetToStartState ()
 ResetToStartState Reset state machine to it initial starting state. More...
 
virtual void ConnectActionsAndFunctions ()
 
virtual bool CheckCondition (const StateMachineCondition &condition, const InteractionEvent *interactionEvent)
 
virtual void ExecuteAction (StateMachineAction *action, InteractionEvent *interactionEvent)
 
virtual bool FilterEvents (InteractionEvent *interactionEvent, DataNode *dataNode)
 
void SetMouseCursor (const char *xpm[], int hotspotX, int hotspotY)
 Sets the specified mouse cursor. More...
 
void ResetMouseCursor ()
 Resets the mouse cursor to its original state. More...
 
StateMachineTransition * GetExecutableTransition (InteractionEvent *event)
 Returns the executable transition for the given event. More...
 
- Protected Member Functions inherited from mitk::InteractionEventHandler
 InteractionEventHandler ()
 
 ~InteractionEventHandler () override
 
PropertyList::Pointer GetAttributes () const
 
std::string MapToEventVariant (InteractionEvent *interactionEvent)
 
virtual void ConfigurationChanged ()
 

Protected Attributes

bool m_IsActive
 
UndoController * m_UndoController
 
bool m_UndoEnabled
 

Detailed Description

Provides state machine functionality for DataInteractors.

A state machine is created by loading an XML state machine pattern via LoadStateMachine(). It consists of states, transitions, and actions:

  • States represent the current status of the interaction.
  • Transitions are the means to switch between states; each is triggered by an event.
  • Actions are executed when a state change is performed.

Subclasses override ConnectActionsAndFunctions() to bind action names from the XML description to C++ member functions using the CONNECT_FUNCTION macro. Conditions can be bound similarly using the CONNECT_CONDITION macro.

See also
DataInteractor
InteractionEventHandler
Dispatcher

Definition at line 74 of file mitkEventStateMachine.h.

Member Typedef Documentation

◆ ActionFunctionDelegate

◆ ConditionFunctionDelegate

◆ StateMachineStateType

Constructor & Destructor Documentation

◆ EventStateMachine()

mitk::EventStateMachine::EventStateMachine ( )
protected

◆ ~EventStateMachine()

mitk::EventStateMachine::~EventStateMachine ( )
overrideprotected

Member Function Documentation

◆ AddActionFunction()

void mitk::EventStateMachine::AddActionFunction ( const std::string &  action,
const ActionFunctionDelegate &  delegate 
)
protected

Connects action from StateMachine (String in XML file) with a function that is called when this action is to be executed.

◆ AddConditionFunction()

void mitk::EventStateMachine::AddConditionFunction ( const std::string &  condition,
const ConditionFunctionDelegate &  delegate 
)
protected

◆ CheckCondition()

virtual bool mitk::EventStateMachine::CheckCondition ( const StateMachineCondition &  condition,
const InteractionEvent *  interactionEvent 
)
protectedvirtual

◆ ConnectActionsAndFunctions()

◆ EnableInteraction()

void mitk::EventStateMachine::EnableInteraction ( bool  enable)
inline

Enable or disable the state machine.

When disabled, the state machine will not react to any events.

Parameters
[in]enableTrue to enable interaction, false to disable.

Definition at line 123 of file mitkEventStateMachine.h.

◆ EnableUndo()

void mitk::EventStateMachine::EnableUndo ( bool  enable)
inline

Enable or disable the undo mechanism for this state machine.

Parameters
[in]enableTrue to enable undo, false to disable.

Definition at line 114 of file mitkEventStateMachine.h.

◆ ExecuteAction()

virtual void mitk::EventStateMachine::ExecuteAction ( StateMachineAction *  action,
InteractionEvent *  interactionEvent 
)
protectedvirtual

Looks up function that is associated with action and executes it. To implement your own execution scheme overwrite this in your DataInteractor.

◆ FilterEvents()

virtual bool mitk::EventStateMachine::FilterEvents ( InteractionEvent *  interactionEvent,
DataNode *  dataNode 
)
protectedvirtual

Implements filter scheme for events. Standard implementation accepts events from 2d and 3d windows, and rejects events if DataNode is not visible.

Returns
true if event is accepted, else false

Overwrite this function to adapt for your own needs, for example to filter out events from 3d windows like this:

bool mitk::EventStateMachine::FilterEvents(InteractionEvent* interactionEvent, DataNode*dataNode)
{
return interactionEvent->GetSender()->GetMapperID() == BaseRenderer::Standard2D; // only 2D mappers
}
@ Standard2D
Use 2D mappers for rendering.
virtual bool FilterEvents(InteractionEvent *interactionEvent, DataNode *dataNode)

or to enforce that the interactor only reacts when the corresponding DataNode is selected in the DataManager view..

Reimplemented in mitk::SegTool2D, mitk::DisplayActionEventBroadcast, mitk::PlanarFigureInteractor, and mitk::Tool.

◆ GetCurrentState()

StateMachineState* mitk::EventStateMachine::GetCurrentState ( ) const
protected

◆ GetExecutableTransition()

StateMachineTransition* mitk::EventStateMachine::GetExecutableTransition ( InteractionEvent *  event)
protected

Returns the executable transition for the given event.

This method takes a list of transitions that correspond to the given event from the current state.

This method iterates through all transitions and checks all corresponding conditions. The results of each condition in stored in map, as other transitions may need the same condition again.

As soon as a transition is found for which all conditions are fulfilled, this instance is returned.

If a transition has no condition, it is automatically returned. If no executable transition is found, nullptr is returned.

◆ HandleEvent()

bool mitk::EventStateMachine::HandleEvent ( InteractionEvent *  event,
DataNode *  dataNode 
)

Process an incoming interaction event.

Receives an event from the Dispatcher, maps it to a variant via the EventConfig, checks if the current state has a matching transition, and if so, transitions to the next state and executes all associated actions.

Parameters
[in]eventThe interaction event to handle.
[in]dataNodeThe DataNode associated with this interactor.
Returns
true if the event was handled (a transition was executed), false otherwise.
Note
If a transition has multiple actions, true is returned as soon as one action succeeds. All actions within a transition should have consistent conditions.

◆ LoadStateMachine()

bool mitk::EventStateMachine::LoadStateMachine ( const std::string &  filename,
const us::Module *  module = nullptr 
)

Load a state machine pattern from an XML resource file.

The file must be located in the Resources/Interaction folder of the given module. Default is the Mitk module (core). After loading, ConnectActionsAndFunctions() is called to bind actions.

Parameters
[in]filenameThe resource filename (e.g. "PointSetInteraction.xml").
[in]moduleThe module containing the resource. Defaults to the Mitk module.
Returns
true if the state machine was loaded successfully, false otherwise.

◆ mitkClassMacro()

mitk::EventStateMachine::mitkClassMacro ( EventStateMachine  ,
InteractionEventHandler   
)

◆ ResetMouseCursor()

void mitk::EventStateMachine::ResetMouseCursor ( )
protected

Resets the mouse cursor to its original state.

Should be used by subclasses and from external application instead of using QmitkApplicationCursor directly to avoid conflicts.

◆ ResetToStartState()

void mitk::EventStateMachine::ResetToStartState ( )
protected

ResetToStartState Reset state machine to it initial starting state.

◆ SetMouseCursor()

void mitk::EventStateMachine::SetMouseCursor ( const char *  xpm[],
int  hotspotX,
int  hotspotY 
)
protected

Sets the specified mouse cursor.

Use this in subclasses instead of using QmitkApplicationCursor directly.

Member Data Documentation

◆ m_IsActive

bool mitk::EventStateMachine::m_IsActive
protected

Definition at line 213 of file mitkEventStateMachine.h.

◆ m_UndoController

UndoController* mitk::EventStateMachine::m_UndoController
protected

Definition at line 215 of file mitkEventStateMachine.h.

◆ m_UndoEnabled

bool mitk::EventStateMachine::m_UndoEnabled
protected

Definition at line 216 of file mitkEventStateMachine.h.


The documentation for this class was generated from the following file: