1 // Copyright (C) 2007-2008 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
22 #ifndef VTKVIEWER_RENDERWINDOWINTERACTOR_H
23 #define VTKVIEWER_RENDERWINDOWINTERACTOR_H
25 #include "VTKViewer.h"
26 #include "VTKViewer_Actor.h"
33 class QContextMenuEvent;
35 // Open CASCADE Includes
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
38 #include <TColStd_IndexedMapOfInteger.hxx>
43 class vtkActorCollection;
45 class VTKViewer_Actor;
46 class VTKViewer_ViewWindow;
47 class VTKViewer_RenderWindow;
48 class VTKViewer_InteractorStyle;
50 #include "VTKViewer_Algorithm.h"
53 #include <vtkVersion.h>
54 #include <vtkRenderWindowInteractor.h>
56 class VTKVIEWER_EXPORT VTKViewer_RenderWindowInteractor : public QObject, public vtkRenderWindowInteractor
61 static VTKViewer_RenderWindowInteractor *New();
63 vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
65 void PrintSelf(ostream& os, vtkIndent indent);
67 virtual void Initialize();
69 virtual void SetInteractorStyle(vtkInteractorObserver *);
70 /*!Return interactor style pointer.*/
71 VTKViewer_InteractorStyle* GetInteractorStyle() const
73 return myInteractorStyle;
78 virtual void Enable();
79 virtual void Disable();
81 virtual void UpdateSize(int x,int y);
83 /** @name Timer options*/
85 virtual int CreateTimer(int ) ;
86 virtual int DestroyTimer() ;
90 * This function is called on 'q','e' keypress if exitmethod is not\n
91 * specified and should be overidden by platform dependent subclasses\n
92 * to provide a termination procedure if one is required.
94 virtual void TerminateApp(void) { /* empty */ }
97 // These methods correspond to the the Exit, User and Pick
98 // callbacks. They allow for the Style to invoke them.
99 //virtual void ExitCallback();
100 //virtual void UserCallback();
101 //virtual void StartPickCallback();
102 //virtual void EndPickCallback();
104 /** @name Selection Management */
106 bool highlightCell(const TColStd_IndexedMapOfInteger& MapIndex,
107 VTKViewer_Actor* theMapActor,
109 bool update = true );
110 bool highlightEdge(const TColStd_IndexedMapOfInteger& MapIndex,
111 VTKViewer_Actor* theMapActor,
113 bool update = true );
114 bool highlightPoint(const TColStd_IndexedMapOfInteger& MapIndex,
115 VTKViewer_Actor* theMapActor,
117 bool update = true );
119 void unHighlightSubSelection();
120 bool unHighlightAll();
122 //void SetSelectionMode(Selection_Mode mode);
123 void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1,
124 const double& theBlue = 0, const int& theWidth = 5);
125 void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001);
128 /** @name Displaymode management*/
130 int GetDisplayMode();
131 void SetDisplayMode(int);
134 /** @name Change all actors to wireframe or surface*/
136 void ChangeRepresentationToWireframe();
137 void ChangeRepresentationToSurface();
140 /** @name Change to wireframe or surface a list of vtkactor*/
142 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
143 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
146 /** @name Erase Display functions*/
150 void RemoveAll( const bool immediatly );
152 void Display( VTKViewer_Actor* SActor, bool immediatly = true );
153 void Erase( VTKViewer_Actor* SActor, bool immediatly = true );
154 void Remove( VTKViewer_Actor* SActor, bool updateViewer = true );
159 vtkRenderer* GetRenderer();
161 void setViewWindow( VTKViewer_ViewWindow* theViewWnd );
163 void setCellData(const int& theIndex,
164 VTKViewer_Actor* theMapActor,
165 VTKViewer_Actor* theActor) {}
166 void setEdgeData(const int& theCellIndex,
167 VTKViewer_Actor* theMapActor,
168 const int& theEdgeIndex,
169 VTKViewer_Actor* theActor ) {} //NB
170 void setPointData(const int& theIndex,
171 VTKViewer_Actor* theMapActor,
172 VTKViewer_Actor* theActor) {}
174 typedef void (*TUpdateActor)(const TColStd_IndexedMapOfInteger& theMapIndex,
175 VTKViewer_Actor* theMapActor,
176 VTKViewer_Actor* theActor);
179 VTKViewer_RenderWindowInteractor();
180 ~VTKViewer_RenderWindowInteractor();
182 VTKViewer_InteractorStyle* myInteractorStyle;
184 bool highlight(const TColStd_IndexedMapOfInteger& theMapIndex,
185 VTKViewer_Actor* theMapActor, VTKViewer_Actor* theActor,
186 TUpdateActor theFun, bool hilight, bool update);
187 void setActorData(const TColStd_IndexedMapOfInteger& theMapIndex,
188 VTKViewer_Actor* theMapActor,
189 VTKViewer_Actor *theActor,
190 TUpdateActor theFun);
192 /*! Timer used during various mouse events to figure
193 * out mouse movements.
199 //NRI: Selection mode
200 VTKViewer_Actor* myPointActor;
201 VTKViewer_Actor* myEdgeActor;
202 VTKViewer_Actor* myCellActor;
203 void MoveInternalActors();
205 vtkPicker* myBasicPicker;
206 vtkCellPicker* myCellPicker;
207 vtkPointPicker* myPointPicker;
209 /*! User for switching to stereo mode.*/
210 int PositionBeforeStereo[2];
213 void MouseMove(QMouseEvent *event) ;
214 void LeftButtonPressed(const QMouseEvent *event) ;
215 void LeftButtonReleased(const QMouseEvent *event) ;
216 void MiddleButtonPressed(const QMouseEvent *event) ;
217 void MiddleButtonReleased(const QMouseEvent *event) ;
218 void RightButtonPressed(const QMouseEvent *event) ;
219 void RightButtonReleased(const QMouseEvent *event) ;
220 void ButtonPressed(const QMouseEvent *event) ;
221 void ButtonReleased(const QMouseEvent *event) ;
222 void KeyPressed(QKeyEvent *event) ;
228 void RenderWindowModified() ;
229 void contextMenuRequested( QContextMenuEvent *e );
232 friend class VTKViewer_ViewWindow;
234 VTKViewer_ViewWindow* myViewWnd;
235 /** Selection node tolerance.*/
237 /** Selection cell tolerance.*/