vtkCommand.h 6.71 KB
Newer Older
Ken Martin's avatar
Ken Martin committed
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkCommand.h

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Ken Martin's avatar
Ken Martin committed
9

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
Ken Martin's avatar
Ken Martin committed
13
14

=========================================================================*/
15
// .NAME vtkCommand - superclass for callback/observer methods
Ken Martin's avatar
Ken Martin committed
16
// .SECTION Description
17
18
// vtkCommand is an implementation of the observer/command design
// pattern.  In this design pattern, any instance of vtkObject can be
19
// "observed" for any events it might invoke. For example,
20
21
22
23
24
25
26
27
28
// vtkRenderer invokes a StartEvent as it begins to render and a
// EndEvent when it finishes rendering. Filters (subclasses of
// vtkProcessObject) invoke StartEvent, ProgressEvent, and EndEvent as
// the filter processes data. Observers of events are added with the
// AddObserver() method found in vtkObject.  AddObserver(), besides
// requiring an event id or name, also takes an instance of vtkCommand
// (or a subclasses). Note that vtkCommand is meant to be subclassed,
// so that you can package the information necessary to support your
// callback.
Will Schroeder's avatar
Will Schroeder committed
29
//
30
31
32
33
34
35
36
37
38
// Event processing can be organized in priority lists, so it is
// possible to truncate the processing of a particular event by
// setting the AbortFlag variable. The priority is set using the
// AddObserver() method.  By default the priority is 0, events of the
// same priority are processed in last-in-first-processed order. The
// ordering/aborting of events is important for things like 3D
// widgets, which handle an event if the widget is selected (and then
// aborting further processing of that event).  Otherwise. the event
// is passed along for further processing.
Will Schroeder's avatar
Will Schroeder committed
39
40

// .SECTION See Also
41
42
// vtkObject vtkCallbackCommand vtkOldStyleCallbackCommand
// vtkInteractorObserver vtk3DWidget
Ken Martin's avatar
Ken Martin committed
43

44
45
#ifndef __vtkCommand_h
#define __vtkCommand_h
Ken Martin's avatar
Ken Martin committed
46

47
#include "vtkObjectBase.h"
Ken Martin's avatar
Ken Martin committed
48
49
50

class vtkObject;

