VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkRenderWindowInteractor.h 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 =========================================================================*/ 00052 #ifndef __vtkRenderWindowInteractor_h 00053 #define __vtkRenderWindowInteractor_h 00054 00055 #include "vtkObject.h" 00056 00057 class vtkTimerIdMap; 00058 00059 00060 // Timer flags for win32/X compatibility 00061 #define VTKI_TIMER_FIRST 0 00062 #define VTKI_TIMER_UPDATE 1 00063 00064 class vtkAbstractPicker; 00065 class vtkAbstractPropPicker; 00066 class vtkInteractorObserver; 00067 class vtkRenderWindow; 00068 class vtkRenderer; 00069 class vtkObserverMediator; 00070 class vtkInteractorEventRecorder; 00071 00072 class VTK_RENDERING_EXPORT vtkRenderWindowInteractor : public vtkObject 00073 { 00074 //BTX 00075 friend class vtkInteractorEventRecorder; 00076 //ETX 00077 public: 00078 static vtkRenderWindowInteractor *New(); 00079 vtkTypeMacro(vtkRenderWindowInteractor,vtkObject); 00080 void PrintSelf(ostream& os, vtkIndent indent); 00081 00083 00085 virtual void Initialize(); 00086 void ReInitialize() { this->Initialized = 0; this->Enabled = 0; 00087 this->Initialize(); } 00089 00092 virtual void UnRegister(vtkObjectBase *o); 00093 00097 virtual void Start() {} 00098 00100 00107 virtual void Enable() { this->Enabled = 1; this->Modified();} 00108 virtual void Disable() { this->Enabled = 0; this->Modified();} 00109 vtkGetMacro(Enabled, int); 00111 00113 00115 vtkBooleanMacro(EnableRender, bool); 00116 vtkSetMacro(EnableRender, bool); 00117 vtkGetMacro(EnableRender, bool); 00119 00121 00122 void SetRenderWindow(vtkRenderWindow *aren); 00123 vtkGetObjectMacro(RenderWindow,vtkRenderWindow); 00125 00128 virtual void UpdateSize(int x,int y); 00129 00131 00146 virtual int CreateTimer(int timerType); //first group, for backward compatibility 00147 virtual int DestroyTimer(); //first group, for backward compatibility 00148 int CreateRepeatingTimer(unsigned long duration); 00149 int CreateOneShotTimer(unsigned long duration); 00150 int IsOneShotTimer(int timerId); 00151 unsigned long GetTimerDuration(int timerId); 00152 int ResetTimer(int timerId); 00153 int DestroyTimer(int timerId); 00154 virtual int GetVTKTimerId(int platformTimerId); 00156 00157 //BTX 00158 // Moved into the public section of the class so that classless timer procs 00159 // can access these enum members without being "friends"... 00160 enum {OneShotTimer=1,RepeatingTimer}; 00161 //ETX 00162 00164 00171 vtkSetClampMacro(TimerDuration,unsigned long,1,100000); 00172 vtkGetMacro(TimerDuration,unsigned long); 00174 00176 00186 vtkSetMacro(TimerEventId, int); 00187 vtkGetMacro(TimerEventId, int); 00188 vtkSetMacro(TimerEventType, int); 00189 vtkGetMacro(TimerEventType, int); 00190 vtkSetMacro(TimerEventDuration, int); 00191 vtkGetMacro(TimerEventDuration, int); 00192 vtkSetMacro(TimerEventPlatformId, int); 00193 vtkGetMacro(TimerEventPlatformId, int); 00195 00199 virtual void TerminateApp(void) {} 00200 00202 00204 virtual void SetInteractorStyle(vtkInteractorObserver *); 00205 vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver); 00207 00209 00211 vtkSetMacro(LightFollowCamera,int); 00212 vtkGetMacro(LightFollowCamera,int); 00213 vtkBooleanMacro(LightFollowCamera,int); 00215 00217 00222 vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_LARGE_FLOAT); 00223 vtkGetMacro(DesiredUpdateRate,double); 00225 00227 00230 vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_LARGE_FLOAT); 00231 vtkGetMacro(StillUpdateRate,double); 00233 00235 00236 vtkGetMacro(Initialized,int); 00238 00240 00244 virtual void SetPicker(vtkAbstractPicker*); 00245 vtkGetObjectMacro(Picker,vtkAbstractPicker); 00247 00250 virtual vtkAbstractPropPicker *CreateDefaultPicker(); 00251 00253 00255 virtual void ExitCallback(); 00256 virtual void UserCallback(); 00257 virtual void StartPickCallback(); 00258 virtual void EndPickCallback(); 00260 00262 virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; } 00263 00265 00267 void HideCursor(); 00268 void ShowCursor(); 00270 00273 virtual void Render(); 00274 00276 00279 void FlyTo(vtkRenderer *ren, double x, double y, double z); 00280 void FlyTo(vtkRenderer *ren, double *x) 00281 {this->FlyTo(ren, x[0], x[1], x[2]);} 00282 void FlyToImage(vtkRenderer *ren, double x, double y); 00283 void FlyToImage(vtkRenderer *ren, double *x) 00284 {this->FlyToImage(ren, x[0], x[1]);} 00286 00288 00289 vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_LARGE_INTEGER); 00290 vtkGetMacro(NumberOfFlyFrames,int); 00292 00294 00296 vtkSetMacro(Dolly,double); 00297 vtkGetMacro(Dolly,double); 00299 00301 00306 vtkGetVector2Macro(EventPosition,int); 00307 vtkGetVector2Macro(LastEventPosition,int); 00308 vtkSetVector2Macro(LastEventPosition,int); 00309 virtual void SetEventPosition(int x, int y) 00310 { 00311 vtkDebugMacro(<< this->GetClassName() << " (" << this 00312 << "): setting EventPosition to (" << x << "," << y << ")"); 00313 if (this->EventPosition[0] != x || this->EventPosition[1] != y || 00314 this->LastEventPosition[0] != x || this->LastEventPosition[1] != y) 00315 { 00316 this->LastEventPosition[0] = this->EventPosition[0]; 00317 this->LastEventPosition[1] = this->EventPosition[1]; 00318 this->EventPosition[0] = x; 00319 this->EventPosition[1] = y; 00320 this->Modified(); 00321 } 00322 } 00323 virtual void SetEventPosition(int pos[2]) 00324 { 00325 this->SetEventPosition(pos[0], pos[1]); 00326 } 00327 virtual void SetEventPositionFlipY(int x, int y) 00328 { 00329 this->SetEventPosition(x, this->Size[1] - y - 1); 00330 } 00331 virtual void SetEventPositionFlipY(int pos[2]) 00332 { 00333 this->SetEventPositionFlipY(pos[0], pos[1]); 00334 } 00335 vtkSetMacro(AltKey, int); 00336 vtkGetMacro(AltKey, int); 00337 vtkSetMacro(ControlKey, int); 00338 vtkGetMacro(ControlKey, int); 00339 vtkSetMacro(ShiftKey, int); 00340 vtkGetMacro(ShiftKey, int); 00341 vtkSetMacro(KeyCode, char); 00342 vtkGetMacro(KeyCode, char); 00343 vtkSetMacro(RepeatCount, int); 00344 vtkGetMacro(RepeatCount, int); 00345 vtkSetStringMacro(KeySym); 00346 vtkGetStringMacro(KeySym); 00348 00350 00351 void SetEventInformation(int x, 00352 int y, 00353 int ctrl=0, 00354 int shift=0, 00355 char keycode=0, 00356 int repeatcount=0, 00357 const char* keysym=0) 00358 { 00359 this->LastEventPosition[0] = this->EventPosition[0]; 00360 this->LastEventPosition[1] = this->EventPosition[1]; 00361 this->EventPosition[0] = x; 00362 this->EventPosition[1] = y; 00363 this->ControlKey = ctrl; 00364 this->ShiftKey = shift; 00365 this->KeyCode = keycode; 00366 this->RepeatCount = repeatcount; 00367 if(keysym) 00368 { 00369 this->SetKeySym(keysym); 00370 } 00371 this->Modified(); 00372 } 00374 00376 00378 void SetEventInformationFlipY(int x, 00379 int y, 00380 int ctrl=0, 00381 int shift=0, 00382 char keycode=0, 00383 int repeatcount=0, 00384 const char* keysym=0) 00385 { 00386 this->SetEventInformation(x, 00387 this->Size[1] - y - 1, 00388 ctrl, 00389 shift, 00390 keycode, 00391 repeatcount, 00392 keysym); 00393 } 00395 00397 00398 void SetKeyEventInformation(int ctrl=0, 00399 int shift=0, 00400 char keycode=0, 00401 int repeatcount=0, 00402 const char* keysym=0) 00403 { 00404 this->ControlKey = ctrl; 00405 this->ShiftKey = shift; 00406 this->KeyCode = keycode; 00407 this->RepeatCount = repeatcount; 00408 if(keysym) 00409 { 00410 this->SetKeySym(keysym); 00411 } 00412 this->Modified(); 00413 } 00415 00417 00424 vtkSetVector2Macro(Size,int); 00425 vtkGetVector2Macro(Size,int); 00426 vtkSetVector2Macro(EventSize,int); 00427 vtkGetVector2Macro(EventSize,int); 00429 00433 virtual vtkRenderer *FindPokedRenderer(int,int); 00434 00441 vtkObserverMediator *GetObserverMediator(); 00442 00444 00449 vtkSetMacro(UseTDx,bool); 00450 vtkGetMacro(UseTDx,bool); 00452 00454 00457 virtual void MouseMoveEvent(); 00458 virtual void RightButtonPressEvent(); 00459 virtual void RightButtonReleaseEvent(); 00460 virtual void LeftButtonPressEvent(); 00461 virtual void LeftButtonReleaseEvent(); 00462 virtual void MiddleButtonPressEvent(); 00463 virtual void MiddleButtonReleaseEvent(); 00464 virtual void MouseWheelForwardEvent(); 00465 virtual void MouseWheelBackwardEvent(); 00466 virtual void ExposeEvent(); 00467 virtual void ConfigureEvent(); 00468 virtual void EnterEvent(); 00469 virtual void LeaveEvent(); 00470 virtual void KeyPressEvent(); 00471 virtual void KeyReleaseEvent(); 00472 virtual void CharEvent(); 00473 virtual void ExitEvent(); 00475 00476 protected: 00477 vtkRenderWindowInteractor(); 00478 ~vtkRenderWindowInteractor(); 00479 00480 vtkRenderWindow *RenderWindow; 00481 vtkInteractorObserver *InteractorStyle; 00482 00483 // Used as a helper object to pick instances of vtkProp 00484 vtkAbstractPicker *Picker; 00485 00486 int Initialized; 00487 int Enabled; 00488 bool EnableRender; 00489 int Style; 00490 int LightFollowCamera; 00491 int ActorMode; 00492 double DesiredUpdateRate; 00493 double StillUpdateRate; 00494 00495 // Event information 00496 int AltKey; 00497 int ControlKey; 00498 int ShiftKey; 00499 char KeyCode; 00500 int RepeatCount; 00501 char* KeySym; 00502 int EventPosition[2]; 00503 int LastEventPosition[2]; 00504 int EventSize[2]; 00505 int Size[2]; 00506 int TimerEventId; 00507 int TimerEventType; 00508 int TimerEventDuration; 00509 int TimerEventPlatformId; 00510 00511 // control the fly to 00512 int NumberOfFlyFrames; 00513 double Dolly; 00514 00515 //BTX 00517 00524 friend class vtkInteractorObserver; 00525 void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL) 00526 {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);} 00527 void ReleaseFocus() 00528 {this->Superclass::InternalReleaseFocus();} 00529 //ETX 00531 00534 vtkObserverMediator *ObserverMediator; 00535 00536 //BTX 00537 // Timer related members 00538 friend struct vtkTimerStruct; 00539 vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes 00540 unsigned long TimerDuration; //in milliseconds 00542 00546 virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration); 00547 virtual int InternalDestroyTimer(int platformTimerId); 00548 int GetCurrentTimerId(); 00549 //ETX 00551 00552 // Force the interactor to handle the Start() event loop, ignoring any 00553 // overrides. (Overrides are registered by observing StartEvent on the 00554 // interactor.) 00555 int HandleEventLoop; 00556 00557 bool UseTDx; // 3DConnexion device. 00558 00559 private: 00560 vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented. 00561 void operator=(const vtkRenderWindowInteractor&); // Not implemented. 00562 }; 00563 00564 #endif