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