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 : VTKViewer_RenderWindowInteractor.h
25 // Author : Nicolas REJNERI
29 #ifndef VTKViewer_RenderWindowInteractor_h
30 #define VTKViewer_RenderWindowInteractor_h
32 //===========================================================
33 // now we define the C++ class
35 #include "SALOME_InteractiveObject.hxx"
36 #include "SALOME_Selection.h"
43 #include <vtkVersion.h>
44 #include <vtkRenderWindowInteractor.h>
46 // Open CASCADE Includes
47 #include <TColStd_MapOfInteger.hxx>
48 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
53 class vtkActorCollection;
56 class VTKViewer_Actor;
57 class VTKViewer_ViewFrame;
58 class VTKViewer_RenderWindow;
59 class VTKViewer_InteractorStyleSALOME;
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
72 friend class VTKViewer_ViewFrame;
75 static VTKViewer_RenderWindowInteractor *New() ;
77 vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
79 void PrintSelf(ostream& os, vtkIndent indent);
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();
87 virtual void SetInteractorStyle(vtkInteractorObserver *);
88 VTKViewer_InteractorStyleSALOME* GetInteractorStyleSALOME(){
89 return myInteractorStyle;
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.
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();
110 // Event loop notification member for Window size change
111 virtual void UpdateSize(int x,int y);
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() ;
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 */ }
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();
136 /* Selection Management */
137 bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
138 SALOME_Actor* theMapActor,
140 bool update = true );
141 bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
142 SALOME_Actor* theMapActor,
144 bool update = true );
145 bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
146 SALOME_Actor* theMapActor,
148 bool update = true );
150 bool highlight(const Handle(SALOME_InteractiveObject)& IObject, bool hiligth, bool immediatly = true );
151 void unHighlightSubSelection();
152 bool unHighlightAll();
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);
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);
163 // Displaymode management
164 int GetDisplayMode();
165 void SetDisplayMode(int);
167 // Switch representation wireframe/shading
168 void SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, int theMode);
170 // Change all actors to wireframe or surface
171 void ChangeRepresentationToWireframe();
172 void ChangeRepresentationToSurface();
174 // Change to wireframe or surface a list of vtkactor
175 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
176 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
178 // Erase Display functions
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);
185 void Display( SALOME_Actor* SActor, bool immediatly = true );
186 void Erase( SALOME_Actor* SActor, bool immediatly = true );
189 void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
190 float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
193 void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
194 QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
198 vtkRenderer* GetRenderer();
200 void setGUIWindow(QWidget* theWindow);
202 void setViewFrame(VTKViewer_ViewFrame* ViewFrame);
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);
215 typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
216 SALOME_Actor* theMapActor,
217 VTKViewer_Actor* theActor);
220 VTKViewer_RenderWindowInteractor();
221 ~VTKViewer_RenderWindowInteractor();
223 VTKViewer_InteractorStyleSALOME* myInteractorStyle;
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);
233 // Timer used during various mouse events to figure
234 // out mouse movements.
239 //NRI: Selection mode
240 VTKViewer_Actor* myPointActor;
241 VTKViewer_Actor* myEdgeActor;
242 VTKViewer_Actor* myCellActor;
243 void MoveInternalActors();
245 vtkPicker* myBasicPicker;
246 vtkCellPicker* myCellPicker;
247 vtkPointPicker* myPointPicker;
249 // User for switching to stereo mode.
250 int PositionBeforeStereo[2];
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) ;
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) ;
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.
278 void RenderWindowModified() ;
281 VTKViewer_ViewFrame* myViewFrame;
282 QWidget* myGUIWindow;