VTK
dox/Rendering/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 "vtkObject.h"
00057 
00058 class vtkTimerIdMap;
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
00149 
00152   int CreateRepeatingTimer(unsigned long duration);
00153 
00156   int CreateOneShotTimer(unsigned long duration);
00157 
00160   int IsOneShotTimer(int timerId);
00161 
00163   unsigned long GetTimerDuration(int timerId);
00164 
00166   int ResetTimer(int timerId);
00167 
00170   int DestroyTimer(int timerId);
00171 
00173   virtual int GetVTKTimerId(int platformTimerId);
00174 
00175   //BTX
00176   // Moved into the public section of the class so that classless timer procs
00177   // can access these enum members without being "friends"...
00178   enum {OneShotTimer=1,RepeatingTimer};
00179   //ETX
00180 
00182 
00189   vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
00190   vtkGetMacro(TimerDuration,unsigned long);
00192 
00194 
00204   vtkSetMacro(TimerEventId, int);
00205   vtkGetMacro(TimerEventId, int);
00206   vtkSetMacro(TimerEventType, int);
00207   vtkGetMacro(TimerEventType, int);
00208   vtkSetMacro(TimerEventDuration, int);
00209   vtkGetMacro(TimerEventDuration, int);
00210   vtkSetMacro(TimerEventPlatformId, int);
00211   vtkGetMacro(TimerEventPlatformId, int);
00213 
00217   virtual void TerminateApp(void) {}
00218 
00220 
00222   virtual void SetInteractorStyle(vtkInteractorObserver *);
00223   vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
00225 
00227 
00229   vtkSetMacro(LightFollowCamera,int);
00230   vtkGetMacro(LightFollowCamera,int);
00231   vtkBooleanMacro(LightFollowCamera,int);
00233 
00235 
00240   vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_LARGE_FLOAT);
00241   vtkGetMacro(DesiredUpdateRate,double);
00243 
00245 
00248   vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_LARGE_FLOAT);
00249   vtkGetMacro(StillUpdateRate,double);
00251 
00253 
00254   vtkGetMacro(Initialized,int);
00256 
00258 
00262   virtual void SetPicker(vtkAbstractPicker*);
00263   vtkGetObjectMacro(Picker,vtkAbstractPicker);
00265 
00268   virtual vtkAbstractPropPicker *CreateDefaultPicker();
00269 
00271 
00273   virtual void ExitCallback();
00274   virtual void UserCallback();
00275   virtual void StartPickCallback();
00276   virtual void EndPickCallback();
00278   
00280   virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
00281 
00283 
00285   void HideCursor();
00286   void ShowCursor();
00288 
00291   virtual void Render();
00292 
00294 
00297   void FlyTo(vtkRenderer *ren, double x, double y, double z);
00298   void FlyTo(vtkRenderer *ren, double *x)
00299     {this->FlyTo(ren, x[0], x[1], x[2]);}
00300   void FlyToImage(vtkRenderer *ren, double x, double y);
00301   void FlyToImage(vtkRenderer *ren, double *x)
00302     {this->FlyToImage(ren, x[0], x[1]);}
00304 
00306 
00307   vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_LARGE_INTEGER);
00308   vtkGetMacro(NumberOfFlyFrames,int);
00310 
00312 
00314   vtkSetMacro(Dolly,double);
00315   vtkGetMacro(Dolly,double);
00317 
00319 
00324   vtkGetVector2Macro(EventPosition,int);
00325   vtkGetVector2Macro(LastEventPosition,int);
00326   vtkSetVector2Macro(LastEventPosition,int);
00327   virtual void SetEventPosition(int x, int y)
00328   {
00329     vtkDebugMacro(<< this->GetClassName() << " (" << this 
00330                   << "): setting EventPosition to (" << x << "," << y << ")");
00331     if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
00332         this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
00333       {
00334       this->LastEventPosition[0] = this->EventPosition[0];
00335       this->LastEventPosition[1] = this->EventPosition[1];
00336       this->EventPosition[0] = x;
00337       this->EventPosition[1] = y;
00338       this->Modified();
00339       }
00340   }
00341   virtual void SetEventPosition(int pos[2])
00342   {
00343     this->SetEventPosition(pos[0], pos[1]);
00344   } 
00345   virtual void SetEventPositionFlipY(int x, int y)
00346   {
00347     this->SetEventPosition(x, this->Size[1] - y - 1);
00348   }
00349   virtual void SetEventPositionFlipY(int pos[2])
00350   {
00351     this->SetEventPositionFlipY(pos[0], pos[1]);
00352   }
00354 
00356 
00357   vtkSetMacro(AltKey, int);
00358   vtkGetMacro(AltKey, int);
00360 
00362 
00363   vtkSetMacro(ControlKey, int);
00364   vtkGetMacro(ControlKey, int);
00366 
00368 
00369   vtkSetMacro(ShiftKey, int);
00370   vtkGetMacro(ShiftKey, int);
00372 
00374 
00375   vtkSetMacro(KeyCode, char);
00376   vtkGetMacro(KeyCode, char);
00378 
00380 
00382   vtkSetMacro(RepeatCount, int);
00383   vtkGetMacro(RepeatCount, int);
00385 
00387 
00392   vtkSetStringMacro(KeySym);
00393   vtkGetStringMacro(KeySym);
00395 
00397 
00398   void SetEventInformation(int x, 
00399                            int y, 
00400                            int ctrl=0, 
00401                            int shift=0, 
00402                            char keycode=0, 
00403                            int repeatcount=0,
00404                            const char* keysym=0)
00405     {
00406       this->LastEventPosition[0] = this->EventPosition[0];
00407       this->LastEventPosition[1] = this->EventPosition[1];
00408       this->EventPosition[0] = x;
00409       this->EventPosition[1] = y;
00410       this->ControlKey = ctrl;
00411       this->ShiftKey = shift;
00412       this->KeyCode = keycode;
00413       this->RepeatCount = repeatcount;
00414       if(keysym)
00415         {
00416         this->SetKeySym(keysym);
00417         }
00418       this->Modified();
00419     }
00421 
00423 
00425   void SetEventInformationFlipY(int x, 
00426                                 int y, 
00427                                 int ctrl=0, 
00428                                 int shift=0, 
00429                                 char keycode=0, 
00430                                 int repeatcount=0,
00431                                 const char* keysym=0)
00432     {
00433       this->SetEventInformation(x, 
00434                                 this->Size[1] - y - 1, 
00435                                 ctrl, 
00436                                 shift, 
00437                                 keycode, 
00438                                 repeatcount, 
00439                                 keysym);
00440     }
00442 
00444 
00445   void SetKeyEventInformation(int ctrl=0, 
00446                               int shift=0, 
00447                               char keycode=0, 
00448                               int repeatcount=0,
00449                               const char* keysym=0)
00450     {
00451       this->ControlKey = ctrl;
00452       this->ShiftKey = shift;
00453       this->KeyCode = keycode;
00454       this->RepeatCount = repeatcount;
00455       if(keysym)
00456         {
00457         this->SetKeySym(keysym);
00458         }
00459       this->Modified();
00460     }
00462 
00464 
00471   vtkSetVector2Macro(Size,int);
00472   vtkGetVector2Macro(Size,int);
00473   vtkSetVector2Macro(EventSize,int);
00474   vtkGetVector2Macro(EventSize,int);
00476 
00480   virtual vtkRenderer *FindPokedRenderer(int,int);
00481 
00488   vtkObserverMediator *GetObserverMediator();
00489 
00491 
00496   vtkSetMacro(UseTDx,bool);
00497   vtkGetMacro(UseTDx,bool);
00499 
00501 
00504   virtual void MouseMoveEvent();
00505   virtual void RightButtonPressEvent();
00506   virtual void RightButtonReleaseEvent();
00507   virtual void LeftButtonPressEvent();
00508   virtual void LeftButtonReleaseEvent();
00509   virtual void MiddleButtonPressEvent();
00510   virtual void MiddleButtonReleaseEvent();
00511   virtual void MouseWheelForwardEvent();
00512   virtual void MouseWheelBackwardEvent();
00513   virtual void ExposeEvent();
00514   virtual void ConfigureEvent();
00515   virtual void EnterEvent();
00516   virtual void LeaveEvent();
00517   virtual void KeyPressEvent();
00518   virtual void KeyReleaseEvent();
00519   virtual void CharEvent();
00520   virtual void ExitEvent();
00522   
00523 protected:
00524   vtkRenderWindowInteractor();
00525   ~vtkRenderWindowInteractor();
00526 
00527   vtkRenderWindow       *RenderWindow;
00528   vtkInteractorObserver *InteractorStyle;
00529 
00530   // Used as a helper object to pick instances of vtkProp
00531   vtkAbstractPicker     *Picker;
00532 
00533   int    Initialized;
00534   int    Enabled;
00535   bool   EnableRender;
00536   int    Style;
00537   int    LightFollowCamera;
00538   int    ActorMode;
00539   double DesiredUpdateRate;
00540   double StillUpdateRate;  
00541 
00542   // Event information
00543   int   AltKey;
00544   int   ControlKey;
00545   int   ShiftKey;
00546   char  KeyCode;
00547   int   RepeatCount;
00548   char* KeySym; 
00549   int   EventPosition[2];
00550   int   LastEventPosition[2];
00551   int   EventSize[2];
00552   int   Size[2];
00553   int   TimerEventId;
00554   int   TimerEventType;
00555   int   TimerEventDuration;
00556   int   TimerEventPlatformId;
00557 
00558   // control the fly to
00559   int NumberOfFlyFrames;
00560   double Dolly;
00561 
00562 //BTX
00564 
00571   friend class vtkInteractorObserver;
00572   void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
00573     {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
00574   void ReleaseFocus()
00575     {this->Superclass::InternalReleaseFocus();}
00576 //ETX
00578 
00581   vtkObserverMediator *ObserverMediator;
00582 
00583 //BTX
00584   // Timer related members
00585   friend struct vtkTimerStruct;
00586   vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
00587   unsigned long  TimerDuration; //in milliseconds
00589 
00593   virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
00594   virtual int InternalDestroyTimer(int platformTimerId);
00595   int GetCurrentTimerId();
00596 //ETX
00598 
00599   // Force the interactor to handle the Start() event loop, ignoring any 
00600   // overrides. (Overrides are registered by observing StartEvent on the 
00601   // interactor.)
00602   int HandleEventLoop;
00603   
00604   bool UseTDx; // 3DConnexion device.
00605   
00606 private:
00607   vtkRenderWindowInteractor(const vtkRenderWindowInteractor&);  // Not implemented.
00608   void operator=(const vtkRenderWindowInteractor&);  // Not implemented.
00609 };
00610 
00611 #endif