1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkCommand.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 // .NAME vtkCommand - superclass for callback/observer methods 16 // .SECTION Description 17 // vtkCommand is an implementation of the observer/command design 18 // pattern. In this design pattern, any instance of vtkObject can be 19 // "observed" for any events it might invoke. For example, 20 // vtkRenderer invokes a StartEvent as it begins to render and a 21 // EndEvent when it finishes rendering. Filters (subclasses of 22 // vtkProcessObject) invoke StartEvent, ProgressEvent, and EndEvent as 23 // the filter processes data. Observers of events are added with the 24 // AddObserver() method found in vtkObject. AddObserver(), besides 25 // requiring an event id or name, also takes an instance of vtkCommand 26 // (or a subclasses). Note that vtkCommand is meant to be subclassed, 27 // so that you can package the information necessary to support your 28 // callback. 29 // 30 // Event processing can be organized in priority lists, so it is 31 // possible to truncate the processing of a particular event by 32 // setting the AbortFlag variable. The priority is set using the 33 // AddObserver() method. By default the priority is 0, events of the 34 // same priority are processed in last-in-first-processed order. The 35 // ordering/aborting of events is important for things like 3D 36 // widgets, which handle an event if the widget is selected (and then 37 // aborting further processing of that event). Otherwise. the event 38 // is passed along for further processing. 39 // 40 // When an instance of vtkObject invokes an event, it also passes an optional 41 // void pointer to a callData. This callData is NULL most of the time. 42 // The callData is not specific to a type of event but specific to a type 43 // of vtkObject invoking a specific event. For instance, vtkCommand::PickEvent 44 // is invoked by vtkProp with a NULL callData but is invoked by 45 // vtkInteractorStyleImage with a pointer to the vtkInteractorStyleImage object 46 // itself. 47 // 48 // Here is the list of events that may be invoked with a non-NULL callData. 49 // - vtkCommand::ProgressEvent 50 // - most of the objects return a pointer to a double value ranged between 51 // 0.0 and 1.0 52 // - Infovis/vtkFixedWidthTextReader returns a pointer to a float value equal 53 // to the number of lines read so far. 54 // - vtkCommand::ErrorEvent 55 // - an error message as a const char * string 56 // - vtkCommand::WarningEvent 57 // - a warning message as a const char * string 58 // - vtkCommand::StartAnimationCueEvent 59 // - a pointer to a vtkAnimationCue::AnimationCueInfo object 60 // - vtkCommand::EndAnimationCueEvent 61 // - a pointer to a vtkAnimationCue::AnimationCueInfo object 62 // - vtkCommand::AnimationCueTickEvent 63 // - a pointer to a vtkAnimationCue::AnimationCueInfo object 64 // - vtkCommand::PickEvent 65 // - Common/vtkProp returns NULL 66 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 67 // - vtkCommand::StartPickEvent 68 // - Rendering/vtkPropPicker returns NULL 69 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 70 // - vtkCommand::EndPickEvent 71 // - Rendering/vtkPropPicker returns NULL 72 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 73 // - vtkCommand::WrongTagEvent 74 // - Parallel/vtkSocketCommunicator returns a received tag as a char * 75 // - vtkCommand::SelectionChangedEvent 76 // - Views/vtkView returns NULL 77 // - Views/vtkDataRepresentation returns a pointer to a vtkSelection 78 // - Rendering/vtkInteractorStyleRubberBand2D returns an array of 5 unsigned 79 // integers (p1x, p1y, p2x, p2y, mode), where mode is 80 // vtkInteractorStyleRubberBand2D::SELECT_UNION or 81 // vtkInteractorStyleRubberBand2D::SELECT_NORMAL 82 // - vtkCommand::AnnotationChangedEvent 83 // - GUISupport/Qt/vtkQtAnnotationView returns a pointer to a 84 // vtkAnnotationLayers 85 // - vtkCommand::PlacePointEvent 86 // - Widgets/vtkSeedWidget returns a pointer to an int, being the current 87 // handle number 88 // - vtkCommand::ResetWindowLevelEvent 89 // - Widgets/vtkImagePlaneWidget returns an array of 2 double values (window 90 // and level) 91 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 92 // - vtkCommand::StartWindowLevelEvent 93 // - Widgets/vtkImagePlaneWidget returns an array of 2 double values (window 94 // and level) 95 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 96 // - vtkCommand::EndWindowLevelEvent 97 // - Widgets/vtkImagePlaneWidget returns an array of 2 double values (window 98 // and level) 99 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 100 // - vtkCommand::WindowLevelEvent 101 // - Widgets/vtkImagePlaneWidget returns an array of 2 double values (window 102 // and level) 103 // - Rendering/vtkInteractorStyleImage returns a pointer to itself 104 // - vtkCommand::CharEvent 105 // - most of the objects return NULL 106 // - GUISupport/Qt/QVTKWidget returns a QKeyEvent * 107 // - vtkCommand::TimerEvent 108 // - most of the objects return a to an int representing a timer id 109 // - Rendering/vtkXRenderWindowTclInteractor returns NULL 110 // - Widgets/vtkHoverWidget returns NULL 111 // - vtkCommand::CreateTimerEvent 112 // - Rendering/vtkGenericRenderWindowInteractor returns a to an int 113 // representing a timer id 114 // - vtkCommand::DestroyTimerEvent 115 // - Rendering/vtkGenericRenderWindowInteractor returns a to an int 116 // representing a timer id 117 // - vtkCommand::UserEvent 118 // - most of the objects return NULL 119 // - Infovis/vtkInteractorStyleTreeMapHover returns a pointer to a vtkIdType 120 // representing a pedigree id 121 // - vtkCommand::KeyPressEvent 122 // - most of the objects return NULL 123 // - GUISupport/Qt/QVTKWidget returns a QKeyEvent* 124 // - vtkCommand::KeyReleaseEvent 125 // - most of the objects return NULL 126 // - GUISupport/Qt/QVTKWidget returns a QKeyEvent* 127 // - vtkCommand::LeftButtonPressEvent 128 // - most of the objects return NULL 129 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 130 // - vtkCommand::LeftButtonReleaseEvent 131 // - most of the objects return NULL 132 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 133 // - vtkCommand::MouseMoveEvent 134 // - most of the objects return NULL 135 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 136 // - vtkCommand::MouseWheelForwardEvent 137 // - most of the objects return NULL 138 // - GUISupport/Qt/QVTKWidget returns a QWheelEvent* 139 // - vtkCommand::MouseWheelBackwardEvent 140 // - most of the objects return NULL 141 // - GUISupport/Qt/QVTKWidget returns a QWheelEvent* 142 // - vtkCommand::RightButtonPressEvent 143 // - most of the objects return NULL 144 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 145 // - vtkCommand::RightButtonReleaseEvent 146 // - most of the objects return NULL 147 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 148 // - vtkCommand::MiddleButtonPressEvent 149 // - most of the objects return NULL 150 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 151 // - vtkCommand::MiddleButtonReleaseEvent 152 // - most of the objects return NULL 153 // - GUISupport/Qt/QVTKWidget returns a QMouseEvent* 154 // - vtkCommand::CursorChangedEvent 155 // - most of the objects return a pointer to an int representing a shape 156 // - Rendering/vtkInteractorObserver returns NULL 157 // - vtkCommand::ResetCameraEvent 158 // - Rendering/vtkRenderer returns a pointer to itself 159 // - vtkCommand::ResetCameraClippingRangeEvent 160 // - Rendering/vtkRenderer returns a pointer to itself 161 // - vtkCommand::ActiveCameraEvent 162 // - Rendering/vtkRenderer returns a pointer to the active camera 163 // - vtkCommand::CreateCameraEvent 164 // - Rendering/vtkRenderer returns a pointer to the created camera 165 // - vtkCommand::EnterEvent 166 // - most of the objects return NULL 167 // - GUISupport/Qt/QVTKWidget returns a QEvent* 168 // - vtkCommand::LeaveEvent 169 // - most of the objects return NULL 170 // - GUISupport/Qt/QVTKWidget returns a QEvent* 171 // - vtkCommand::RenderWindowMessageEvent 172 // - Rendering/vtkWin32OpenGLRenderWindow return a pointer to a UINT message 173 // - vtkCommand::ComputeVisiblePropBoundsEvent 174 // - Rendering/vtkRenderer returns a pointer to itself 175 // - QVTKWidget::ContextMenuEvent 176 // - GUISupport/Qt/QVTKWidget returns a QContextMenuEvent* 177 // - QVTKWidget::DragEnterEvent 178 // - GUISupport/Qt/QVTKWidget returns a QDragEnterEvent* 179 // - QVTKWidget::DragMoveEvent 180 // - GUISupport/Qt/QVTKWidget returns a QDragMoveEvent* 181 // - QVTKWidget::DragLeaveEvent 182 // - GUISupport/Qt/QVTKWidget returns a QDragLeaveEvent* 183 // - QVTKWidget::DropEvent 184 // - GUISupport/Qt/QVTKWidget returns a QDropEvent* 185 // - vtkCommand::ViewProgressEvent 186 // - View/vtkView returns a ViewProgressEventCallData* 187 // - vtkCommand::VolumeMapperRenderProgressEvent 188 // - A pointer to a double value between 0.0 and 1.0 189 // - vtkCommand::VolumeMapperComputeGradientsProgressEvent 190 // - A pointer to a double value between 0.0 and 1.0 191 // - vtkCommand::TDxMotionEvent (TDx=3DConnexion) 192 // - A vtkTDxMotionEventInfo* 193 // - vtkCommand::TDxButtonPressEvent 194 // - A int* being the number of the button 195 // - vtkCommand::TDxButtonReleaseEvent 196 // - A int* being the number of the button 197 // 198 // .SECTION See Also 199 // vtkObject vtkCallbackCommand vtkOldStyleCallbackCommand 200 // vtkInteractorObserver vtk3DWidget 201 202 #ifndef vtkCommand_h 203 #define vtkCommand_h 204 205 #include "vtkCommonCoreModule.h" // For export macro 206 #include "vtkObjectBase.h" 207 #include "vtkObject.h" // Need vtkTypeMacro 208 209 // Define all types of events here. 210 // Using this macro makes it possible to avoid mismatches between the event 211 // enums and their string counterparts. 212 #define vtkAllEventsMacro() \ 213 _vtk_add_event(AnyEvent)\ 214 _vtk_add_event(DeleteEvent)\ 215 _vtk_add_event(StartEvent)\ 216 _vtk_add_event(EndEvent)\ 217 _vtk_add_event(RenderEvent)\ 218 _vtk_add_event(ProgressEvent)\ 219 _vtk_add_event(PickEvent)\ 220 _vtk_add_event(StartPickEvent)\ 221 _vtk_add_event(EndPickEvent)\ 222 _vtk_add_event(AbortCheckEvent)\ 223 _vtk_add_event(ExitEvent)\ 224 _vtk_add_event(LeftButtonPressEvent)\ 225 _vtk_add_event(LeftButtonReleaseEvent)\ 226 _vtk_add_event(MiddleButtonPressEvent)\ 227 _vtk_add_event(MiddleButtonReleaseEvent)\ 228 _vtk_add_event(RightButtonPressEvent)\ 229 _vtk_add_event(RightButtonReleaseEvent)\ 230 _vtk_add_event(EnterEvent)\ 231 _vtk_add_event(LeaveEvent)\ 232 _vtk_add_event(KeyPressEvent)\ 233 _vtk_add_event(KeyReleaseEvent)\ 234 _vtk_add_event(CharEvent)\ 235 _vtk_add_event(ExposeEvent)\ 236 _vtk_add_event(ConfigureEvent)\ 237 _vtk_add_event(TimerEvent)\ 238 _vtk_add_event(MouseMoveEvent)\ 239 _vtk_add_event(MouseWheelForwardEvent)\ 240 _vtk_add_event(MouseWheelBackwardEvent)\ 241 _vtk_add_event(ActiveCameraEvent)\ 242 _vtk_add_event(CreateCameraEvent)\ 243 _vtk_add_event(ResetCameraEvent)\ 244 _vtk_add_event(ResetCameraClippingRangeEvent)\ 245 _vtk_add_event(ModifiedEvent)\ 246 _vtk_add_event(WindowLevelEvent)\ 247 _vtk_add_event(StartWindowLevelEvent)\ 248 _vtk_add_event(EndWindowLevelEvent)\ 249 _vtk_add_event(ResetWindowLevelEvent)\ 250 _vtk_add_event(SetOutputEvent)\ 251 _vtk_add_event(ErrorEvent)\ 252 _vtk_add_event(WarningEvent)\ 253 _vtk_add_event(StartInteractionEvent)\ 254 /*^ mainly used by vtkInteractorObservers*/\ 255 _vtk_add_event(InteractionEvent)\ 256 _vtk_add_event(EndInteractionEvent)\ 257 _vtk_add_event(EnableEvent)\ 258 _vtk_add_event(DisableEvent)\ 259 _vtk_add_event(CreateTimerEvent)\ 260 _vtk_add_event(DestroyTimerEvent)\ 261 _vtk_add_event(PlacePointEvent)\ 262 _vtk_add_event(PlaceWidgetEvent)\ 263 _vtk_add_event(CursorChangedEvent)\ 264 _vtk_add_event(ExecuteInformationEvent)\ 265 _vtk_add_event(RenderWindowMessageEvent)\ 266 _vtk_add_event(WrongTagEvent)\ 267 _vtk_add_event(StartAnimationCueEvent)\ 268 /*^ used by vtkAnimationCue*/ \ 269 _vtk_add_event(AnimationCueTickEvent)\ 270 _vtk_add_event(EndAnimationCueEvent)\ 271 _vtk_add_event(VolumeMapperRenderEndEvent)\ 272 _vtk_add_event(VolumeMapperRenderProgressEvent)\ 273 _vtk_add_event(VolumeMapperRenderStartEvent)\ 274 _vtk_add_event(VolumeMapperComputeGradientsEndEvent)\ 275 _vtk_add_event(VolumeMapperComputeGradientsProgressEvent)\ 276 _vtk_add_event(VolumeMapperComputeGradientsStartEvent)\ 277 _vtk_add_event(WidgetModifiedEvent)\ 278 _vtk_add_event(WidgetValueChangedEvent)\ 279 _vtk_add_event(WidgetActivateEvent)\ 280 _vtk_add_event(ConnectionCreatedEvent)\ 281 _vtk_add_event(ConnectionClosedEvent)\ 282 _vtk_add_event(DomainModifiedEvent)\ 283 _vtk_add_event(PropertyModifiedEvent)\ 284 _vtk_add_event(UpdateEvent)\ 285 _vtk_add_event(RegisterEvent)\ 286 _vtk_add_event(UnRegisterEvent)\ 287 _vtk_add_event(UpdateInformationEvent)\ 288 _vtk_add_event(AnnotationChangedEvent)\ 289 _vtk_add_event(SelectionChangedEvent)\ 290 _vtk_add_event(UpdatePropertyEvent)\ 291 _vtk_add_event(ViewProgressEvent)\ 292 _vtk_add_event(UpdateDataEvent)\ 293 _vtk_add_event(CurrentChangedEvent)\ 294 _vtk_add_event(ComputeVisiblePropBoundsEvent)\ 295 _vtk_add_event(TDxMotionEvent)\ 296 /*^ 3D Connexion device event */\ 297 _vtk_add_event(TDxButtonPressEvent)\ 298 /*^ 3D Connexion device event */\ 299 _vtk_add_event(TDxButtonReleaseEvent)\ 300 /* 3D Connexion device event */\ 301 _vtk_add_event(HoverEvent)\ 302 _vtk_add_event(LoadStateEvent)\ 303 _vtk_add_event(SaveStateEvent)\ 304 _vtk_add_event(StateChangedEvent)\ 305 _vtk_add_event(WindowMakeCurrentEvent)\ 306 _vtk_add_event(WindowIsCurrentEvent)\ 307 _vtk_add_event(WindowFrameEvent)\ 308 _vtk_add_event(HighlightEvent)\ 309 _vtk_add_event(WindowSupportsOpenGLEvent)\ 310 _vtk_add_event(WindowIsDirectEvent)\ 311 _vtk_add_event(UncheckedPropertyModifiedEvent)\ 312 _vtk_add_event(MessageEvent) 313 314 #define vtkEventDeclarationMacro(_enum_name)\ 315 enum _enum_name{\ 316 NoEvent = 0,\ 317 vtkAllEventsMacro() \ 318 UserEvent = 1000\ 319 }; 320 321 322 // The superclass that all commands should be subclasses of 323 class VTKCOMMONCORE_EXPORT vtkCommand : public vtkObjectBase 324 { 325 public: 326 vtkTypeMacro(vtkCommand,vtkObjectBase); 327 328 // Description: 329 // Decrease the reference count (release by another object). This has 330 // the same effect as invoking Delete() (i.e., it reduces the reference 331 // count by 1). 332 void UnRegister(); UnRegister(vtkObjectBase *)333 virtual void UnRegister(vtkObjectBase *) 334 { this->UnRegister(); } 335 336 // Description: 337 // All derived classes of vtkCommand must implement this 338 // method. This is the method that actually does the work of the 339 // callback. The caller argument is the object invoking the event, 340 // the eventId parameter is the id of the event, and callData 341 // parameter is data that can be passed into the execute 342 // method. (Note: vtkObject::InvokeEvent() takes two parameters: the 343 // event id (or name) and call data. Typically call data is NULL, 344 // but the user can package data and pass it this 345 // way. Alternatively, a derived class of vtkCommand can be used to 346 // pass data.) 347 virtual void Execute(vtkObject *caller, unsigned long eventId, 348 void *callData) = 0; 349 350 // Description: 351 // Convenience methods for translating between event names and event 352 // ids. 353 static const char *GetStringFromEventId(unsigned long event); 354 static unsigned long GetEventIdFromString(const char *event); 355 356 // Description: 357 // Set/Get the abort flag. If this is set to true no further 358 // commands are executed. SetAbortFlag(int f)359 void SetAbortFlag(int f) 360 { this->AbortFlag = f; } GetAbortFlag()361 int GetAbortFlag() 362 { return this->AbortFlag; } AbortFlagOn()363 void AbortFlagOn() 364 { this->SetAbortFlag(1); } AbortFlagOff()365 void AbortFlagOff() 366 { this->SetAbortFlag(0); } 367 368 // Description: 369 // Set/Get the passive observer flag. If this is set to true, this 370 // indicates that this command does not change the state of the 371 // system in any way. Passive observers are processed first, and 372 // are not called even when another command has focus. SetPassiveObserver(int f)373 void SetPassiveObserver(int f) 374 { this->PassiveObserver = f; } GetPassiveObserver()375 int GetPassiveObserver() 376 { return this->PassiveObserver; } PassiveObserverOn()377 void PassiveObserverOn() 378 { this->SetPassiveObserver(1); } PassiveObserverOff()379 void PassiveObserverOff() 380 { this->SetPassiveObserver(0); } 381 382 //BTX 383 // Description: 384 // All the currently defined events are listed here. Developers can 385 // use -- vtkCommand::UserEvent + int to specify their own event 386 // ids. 387 // Add new events by updating vtkAllEventsMacro. 388 #define _vtk_add_event(Enum) Enum, 389 vtkEventDeclarationMacro(EventIds) 390 #undef _vtk_add_event 391 //ETX 392 393 protected: 394 int AbortFlag; 395 int PassiveObserver; 396 397 vtkCommand(); ~vtkCommand()398 virtual ~vtkCommand() {} 399 400 friend class vtkSubjectHelper; 401 //BTX vtkCommand(const vtkCommand & c)402 vtkCommand(const vtkCommand& c) : vtkObjectBase(c) {} 403 void operator=(const vtkCommand&) {} 404 //ETX 405 }; 406 407 #endif /* vtkCommand_h */ 408 409 // VTK-HeaderTest-Exclude: vtkCommand.h 410