1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H
24 #define VTKVIEWER_RENDERWINDOWINTERACTOR_H
26 #include "VTKViewer.h"
27 #include "VTKViewer_Actor.h"
34 class QContextMenuEvent;
36 // Open CASCADE Includes
37 #include <TColStd_MapOfInteger.hxx>
38 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
44 class vtkActorCollection;
46 class VTKViewer_Actor;
47 class VTKViewer_ViewWindow;
48 class VTKViewer_RenderWindow;
49 class VTKViewer_InteractorStyle;
51 #include "VTKViewer_Algorithm.h"
54 #include <vtkVersion.h>
55 #include <vtkRenderWindowInteractor.h>
57 class VTKVIEWER_EXPORT VTKViewer_RenderWindowInteractor : public QObject, public vtkRenderWindowInteractor
62 static VTKViewer_RenderWindowInteractor *New();
64 vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
66 void PrintSelf(ostream& os, vtkIndent indent);
68 virtual void Initialize();
70 virtual void SetInteractorStyle(vtkInteractorObserver *);
71 /*!Return interactor style pointer.*/
72 VTKViewer_InteractorStyle* GetInteractorStyle() const
74 return myInteractorStyle;
79 virtual void Enable();
80 virtual void Disable();
82 virtual void UpdateSize(int x,int y);
84 /** @name Timer options*/
86 virtual int CreateTimer(int ) ;
87 virtual int DestroyTimer() ;
91 * This function is called on 'q','e' keypress if exitmethod is not\n
92 * specified and should be overidden by platform dependent subclasses\n
93 * to provide a termination procedure if one is required.
95 virtual void TerminateApp(void) { /* empty */ }
98 // These methods correspond to the the Exit, User and Pick
99 // callbacks. They allow for the Style to invoke them.
100 //virtual void ExitCallback();
101 //virtual void UserCallback();
102 //virtual void StartPickCallback();
103 //virtual void EndPickCallback();
105 /** @name Selection Management */
107 bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
108 VTKViewer_Actor* theMapActor,
110 bool update = true );
111 bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
112 VTKViewer_Actor* theMapActor,
114 bool update = true );
115 bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
116 VTKViewer_Actor* theMapActor,
118 bool update = true );
120 void unHighlightSubSelection();
121 bool unHighlightAll();
123 //void SetSelectionMode(Selection_Mode mode);
124 void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
125 const double& theBlue = 0, const int& theWidth = 5);
126 void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
129 /** @name Displaymode management*/
131 int GetDisplayMode();
132 void SetDisplayMode(int);
135 /** @name Change all actors to wireframe or surface*/
137 void ChangeRepresentationToWireframe();
138 void ChangeRepresentationToSurface();
139 void ChangeRepresentationToSurfaceWithEdges();
142 /** @name Change to wireframe or surface a list of vtkactor*/
144 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
145 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
146 void ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* ListofActors);
149 /** @name Erase Display functions*/
153 void RemoveAll( const bool immediatly );
155 void Display( VTKViewer_Actor* SActor, bool immediatly = true );
156 void Erase( VTKViewer_Actor* SActor, bool immediatly = true );
157 void Remove( VTKViewer_Actor* SActor, bool updateViewer = true );
162 vtkRenderer* GetRenderer();
164 void setViewWindow( VTKViewer_ViewWindow* theViewWnd );
166 void setCellData(const int& theIndex,
167 VTKViewer_Actor* theMapActor,
168 VTKViewer_Actor* theActor) {}
169 void setEdgeData(const int& theCellIndex,
170 VTKViewer_Actor* theMapActor,
171 const int& theEdgeIndex,
172 VTKViewer_Actor* theActor ) {} //NB
173 void setPointData(const int& theIndex,
174 VTKViewer_Actor* theMapActor,
175 VTKViewer_Actor* theActor) {}
177 typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
178 VTKViewer_Actor* theMapActor,
179 VTKViewer_Actor* theActor);
182 VTKViewer_RenderWindowInteractor();
183 ~VTKViewer_RenderWindowInteractor();
185 VTKViewer_InteractorStyle* myInteractorStyle;
187 bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
188 VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
189 TUpdateActor theFun, bool hilight, bool update);
190 void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
191 VTKViewer_Actor* theMapActor,
192 VTKViewer_Actor *theActor,
193 TUpdateActor theFun);
195 /*! Timer used during various mouse events to figure
196 * out mouse movements.
202 //NRI: Selection mode
203 VTKViewer_Actor* myPointActor;
204 VTKViewer_Actor* myEdgeActor;
205 VTKViewer_Actor* myCellActor;
206 void MoveInternalActors();
208 vtkPicker* myBasicPicker;
209 vtkCellPicker* myCellPicker;
210 vtkPointPicker* myPointPicker;
212 /*! User for switching to stereo mode.*/
213 int PositionBeforeStereo[2];
216 void MouseMove(QMouseEvent *event) ;
217 void LeftButtonPressed(const QMouseEvent *event) ;
218 void LeftButtonReleased(const QMouseEvent *event) ;
219 void MiddleButtonPressed(const QMouseEvent *event) ;
220 void MiddleButtonReleased(const QMouseEvent *event) ;
221 void RightButtonPressed(const QMouseEvent *event) ;
222 void RightButtonReleased(const QMouseEvent *event) ;
223 void ButtonPressed(const QMouseEvent *event) ;
224 void ButtonReleased(const QMouseEvent *event) ;
225 void KeyPressed(QKeyEvent *event) ;
231 void RenderWindowModified() ;
232 void contextMenuRequested( QContextMenuEvent *e );
235 friend class VTKViewer_ViewWindow;
237 VTKViewer_ViewWindow* myViewWnd;
238 /** Selection node tolerance.*/
240 /** Selection cell tolerance.*/