VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkRenderWindowInteractor.h,v $ 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00049 #ifndef __vtkRenderWindowInteractor_h 00050 #define __vtkRenderWindowInteractor_h 00051 00052 #include "vtkObject.h" 00053 00054 class vtkTimerIdMap; 00055 00056 00057 // Timer flags for win32/X compatibility 00058 #define VTKI_TIMER_FIRST 0 00059 #define VTKI_TIMER_UPDATE 1 00060 00061 class vtkAbstractPicker; 00062 class vtkAbstractPropPicker; 00063 class vtkInteractorObserver; 00064 class vtkRenderWindow; 00065 class vtkRenderer; 00066 class vtkObserverMediator; 00067 class vtkInteractorEventRecorder; 00068 00069 class VTK_RENDERING_EXPORT vtkRenderWindowInteractor : public vtkObject 00070 { 00071 //BTX 00072 friend class vtkInteractorEventRecorder; 00073 //ETX 00074 public: 00075 static vtkRenderWindowInteractor *New(); 00076 vtkTypeRevisionMacro(vtkRenderWindowInteractor,vtkObject); 00077 void PrintSelf(ostream& os, vtkIndent indent); 00078 00080 00082 virtual void Initialize(); 00083 void ReInitialize() { this->Initialized = 0; this->Enabled = 0; 00084 this->Initialize(); } 00086 00089 virtual void UnRegister(vtkObjectBase *o); 00090 00094 virtual void Start() {} 00095 00097 00104 virtual void Enable() { this->Enabled = 1; this->Modified();} 00105 virtual void Disable() { this->Enabled = 0; this->Modified();} 00106 vtkGetMacro(Enabled, int); 00108 00110 00112 vtkBooleanMacro(EnableRender, bool); 00113 vtkSetMacro(EnableRender, bool); 00114 vtkGetMacro(EnableRender, bool); 00116 00118 00119 void SetRenderWindow(vtkRenderWindow *aren); 00120 vtkGetObjectMacro(RenderWindow,vtkRenderWindow); 00122 00125 virtual void UpdateSize(int x,int y); 00126 00128 00143 virtual int CreateTimer(int timerType); //first group, for backward compatibility 00144 virtual int DestroyTimer(); //first group, for backward compatibility 00145 int CreateRepeatingTimer(unsigned long duration); 00146 int CreateOneShotTimer(unsigned long duration); 00147 int IsOneShotTimer(int timerId); 00148 unsigned long GetTimerDuration(int timerId); 00149 int ResetTimer(int timerId); 00150 int DestroyTimer(int timerId); 00151 virtual int GetVTKTimerId(int platformTimerId); 00153 00154 //BTX 00155 // Moved into the public section of the class so that classless timer procs 00156 // can access these enum members without being "friends"... 00157 enum {OneShotTimer=1,RepeatingTimer}; 00158 //ETX 00159 00161 00168 vtkSetClampMacro(TimerDuration,unsigned long,1,100000); 00169 vtkGetMacro(TimerDuration,unsigned long); 00171 00173 00183 vtkSetMacro(TimerEventId, int); 00184 vtkGetMacro(TimerEventId, int); 00185 vtkSetMacro(TimerEventType, int); 00186 vtkGetMacro(TimerEventType, int); 00187 vtkSetMacro(TimerEventDuration, int); 00188 vtkGetMacro(TimerEventDuration, int); 00189 vtkSetMacro(TimerEventPlatformId, int); 00190 vtkGetMacro(TimerEventPlatformId, int); 00192 00196 virtual void TerminateApp(void) {} 00197 00199 00201 virtual void SetInteractorStyle(vtkInteractorObserver *); 00202 vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver); 00204 00206 00208 vtkSetMacro(LightFollowCamera,int); 00209 vtkGetMacro(LightFollowCamera,int); 00210 vtkBooleanMacro(LightFollowCamera,int); 00212 00214 00218 vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_LARGE_FLOAT); 00219 vtkGetMacro(DesiredUpdateRate,double); 00221 00223 00225 vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_LARGE_FLOAT); 00226 vtkGetMacro(StillUpdateRate,double); 00228 00230 00231 vtkGetMacro(Initialized,int); 00233 00235 00239 virtual void SetPicker(vtkAbstractPicker*); 00240 vtkGetObjectMacro(Picker,vtkAbstractPicker); 00242 00245 virtual vtkAbstractPropPicker *CreateDefaultPicker(); 00246 00248 00250 virtual void ExitCallback(); 00251 virtual void UserCallback(); 00252 virtual void StartPickCallback(); 00253 virtual void EndPickCallback(); 00255 00257 virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; } 00258 00260 00262 void HideCursor(); 00263 void ShowCursor(); 00265 00268 virtual void Render(); 00269 00271 00274 void FlyTo(vtkRenderer *ren, double x, double y, double z); 00275 void FlyTo(vtkRenderer *ren, double *x) 00276 {this->FlyTo(ren, x[0], x[1], x[2]);} 00277 void FlyToImage(vtkRenderer *ren, double x, double y); 00278 void FlyToImage(vtkRenderer *ren, double *x) 00279 {this->FlyToImage(ren, x[0], x[1]);} 00281 00283 00284 vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_LARGE_INTEGER); 00285 vtkGetMacro(NumberOfFlyFrames,int); 00287 00289 00291 vtkSetMacro(Dolly,double); 00292 vtkGetMacro(Dolly,double); 00294 00296 00301 vtkGetVector2Macro(EventPosition,int); 00302 vtkGetVector2Macro(LastEventPosition,int); 00303 vtkSetVector2Macro(LastEventPosition,int); 00304 virtual void SetEventPosition(int x, int y) 00305 { 00306 vtkDebugMacro(<< this->GetClassName() << " (" << this 00307 << "): setting EventPosition to (" << x << "," << y << ")"); 00308 if (this->EventPosition[0] != x || this->EventPosition[1] != y) 00309 { 00310 this->LastEventPosition[0] = this->EventPosition[0]; 00311 this->LastEventPosition[1] = this->EventPosition[1]; 00312 this->EventPosition[0] = x; 00313 this->EventPosition[1] = y; 00314 this->Modified(); 00315 } 00316 } 00317 virtual void SetEventPosition(int pos[2]) 00318 { 00319 this->SetEventPosition(pos[0], pos[1]); 00320 } 00321 virtual void SetEventPositionFlipY(int x, int y) 00322 { 00323 this->SetEventPosition(x, this->Size[1] - y - 1); 00324 } 00325 virtual void SetEventPositionFlipY(int pos[2]) 00326 { 00327 this->SetEventPositionFlipY(pos[0], pos[1]); 00328 } 00329 vtkSetMacro(AltKey, int); 00330 vtkGetMacro(AltKey, int); 00331 vtkSetMacro(ControlKey, int); 00332 vtkGetMacro(ControlKey, int); 00333 vtkSetMacro(ShiftKey, int); 00334 vtkGetMacro(ShiftKey, int); 00335 vtkSetMacro(KeyCode, char); 00336 vtkGetMacro(KeyCode, char); 00337 vtkSetMacro(RepeatCount, int); 00338 vtkGetMacro(RepeatCount, int); 00339 vtkSetStringMacro(KeySym); 00340 vtkGetStringMacro(KeySym); 00342 00344 00345 void SetEventInformation(int x, 00346 int y, 00347 int ctrl=0, 00348 int shift=0, 00349 char keycode=0, 00350 int repeatcount=0, 00351 const char* keysym=0) 00352 { 00353 this->LastEventPosition[0] = this->EventPosition[0]; 00354 this->LastEventPosition[1] = this->EventPosition[1]; 00355 this->EventPosition[0] = x; 00356 this->EventPosition[1] = y; 00357 this->ControlKey = ctrl; 00358 this->ShiftKey = shift; 00359 this->KeyCode = keycode; 00360 this->RepeatCount = repeatcount; 00361 if(keysym) 00362 { 00363 this->SetKeySym(keysym); 00364 } 00365 this->Modified(); 00366 } 00368 00370 00372 void SetEventInformationFlipY(int x, 00373 int y, 00374 int ctrl=0, 00375 int shift=0, 00376 char keycode=0, 00377 int repeatcount=0, 00378 const char* keysym=0) 00379 { 00380 this->SetEventInformation(x, 00381 this->Size[1] - y - 1, 00382 ctrl, 00383 shift, 00384 keycode, 00385 repeatcount, 00386 keysym); 00387 } 00389 00391 00392 void SetKeyEventInformation(int ctrl=0, 00393 int shift=0, 00394 char keycode=0, 00395 int repeatcount=0, 00396 const char* keysym=0) 00397 { 00398 this->ControlKey = ctrl; 00399 this->ShiftKey = shift; 00400 this->KeyCode = keycode; 00401 this->RepeatCount = repeatcount; 00402 if(keysym) 00403 { 00404 this->SetKeySym(keysym); 00405 } 00406 this->Modified(); 00407 } 00409 00411 00418 vtkSetVector2Macro(Size,int); 00419 vtkGetVector2Macro(Size,int); 00420 vtkSetVector2Macro(EventSize,int); 00421 vtkGetVector2Macro(EventSize,int); 00423 00427 virtual vtkRenderer *FindPokedRenderer(int,int); 00428 00435 vtkObserverMediator *GetObserverMediator(); 00436 00437 protected: 00438 vtkRenderWindowInteractor(); 00439 ~vtkRenderWindowInteractor(); 00440 00441 vtkRenderWindow *RenderWindow; 00442 vtkInteractorObserver *InteractorStyle; 00443 00444 // Used as a helper object to pick instances of vtkProp 00445 vtkAbstractPicker *Picker; 00446 00447 int Initialized; 00448 int Enabled; 00449 bool EnableRender; 00450 int Style; 00451 int LightFollowCamera; 00452 int ActorMode; 00453 double DesiredUpdateRate; 00454 double StillUpdateRate; 00455 00456 // Event information 00457 int AltKey; 00458 int ControlKey; 00459 int ShiftKey; 00460 char KeyCode; 00461 int RepeatCount; 00462 char* KeySym; 00463 int EventPosition[2]; 00464 int LastEventPosition[2]; 00465 int EventSize[2]; 00466 int Size[2]; 00467 int TimerEventId; 00468 int TimerEventType; 00469 int TimerEventDuration; 00470 int TimerEventPlatformId; 00471 00472 // control the fly to 00473 int NumberOfFlyFrames; 00474 double Dolly; 00475 00477 00484 friend class vtkInteractorObserver; 00485 void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL) 00486 {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);} 00487 void ReleaseFocus() 00488 {this->Superclass::InternalReleaseFocus();} 00489 //ETX 00491 00494 vtkObserverMediator *ObserverMediator; 00495 00496 // Timer related members 00497 //BTX 00498 friend struct vtkTimerStruct; 00499 vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes 00500 unsigned long TimerDuration; //in milliseconds 00502 00506 virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration); 00507 virtual int InternalDestroyTimer(int platformTimerId); 00508 int GetCurrentTimerId(); 00509 //ETX 00511 00512 // Force the interactor to handle the Start() event loop, ignoring any 00513 // overrides. (Overrides are registered by observing StartEvent on the 00514 // interactor.) 00515 int HandleEventLoop; 00516 00517 private: 00518 vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented. 00519 void operator=(const vtkRenderWindowInteractor&); // Not implemented. 00520 }; 00521 00522 #endif