Salome HOME
Initial version
[modules/gui.git] / src / VTKViewer / VTKViewer_RenderWindowInteractor.h
1 #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H
2 #define VTKVIEWER_RENDERWINDOWINTERACTOR_H
3
4 #include "VTKViewer.h"
5 #include "VTKViewer_Actor.h"
6
7 #include <qtimer.h>
8 #include <qobject.h>
9
10 // Open CASCADE Includes
11 #include <TColStd_MapOfInteger.hxx>
12 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
13 #include <TColStd_IndexedMapOfInteger.hxx>
14
15 class vtkPicker;
16 class vtkCellPicker;
17 class vtkPointPicker;
18 class vtkActorCollection;
19
20 class VTKViewer_Actor;
21 class VTKViewer_ViewWindow;
22 class VTKViewer_RenderWindow;
23 class VTKViewer_InteractorStyle;
24
25 #include "VTKViewer_Algorithm.h"
26
27 #include <vtkActor.h>
28 #include <vtkVersion.h>
29 #include <vtkRenderWindowInteractor.h>
30
31 class VTKVIEWER_EXPORT VTKViewer_RenderWindowInteractor : public QObject, public vtkRenderWindowInteractor
32 {
33   Q_OBJECT
34
35 public:
36   static VTKViewer_RenderWindowInteractor *New();
37
38   vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
39
40   void PrintSelf(ostream& os, vtkIndent indent);
41
42   // Description:
43   // Initializes the event handlers without an XtAppContext.  This is
44   // good for when you don`t have a user interface, but you still
45   // want to have mouse interaction.
46   virtual void Initialize();
47
48   virtual void               SetInteractorStyle(vtkInteractorObserver *);
49   VTKViewer_InteractorStyle* GetInteractorStyle() const
50   {
51     return myInteractorStyle;
52   }
53
54   // Description:
55   // This will start up the X event loop and never return. If you
56   // call this method it will loop processing X events until the
57   // application is exited.
58   virtual void Start();
59   
60   // Description:
61   // Enable/Disable interactions.  By default interactors are enabled when
62   // initialized.  Initialize() must be called prior to enabling/disabling
63   // interaction. These methods are used when a window/widget is being
64   // shared by multiple renderers and interactors.  This allows a "modal"
65   // display where one interactor is active when its data is to be displayed
66   // and all other interactors associated with the widget are disabled
67   // when their data is not displayed.
68   virtual void Enable();
69   virtual void Disable();
70
71   // Description:
72   // Event loop notification member for Window size change
73   virtual void UpdateSize(int x,int y);
74
75   // Description:
76   // Timer methods must be overridden by platform dependent subclasses.
77   // flag is passed to indicate if this is first timer set or an update
78   // as Win32 uses repeating timers, whereas X uses One shot more timer
79   // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
80   // otherwise Win32 should exit and X should perform AddTimeOut()
81   virtual int CreateTimer(int ) ; 
82   virtual int DestroyTimer() ; 
83   
84   // Description:
85   // This function is called on 'q','e' keypress if exitmethod is not
86   // specified and should be overidden by platform dependent subclasses
87   // to provide a termination procedure if one is required.
88   virtual void TerminateApp(void) { /* empty */ }
89   
90   // Description:
91   // These methods correspond to the the Exit, User and Pick
92   // callbacks. They allow for the Style to invoke them.
93   //virtual void ExitCallback();
94   //virtual void UserCallback();
95   //virtual void StartPickCallback();
96   //virtual void EndPickCallback();
97   
98   /* Selection Management */
99   bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
100                      VTKViewer_Actor* theMapActor,
101                      bool hilight,
102                      bool update = true );
103   bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
104                      VTKViewer_Actor* theMapActor,
105                      bool hilight,
106                      bool update = true );
107   bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
108                       VTKViewer_Actor* theMapActor,
109                       bool hilight,
110                       bool update = true );
111
112   void unHighlightSubSelection();
113   bool unHighlightAll();
114
115   //void SetSelectionMode(Selection_Mode mode);
116   void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
117                         const double& theBlue = 0, const int& theWidth = 5);
118   void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
119
120   // Displaymode management
121   int GetDisplayMode();
122   void SetDisplayMode(int);
123
124   // Change all actors to wireframe or surface
125   void ChangeRepresentationToWireframe();
126   void ChangeRepresentationToSurface();
127
128   // Change to wireframe or surface a list of vtkactor
129   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
130   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
131
132   // Erase Display functions
133   void EraseAll();
134   void DisplayAll();
135   void RemoveAll( const bool immediatly );
136
137   void Display( VTKViewer_Actor* SActor, bool immediatly = true );
138   void Erase( VTKViewer_Actor* SActor, bool immediatly = true );
139   void Remove( VTKViewer_Actor* SActor, bool updateViewer = true );
140
141   void Update();
142
143   vtkRenderer* GetRenderer();
144
145   void setViewWindow( VTKViewer_ViewWindow* theViewWnd );
146
147   void setCellData(const int& theIndex,
148                    VTKViewer_Actor* theMapActor,
149                    VTKViewer_Actor* theActor) {}
150   void setEdgeData(const int& theCellIndex,
151                    VTKViewer_Actor* theMapActor,
152                    const int& theEdgeIndex,
153                    VTKViewer_Actor* theActor ) {} //NB
154   void setPointData(const int& theIndex,
155                     VTKViewer_Actor* theMapActor,
156                     VTKViewer_Actor* theActor) {}
157
158   typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
159                                VTKViewer_Actor* theMapActor,
160                                VTKViewer_Actor* theActor);
161  protected:
162
163   VTKViewer_RenderWindowInteractor();
164   ~VTKViewer_RenderWindowInteractor();
165
166   VTKViewer_InteractorStyle* myInteractorStyle;
167
168   bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
169                  VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
170                  TUpdateActor theFun, bool hilight, bool update);
171   void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
172                     VTKViewer_Actor* theMapActor,
173                     VTKViewer_Actor *theActor,
174                     TUpdateActor theFun);
175
176   // Timer used during various mouse events to figure 
177   // out mouse movements. 
178   QTimer *mTimer ;
179
180   int myDisplayMode;
181
182   //NRI: Selection mode
183   VTKViewer_Actor* myPointActor;
184   VTKViewer_Actor* myEdgeActor;
185   VTKViewer_Actor* myCellActor;
186   void MoveInternalActors();
187
188   vtkPicker* myBasicPicker;
189   vtkCellPicker* myCellPicker;
190   vtkPointPicker* myPointPicker;
191   
192   // User for switching to stereo mode.
193   int PositionBeforeStereo[2];
194
195  public slots:
196   void MouseMove(QMouseEvent *event) ;
197   void LeftButtonPressed(const QMouseEvent *event) ;
198   void LeftButtonReleased(const QMouseEvent *event) ;
199   void MiddleButtonPressed(const QMouseEvent *event) ;
200   void MiddleButtonReleased(const QMouseEvent *event) ;
201   void RightButtonPressed(const QMouseEvent *event) ;
202   void RightButtonReleased(const QMouseEvent *event) ;
203   void ButtonPressed(const QMouseEvent *event) ;
204   void ButtonReleased(const QMouseEvent *event) ;
205   void KeyPressed(QKeyEvent *event) ;
206
207   private slots:
208     // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
209     // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
210     // we have to include all of these for the time being. Once,
211     // this bug in MOC is fixed, we can separate these. 
212     void TimerFunc() ;
213
214 signals:
215   void RenderWindowModified() ;
216   void contextMenuRequested( QContextMenuEvent *e );
217
218 private:
219   friend class VTKViewer_ViewWindow;
220
221   VTKViewer_ViewWindow* myViewWnd;
222   double       myTolNodes;
223   double       myTolItems;
224 };
225
226 #endif