vtkCommand.h 5.92 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
//BTX
96
97
98
99
100
  // 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
101
102
  enum EventIds {
    NoEvent = 0,
Ken Martin's avatar
Ken Martin committed
103
    AnyEvent,
Ken Martin's avatar
Ken Martin committed
104
105
106
    DeleteEvent,
    StartEvent,
    EndEvent,
Sebastien Barre's avatar
Sebastien Barre committed
107
    RenderEvent,
Ken Martin's avatar
Ken Martin committed
108
109
    ProgressEvent,
    PickEvent,
Ken Martin's avatar
Ken Martin committed
110
111
    StartPickEvent,
    EndPickEvent,
Ken Martin's avatar
Ken Martin committed
112
    AbortCheckEvent,
Ken Martin's avatar
Ken Martin committed
113
    ExitEvent,
Ken Martin's avatar
Ken Martin committed
114
115
116
117
118
119
120
121
122
123
124
    LeftButtonPressEvent,
    LeftButtonReleaseEvent,
    MiddleButtonPressEvent,
    MiddleButtonReleaseEvent,
    RightButtonPressEvent,
    RightButtonReleaseEvent,
    EnterEvent,
    LeaveEvent,
    KeyPressEvent,
    KeyReleaseEvent,
    CharEvent,
Sebastien Barre's avatar
Sebastien Barre committed
125
    ExposeEvent,
Ken Martin's avatar
Ken Martin committed
126
127
128
    ConfigureEvent,
    TimerEvent,
    MouseMoveEvent,
129
130
    MouseWheelForwardEvent,
    MouseWheelBackwardEvent,
Charles Law's avatar
Charles Law committed
131
132
    ResetCameraEvent,
    ResetCameraClippingRangeEvent,
133
    ModifiedEvent,
Ken Martin's avatar
Ken Martin committed
134
    WindowLevelEvent,
135
136
    StartWindowLevelEvent,
    EndWindowLevelEvent,
137
    ResetWindowLevelEvent,
John Biddiscombe's avatar
John Biddiscombe committed
138
    SetOutputEvent,
139
    ErrorEvent,
Andy Cedilnik's avatar
Andy Cedilnik committed
140
    WarningEvent,
141
    StartInteractionEvent, //mainly used by vtkInteractorObservers
Will Schroeder's avatar
Will Schroeder committed
142
143
    InteractionEvent,
    EndInteractionEvent,
144
145
    EnableEvent,
    DisableEvent,
146
147
    CreateTimerEvent,
    DestroyTimerEvent,
148
    PlacePointEvent,
149
    PlaceWidgetEvent,
150
    CursorChangedEvent,
151
    ExecuteInformationEvent,
152
    RenderWindowMessageEvent,
153
    WrongTagEvent,
154
155
156
    StartAnimationCueEvent, // used by vtkAnimationCue
    AnimationCueTickEvent,
    EndAnimationCueEvent,
157
158
159
160
    VolumeMapperRenderProgressEvent,
    VolumeMapperComputeGradientsEndEvent,
    VolumeMapperComputeGradientsProgressEvent,
    VolumeMapperComputeGradientsStartEvent,
161
    WidgetModifiedEvent,
162
163
    WidgetValueChangedEvent,
    WidgetActivateEvent,
Berk Geveci's avatar
Berk Geveci committed
164
    DomainModifiedEvent,
165
166
    PropertyModifiedEvent,
    UpdateEvent,
167
    UserEvent = 1000
Ken Martin's avatar
Ken Martin committed
168
  };
169
//ETX
Will Schroeder's avatar
Will Schroeder committed
170

Ken Martin's avatar
Ken Martin committed
171
protected:
172
  int AbortFlag;
173
  vtkCommand();
Will Schroeder's avatar
Will Schroeder committed
174
175
176
  virtual ~vtkCommand() {}

  friend class vtkSubjectHelper;
177
//BTX
Andy Cedilnik's avatar
Andy Cedilnik committed
178
  vtkCommand(const vtkCommand& c) : vtkObjectBase(c) {}
179
180
  void operator=(const vtkCommand&) {}
//ETX
Ken Martin's avatar
Ken Martin committed
181
182
};

183
184
#endif /* __vtkCommand_h */