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>
50 class VTKViewer_RenderWindow;
52 class vtkPolyDataMapper;
54 // ------------------------------------------------------------
55 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
56 // The Signal/Slot mechanism used by Qt requires that QObject
57 // appear as the first class when using multiple inheritance.
58 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
59 // matters here. Be careful not to change it by accident.
60 // ------------------------------------------------------------
61 class VTK_EXPORT VTKViewer_RenderWindowInteractor :
62 public QObject, public vtkRenderWindowInteractor
67 static VTKViewer_RenderWindowInteractor *New() ;
69 vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
71 void PrintSelf(ostream& os, vtkIndent indent);
74 // Initializes the event handlers without an XtAppContext. This is
75 // good for when you don`t have a user interface, but you still
76 // want to have mouse interaction.
77 virtual void Initialize();
80 // This will start up the X event loop and never return. If you
81 // call this method it will loop processing X events until the
82 // application is exited.
86 // Enable/Disable interactions. By default interactors are enabled when
87 // initialized. Initialize() must be called prior to enabling/disabling
88 // interaction. These methods are used when a window/widget is being
89 // shared by multiple renderers and interactors. This allows a "modal"
90 // display where one interactor is active when its data is to be displayed
91 // and all other interactors associated with the widget are disabled
92 // when their data is not displayed.
93 virtual void Enable();
94 virtual void Disable();
97 // Event loop notification member for Window size change
98 virtual void UpdateSize(int x,int y);
101 // Timer methods must be overridden by platform dependent subclasses.
102 // flag is passed to indicate if this is first timer set or an update
103 // as Win32 uses repeating timers, whereas X uses One shot more timer
104 // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
105 // otherwise Win32 should exit and X should perform AddTimeOut()
106 virtual int CreateTimer(int ) ;
107 virtual int DestroyTimer() ;
110 // This function is called on 'q','e' keypress if exitmethod is not
111 // specified and should be overidden by platform dependent subclasses
112 // to provide a termination procedure if one is required.
113 virtual void TerminateApp(void) { /* empty */ }
116 // These methods correspond to the the Exit, User and Pick
117 // callbacks. They allow for the Style to invoke them.
118 //virtual void ExitCallback();
119 //virtual void UserCallback();
120 //virtual void StartPickCallback();
121 //virtual void EndPickCallback();
123 /* Selection Management */
124 bool highlightCell(const Handle(SALOME_InteractiveObject)& IObject, bool hilight,
125 const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
126 bool highlightEdge(const Handle(SALOME_InteractiveObject)& IObject, bool hilight,
127 const TColStd_MapOfInteger& MapIndex, bool immediatly = true ); //NB
128 bool highlightPoint(const Handle(SALOME_InteractiveObject)& IObject, bool hilight,
129 const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
131 bool highlight(const Handle(SALOME_InteractiveObject)& IObject, bool hiligth, bool immediatly = true );
132 bool unHighlightAll();
133 bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
134 bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
135 void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
138 void SetSelectionMode(int mode);
140 // Displaymode management
141 int GetDisplayMode();
142 void SetDisplayMode(int);
144 // Switch representation wireframe/shading
145 void SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject, bool update = true);
147 // Change all actors to wireframe or surface
148 void ChangeRepresentationToWireframe();
149 void ChangeRepresentationToSurface();
151 // Change to wireframe or surface a list of vtkactor
152 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
153 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
155 // Erase Display functions
158 void Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
159 void Remove(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
160 void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
162 void Display( SALOME_Actor* SActor, bool immediatly = true );
165 void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
166 float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
169 void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
170 QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
174 vtkRenderer* GetRenderer();
176 QWidget* getGUIWindow() {return myGUIWindow;}
177 void setGUIWindow(QWidget* theWin) { myGUIWindow = theWin;}
179 typedef void (*TCreateMapperFun)(vtkPolyData *theSourcePolyData,
180 vtkPolyDataMapper* theMapper,
181 const TColStd_MapOfInteger& theMapIndex);
184 VTKViewer_RenderWindowInteractor();
185 ~VTKViewer_RenderWindowInteractor();
187 bool highlight(const Handle(SALOME_InteractiveObject)& IObject,
188 const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
189 vtkActor *theActor, bool hilight, bool update );
191 // Timer used during various mouse events to figure
192 // out mouse movements.
199 //NRI: Selection mode
201 vtkActor* Point_Actor;
202 vtkActor* Edge_Actor; //NB
203 vtkActor* Cell_Actor;
206 // User for switching to stereo mode.
208 int PositionBeforeStereo[2];
210 // Connect/disconnect all slots which allow events on the
211 // render window to be passed to the interactor.
213 void ConnectSlots() ;
214 void DisconnectSlots() ;
215 void ProcessSlotConnections(bool conn) ;
218 void MouseMove(const QMouseEvent *event) ;
219 void LeftButtonPressed(const QMouseEvent *event) ;
220 void LeftButtonReleased(const QMouseEvent *event) ;
221 void MiddleButtonPressed(const QMouseEvent *event) ;
222 void MiddleButtonReleased(const QMouseEvent *event) ;
223 void RightButtonPressed(const QMouseEvent *event) ;
224 void RightButtonReleased(const QMouseEvent *event) ;
225 void ButtonPressed(const QMouseEvent *event) ;
226 void ButtonReleased(const QMouseEvent *event) ;
227 void KeyPressed(QKeyEvent *event) ;
231 // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
232 // but moc does not understand "#if VTK_MAJOR_VERSION". Hence,
233 // we have to include all of these for the time being. Once,
234 // this bug in MOC is fixed, we can separate these.
238 void RenderWindowModified() ;
241 QWidget* myGUIWindow;