Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / VTKViewer / VTKViewer_RenderWindowInteractor.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H
23 #define VTKVIEWER_RENDERWINDOWINTERACTOR_H
24
25 #include "VTKViewer.h"
26 #include "VTKViewer_Actor.h"
27
28 #include <QObject>
29
30 class QTimer;
31 class QMouseEvent;
32 class QKeyEvent;
33 class QContextMenuEvent;
34
35 // Open CASCADE Includes
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
39
40 class vtkPicker;
41 class vtkCellPicker;
42 class vtkPointPicker;
43 class vtkActorCollection;
44
45 class VTKViewer_Actor;
46 class VTKViewer_ViewWindow;
47 class VTKViewer_RenderWindow;
48 class VTKViewer_InteractorStyle;
49
50 #include "VTKViewer_Algorithm.h"
51
52 #include <vtkActor.h>
53 #include <vtkVersion.h>
54 #include <vtkRenderWindowInteractor.h>
55
56 class VTKVIEWER_EXPORT VTKViewer_RenderWindowInteractor : public QObject, public vtkRenderWindowInteractor
57 {
58   Q_OBJECT
59
60 public:
61   static VTKViewer_RenderWindowInteractor *New();
62
63   vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
64
65   void PrintSelf(ostream& os, vtkIndent indent);
66
67   virtual void Initialize();
68
69   virtual void               SetInteractorStyle(vtkInteractorObserver *);
70   /*!Return interactor style pointer.*/
71   VTKViewer_InteractorStyle* GetInteractorStyle() const
72   {
73     return myInteractorStyle;
74   }
75
76   virtual void Start();
77   
78   virtual void Enable();
79   virtual void Disable();
80
81   virtual void UpdateSize(int x,int y);
82
83   /** @name Timer options*/
84   //@{
85   virtual int CreateTimer(int ) ;
86   virtual int DestroyTimer() ; 
87   //@}
88   
89   /*! Description:\n
90    * This function is called on 'q','e' keypress if exitmethod is not\n
91    * specified and should be overidden by platform dependent subclasses\n
92    * to provide a termination procedure if one is required.
93    */
94   virtual void TerminateApp(void) { /* empty */ }
95   
96   // Description:
97   // These methods correspond to the the Exit, User and Pick
98   // callbacks. They allow for the Style to invoke them.
99   //virtual void ExitCallback();
100   //virtual void UserCallback();
101   //virtual void StartPickCallback();
102   //virtual void EndPickCallback();
103   
104   /** @name Selection Management */
105   //@{
106   bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
107                      VTKViewer_Actor* theMapActor,
108                      bool hilight,
109                      bool update = true );
110   bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
111                      VTKViewer_Actor* theMapActor,
112                      bool hilight,
113                      bool update = true );
114   bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
115                       VTKViewer_Actor* theMapActor,
116                       bool hilight,
117                       bool update = true );
118
119   void unHighlightSubSelection();
120   bool unHighlightAll();
121
122   //void SetSelectionMode(Selection_Mode mode);
123   void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
124                         const double& theBlue = 0, const int& theWidth = 5);
125   void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
126   //@}
127
128   /** @name Displaymode management*/
129   //@{
130   int GetDisplayMode();
131   void SetDisplayMode(int);
132   //@}
133
134   /** @name Change all actors to wireframe or surface*/
135   //@{
136   void ChangeRepresentationToWireframe();
137   void ChangeRepresentationToSurface();
138   //@}
139
140   /** @name Change to wireframe or surface a list of vtkactor*/
141   //@{
142   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
143   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
144   //@}
145
146   /** @name Erase Display functions*/
147   //@{
148   void EraseAll();
149   void DisplayAll();
150   void RemoveAll( const bool immediatly );
151
152   void Display( VTKViewer_Actor* SActor, bool immediatly = true );
153   void Erase( VTKViewer_Actor* SActor, bool immediatly = true );
154   void Remove( VTKViewer_Actor* SActor, bool updateViewer = true );
155   //@}
156
157   void Update();
158
159   vtkRenderer* GetRenderer();
160
161   void setViewWindow( VTKViewer_ViewWindow* theViewWnd );
162
163   void setCellData(const int& theIndex,
164                    VTKViewer_Actor* theMapActor,
165                    VTKViewer_Actor* theActor) {}
166   void setEdgeData(const int& theCellIndex,
167                    VTKViewer_Actor* theMapActor,
168                    const int& theEdgeIndex,
169                    VTKViewer_Actor* theActor ) {} //NB
170   void setPointData(const int& theIndex,
171                     VTKViewer_Actor* theMapActor,
172                     VTKViewer_Actor* theActor) {}
173
174   typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
175                                VTKViewer_Actor* theMapActor,
176                                VTKViewer_Actor* theActor);
177  protected:
178
179   VTKViewer_RenderWindowInteractor();
180   ~VTKViewer_RenderWindowInteractor();
181
182   VTKViewer_InteractorStyle* myInteractorStyle;
183
184   bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
185                  VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
186                  TUpdateActor theFun, bool hilight, bool update);
187   void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
188                     VTKViewer_Actor* theMapActor,
189                     VTKViewer_Actor *theActor,
190                     TUpdateActor theFun);
191
192   /*! Timer used during various mouse events to figure 
193    * out mouse movements.
194    */
195   QTimer *mTimer ;
196
197   int myDisplayMode;
198
199   //NRI: Selection mode
200   VTKViewer_Actor* myPointActor;
201   VTKViewer_Actor* myEdgeActor;
202   VTKViewer_Actor* myCellActor;
203   void MoveInternalActors();
204
205   vtkPicker* myBasicPicker;
206   vtkCellPicker* myCellPicker;
207   vtkPointPicker* myPointPicker;
208   
209   /*! User for switching to stereo mode.*/
210   int PositionBeforeStereo[2];
211
212  public slots:
213   void MouseMove(QMouseEvent *event) ;
214   void LeftButtonPressed(const QMouseEvent *event) ;
215   void LeftButtonReleased(const QMouseEvent *event) ;
216   void MiddleButtonPressed(const QMouseEvent *event) ;
217   void MiddleButtonReleased(const QMouseEvent *event) ;
218   void RightButtonPressed(const QMouseEvent *event) ;
219   void RightButtonReleased(const QMouseEvent *event) ;
220   void ButtonPressed(const QMouseEvent *event) ;
221   void ButtonReleased(const QMouseEvent *event) ;
222   void KeyPressed(QKeyEvent *event) ;
223
224   private slots:
225     void TimerFunc() ;
226
227 signals:
228   void RenderWindowModified() ;
229   void contextMenuRequested( QContextMenuEvent *e );
230
231 private:
232   friend class VTKViewer_ViewWindow;
233
234   VTKViewer_ViewWindow* myViewWnd;
235   /** Selection node tolerance.*/
236   double       myTolNodes;
237   /** Selection cell tolerance.*/
238   double       myTolItems;
239 };
240
241 #endif