Salome HOME
[bos #42109][CEA] (2024) Import med and show python console shortcuts does not work...
[modules/gui.git] / SVTK / SVTK_RenderWindowInteractor.h
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SVTK_RenderWindowInteractor.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef SVTK_RenderWindowInteractor_h
30 #define SVTK_RenderWindowInteractor_h
31
32 #include "SVTK.h"
33
34 #include "SVTK_Selection.h"
35 #include "SALOME_InteractiveObject.hxx"
36
37 // QT Includes
38 #include <qobject.h>
39 #include <qtimer.h>
40
41 // VTK Includes
42 #include <vtkVersion.h>
43 #include <vtkRenderWindowInteractor.h>
44
45 // Open CASCADE Includes
46 #include <TColStd_MapOfInteger.hxx>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
49
50 class vtkPicker;
51 class vtkCellPicker;
52 class vtkPointPicker;
53 class vtkActorCollection;
54
55 class SALOME_Actor;
56 class SVTK_Actor;
57
58 class SVTK_ViewWindow;
59 class SVTK_RenderWindow;
60 class SVTK_InteractorStyle;
61
62 // ------------------------------------------------------------
63 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
64 // The Signal/Slot mechanism used by Qt requires that QObject 
65 // appear as the first class when using multiple inheritance. 
66 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
67 // matters here. Be careful not to change it by accident. 
68 // ------------------------------------------------------------
69 class SVTK_EXPORT SVTK_RenderWindowInteractor: public QObject, 
70   public vtkRenderWindowInteractor
71 {
72   Q_OBJECT ;   
73   friend class SVTK_ViewWindow;
74 public:
75
76   static SVTK_RenderWindowInteractor *New() ; 
77
78   vtkTypeMacro(SVTK_RenderWindowInteractor,vtkRenderWindowInteractor);
79
80   // Description:
81   // Initializes the event handlers without an XtAppContext.  This is
82   // good for when you don`t have a user interface, but you still
83   // want to have mouse interaction.
84   virtual void Initialize();
85
86   virtual void SetInteractorStyle(vtkInteractorObserver *);
87   SVTK_InteractorStyle* GetSInteractorStyle(){ return myInteractorStyle;}
88
89   // Description:
90   // This will start up the X event loop and never return. If you
91   // call this method it will loop processing X events until the
92   // application is exited.
93   virtual void Start();
94   
95   // Description:
96   // Event loop notification member for Window size change
97   virtual void UpdateSize(int x,int y);
98
99   // Description:
100   // Timer methods must be overridden by platform dependent subclasses.
101   // flag is passed to indicate if this is first timer set or an update
102   // as Win32 uses repeating timers, whereas X uses One shot more timer
103   // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
104   // otherwise Win32 should exit and X should perform AddTimeOut()
105   virtual int CreateTimer(int ) ; 
106   virtual int DestroyTimer() ; 
107   
108   /* Selection Management */
109   bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex, 
110                      SALOME_Actor* theMapActor, 
111                      bool hilight, 
112                      bool update = true );
113   bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex, 
114                      SALOME_Actor* theMapActor, 
115                      bool hilight, 
116                      bool update = true );
117   bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex, 
118                       SALOME_Actor* theMapActor, 
119                       bool hilight, 
120                       bool update = true );
121   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, 
122                  bool hiligth, 
123                  bool immediatly = true );
124   void unHighlightSubSelection();
125   bool unHighlightAll();
126
127   bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
128   bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
129   void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
130
131   void SetSelectionMode(Selection_Mode mode);
132   void SetSelectionProp(const double& theRed = 1, 
133                         const double& theGreen = 1,
134                         const double& theBlue = 0, 
135                         const int& theWidth = 5);
136   void SetSelectionTolerance(const double& theTolNodes = 0.025, 
137                              const double& theTolCell = 0.001);
138
139   // Displaymode management
140   int GetDisplayMode();
141   void SetDisplayMode(int);
142
143   // Switch representation wireframe/shading
144   void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode);
145
146   // Change all actors to wireframe or surface
147   void ChangeRepresentationToWireframe();
148   void ChangeRepresentationToSurface();
149
150   // Change to wireframe or surface a list of vtkactor
151   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
152   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
153
154   // Erase Display functions
155   void EraseAll();
156   void DisplayAll();
157   void RemoveAll( const bool immediatly );
158   void Erase(const Handle(SALOME_InteractiveObject)& IObject, 
159              bool immediatly=true);
160   void Remove(const Handle(SALOME_InteractiveObject)& IObject, 
161               bool immediatly=true);
162   void Display(const Handle(SALOME_InteractiveObject)& IObject, 
163                bool immediatly=true);
164
165   void Display( SALOME_Actor* SActor, 
166                 bool immediatly = true );
167   void Erase( SALOME_Actor* SActor, 
168               bool immediatly = true );
169   void Remove( SALOME_Actor* SActor, 
170                bool updateViewer = true );
171
172   // Transparency
173   void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,
174                        float trans);
175   float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
176
177   // Color
178   void SetColor(const Handle(SALOME_InteractiveObject)& IObject,
179                 QColor thecolor);
180   QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
181
182   void Update();
183
184   vtkRenderer* GetRenderer();
185
186   void setGUIWindow(QWidget* theWindow);
187
188   void setViewWindow(SVTK_ViewWindow* theViewWindow);
189   
190   void setCellData(const int& theIndex, 
191                    SALOME_Actor* theMapActor,
192                    SVTK_Actor* theActor);
193   void setEdgeData(const int& theCellIndex, 
194                    SALOME_Actor* theMapActor,
195                    const int& theEdgeIndex, 
196                    SVTK_Actor* theActor ); //NB
197   void setPointData(const int& theIndex, 
198                     SALOME_Actor* theMapActor,
199                     SVTK_Actor* theActor);
200
201   typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
202                                SALOME_Actor* theMapActor, 
203                                SVTK_Actor* theActor);
204  protected:
205
206   SVTK_RenderWindowInteractor();
207   ~SVTK_RenderWindowInteractor();
208
209   SVTK_InteractorStyle* myInteractorStyle;
210
211   bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex, 
212                  SALOME_Actor* theMapActor, 
213                  SVTK_Actor* theActor,
214                  TUpdateActor theFun, 
215                  bool hilight, 
216                  bool update);
217   void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
218                     SALOME_Actor* theMapActor,
219                     SVTK_Actor *theActor,
220                     TUpdateActor theFun);
221   
222   // Timer used during various mouse events to figure 
223   // out mouse movements. 
224   QTimer *mTimer ;
225
226   int myDisplayMode;
227
228   //NRI: Selection mode
229   SVTK_Actor* myPointActor;
230   SVTK_Actor* myEdgeActor;
231   SVTK_Actor* myCellActor;
232   void MoveInternalActors();
233
234   vtkPicker* myBasicPicker;
235   vtkCellPicker* myCellPicker;
236   vtkPointPicker* myPointPicker;
237   
238   // User for switching to stereo mode.
239   int PositionBeforeStereo[2];
240
241  public slots:
242   void MouseMove(const QMouseEvent *event) ;
243   void LeftButtonPressed(const QMouseEvent *event) ;
244   void LeftButtonReleased(const QMouseEvent *event) ;
245   void MiddleButtonPressed(const QMouseEvent *event) ;
246   void MiddleButtonReleased(const QMouseEvent *event) ;
247   void RightButtonPressed(const QMouseEvent *event) ;
248   void RightButtonReleased(const QMouseEvent *event) ;
249   void ButtonPressed(const QMouseEvent *event) ;
250   void ButtonReleased(const QMouseEvent *event) ;
251   void KeyPressed(QKeyEvent *event) ;
252
253  private slots:
254   // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
255   // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
256   // we have to include all of these for the time being. Once,
257   // this bug in MOC is fixed, we can separate these. 
258   void TimerFunc() ;
259
260  signals:
261   void RenderWindowModified() ;
262   void contextMenuRequested( QContextMenuEvent *e );
263
264  private:
265   SVTK_ViewWindow* myViewWindow;  
266   QWidget* myGUIWindow;  
267   double myTolNodes;
268   double myTolItems;
269 };
270
271
272 #endif