00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWStateMachineTransition.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWStateMachineTransition - a state machine transition. 00015 // .SECTION Description 00016 // This class is the basis for a state machine transition. 00017 // A state machine is defined by a set of states, a set of inputs and a 00018 // transition matrix that defines for each pair of (state,input) what is 00019 // the next state to assume. 00020 // .SECTION Thanks 00021 // This work is part of the National Alliance for Medical Image 00022 // Computing (NAMIC), funded by the National Institutes of Health 00023 // through the NIH Roadmap for Medical Research, Grant U54 EB005149. 00024 // Information on the National Centers for Biomedical Computing 00025 // can be obtained from http://nihroadmap.nih.gov/bioinformatics. 00026 // .SECTION See Also 00027 // vtkKWStateMachine vtkKWStateMachineState vtkKWStateMachineTransition 00028 00029 #ifndef __vtkKWStateMachineTransition_h 00030 #define __vtkKWStateMachineTransition_h 00031 00032 #include "vtkKWObject.h" 00033 00034 class vtkKWStateMachineState; 00035 class vtkKWStateMachineInput; 00036 00037 class KWWidgets_EXPORT vtkKWStateMachineTransition : public vtkKWObject 00038 { 00039 public: 00040 static vtkKWStateMachineTransition* New(); 00041 vtkTypeRevisionMacro(vtkKWStateMachineTransition, vtkKWObject); 00042 void PrintSelf(ostream& os, vtkIndent indent); 00043 00044 // Description: 00045 // Get id. 00046 vtkGetMacro(Id, vtkIdType); 00047 00048 // Description: 00049 // Set/Get the state this transition is originating from. 00050 vtkGetObjectMacro(OriginState, vtkKWStateMachineState); 00051 virtual void SetOriginState(vtkKWStateMachineState*); 00052 00053 // Description: 00054 // Set/Get the input this transition is triggered by. 00055 vtkGetObjectMacro(Input, vtkKWStateMachineInput); 00056 virtual void SetInput(vtkKWStateMachineInput*); 00057 00058 // Description: 00059 // Set/Get the state this transition is leading to. 00060 vtkGetObjectMacro(DestinationState, vtkKWStateMachineState); 00061 virtual void SetDestinationState(vtkKWStateMachineState*); 00062 00063 // Description: 00064 // Get if the transition is complete, i.e. it has an originating 00065 // state (OriginState), a destination state (DestinationState), and 00066 // an input (Input). 00067 virtual int IsComplete(); 00068 00069 // Description: 00070 // Start the transition. This method should be invoked when the transition 00071 // is "started" by the state machine, as the state machine is about to 00072 // leave the OriginState but has not yet entered the DestinationState. 00073 // This can prove useful to push bew inputs that rely on the fact that the 00074 // state machine is still at the OriginState. 00075 // It will take care of calling the corresponding callbacks (StartCommand) 00076 // and events (StartEvent). Subclasses that override this method should 00077 // make sure they call their superclass's Start() method. 00078 virtual void Start(); 00079 00080 // Description: 00081 // End the transition. This command should be invoked when the transition 00082 // is "ended" by the state machine, as the state machine has left the 00083 // OriginState and already entered the DestinationState. 00084 // This can prove useful to push new inputs that rely on the fact that the 00085 // state machine is now at the DestinationState. 00086 // It will take care of calling the corresponding callbacks (EndCommand) 00087 // and events (EndEvent). Subclasses that override this method should 00088 // make sure they call their superclass's End() method. 00089 virtual void End(); 00090 00091 // Description: 00092 // Specifies a command to associate with this transition. This command 00093 // should be invoked when the transition is "started" by the state machine, 00094 // as the state machine is about to leave the OriginState but has not yet 00095 // entered the DestinationState. State machine (sub)classes should call 00096 // the Start() method most of the time, which will take care of triggering 00097 // this callback and firing the StartEvent as well. 00098 // The 'object' argument is the object that will have the method called on 00099 // it. The 'method' argument is the name of the method to be called and any 00100 // arguments in string form. If the object is NULL, the method is still 00101 // evaluated as a simple command. 00102 virtual void SetStartCommand(vtkObject *object, const char *method); 00103 virtual void InvokeStartCommand(); 00104 virtual int HasStartCommand(); 00105 00106 // Description: 00107 // Specifies a command to associate with this transition. This command 00108 // should be invoked when the transition is "ended" by the state machine, as 00109 // the state machine has left the OriginState and already entered 00110 // the DestinationState. State machine (sub)classes should call 00111 // the End() method most of the time, which will take care of triggering this 00112 // callback and firing the EndEvent as well. 00113 // The 'object' argument is the object that will have the method called on 00114 // it. The 'method' argument is the name of the method to be called and any 00115 // arguments in string form. If the object is NULL, the method is still 00116 // evaluated as a simple command. 00117 virtual void SetEndCommand(vtkObject *object, const char *method); 00118 virtual void InvokeEndCommand(); 00119 virtual int HasEndCommand(); 00120 00121 // Description: 00122 // Events. The StartEvent should be fired when the transition is "started" 00123 // by the state machine, as the state machine is about to leave the 00124 // OriginState but has not yet entered the DestinationState. The "EndEvent" 00125 // should be fired when the transition is "ended" by the state machine, as 00126 // the state machine has left the OriginState and already entered the 00127 // DestinationState. In both case, State machine (sub)classes should call 00128 // the corresponding Start() end End() methods most of the time, which will 00129 // take care of triggering both the callbacks and firing the events. 00130 //BTX 00131 enum 00132 { 00133 StartEvent = 10000, 00134 EndEvent 00135 }; 00136 //ETX 00137 00138 protected: 00139 vtkKWStateMachineTransition(); 00140 ~vtkKWStateMachineTransition(); 00141 00142 vtkIdType Id; 00143 vtkKWStateMachineState *OriginState; 00144 vtkKWStateMachineInput *Input; 00145 vtkKWStateMachineState *DestinationState; 00146 00147 char *EndCommand; 00148 char *StartCommand; 00149 00150 private: 00151 00152 static vtkIdType IdCounter; 00153 00154 vtkKWStateMachineTransition(const vtkKWStateMachineTransition&); // Not implemented 00155 void operator=(const vtkKWStateMachineTransition&); // Not implemented 00156 }; 00157 00158 #endif