VTK
vtkRenderWindowInteractor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkRenderWindowInteractor.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 =========================================================================*/
52 #ifndef __vtkRenderWindowInteractor_h
53 #define __vtkRenderWindowInteractor_h
54 
55 #include "vtkObject.h"
56 
57 class vtkTimerIdMap;
58 
59 
60 // Timer flags for win32/X compatibility
61 #define VTKI_TIMER_FIRST 0
62 #define VTKI_TIMER_UPDATE 1
63 
64 class vtkAbstractPicker;
67 class vtkRenderWindow;
68 class vtkRenderer;
71 
73 {
74  //BTX
76  //ETX
77 public:
80  void PrintSelf(ostream& os, vtkIndent indent);
81 
83 
85  virtual void Initialize();
86  void ReInitialize() { this->Initialized = 0; this->Enabled = 0;
87  this->Initialize(); }
89 
92  virtual void UnRegister(vtkObjectBase *o);
93 
97  virtual void Start() {}
98 
100 
107  virtual void Enable() { this->Enabled = 1; this->Modified();}
108  virtual void Disable() { this->Enabled = 0; this->Modified();}
109  vtkGetMacro(Enabled, int);
111 
113 
115  vtkBooleanMacro(EnableRender, bool);
116  vtkSetMacro(EnableRender, bool);
117  vtkGetMacro(EnableRender, bool);
119 
121 
122  void SetRenderWindow(vtkRenderWindow *aren);
123  vtkGetObjectMacro(RenderWindow,vtkRenderWindow);
125 
128  virtual void UpdateSize(int x,int y);
129 
131 
146  virtual int CreateTimer(int timerType); //first group, for backward compatibility
147  virtual int DestroyTimer(); //first group, for backward compatibility
148  int CreateRepeatingTimer(unsigned long duration);
149  int CreateOneShotTimer(unsigned long duration);
150  int IsOneShotTimer(int timerId);
151  unsigned long GetTimerDuration(int timerId);
152  int ResetTimer(int timerId);
153  int DestroyTimer(int timerId);
154  virtual int GetVTKTimerId(int platformTimerId);
156 
157  //BTX
158  // Moved into the public section of the class so that classless timer procs
159  // can access these enum members without being "friends"...
160  enum {OneShotTimer=1,RepeatingTimer};
161  //ETX
162 
164 
171  vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
172  vtkGetMacro(TimerDuration,unsigned long);
174 
176 
186  vtkSetMacro(TimerEventId, int);
187  vtkGetMacro(TimerEventId, int);
188  vtkSetMacro(TimerEventType, int);
189  vtkGetMacro(TimerEventType, int);
190  vtkSetMacro(TimerEventDuration, int);
191  vtkGetMacro(TimerEventDuration, int);
192  vtkSetMacro(TimerEventPlatformId, int);
193  vtkGetMacro(TimerEventPlatformId, int);
195 
199  virtual void TerminateApp(void) {}
200 
202 
204  virtual void SetInteractorStyle(vtkInteractorObserver *);
205  vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
207 
209 
211  vtkSetMacro(LightFollowCamera,int);
212  vtkGetMacro(LightFollowCamera,int);
213  vtkBooleanMacro(LightFollowCamera,int);
215 
217 
222  vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_LARGE_FLOAT);
223  vtkGetMacro(DesiredUpdateRate,double);
225 
227 
230  vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_LARGE_FLOAT);
231  vtkGetMacro(StillUpdateRate,double);
233 
235 
236  vtkGetMacro(Initialized,int);
238 
240 
244  virtual void SetPicker(vtkAbstractPicker*);
245  vtkGetObjectMacro(Picker,vtkAbstractPicker);
247 
250  virtual vtkAbstractPropPicker *CreateDefaultPicker();
251 
253 
255  virtual void ExitCallback();
256  virtual void UserCallback();
257  virtual void StartPickCallback();
258  virtual void EndPickCallback();
260 
262  virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
263 
265 
267  void HideCursor();
268  void ShowCursor();
270 
273  virtual void Render();
274 
276 
279  void FlyTo(vtkRenderer *ren, double x, double y, double z);
280  void FlyTo(vtkRenderer *ren, double *x)
281  {this->FlyTo(ren, x[0], x[1], x[2]);}
282  void FlyToImage(vtkRenderer *ren, double x, double y);
283  void FlyToImage(vtkRenderer *ren, double *x)
284  {this->FlyToImage(ren, x[0], x[1]);}
286 
288 
289  vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_LARGE_INTEGER);
290  vtkGetMacro(NumberOfFlyFrames,int);
292 
294 
296  vtkSetMacro(Dolly,double);
297  vtkGetMacro(Dolly,double);
299 
301 
306  vtkGetVector2Macro(EventPosition,int);
307  vtkGetVector2Macro(LastEventPosition,int);
308  vtkSetVector2Macro(LastEventPosition,int);
309  virtual void SetEventPosition(int x, int y)
310  {
311  vtkDebugMacro(<< this->GetClassName() << " (" << this
312  << "): setting EventPosition to (" << x << "," << y << ")");
313  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
314  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
315  {
316  this->LastEventPosition[0] = this->EventPosition[0];
317  this->LastEventPosition[1] = this->EventPosition[1];
318  this->EventPosition[0] = x;
319  this->EventPosition[1] = y;
320  this->Modified();
321  }
322  }
323  virtual void SetEventPosition(int pos[2])
324  {
325  this->SetEventPosition(pos[0], pos[1]);
326  }
327  virtual void SetEventPositionFlipY(int x, int y)
328  {
329  this->SetEventPosition(x, this->Size[1] - y - 1);
330  }
331  virtual void SetEventPositionFlipY(int pos[2])
332  {
333  this->SetEventPositionFlipY(pos[0], pos[1]);
334  }
335  vtkSetMacro(AltKey, int);
336  vtkGetMacro(AltKey, int);
337  vtkSetMacro(ControlKey, int);
338  vtkGetMacro(ControlKey, int);
339  vtkSetMacro(ShiftKey, int);
340  vtkGetMacro(ShiftKey, int);
341  vtkSetMacro(KeyCode, char);
342  vtkGetMacro(KeyCode, char);
343  vtkSetMacro(RepeatCount, int);
344  vtkGetMacro(RepeatCount, int);
345  vtkSetStringMacro(KeySym);
346  vtkGetStringMacro(KeySym);
348 
350 
351  void SetEventInformation(int x,
352  int y,
353  int ctrl=0,
354  int shift=0,
355  char keycode=0,
356  int repeatcount=0,
357  const char* keysym=0)
358  {
359  this->LastEventPosition[0] = this->EventPosition[0];
360  this->LastEventPosition[1] = this->EventPosition[1];
361  this->EventPosition[0] = x;
362  this->EventPosition[1] = y;
363  this->ControlKey = ctrl;
364  this->ShiftKey = shift;
365  this->KeyCode = keycode;
366  this->RepeatCount = repeatcount;
367  if(keysym)
368  {
369  this->SetKeySym(keysym);
370  }
371  this->Modified();
372  }
374 
376 
378  void SetEventInformationFlipY(int x,
379  int y,
380  int ctrl=0,
381  int shift=0,
382  char keycode=0,
383  int repeatcount=0,
384  const char* keysym=0)
385  {
386  this->SetEventInformation(x,
387  this->Size[1] - y - 1,
388  ctrl,
389  shift,
390  keycode,
391  repeatcount,
392  keysym);
393  }
395 
397 
398  void SetKeyEventInformation(int ctrl=0,
399  int shift=0,
400  char keycode=0,
401  int repeatcount=0,
402  const char* keysym=0)
403  {
404  this->ControlKey = ctrl;
405  this->ShiftKey = shift;
406  this->KeyCode = keycode;
407  this->RepeatCount = repeatcount;
408  if(keysym)
409  {
410  this->SetKeySym(keysym);
411  }
412  this->Modified();
413  }
415 
417 
424  vtkSetVector2Macro(Size,int);
425  vtkGetVector2Macro(Size,int);
426  vtkSetVector2Macro(EventSize,int);
427  vtkGetVector2Macro(EventSize,int);
429 
433  virtual vtkRenderer *FindPokedRenderer(int,int);
434 
441  vtkObserverMediator *GetObserverMediator();
442 
444 
449  vtkSetMacro(UseTDx,bool);
450  vtkGetMacro(UseTDx,bool);
452 
454 
457  virtual void MouseMoveEvent();
458  virtual void RightButtonPressEvent();
459  virtual void RightButtonReleaseEvent();
460  virtual void LeftButtonPressEvent();
461  virtual void LeftButtonReleaseEvent();
462  virtual void MiddleButtonPressEvent();
463  virtual void MiddleButtonReleaseEvent();
464  virtual void MouseWheelForwardEvent();
465  virtual void MouseWheelBackwardEvent();
466  virtual void ExposeEvent();
467  virtual void ConfigureEvent();
468  virtual void EnterEvent();
469  virtual void LeaveEvent();
470  virtual void KeyPressEvent();
471  virtual void KeyReleaseEvent();
472  virtual void CharEvent();
473  virtual void ExitEvent();
475 
476 protected:
479 
482 
483  // Used as a helper object to pick instances of vtkProp
485 
487  int Enabled;
489  int Style;
494 
495  // Event information
496  int AltKey;
498  int ShiftKey;
499  char KeyCode;
501  char* KeySym;
502  int EventPosition[2];
503  int LastEventPosition[2];
504  int EventSize[2];
505  int Size[2];
510 
511  // control the fly to
513  double Dolly;
514 
515 //BTX
517 
524  friend class vtkInteractorObserver;
525  void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
526  {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
529 //ETX
531 
535 
536 //BTX
537  // Timer related members
538  friend struct vtkTimerStruct;
539  vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
540  unsigned long TimerDuration; //in milliseconds
542 
546  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
547  virtual int InternalDestroyTimer(int platformTimerId);
548  int GetCurrentTimerId();
549 //ETX
551 
552  // Force the interactor to handle the Start() event loop, ignoring any
553  // overrides. (Overrides are registered by observing StartEvent on the
554  // interactor.)
556 
557  bool UseTDx; // 3DConnexion device.
558 
559 private:
560  vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented.
561  void operator=(const vtkRenderWindowInteractor&); // Not implemented.
562 };
563 
564 #endif