00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 00019 #ifndef INTERACTOR_H_HEADER_INCLUDED 00020 #define INTERACTOR_H_HEADER_INCLUDED 00021 00022 #include "mitkCommon.h" 00023 #include "mitkStateMachine.h" 00024 #include "mitkGeometry3D.h" 00025 00026 #include <string> 00027 00028 namespace mitk { 00029 00030 class DataNode; 00031 class BaseData; 00032 00033 //##Documentation 00034 //## @brief Interface for an Interactor. 00035 //## 00036 //## The Interactor is held with a SmartPointer by a DataNode 00037 //## and holds its Node with a Pointer. That way Smartpointer doesn't build a circle. 00038 //## Different Modes: In order to not send Events to all StateMachines, a StateMachine can be 00039 //## in three different modes: 00040 //## DESELECTED: this statemachine doesn't wait for an event 00041 //## SELECTED: this statemachine just has handled an event and waits for the next one 00042 //## SUBSELECTED: depricate; was used for hierarchical statemachines before. 00043 //## Guidelines for the modevalues: Selected if the coresponding data is selected, deselected if deselect of data. 00044 //## 00045 //## In moving the machine is selected. After a new insert the machine is selected, since the data is also selected 00046 //## In method ExecuteAction(..) the different actions are divided up through switch/case statements. Each block has to check 00047 //## the appropriate type of event to process the actions. Especially in guarding states (a state, that checks certain conditions (e.g. is picked) 00048 //## the according Event must be called to continue in states. No return false here! 00049 //## @ingroup Interaction 00050 class MITK_CORE_EXPORT Interactor : public StateMachine 00051 { 00052 public: 00053 mitkClassMacro(Interactor, StateMachine); 00054 00058 mitkNewMacro2Param(Self, const char*, DataNode*); 00059 00060 //##Documentation 00061 //##@brief Enumeration of the different modes an Interactor can be into. 00062 //## See class documentation for further details 00063 enum SMMode 00064 { 00065 SMDESELECTED = 0, 00066 SMSELECTED, 00067 SMSUBSELECTED 00068 }; 00069 00070 typedef SMMode ModeType; 00071 00072 //##Documentation 00073 //## @brief Get the Mode of the Interactor. Use enum SMMode for return parameter 00074 SMMode GetMode() const; 00075 00076 //##Documentation 00077 //## @brief Check the interaction mode 00078 bool IsNotSelected() const; 00079 00080 //##Documentation 00081 //## @brief Check the interaction mode 00082 bool IsSelected() const; 00083 00084 //##Documentation 00085 //## @brief calculates how good the data, this statemachine handles, is hit by the event. 00086 //## 00087 //## Returns a value between 0 and 1 00088 //## where 0 represents not responsible and 1 represents definitive responsible! 00089 //## Standard function to override if needed. 00090 //## (Used by GlobalInteraction to decide which DESELECTED statemachine to send the event to.) 00091 virtual float CanHandleEvent(StateEvent const* stateEvent) const; 00092 00096 bool HandleEvent(StateEvent const* stateEvent); 00097 00105 virtual void DataChanged(){}; 00106 00107 00108 static const std::string XML_NODE_NAME; 00109 00110 protected: 00118 Interactor(const char * type, DataNode* dataNode); 00119 00123 ~Interactor(){} 00124 00125 bool OnModeSelect(Action* action, StateEvent const*); 00126 bool OnModeDeselect(Action* action, StateEvent const*); 00127 bool OnModeSubSelect(Action* action, StateEvent const*); 00128 00129 //##Documentation 00130 //## @brief adds handling of operations used for mode change. Unrecognized Operations are send to Superclass. 00131 virtual void ExecuteOperation(Operation* operation); 00132 00133 //##Documentation 00134 virtual const std::string& GetXMLNodeName() const; 00135 00136 //##Documentation 00137 //## @brief creates a ModeOperation with the transmitted mode and sends it to this. Undo supported! 00138 void CreateModeOperation(ModeType mode); 00139 00140 //##Documentation 00141 //## @brief convenience method for accessing the data contained in the 00142 //## node to which this interactor is associated to 00143 BaseData* GetData() const; 00144 00145 00146 //##Documentation 00147 //## @brief Used by friend class DataNode 00148 virtual void SetDataNode( DataNode* dataNode ); 00149 00155 virtual void UpdateTimeStep(unsigned int timeStep); 00156 00157 //##Documentation 00158 //## @brief Pointer to the data, this object handles the Interaction for 00159 DataNode* m_DataNode; 00160 00161 //##Documentation 00162 //## @brief Mode of Selection 00163 ModeType m_Mode; 00164 00165 friend class DataNode; 00166 }; 00167 00168 }//namespace mitk 00169 #endif /* INTERACTOR_H_HEADER_INCLUDED */ 00170 00171