1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SVTK_RenderWindowInteractor.h
25 // Author : Nicolas REJNERI
29 #ifndef SVTK_RenderWindowInteractor_h
30 #define SVTK_RenderWindowInteractor_h
34 #include "SVTK_Selection.h"
35 #include "SALOME_InteractiveObject.hxx"
42 #include <vtkVersion.h>
43 #include <vtkRenderWindowInteractor.h>
45 // Open CASCADE Includes
46 #include <TColStd_MapOfInteger.hxx>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
53 class vtkActorCollection;
58 class SVTK_ViewWindow;
59 class SVTK_RenderWindow;
60 class SVTK_InteractorStyle;
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
73 friend class SVTK_ViewWindow;
76 static SVTK_RenderWindowInteractor *New() ;
78 vtkTypeMacro(SVTK_RenderWindowInteractor,vtkRenderWindowInteractor);
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();
86 virtual void SetInteractorStyle(vtkInteractorObserver *);
87 SVTK_InteractorStyle* GetSInteractorStyle(){ return myInteractorStyle;}
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.
96 // Event loop notification member for Window size change
97 virtual void UpdateSize(int x,int y);
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() ;
108 /* Selection Management */
109 bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
110 SALOME_Actor* theMapActor,
112 bool update = true );
113 bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
114 SALOME_Actor* theMapActor,
116 bool update = true );
117 bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
118 SALOME_Actor* theMapActor,
120 bool update = true );
121 bool highlight(const Handle(SALOME_InteractiveObject)& IObject,
123 bool immediatly = true );
124 void unHighlightSubSelection();
125 bool unHighlightAll();
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);
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);
139 // Displaymode management
140 int GetDisplayMode();
141 void SetDisplayMode(int);
143 // Switch representation wireframe/shading
144 void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode);
146 // Change all actors to wireframe or surface
147 void ChangeRepresentationToWireframe();
148 void ChangeRepresentationToSurface();
150 // Change to wireframe or surface a list of vtkactor
151 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
152 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
154 // Erase Display functions
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);
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 );
173 void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,
175 float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
178 void SetColor(const Handle(SALOME_InteractiveObject)& IObject,
180 QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
184 vtkRenderer* GetRenderer();
186 void setGUIWindow(QWidget* theWindow);
188 void setViewWindow(SVTK_ViewWindow* theViewWindow);
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);
201 typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
202 SALOME_Actor* theMapActor,
203 SVTK_Actor* theActor);
206 SVTK_RenderWindowInteractor();
207 ~SVTK_RenderWindowInteractor();
209 SVTK_InteractorStyle* myInteractorStyle;
211 bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
212 SALOME_Actor* theMapActor,
213 SVTK_Actor* theActor,
217 void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
218 SALOME_Actor* theMapActor,
219 SVTK_Actor *theActor,
220 TUpdateActor theFun);
222 // Timer used during various mouse events to figure
223 // out mouse movements.
228 //NRI: Selection mode
229 SVTK_Actor* myPointActor;
230 SVTK_Actor* myEdgeActor;
231 SVTK_Actor* myCellActor;
232 void MoveInternalActors();
234 vtkPicker* myBasicPicker;
235 vtkCellPicker* myCellPicker;
236 vtkPointPicker* myPointPicker;
238 // User for switching to stereo mode.
239 int PositionBeforeStereo[2];
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) ;
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.
261 void RenderWindowModified() ;
262 void contextMenuRequested( QContextMenuEvent *e );
265 SVTK_ViewWindow* myViewWindow;
266 QWidget* myGUIWindow;