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