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