51
// The superclass that all commands should be subclasses of
52
class VTK_COMMON_EXPORT vtkCommand : public vtkObjectBase
Ken Martin's avatar
Ken Martin committed
53
54
{
public:
Ken Martin's avatar
Ken Martin committed
55
56
57
58
59
  // Description:
  // Decrease the reference count (release by another object). This has
  // the same effect as invoking Delete() (i.e., it reduces the reference
  // count by 1).
  void UnRegister();
60
  virtual void UnRegister(vtkObjectBase *) 
Will Schroeder's avatar
Will Schroeder committed
61
    { this->UnRegister(); }
Ken Martin's avatar
Ken Martin committed
62
  
Will Schroeder's avatar
Will Schroeder committed
63
  // Description:
64
65
66
67
68
69
70
71
72
73
  // All derived classes of vtkCommand must implement this
  // method. This is the method that actually does the work of the
  // callback. The caller argument is the object invoking the event,
  // the eventId parameter is the id of the event, and callData
  // parameter is data that can be passed into the execute
  // method. (Note: vtkObject::InvokeEvent() takes two parameters: the
  // event id (or name) and call data. Typically call data is NULL,
  // but the user can package data and pass it this
  // way. Alternatively, a derived class of vtkCommand can be used to
  // pass data.)
74
75
  virtual void Execute(vtkObject *caller, unsigned long eventId, 
                       void *callData) = 0;
Will Schroeder's avatar
Will Schroeder committed
76
77

  // Description:
78
79
  // Convenience methods for translating between event names and event
  // ids.
80
  static const char *GetStringFromEventId(unsigned long event);
81
  static unsigned long GetEventIdFromString(const char *event);
Ken Martin's avatar
Ken Martin committed
82

83
84
85
  // Description:
  // Set/Get the abort flag. If this is set to true no further
  // commands are executed.
Will Schroeder's avatar
Will Schroeder committed
86
  void SetAbortFlag(int f)  
87
    { this->AbortFlag = f; }
Will Schroeder's avatar
Will Schroeder committed
88
  int GetAbortFlag() 
89
    { return this->AbortFlag; }
Will Schroeder's avatar
Will Schroeder committed
90
91
92
93
  void AbortFlagOn() 
    { this->SetAbortFlag(1); }
  void AbortFlagOff() 
    { this->SetAbortFlag(0); }
Bill Hoffman's avatar
Bill Hoffman committed
94
  
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  // Description:
  // Set/Get the passive observer flag. If this is set to true, this
  // indicates that this command does not change the state of the
  // system in any way. Passive observers are processed first, and
  // are not called even when another command has focus.
  void SetPassiveObserver(int f)  
    { this->PassiveObserver = f; }
  int GetPassiveObserver() 
    { return this->PassiveObserver; }
  void PassiveObserverOn() 
    { this->SetPassiveObserver(1); }
  void PassiveObserverOff() 
    { this->SetPassiveObserver(0); }
  
109
//BTX
110
111
112
113
114
  // Description:
  // All the currently defined events are listed here.  Developers can
  // use -- vtkCommand::UserEvent + int to specify their own event
  // ids. If this list is adjusted, be sure to adjust
  // vtkCommandEventStrings in vtkCommand.cxx to match.
Ken Martin's avatar
Ken Martin committed
115
116
  enum EventIds {
    NoEvent = 0,
Ken Martin's avatar
Ken Martin committed
117
    AnyEvent,
Ken Martin's avatar
Ken Martin committed
118
119
120
    DeleteEvent,
    StartEvent,
    EndEvent,
Sebastien Barre's avatar
Sebastien Barre committed
121
    RenderEvent,
Ken Martin's avatar
Ken Martin committed
122
123
    ProgressEvent,
    PickEvent,
Ken Martin's avatar
Ken Martin committed
124
125
    StartPickEvent,
    EndPickEvent,
Ken Martin's avatar
Ken Martin committed
126
    AbortCheckEvent,
Ken Martin's avatar
Ken Martin committed
127
    ExitEvent,
Ken Martin's avatar
Ken Martin committed
128
129
130
131
132
133
134
135
136
137
138
    LeftButtonPressEvent,
    LeftButtonReleaseEvent,
    MiddleButtonPressEvent,
    MiddleButtonReleaseEvent,
    RightButtonPressEvent,
    RightButtonReleaseEvent,
    EnterEvent,
    LeaveEvent,
    KeyPressEvent,
    KeyReleaseEvent,
    CharEvent,
Sebastien Barre's avatar
Sebastien Barre committed
139
    ExposeEvent,
Ken Martin's avatar
Ken Martin committed
140
141
142
    ConfigureEvent,
    TimerEvent,
    MouseMoveEvent,
143
144
    MouseWheelForwardEvent,
    MouseWheelBackwardEvent,
Charles Law's avatar
Charles Law committed
145
146
    ResetCameraEvent,
    ResetCameraClippingRangeEvent,
147
    ModifiedEvent,
Ken Martin's avatar
Ken Martin committed
148
    WindowLevelEvent,
149
150
    StartWindowLevelEvent,
    EndWindowLevelEvent,
151
    ResetWindowLevelEvent,
John Biddiscombe's avatar
John Biddiscombe committed
152
    SetOutputEvent,
153
    ErrorEvent,
Andy Cedilnik's avatar
Andy Cedilnik committed
154
    WarningEvent,
155
    StartInteractionEvent, //mainly used by vtkInteractorObservers
Will Schroeder's avatar
Will Schroeder committed
156
157
    InteractionEvent,
    EndInteractionEvent,
158
159
    EnableEvent,
    DisableEvent,
160
161
    CreateTimerEvent,
    DestroyTimerEvent,
162
    PlacePointEvent,
163
    PlaceWidgetEvent,
164
    CursorChangedEvent,
165
    ExecuteInformationEvent,
166
    RenderWindowMessageEvent,
167
    WrongTagEvent,
168
169
170
    StartAnimationCueEvent, // used by vtkAnimationCue
    AnimationCueTickEvent,
    EndAnimationCueEvent,
171
    VolumeMapperRenderEndEvent,
172
    VolumeMapperRenderProgressEvent,
173
    VolumeMapperRenderStartEvent,
174
175
176
    VolumeMapperComputeGradientsEndEvent,
    VolumeMapperComputeGradientsProgressEvent,
    VolumeMapperComputeGradientsStartEvent,
177
    WidgetModifiedEvent,
178
179
    WidgetValueChangedEvent,
    WidgetActivateEvent,
180
181
    ConnectionCreatedEvent, 
    ConnectionClosedEvent,
Berk Geveci's avatar
Berk Geveci committed
182
    DomainModifiedEvent,
183
184
    PropertyModifiedEvent,
    UpdateEvent,
185
186
    RegisterEvent,
    UnRegisterEvent,
187
    UpdateInformationEvent,
188
    SelectionChangedEvent,
189
    UpdatePropertyEvent,
190
    UserEvent = 1000
Ken Martin's avatar
Ken Martin committed
191
  };
192
//ETX
Will Schroeder's avatar
Will Schroeder committed
193

Ken Martin's avatar
Ken Martin committed
194
protected:
195
  int AbortFlag;
196
197
  int PassiveObserver;

198
  vtkCommand();
Will Schroeder's avatar
Will Schroeder committed
199
200
201
  virtual ~vtkCommand() {}

  friend class vtkSubjectHelper;
202
//BTX
Andy Cedilnik's avatar
Andy Cedilnik committed
203
  vtkCommand(const vtkCommand& c) : vtkObjectBase(c) {}
204
205
  void operator=(const vtkCommand&) {}
//ETX
Ken Martin's avatar
Ken Martin committed
206
207
};

208
209
#endif /* __vtkCommand_h */