1 // File : VTKViewer_RenderWindowInteractor.h
2 // Created : Wed Mar 20 11:31:36 2002
3 // Author : Nicolas REJNERI
6 // Copyright : Open CASCADE 2002
9 #ifndef VTKViewer_RenderWindowInteractor_h
10 #define VTKViewer_RenderWindowInteractor_h
12 //===========================================================
13 // now we define the C++ class
15 #include "SALOME_InteractiveObject.hxx"
16 #include "SALOME_Actor.h"
23 #include <vtkVersion.h>
24 #include <vtkRenderWindowInteractor.h>
25 #include <vtkUnstructuredGrid.h>
27 // Open CASCADE Includes
28 #include <TColStd_MapOfInteger.hxx>
29 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
31 class VTKViewer_RenderWindow ;
33 // ------------------------------------------------------------
34 // :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
35 // The Signal/Slot mechanism used by Qt requires that QObject
36 // appear as the first class when using multiple inheritance.
37 // Hence the order of the two classes QObject and vtkRenderWindowInteractor
38 // matters here. Be careful not to change it by accident.
39 // ------------------------------------------------------------
40 class VTK_EXPORT VTKViewer_RenderWindowInteractor :
41 public QObject, public vtkRenderWindowInteractor
46 static VTKViewer_RenderWindowInteractor *New() ;
48 vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
50 void PrintSelf(ostream& os, vtkIndent indent);
53 // Initializes the event handlers without an XtAppContext. This is
54 // good for when you don`t have a user interface, but you still
55 // want to have mouse interaction.
56 virtual void Initialize();
59 // This will start up the X event loop and never return. If you
60 // call this method it will loop processing X events until the
61 // application is exited.
65 // Enable/Disable interactions. By default interactors are enabled when
66 // initialized. Initialize() must be called prior to enabling/disabling
67 // interaction. These methods are used when a window/widget is being
68 // shared by multiple renderers and interactors. This allows a "modal"
69 // display where one interactor is active when its data is to be displayed
70 // and all other interactors associated with the widget are disabled
71 // when their data is not displayed.
72 virtual void Enable();
73 virtual void Disable();
76 // Event loop notification member for Window size change
77 virtual void UpdateSize(int x,int y);
80 // Timer methods must be overridden by platform dependent subclasses.
81 // flag is passed to indicate if this is first timer set or an update
82 // as Win32 uses repeating timers, whereas X uses One shot more timer
83 // if flag==VTKXI_TIMER_FIRST Win32 and X should createtimer
84 // otherwise Win32 should exit and X should perform AddTimeOut()
85 virtual int CreateTimer(int ) ;
86 virtual int DestroyTimer() ;
89 // This function is called on 'q','e' keypress if exitmethod is not
90 // specified and should be overidden by platform dependent subclasses
91 // to provide a termination procedure if one is required.
92 virtual void TerminateApp(void) { /* empty */ }
95 // These methods correspond to the the Exit, User and Pick
96 // callbacks. They allow for the Style to invoke them.
97 //virtual void ExitCallback();
98 //virtual void UserCallback();
99 //virtual void StartPickCallback();
100 //virtual void EndPickCallback();
102 /* Selection Management */
103 bool highlightCell(const Handle(SALOME_InteractiveObject)& IObject, bool hilight,
104 const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
105 bool highlightEdge(const Handle(SALOME_InteractiveObject)& IObject, bool hilight,
106 const TColStd_MapOfInteger& MapIndex, bool immediatly = true ); //NB
107 bool highlightPoint(const Handle(SALOME_InteractiveObject)& IObject, bool hilight,
108 const TColStd_MapOfInteger& MapIndex, bool immediatly = true );
110 bool highlight(const Handle(SALOME_InteractiveObject)& IObject, bool hiligth, bool immediatly = true );
111 bool unHighlightAll();
112 bool isInViewer( const Handle(SALOME_InteractiveObject)& IObject);
113 bool isVisible( const Handle(SALOME_InteractiveObject)& IObject);
114 void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName);
117 void SetSelectionMode(int mode);
119 // Displaymode management
120 int GetDisplayMode();
121 void SetDisplayMode(int);
123 // Switch representation wireframe/shading
124 void SwitchRepresentation(const Handle(SALOME_InteractiveObject)& IObject, bool update = true);
126 // Change all actors to wireframe or surface
127 void ChangeRepresentationToWireframe();
128 void ChangeRepresentationToSurface();
130 // Change to wireframe or surface a list of vtkactor
131 void ChangeRepresentationToWireframe(vtkActorCollection* ListofActors);
132 void ChangeRepresentationToSurface(vtkActorCollection* ListofActors);
134 // Erase Display functions
137 void Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
138 void Remove(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
139 void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true);
141 void Display( SALOME_Actor* SActor, bool immediatly = true );
144 void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans);
145 float GetTransparency(const Handle(SALOME_InteractiveObject)& IObject);
148 void SetColor(const Handle(SALOME_InteractiveObject)& IObject,QColor thecolor);
149 QColor GetColor(const Handle(SALOME_InteractiveObject)& IObject);
153 vtkRenderer* GetRenderer();
157 VTKViewer_RenderWindowInteractor();
158 ~VTKViewer_RenderWindowInteractor();
160 // Timer used during various mouse events to figure
161 // out mouse movements.
168 //NRI: Selection mode
170 vtkActor* Point_Actor;
171 vtkActor* Edge_Actor; //NB
172 vtkActor* Cell_Actor;
175 // User for switching to stereo mode.
177 int PositionBeforeStereo[2];
179 // Connect/disconnect all slots which allow events on the
180 // render window to be passed to the interactor.
182 void ConnectSlots() ;
183 void DisconnectSlots() ;
184 void ProcessSlotConnections(bool conn) ;
187 void MouseMove(const QMouseEvent *event) ;
188 void LeftButtonPressed(const QMouseEvent *event) ;
189 void LeftButtonReleased(const QMouseEvent *event) ;
190 void MiddleButtonPressed(const QMouseEvent *event) ;
191 void MiddleButtonReleased(const QMouseEvent *event) ;
192 void RightButtonPressed(const QMouseEvent *event) ;
193 void RightButtonReleased(const QMouseEvent *event) ;
194 void ButtonPressed(const QMouseEvent *event) ;
195 void ButtonReleased(const QMouseEvent *event) ;
196 void KeyPressed(QKeyEvent *event) ;
200 // Not all of these slots are needed in VTK_MAJOR_VERSION=3,
201 // but moc does not understand "#if VTK_MAJOR_VERSION". Hence,
202 // we have to include all of these for the time being. Once,
203 // this bug in MOC is fixed, we can separate these.
207 void RenderWindowModified() ;