]> SALOME platform Git repositories - modules/kernel.git/blob - src/VTKViewer/VTKViewer_RenderWindowInteractor.h
Salome HOME
PR: mergefrom_PAL_OCC_21Oct04
[modules/kernel.git] / src / VTKViewer / VTKViewer_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   : VTKViewer_RenderWindowInteractor.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef VTKViewer_RenderWindowInteractor_h
30 #define VTKViewer_RenderWindowInteractor_h
31
32 //===========================================================
33 // now we define the C++ class
34
35 #include "SALOME_InteractiveObject.hxx"
36 #include "SALOME_Selection.h"
37
38 // QT Includes
39 #include <qobject.h>
40 #include <qtimer.h>
41
42 // VTK Includes
43 #include <vtkVersion.h>
44 #include <vtkRenderWindowInteractor.h>
45
46 // Open CASCADE Includes
47 #include <TColStd_MapOfInteger.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 VTKViewer_Actor;
57 class VTKViewer_ViewFrame;
58 class VTKViewer_RenderWindow;
59 class VTKViewer_InteractorStyleSALOME;
60
61 // ------------------------------------------------------------
62 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
63 // The Signal/Slot mechanism used by Qt requires that QObject 
64 // appear as the first class when using multiple inheritance. 
65 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
66 // matters here. Be careful not to change it by accident. 
67 // ------------------------------------------------------------
68 class VTK_EXPORT VTKViewer_RenderWindowInteractor : 
69   public QObject, public vtkRenderWindowInteractor
70 {
71   Q_OBJECT ;
72   friend class VTKViewer_ViewFrame;
73 public:
74
75   static VTKViewer_RenderWindowInteractor *New() ; 
76
77   vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
78
79   void PrintSelf(ostream& os, vtkIndent indent);
80
81   // Description:
82   // Initializes the event handlers without an XtAppContext.  This is
83   // good for when you don`t have a user interface, but you still
84   // want to have mouse interaction.
85   virtual void Initialize();
86
87   virtual void SetInteractorStyle(vtkInteractorObserver *);
88   VTKViewer_InteractorStyleSALOME* GetInteractorStyleSALOME(){
89     return myInteractorStyle;
90   }
91
92   // Description:
93   // This will start up the X event loop and never return. If you
94   // call this method it will loop processing X events until the
95   // application is exited.
96   virtual void Start();
97   
98   // Description:
99   // Enable/Disable interactions.  By default interactors are enabled when
100   // initialized.  Initialize() must be called prior to enabling/disabling
101   // interaction. These methods are used when a window/widget is being
102   // shared by multiple renderers and interactors.  This allows a "modal"
103   // display where one interactor is active when its data is to be displayed
104   // and all other interactors associated with the widget are disabled
105   // when their data is not displayed.
106   virtual void Enable();
107   virtual void Disable();
108
109   // Description:
110   // Event loop notification member for Window size change
111   virtual void UpdateSize(int x,int y);
112
113   // Description:
114   // Timer methods must be overridden by platform dependent subclasses.
115   // flag is passed to indicate if this is first timer set or an update
116   // as Win32 uses repeating timers, whereas X uses One shot more timer
117   // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
118   // otherwise Win32 should exit and X should perform AddTimeOut()
119   virtual int CreateTimer(int ) ; 
120   virtual int DestroyTimer() ; 
121   
122   // Description:
123   // This function is called on 'q','e' keypress if exitmethod is not
124   // specified and should be overidden by platform dependent subclasses
125   // to provide a termination procedure if one is required.
126   virtual void TerminateApp(void) { /* empty */ }
127   
128   // Description:
129   // These methods correspond to the the Exit, User and Pick
130   // callbacks. They allow for the Style to invoke them.
131   //virtual void ExitCallback();
132   //virtual void UserCallback();
133   //virtual void StartPickCallback();
134   //virtual void EndPickCallback();
135   
136   /* Selection Management */
137   bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex, 
138                      SALOME_Actor* theMapActor, 
139                      bool hilight, 
140                      bool update = true );
141   bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex, 
142                      SALOME_Actor* theMapActor, 
143                      bool hilight, 
144                      bool update = true );
145   bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex, 
146                       SALOME_Actor* theMapActor, 
147                       bool hilight, 
148                       bool update = true );
149
150   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, bool hiligth, bool immediatly = true );
151   void unHighlightSubSelection();
152   bool unHighlightAll();
153
154   bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
155   bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
156   void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
157
158   void SetSelectionMode(Selection_Mode mode);
159   void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
160                         const double& theBlue = 0, const int& theWidth = 5);
161   void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
162
163   // Displaymode management
164   int GetDisplayMode();
165   void SetDisplayMode(int);
166
167   // Switch representation wireframe/shading
168   void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode);
169
170   // Change all actors to wireframe or surface
171   void ChangeRepresentationToWireframe();
172   void ChangeRepresentationToSurface();
173
174   // Change to wireframe or surface a list of vtkactor
175   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
176   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
177
178   // Erase Display functions
179   void EraseAll();
180   void DisplayAll();
181   void Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
182   void Remove(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
183   void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
184
185   void Display( SALOME_Actor* SActor, bool immediatly = true );
186   void Erase( SALOME_Actor* SActor, bool immediatly = true );
187
188   // Transparency
189   void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
190   float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
191
192   // Color
193   void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
194   QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
195
196   void Update();
197
198   vtkRenderer* GetRenderer();
199
200   void setGUIWindow(QWidget* theWindow);
201
202   void setViewFrame(VTKViewer_ViewFrame* ViewFrame);
203   
204   void setCellData(const int& theIndex, 
205                    SALOME_Actor* theMapActor,
206                    VTKViewer_Actor* theActor);
207   void setEdgeData(const int& theCellIndex, 
208                    SALOME_Actor* theMapActor,
209                    const int& theEdgeIndex, 
210                    VTKViewer_Actor* theActor ); //NB
211   void setPointData(const int& theIndex, 
212                     SALOME_Actor* theMapActor,
213                     VTKViewer_Actor* theActor);
214
215   typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
216                                SALOME_Actor* theMapActor, 
217                                VTKViewer_Actor* theActor);
218  protected:
219
220   VTKViewer_RenderWindowInteractor();
221   ~VTKViewer_RenderWindowInteractor();
222
223   VTKViewer_InteractorStyleSALOME* myInteractorStyle;
224
225   bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex, 
226                  SALOME_Actor* theMapActor, VTKViewer_Actor* theActor,
227                  TUpdateActor theFun, bool hilight, bool update);
228   void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
229                     SALOME_Actor* theMapActor,
230                     VTKViewer_Actor *theActor,
231                     TUpdateActor theFun);
232   
233   // Timer used during various mouse events to figure 
234   // out mouse movements. 
235   QTimer *mTimer ;
236
237   int myDisplayMode;
238
239   //NRI: Selection mode
240   VTKViewer_Actor* myPointActor;
241   VTKViewer_Actor* myEdgeActor;
242   VTKViewer_Actor* myCellActor;
243   void MoveInternalActors();
244
245   vtkPicker* myBasicPicker;
246   vtkCellPicker* myCellPicker;
247   vtkPointPicker* myPointPicker;
248   
249   // User for switching to stereo mode.
250   int PositionBeforeStereo[2];
251
252   // Connect/disconnect all slots which allow events on the
253   // render window to be passed to the interactor. 
254   void ConnectSlots() ;
255   void DisconnectSlots() ;
256   void ProcessSlotConnections(bool conn) ;
257
258  public slots:
259   void MouseMove(const QMouseEvent *event) ;
260   void LeftButtonPressed(const QMouseEvent *event) ;
261   void LeftButtonReleased(const QMouseEvent *event) ;
262   void MiddleButtonPressed(const QMouseEvent *event) ;
263   void MiddleButtonReleased(const QMouseEvent *event) ;
264   void RightButtonPressed(const QMouseEvent *event) ;
265   void RightButtonReleased(const QMouseEvent *event) ;
266   void ButtonPressed(const QMouseEvent *event) ;
267   void ButtonReleased(const QMouseEvent *event) ;
268   void KeyPressed(QKeyEvent *event) ;
269
270   private slots:
271     // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
272     // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
273     // we have to include all of these for the time being. Once,
274     // this bug in MOC is fixed, we can separate these. 
275     void TimerFunc() ;
276
277  signals:
278   void RenderWindowModified() ;
279
280  private:
281   VTKViewer_ViewFrame* myViewFrame;  
282   QWidget* myGUIWindow;  
283   double myTolNodes;
284   double myTolItems;
285 };
286
287 #endif
288
289