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_Actor.h"
43 #include <vtkVersion.h>
44 #include <vtkRenderWindowInteractor.h>
46 // Open CASCADE Includes
47 #include <TColStd_MapOfInteger.hxx>
48 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
51 class vtkPolyDataMapper;
53 class VTKViewer_RenderWindow;
54 class VTKViewer_InteractorStyleSALOME;
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
69 static VTKViewer_RenderWindowInteractor *New() ;
71 vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
73 void PrintSelf(ostream& os, vtkIndent indent);
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();
81 virtual void SetInteractorStyle(vtkInteractorObserver *);
82 VTKViewer_InteractorStyleSALOME* GetInteractorStyleSALOME(){
83 return myInteractorStyle;
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.
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();
104 // Event loop notification member for Window size change
105 virtual void UpdateSize(int x,int y);
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() ;
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 */ }
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();
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 );
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);
145 void SetSelectionMode(int mode);
147 // Displaymode management
148 int GetDisplayMode();
149 void SetDisplayMode(int);
151 // Switch representation wireframe/shading
152 void SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject, bool update = true);
154 // Change all actors to wireframe or surface
155 void ChangeRepresentationToWireframe();
156 void ChangeRepresentationToSurface();
158 // Change to wireframe or surface a list of vtkactor
159 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
160 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
162 // Erase Display functions
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);
169 void Display( SALOME_Actor* SActor, bool immediatly = true );
172 void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
173 float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
176 void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
177 QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
181 vtkRenderer* GetRenderer();
183 QWidget* getGUIWindow() {return myGUIWindow;}
184 void setGUIWindow(QWidget* theWin) {myGUIWindow = theWin;}
186 typedef void (*TCreateMapperFun)(vtkPolyData *theSourcePolyData,
187 vtkPolyDataMapper* theMapper,
188 const TColStd_MapOfInteger& theMapIndex);
191 VTKViewer_RenderWindowInteractor();
192 ~VTKViewer_RenderWindowInteractor();
194 VTKViewer_InteractorStyleSALOME* myInteractorStyle;
196 bool highlight(const Handle(SALOME_InteractiveObject)& IObject,
197 const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
198 vtkActor *theActor, bool hilight, bool update );
200 // Timer used during various mouse events to figure
201 // out mouse movements.
207 //NRI: Selection mode
209 vtkActor* Point_Actor;
210 vtkActor* Edge_Actor; //NB
211 vtkActor* Cell_Actor;
213 // User for switching to stereo mode.
214 int PositionBeforeStereo[2];
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) ;
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) ;
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.
242 void RenderWindowModified() ;
245 QWidget* myGUIWindow;