Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[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_Actor.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 VTKViewer_RenderWindow;
51 class vtkPolyData;
52 class vtkPolyDataMapper;
53
54 // ------------------------------------------------------------
55 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
56 // The Signal/Slot mechanism used by Qt requires that QObject 
57 // appear as the first class when using multiple inheritance. 
58 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
59 // matters here. Be careful not to change it by accident. 
60 // ------------------------------------------------------------
61 class VTK_EXPORT VTKViewer_RenderWindowInteractor : 
62   public QObject, public vtkRenderWindowInteractor
63 {
64   Q_OBJECT 
65 public:
66
67   static VTKViewer_RenderWindowInteractor *New() ; 
68
69   vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
70
71   void PrintSelf(ostream& os, vtkIndent indent);
72
73   // Description:
74   // Initializes the event handlers without an XtAppContext.  This is
75   // good for when you don`t have a user interface, but you still
76   // want to have mouse interaction.
77   virtual void Initialize();
78
79   // Description:
80   // This will start up the X event loop and never return. If you
81   // call this method it will loop processing X events until the
82   // application is exited.
83   virtual void Start();
84   
85   // Description:
86   // Enable/Disable interactions.  By default interactors are enabled when
87   // initialized.  Initialize() must be called prior to enabling/disabling
88   // interaction. These methods are used when a window/widget is being
89   // shared by multiple renderers and interactors.  This allows a "modal"
90   // display where one interactor is active when its data is to be displayed
91   // and all other interactors associated with the widget are disabled
92   // when their data is not displayed.
93   virtual void Enable();
94   virtual void Disable();
95
96   // Description:
97   // Event loop notification member for Window size change
98   virtual void UpdateSize(int x,int y);
99
100   // Description:
101   // Timer methods must be overridden by platform dependent subclasses.
102   // flag is passed to indicate if this is first timer set or an update
103   // as Win32 uses repeating timers, whereas X uses One shot more timer
104   // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
105   // otherwise Win32 should exit and X should perform AddTimeOut()
106   virtual int CreateTimer(int ) ; 
107   virtual int DestroyTimer() ; 
108   
109   // Description:
110   // This function is called on 'q','e' keypress if exitmethod is not
111   // specified and should be overidden by platform dependent subclasses
112   // to provide a termination procedure if one is required.
113   virtual void TerminateApp(void) { /* empty */ }
114   
115   // Description:
116   // These methods correspond to the the Exit, User and Pick
117   // callbacks. They allow for the Style to invoke them.
118   //virtual void ExitCallback();
119   //virtual void UserCallback();
120   //virtual void StartPickCallback();
121   //virtual void EndPickCallback();
122   
123   /* Selection Management */
124   bool highlightCell(const Handle(SALOME_InteractiveObject)& IObject, bool hilight, 
125                      const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
126   bool highlightEdge(const Handle(SALOME_InteractiveObject)& IObject, bool hilight, 
127                      const TColStd_MapOfInteger& MapIndex, bool immediatly = true ); //NB
128   bool highlightPoint(const Handle(SALOME_InteractiveObject)& IObject, bool hilight, 
129                       const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
130
131   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, bool hiligth, bool immediatly = true );
132   bool unHighlightAll();
133   bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
134   bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
135   void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
136
137
138   void SetSelectionMode(int mode);
139
140   // Displaymode management
141   int GetDisplayMode();
142   void SetDisplayMode(int);
143
144   // Switch representation wireframe/shading
145   void SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject, bool update = true);
146
147   // Change all actors to wireframe or surface
148   void ChangeRepresentationToWireframe();
149   void ChangeRepresentationToSurface();
150
151   // Change to wireframe or surface a list of vtkactor
152   void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
153   void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
154
155   // Erase Display functions
156   void EraseAll();
157   void DisplayAll();
158   void Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
159   void Remove(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
160   void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
161
162   void Display( SALOME_Actor* SActor, bool immediatly = true );
163
164   // Transparency
165   void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
166   float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
167
168   // Color
169   void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
170   QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
171
172   void Update();
173
174   vtkRenderer* GetRenderer();
175
176   QWidget* getGUIWindow() {return myGUIWindow;}
177   void setGUIWindow(QWidget* theWin) { myGUIWindow = theWin;}
178
179   typedef void (*TCreateMapperFun)(vtkPolyData *theSourcePolyData, 
180                                            vtkPolyDataMapper* theMapper, 
181                                            const TColStd_MapOfInteger& theMapIndex);
182  protected:
183
184   VTKViewer_RenderWindowInteractor();
185   ~VTKViewer_RenderWindowInteractor();
186
187   bool highlight(const Handle(SALOME_InteractiveObject)& IObject, 
188                  const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
189                  vtkActor *theActor, bool hilight, bool update );
190   //
191   // Timer used during various mouse events to figure 
192   // out mouse movements. 
193   //
194   QTimer *mTimer ;
195
196   //CAI: Display mode
197   int displaymode;
198
199   //NRI: Selection mode
200   int selectionmode;
201   vtkActor* Point_Actor;
202   vtkActor* Edge_Actor; //NB
203   vtkActor* Cell_Actor;
204   
205   //
206   // User for switching to stereo mode.
207   //
208   int PositionBeforeStereo[2];
209   //
210   // Connect/disconnect all slots which allow events on the
211   // render window to be passed to the interactor. 
212   //
213   void ConnectSlots() ;
214   void DisconnectSlots() ;
215   void ProcessSlotConnections(bool conn) ;
216
217  public slots:
218   void MouseMove(const QMouseEvent *event) ;
219   void LeftButtonPressed(const QMouseEvent *event) ;
220   void LeftButtonReleased(const QMouseEvent *event) ;
221   void MiddleButtonPressed(const QMouseEvent *event) ;
222   void MiddleButtonReleased(const QMouseEvent *event) ;
223   void RightButtonPressed(const QMouseEvent *event) ;
224   void RightButtonReleased(const QMouseEvent *event) ;
225   void ButtonPressed(const QMouseEvent *event) ;
226   void ButtonReleased(const QMouseEvent *event) ;
227   void KeyPressed(QKeyEvent *event) ;
228
229   private slots:
230     //
231     // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
232     // but moc does not understand "#if VTK_MAJOR_VERSION". Hence, 
233     // we have to include all of these for the time being. Once,
234     // this bug in MOC is fixed, we can separate these. 
235     //
236     void TimerFunc() ;
237  signals:
238   void RenderWindowModified() ;
239
240  private:
241   QWidget*     myGUIWindow;  
242 };
243
244 #endif
245