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 =========================================================================*/
53 #ifndef __vtkRenderWindowInteractor_h
54 #define __vtkRenderWindowInteractor_h
55 
56 #include "vtkObject.h"
57 
58 class vtkTimerIdMap;
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
149 
152  int CreateRepeatingTimer(unsigned long duration);
153 
156  int CreateOneShotTimer(unsigned long duration);
157 
160  int IsOneShotTimer(int timerId);
161 
163  unsigned long GetTimerDuration(int timerId);
164 
166  int ResetTimer(int timerId);
167 
170  int DestroyTimer(int timerId);
171 
173  virtual int GetVTKTimerId(int platformTimerId);
174 
175  //BTX
176  // Moved into the public section of the class so that classless timer procs
177  // can access these enum members without being "friends"...
178  enum {OneShotTimer=1,RepeatingTimer};
179  //ETX
180 
182 
189  vtkSetClampMacro(TimerDuration,unsigned long,1,100000);
190  vtkGetMacro(TimerDuration,unsigned long);
192 
194 
204  vtkSetMacro(TimerEventId, int);
205  vtkGetMacro(TimerEventId, int);
206  vtkSetMacro(TimerEventType, int);
207  vtkGetMacro(TimerEventType, int);
208  vtkSetMacro(TimerEventDuration, int);
209  vtkGetMacro(TimerEventDuration, int);
210  vtkSetMacro(TimerEventPlatformId, int);
211  vtkGetMacro(TimerEventPlatformId, int);
213 
217  virtual void TerminateApp(void) {}
218 
220 
222  virtual void SetInteractorStyle(vtkInteractorObserver *);
223  vtkGetObjectMacro(InteractorStyle,vtkInteractorObserver);
225 
227 
229  vtkSetMacro(LightFollowCamera,int);
230  vtkGetMacro(LightFollowCamera,int);
231  vtkBooleanMacro(LightFollowCamera,int);
233 
235 
240  vtkSetClampMacro(DesiredUpdateRate,double,0.0001,VTK_LARGE_FLOAT);
241  vtkGetMacro(DesiredUpdateRate,double);
243 
245 
248  vtkSetClampMacro(StillUpdateRate,double,0.0001,VTK_LARGE_FLOAT);
249  vtkGetMacro(StillUpdateRate,double);
251 
253 
254  vtkGetMacro(Initialized,int);
256 
258 
262  virtual void SetPicker(vtkAbstractPicker*);
263  vtkGetObjectMacro(Picker,vtkAbstractPicker);
265 
268  virtual vtkAbstractPropPicker *CreateDefaultPicker();
269 
271 
273  virtual void ExitCallback();
274  virtual void UserCallback();
275  virtual void StartPickCallback();
276  virtual void EndPickCallback();
278 
280  virtual void GetMousePosition(int *x, int *y) { *x = 0 ; *y = 0; }
281 
283 
285  void HideCursor();
286  void ShowCursor();
288 
291  virtual void Render();
292 
294 
297  void FlyTo(vtkRenderer *ren, double x, double y, double z);
298  void FlyTo(vtkRenderer *ren, double *x)
299  {this->FlyTo(ren, x[0], x[1], x[2]);}
300  void FlyToImage(vtkRenderer *ren, double x, double y);
301  void FlyToImage(vtkRenderer *ren, double *x)
302  {this->FlyToImage(ren, x[0], x[1]);}
304 
306 
307  vtkSetClampMacro(NumberOfFlyFrames,int,1,VTK_LARGE_INTEGER);
308  vtkGetMacro(NumberOfFlyFrames,int);
310 
312 
314  vtkSetMacro(Dolly,double);
315  vtkGetMacro(Dolly,double);
317 
319 
324  vtkGetVector2Macro(EventPosition,int);
325  vtkGetVector2Macro(LastEventPosition,int);
326  vtkSetVector2Macro(LastEventPosition,int);
327  virtual void SetEventPosition(int x, int y)
328  {
329  vtkDebugMacro(<< this->GetClassName() << " (" << this
330  << "): setting EventPosition to (" << x << "," << y << ")");
331  if (this->EventPosition[0] != x || this->EventPosition[1] != y ||
332  this->LastEventPosition[0] != x || this->LastEventPosition[1] != y)
333  {
334  this->LastEventPosition[0] = this->EventPosition[0];
335  this->LastEventPosition[1] = this->EventPosition[1];
336  this->EventPosition[0] = x;
337  this->EventPosition[1] = y;
338  this->Modified();
339  }
340  }
341  virtual void SetEventPosition(int pos[2])
342  {
343  this->SetEventPosition(pos[0], pos[1]);
344  }
345  virtual void SetEventPositionFlipY(int x, int y)
346  {
347  this->SetEventPosition(x, this->Size[1] - y - 1);
348  }
349  virtual void SetEventPositionFlipY(int pos[2])
350  {
351  this->SetEventPositionFlipY(pos[0], pos[1]);
352  }
354 
356 
357  vtkSetMacro(AltKey, int);
358  vtkGetMacro(AltKey, int);
360 
362 
363  vtkSetMacro(ControlKey, int);
364  vtkGetMacro(ControlKey, int);
366 
368 
369  vtkSetMacro(ShiftKey, int);
370  vtkGetMacro(ShiftKey, int);
372 
374 
375  vtkSetMacro(KeyCode, char);
376  vtkGetMacro(KeyCode, char);
378 
380 
382  vtkSetMacro(RepeatCount, int);
383  vtkGetMacro(RepeatCount, int);
385 
387 
392  vtkSetStringMacro(KeySym);
393  vtkGetStringMacro(KeySym);
395 
397 
398  void SetEventInformation(int x,
399  int y,
400  int ctrl=0,
401  int shift=0,
402  char keycode=0,
403  int repeatcount=0,
404  const char* keysym=0)
405  {
406  this->LastEventPosition[0] = this->EventPosition[0];
407  this->LastEventPosition[1] = this->EventPosition[1];
408  this->EventPosition[0] = x;
409  this->EventPosition[1] = y;
410  this->ControlKey = ctrl;
411  this->ShiftKey = shift;
412  this->KeyCode = keycode;
413  this->RepeatCount = repeatcount;
414  if(keysym)
415  {
416  this->SetKeySym(keysym);
417  }
418  this->Modified();
419  }
421 
423 
425  void SetEventInformationFlipY(int x,
426  int y,
427  int ctrl=0,
428  int shift=0,
429  char keycode=0,
430  int repeatcount=0,
431  const char* keysym=0)
432  {
433  this->SetEventInformation(x,
434  this->Size[1] - y - 1,
435  ctrl,
436  shift,
437  keycode,
438  repeatcount,
439  keysym);
440  }
442 
444 
445  void SetKeyEventInformation(int ctrl=0,
446  int shift=0,
447  char keycode=0,
448  int repeatcount=0,
449  const char* keysym=0)
450  {
451  this->ControlKey = ctrl;
452  this->ShiftKey = shift;
453  this->KeyCode = keycode;
454  this->RepeatCount = repeatcount;
455  if(keysym)
456  {
457  this->SetKeySym(keysym);
458  }
459  this->Modified();
460  }
462 
464 
471  vtkSetVector2Macro(Size,int);
472  vtkGetVector2Macro(Size,int);
473  vtkSetVector2Macro(EventSize,int);
474  vtkGetVector2Macro(EventSize,int);
476 
480  virtual vtkRenderer *FindPokedRenderer(int,int);
481 
488  vtkObserverMediator *GetObserverMediator();
489 
491 
496  vtkSetMacro(UseTDx,bool);
497  vtkGetMacro(UseTDx,bool);
499 
501 
504  virtual void MouseMoveEvent();
505  virtual void RightButtonPressEvent();
506  virtual void RightButtonReleaseEvent();
507  virtual void LeftButtonPressEvent();
508  virtual void LeftButtonReleaseEvent();
509  virtual void MiddleButtonPressEvent();
510  virtual void MiddleButtonReleaseEvent();
511  virtual void MouseWheelForwardEvent();
512  virtual void MouseWheelBackwardEvent();
513  virtual void ExposeEvent();
514  virtual void ConfigureEvent();
515  virtual void EnterEvent();
516  virtual void LeaveEvent();
517  virtual void KeyPressEvent();
518  virtual void KeyReleaseEvent();
519  virtual void CharEvent();
520  virtual void ExitEvent();
522 
523 protected:
526 
529 
530  // Used as a helper object to pick instances of vtkProp
532 
534  int Enabled;
536  int Style;
541 
542  // Event information
543  int AltKey;
545  int ShiftKey;
546  char KeyCode;
548  char* KeySym;
549  int EventPosition[2];
550  int LastEventPosition[2];
551  int EventSize[2];
552  int Size[2];
557 
558  // control the fly to
560  double Dolly;
561 
562 //BTX
564 
571  friend class vtkInteractorObserver;
572  void GrabFocus(vtkCommand *mouseEvents, vtkCommand *keypressEvents=NULL)
573  {this->Superclass::InternalGrabFocus(mouseEvents,keypressEvents);}
576 //ETX
578 
582 
583 //BTX
584  // Timer related members
585  friend struct vtkTimerStruct;
586  vtkTimerIdMap *TimerMap; // An internal, PIMPLd map of timers and associated attributes
587  unsigned long TimerDuration; //in milliseconds
589 
593  virtual int InternalCreateTimer(int timerId, int timerType, unsigned long duration);
594  virtual int InternalDestroyTimer(int platformTimerId);
595  int GetCurrentTimerId();
596 //ETX
598 
599  // Force the interactor to handle the Start() event loop, ignoring any
600  // overrides. (Overrides are registered by observing StartEvent on the
601  // interactor.)
603 
604  bool UseTDx; // 3DConnexion device.
605 
606 private:
607  vtkRenderWindowInteractor(const vtkRenderWindowInteractor&); // Not implemented.
608  void operator=(const vtkRenderWindowInteractor&); // Not implemented.
609 };
610 
611 #endif