KWWidgets
vtkKWStateMachineState.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWStateMachineState.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWStateMachineState - a state machine state.
15 // .SECTION Description
16 // This class is the basis for a state machine state.
17 // A state machine is defined by a set of states, a set of inputs and a
18 // transition matrix that defines for each pair of (state,input) what is
19 // the next state to assume.
20 // .SECTION Thanks
21 // This work is part of the National Alliance for Medical Image
22 // Computing (NAMIC), funded by the National Institutes of Health
23 // through the NIH Roadmap for Medical Research, Grant U54 EB005149.
24 // Information on the National Centers for Biomedical Computing
25 // can be obtained from http://nihroadmap.nih.gov/bioinformatics.
26 // .SECTION See Also
27 // vtkKWStateMachine vtkKWStateMachineInput vtkKWStateMachineTransition
28 
29 #ifndef __vtkKWStateMachineState_h
30 #define __vtkKWStateMachineState_h
31 
32 #include "vtkKWObject.h"
33 
35 {
36 public:
37  static vtkKWStateMachineState* New();
38  vtkTypeRevisionMacro(vtkKWStateMachineState, vtkKWObject);
39  void PrintSelf(ostream& os, vtkIndent indent);
40 
41  // Description:
42  // Get id.
43  vtkGetMacro(Id, vtkIdType);
44 
45  // Description:
46  // Set/Get simple name.
47  vtkGetStringMacro(Name);
48  vtkSetStringMacro(Name);
49 
50  // Description:
51  // Set/Get longer description.
52  vtkGetStringMacro(Description);
53  vtkSetStringMacro(Description);
54 
55  // Description:
56  // Enter the state. This method should be invoked by the state machine when
57  // it enters this state. It will take care of calling the corresponding
58  // callbacks (EnterCommand) and events (EnterEvent). Subclasses that
59  // override this method should make sure they call their superclass's
60  // Enter() method.
61  virtual void Enter();
62 
63  // Description:
64  // Leave the state. This method should be invoked by the state machine when
65  // it leaves this state. It will take care of calling the corresponding
66  // callbacks (LeaveCommand) and events (LeaveEvent). Subclasses that
67  // override this method should make sure they call their superclass's
68  // Leave() method.
69  virtual void Leave();
70 
71  // Description:
72  // Specifies a command to associate with this state. This command
73  // should be invoked by the state machine when it enters this state.
74  // State machine (sub)classes should call the Enter() method most of the
75  // time, which will take care of triggering this callback and firing
76  // the EnterEvent as well.
77  // The 'object' argument is the object that will have the method called on
78  // it. The 'method' argument is the name of the method to be called and any
79  // arguments in string form. If the object is NULL, the method is still
80  // evaluated as a simple command.
81  virtual void SetEnterCommand(vtkObject *object, const char *method);
82  virtual void InvokeEnterCommand();
83  virtual int HasEnterCommand();
84 
85  // Description:
86  // Specifies a command to associate with this state. This command
87  // should be invoked by the state machine when it leaves this state.
88  // State machine (sub)classes should call the Leave() method most of the
89  // time, which will take care of triggering this callback and firing
90  // the EnterEvent as well.
91  // The 'object' argument is the object that will have the method called on
92  // it. The 'method' argument is the name of the method to be called and any
93  // arguments in string form. If the object is NULL, the method is still
94  // evaluated as a simple command.
95  virtual void SetLeaveCommand(vtkObject *object, const char *method);
96  virtual void InvokeLeaveCommand();
97  virtual int HasLeaveCommand();
98 
99  // Description:
100  // Events. The EnterEvent should be fired when the state machine enters
101  // this state. The LeaveEvent should be fired when the state machine
102  // leaves this state. In both case, state machine (sub)classes should call
103  // the corresponding Enter() end Leave() methods most of the time, which will
104  // take care of triggering both the callbacks and firing the events.
105  //BTX
106  enum
107  {
108  EnterEvent = 10000,
109  LeaveEvent
110  };
111  //ETX
112 
113  // Description:
114  // Set/Get if the set is an accepting state. This is mainly used for
115  // display or IO purposes (see vtkKWStateMachineDOTWriter).
116  vtkBooleanMacro(Accepting, int);
117  vtkGetMacro(Accepting, int);
118  vtkSetMacro(Accepting, int);
119 
120 protected:
123 
124  vtkIdType Id;
125  char *Name;
126  char *Description;
127  int Accepting;
128 
129  char *EnterCommand;
130  char *LeaveCommand;
131 
132 private:
133 
134  static vtkIdType IdCounter;
135 
136  vtkKWStateMachineState(const vtkKWStateMachineState&); // Not implemented
137  void operator=(const vtkKWStateMachineState&); // Not implemented
138 };
139 
140 #endif