VTK
dox/Rendering/Core/vtkRenderWindowInteractor.h
Go to the documentation of this file.
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 =========================================================================*/
00053 #ifndef __vtkRenderWindowInteractor_h
00054 #define __vtkRenderWindowInteractor_h
00055 
00056 #include "vtkRenderingCoreModule.h" // For export macro
00057 #include "vtkObject.h"
00058 
00059 class vtkTimerIdMap;
00060 
00061 // Timer flags for win32/X compatibility
00062 #define VTKI_TIMER_FIRST  0
00063 #define VTKI_TIMER_UPDATE 1
00064 
00065 class vtkAbstractPicker;
00066 class vtkAbstractPropPicker;
00067 class vtkAssemblyPath;
00068 class vtkInteractorObserver;
00069 class vtkRenderWindow;
00070 class vtkRenderer;
00071 class vtkObserverMediator;
00072 class vtkInteractorEventRecorder;
00073 class vtkPickingManager;
00074 
00075 class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor : public vtkObject
00076 {
00077 //BTX
00078   friend class vtkInteractorEventRecorder;
00079 //ETX
00080 public:
00081   static vtkRenderWindowInteractor *New();
00082   vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
00083   void PrintSelf(ostream& os, vtkIndent indent);
00084 
00086 
00088   virtual void Initialize();
00089   void ReInitialize() {  this->Initialized = 0; this->Enabled = 0;
00090                         this->Initialize(); }
00092 
00095   virtual void UnRegister(vtkObjectBase *o);
00096 
00100   virtual void Start() {}
00101 
00103 
00110   virtual void Enable() { this->Enabled = 1; this->Modified();}
00111   virtual void Disable() { this->Enabled = 0; this->Modified();}
00112   vtkGetMacro(Enabled, int);
00114 
00116 
00118   vtkBooleanMacro(EnableRender, bool);
00119   vtkSetMacro(EnableRender, bool);
00120   vtkGetMacro(EnableRender, bool);
00122 
00124 
00125   void SetRenderWindow(vtkRenderWindow *aren);
00126   vtkGetObjectMacro(RenderWindow,vtkRenderWindow);
00128 
00131   virtual void UpdateSize(int x,int y);
00132 
00134 
00149   virtual int CreateTimer(int timerType); //first group, for backward compatibility
00150   virtual int DestroyTimer(); //first group, for backward compatibility
00152 
00155   int CreateRepeatingTimer(unsigned long duration);
00156 
00159   int CreateOneShotTimer(unsigned long duration);
00160 
00163   int IsOneShotTimer(int timerId);
00164 
00166   unsigned long GetTimerDuration(int timerId);
00167 
00169   int ResetTimer(int timerId);
00170 
00173   int DestroyTimer(int timerId);
00174 
00176   virtual int GetVTKTimerId(int platformTimerId);
00177 
00178   //BTX
00179   // Moved into the public section of the class so that classless timer procs
00180   // can access these enum members without being "friends"...
00181   enum {OneShotTimer=1,RepeatingTimer};
00182   //ETX
00183 
00185 
00192   vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
00193   vtkGetMacro(TimerDuration,unsigned long);
00195 
00197 
00207   vtkSetMacro(TimerEventId, int);
00208   vtkGetMacro(TimerEventId, int);
00209   vtkSetMacro(TimerEventType, int);
00210   vtkGetMacro(TimerEventType, int);
00211   vtkSetMacro(TimerEventDuration, int);
00212   vtkGetMacro(TimerEventDuration, int);
00213   vtkSetMacro(TimerEventPlatformId, int);
00214   vtkGetMacro(TimerEventPlatformId, int);
00216 
00220   virtual void TerminateApp(void) {}
00221 
00223 
00225   virtual void SetInteractorStyle(vtkInteractorObserver *);
00226   vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
00228 
00230 
00232   vtkSetMacro(LightFollowCamera,int);
00233   vtkGetMacro(LightFollowCamera,int);
00234   vtkBooleanMacro(LightFollowCamera,int);
00236 
00238 
00243   vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_FLOAT_MAX);
00244   vtkGetMacro(DesiredUpdateRate,double);
00246 
00248 
00251   vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_FLOAT_MAX);
00252   vtkGetMacro(StillUpdateRate,double);
00254 
00256 
00257   vtkGetMacro(Initialized,int);
00259 
00261 
00265   virtual void SetPicker(vtkAbstractPicker*);
00266   vtkGetObjectMacro(Picker,vtkAbstractPicker);
00268 
00271   virtual vtkAbstractPropPicker *CreateDefaultPicker();
00272 
00274 
00277   virtual void SetPickingManager(vtkPickingManager*);
00278   vtkGetObjectMacro(PickingManager,vtkPickingManager);
00280 
00282 
00284   virtual void ExitCallback();
00285   virtual void UserCallback();
00286   virtual void StartPickCallback();
00287   virtual void EndPickCallback();
00289 
00291   virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
00292 
00294 
00296   void HideCursor();
00297   void ShowCursor();
00299 
00302   virtual void Render();
00303 
00305 
00308   void FlyTo(vtkRenderer *ren, double x, double y, double z);
00309   void FlyTo(vtkRenderer *ren, double *x)
00310     {this->FlyTo(ren, x[0], x[1], x[2]);}
00311   void FlyToImage(vtkRenderer *ren, double x, double y);
00312   void FlyToImage(vtkRenderer *ren, double *x)
00313     {this->FlyToImage(ren, x[0], x[1]);}
00315 
00317 
00318   vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_INT_MAX);
00319   vtkGetMacro(NumberOfFlyFrames,int);
00321 
00323 
00325   vtkSetMacro(Dolly,double);
00326   vtkGetMacro(Dolly,double);
00328 
00330 
00335   vtkGetVector2Macro(EventPosition,int);
00336   vtkGetVector2Macro(LastEventPosition,int);
00337   vtkSetVector2Macro(LastEventPosition,int);
00338   virtual void SetEventPosition(int x, int y)
00339   {
00340     vtkDebugMacro(<< this->GetClassName() << " (" << this
00341                   << "): setting EventPosition to (" << x << "," << y << ")");
00342     if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
00343         this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
00344       {
00345       this->LastEventPosition[0] = this->EventPosition[0];
00346       this->LastEventPosition[1] = this->EventPosition[1];
00347       this->EventPosition[0] = x;
00348       this->EventPosition[1] = y;
00349       this->Modified();
00350       }
00351   }
00352   virtual void SetEventPosition(int pos[2])
00353   {
00354     this->SetEventPosition(pos[0], pos[1]);
00355   }
00356   virtual void SetEventPositionFlipY(int x, int y)
00357   {
00358     this->SetEventPosition(x, this->Size[1] - y - 1);
00359   }
00360   virtual void SetEventPositionFlipY(int pos[2])
00361   {
00362     this->SetEventPositionFlipY(pos[0], pos[1]);
00363   }
00365 
00367 
00368   vtkSetMacro(AltKey, int);
00369   vtkGetMacro(AltKey, int);
00371 
00373 
00374   vtkSetMacro(ControlKey, int);
00375   vtkGetMacro(ControlKey, int);
00377 
00379 
00380   vtkSetMacro(ShiftKey, int);
00381   vtkGetMacro(ShiftKey, int);
00383 
00385 
00386   vtkSetMacro(KeyCode, char);
00387   vtkGetMacro(KeyCode, char);
00389 
00391 
00393   vtkSetMacro(RepeatCount, int);
00394   vtkGetMacro(RepeatCount, int);
00396 
00398 
00403   vtkSetStringMacro(KeySym);
00404   vtkGetStringMacro(KeySym);
00406 
00408 
00409   void SetEventInformation(int x,
00410                            int y,
00411                            int ctrl=0,
00412                            int shift=0,
00413                            char keycode=0,
00414                            int repeatcount=0,
00415                            const char* keysym=0)
00416     {
00417       this->LastEventPosition[0] = this->EventPosition[0];
00418       this->LastEventPosition[1] = this->EventPosition[1];
00419       this->EventPosition[0] = x;
00420       this->EventPosition[1] = y;
00421       this->ControlKey = ctrl;
00422       this->ShiftKey = shift;
00423       this->KeyCode = keycode;
00424       this->RepeatCount = repeatcount;
00425       if(keysym)
00426         {
00427         this->SetKeySym(keysym);
00428         }
00429       this->Modified();
00430     }
00432 
00434 
00436   void SetEventInformationFlipY(int x,
00437                                 int y,
00438                                 int ctrl=0,
00439                                 int shift=0,
00440                                 char keycode=0,
00441                                 int repeatcount=0,
00442                                 const char* keysym=0)
00443     {
00444       this->SetEventInformation(x,
00445                                 this->Size[1] - y - 1,
00446                                 ctrl,
00447                                 shift,
00448                                 keycode,
00449                                 repeatcount,
00450                                 keysym);
00451     }
00453 
00455 
00456   void SetKeyEventInformation(int ctrl=0,
00457                               int shift=0,
00458                               char keycode=0,
00459                               int repeatcount=0,
00460                               const char* keysym=0)
00461     {
00462       this->ControlKey = ctrl;
00463       this->ShiftKey = shift;
00464       this->KeyCode = keycode;
00465       this->RepeatCount = repeatcount;
00466       if(keysym)
00467         {
00468         this->SetKeySym(keysym);
00469         }
00470       this->Modified();
00471     }
00473 
00475 
00482   vtkSetVector2Macro(Size,int);
00483   vtkGetVector2Macro(Size,int);
00484   vtkSetVector2Macro(EventSize,int);
00485   vtkGetVector2Macro(EventSize,int);
00487 
00491   virtual vtkRenderer *FindPokedRenderer(int,int);
00492 
00499   vtkObserverMediator *GetObserverMediator();
00500 
00502 
00507   vtkSetMacro(UseTDx,bool);
00508   vtkGetMacro(UseTDx,bool);
00510 
00512 
00515   virtual void MouseMoveEvent();
00516   virtual void RightButtonPressEvent();
00517   virtual void RightButtonReleaseEvent();
00518   virtual void LeftButtonPressEvent();
00519   virtual void LeftButtonReleaseEvent();
00520   virtual void MiddleButtonPressEvent();
00521   virtual void MiddleButtonReleaseEvent();
00522   virtual void MouseWheelForwardEvent();
00523   virtual void MouseWheelBackwardEvent();
00524   virtual void ExposeEvent();
00525   virtual void ConfigureEvent();
00526   virtual void EnterEvent();
00527   virtual void LeaveEvent();
00528   virtual void KeyPressEvent();
00529   virtual void KeyReleaseEvent();
00530   virtual void CharEvent();
00531   virtual void ExitEvent();
00533 
00534 protected:
00535   vtkRenderWindowInteractor();
00536   ~vtkRenderWindowInteractor();
00537 
00538   vtkRenderWindow       *RenderWindow;
00539   vtkInteractorObserver *InteractorStyle;
00540 
00541   // Used as a helper object to pick instances of vtkProp
00542   vtkAbstractPicker     *Picker;
00543   vtkPickingManager     *PickingManager;
00544 
00547   virtual vtkPickingManager *CreateDefaultPickingManager();
00548 
00549   int    Initialized;
00550   int    Enabled;
00551   bool   EnableRender;
00552   int    Style;
00553   int    LightFollowCamera;
00554   int    ActorMode;
00555   double DesiredUpdateRate;
00556   double StillUpdateRate;
00557 
00558   // Event information
00559   int   AltKey;
00560   int   ControlKey;
00561   int   ShiftKey;
00562   char  KeyCode;
00563   int   RepeatCount;
00564   char* KeySym;
00565   int   EventPosition[2];
00566   int   LastEventPosition[2];
00567   int   EventSize[2];
00568   int   Size[2];
00569   int   TimerEventId;
00570   int   TimerEventType;
00571   int   TimerEventDuration;
00572   int   TimerEventPlatformId;
00573 
00574   // control the fly to
00575   int NumberOfFlyFrames;
00576   double Dolly;
00577 
00578 //BTX
00580 
00587   friend class vtkInteractorObserver;
00588   void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
00589     {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
00590   void ReleaseFocus()
00591     {this->Superclass::InternalReleaseFocus();}
00592 //ETX
00594 
00597   vtkObserverMediator *ObserverMediator;
00598 
00599 //BTX
00600   // Timer related members
00601   friend struct vtkTimerStruct;
00602   vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
00603   unsigned long  TimerDuration; //in milliseconds
00605 
00609   virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
00610   virtual int InternalDestroyTimer(int platformTimerId);
00611   int GetCurrentTimerId();
00612 //ETX
00614 
00615   // Force the interactor to handle the Start() event loop, ignoring any
00616   // overrides. (Overrides are registered by observing StartEvent on the
00617   // interactor.)
00618   int HandleEventLoop;
00619 
00620   bool UseTDx; // 3DConnexion device.
00621 
00622 private:
00623   vtkRenderWindowInteractor(const vtkRenderWindowInteractor&);  // Not implemented.
00624   void operator=(const vtkRenderWindowInteractor&);  // Not implemented.
00625 };
00626 
00627 #endif