Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef STATEMACHINE_H_HEADER_INCLUDED_C18896BD
00020 #define STATEMACHINE_H_HEADER_INCLUDED_C18896BD
00021
00022 #include "mitkCommon.h"
00023 #include <itkObject.h>
00024 #include "mitkOperationActor.h"
00025 #include <string>
00026 #include "mitkState.h"
00027 #include "mitkUndoModel.h"
00028
00029 namespace mitk {
00030
00031 class Action;
00032 class StateEvent;
00033 class UndoController;
00034
00035
00036 class MITK_CORE_EXPORT TStateMachineFunctor
00037 {
00038 public:
00039 virtual bool DoAction(Action*, const StateEvent*)=0;
00040 virtual ~TStateMachineFunctor() {}
00041 };
00042
00043
00044 template <class T>
00045 class TSpecificStateMachineFunctor : public TStateMachineFunctor
00046 {
00047 public:
00048
00049
00050
00051 TSpecificStateMachineFunctor(T* object, bool(T::*memberFunctionPointer)(Action*, const StateEvent*))
00052 :m_Object(object),
00053 m_MemberFunctionPointer(memberFunctionPointer)
00054 {
00055 }
00056
00057 virtual ~TSpecificStateMachineFunctor() {}
00058
00059
00060 virtual bool DoAction(Action* action, const StateEvent* stateEvent)
00061 {
00062 return (*m_Object.*m_MemberFunctionPointer)(action, stateEvent);
00063 }
00064
00065 private:
00066 T* m_Object;
00067 bool (T::*m_MemberFunctionPointer)(Action*, const StateEvent*);
00068 };
00069
00072 #define CONNECT_ACTION(a, f) \
00073 StateMachine::AddActionFunction(a, new TSpecificStateMachineFunctor<Self>(this, &Self::f));
00074
00075 #define STATEMACHINE_INFO MITK_INFO("StateMachine")
00076 #define STATEMACHINE_WARN MITK_WARN("StateMachine")
00077 #define STATEMACHINE_FATAL MITK_FATAL("StateMachine")
00078 #define STATEMACHINE_ERROR MITK_ERROR("StateMachine")
00079 #define STATEMACHINE_DEBUG MITK_DEBUG("StateMachine")
00080
00134 class MITK_CORE_EXPORT StateMachine : public itk::Object, public mitk::OperationActor
00135 {
00136
00137 public:
00138 mitkClassMacro(StateMachine,itk::Object);
00139
00143 mitkNewMacro1Param(Self, const char*);
00144
00145
00149 typedef std::map<int, TStateMachineFunctor*> ActionFunctionsMapType;
00150
00154 typedef std::vector<State::Pointer> StartStateVectorType;
00155
00159 std::string GetType() const;
00160
00170 virtual bool HandleEvent(StateEvent const* stateEvent);
00171
00175 void EnableUndo(bool enable);
00176
00180 friend class UndoModel;
00181
00182 friend class GlobalInteraction;
00183
00184
00185 protected:
00189 StateMachine(const char * type);
00190
00194 ~StateMachine();
00195
00199 void AddActionFunction(int action, TStateMachineFunctor* functor);
00200
00208 virtual bool ExecuteAction(Action* action, StateEvent const* stateEvent);
00209
00213 const State* GetCurrentState(unsigned int timeStep = 0) const;
00214
00220 bool m_UndoEnabled;
00221
00225 void IncCurrGroupEventId();
00226
00230 UndoController* m_UndoController;
00231
00239 virtual void ExecuteOperation(Operation* operation);
00240
00245 void ResetStatemachineToStartState(unsigned int timeStep = 0);
00246
00250 void ExpandStartStateVector(unsigned int timeSteps);
00251
00255 void InitializeStartStates(unsigned int timeSteps);
00256
00260 virtual void UpdateTimeStep(unsigned int timeStep);
00261
00265 unsigned int m_TimeStep;
00266
00267 private:
00271 std::string m_Type;
00272
00276 StartStateVectorType m_CurrentStateVector;
00277
00281 ActionFunctionsMapType m_ActionFunctionsMap;
00282
00283 };
00284
00285 }
00286
00287
00288
00289 #endif
00290
00291