]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_View.h
Salome HOME
0542c24f9fa231426ae3ef84847a6848d81c4656
[modules/gui.git] / src / SVTK / SVTK_View.h
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef SVTK_VIEW_H
24 #define SVTK_VIEW_H
25
26 #ifdef WIN32
27 #pragma warning( disable:4251 )
28 #endif
29
30 #include "SVTK.h"
31
32 #include <SALOME_InteractiveObject.hxx>
33 #include <SALOME_ListIO.hxx>
34
35 #include <QObject>
36
37 class vtkActorCollection;
38 class vtkRenderer;
39 class vtkProperty;
40
41 class SVTK_ViewWindow;
42 class SVTK_Renderer;
43
44 class SALOME_Actor;
45
46 class QMouseEvent;
47 class QWheelEvent;
48 class QKeyEvent;
49 class QContextMenuEvent;
50 class QColor;
51
52
53 //! Main purpose of the class is to provide a way to customize #SVTK_ViewWindow.
54 /*!
55   This class is initialized by #SVTK_ViewWindow and just pass Qt signals from 
56   corresponding #SVTK_RenderWindowInteractor of the #SVTK_ViewWindow.
57   Its main purpose is to provide a simple and flexible way to customize the #SVTK_ViewWindow.
58   So, in your own viewer it is possible to derive new #SVTK_ViewWindow and 
59   use existing functionality without any modifications.
60  */
61 class SVTK_EXPORT SVTK_SignalHandler : public QObject
62 {
63   Q_OBJECT;
64
65 public:
66   SVTK_SignalHandler(SVTK_ViewWindow* theMainWindow);
67
68   virtual
69   ~SVTK_SignalHandler();
70
71   //! Get reference to its #SVTK_ViewWindow
72   SVTK_ViewWindow*
73   GetMainWindow();
74
75   //----------------------------------------------------------------------------
76   //! Redirect the request to #SVTK_ViewWindow::Repaint (just for flexibility)
77   void
78   Repaint(bool theUpdateTrihedron = true);
79
80   //----------------------------------------------------------------------------
81   //! Redirect the request to #SVTK_ViewWindow::GetRenderer (just for flexibility)
82   SVTK_Renderer* 
83   GetRenderer();
84
85   //! Redirect the request to #SVTK_ViewWindow::getRenderer (just for flexibility)
86   vtkRenderer* 
87   getRenderer();
88
89   //----------------------------------------------------------------------------
90  public slots:
91   void onSelectionChanged();
92
93  public:
94  signals:
95   void MouseMove( QMouseEvent* );
96   void MouseButtonPressed( QMouseEvent* );
97   void MouseButtonReleased( QMouseEvent* );
98   void MouseDoubleClicked( QMouseEvent* );
99   void ButtonPressed(const QMouseEvent *event);
100   void ButtonReleased(const QMouseEvent *event);
101   void WheelMoved( QWheelEvent* );
102   void KeyPressed( QKeyEvent* );
103   void KeyReleased( QKeyEvent* );
104   void contextMenuRequested( QContextMenuEvent *e );
105   void selectionChanged();
106
107  protected:
108   SVTK_ViewWindow* myMainWindow;
109 };
110
111
112 //! This class is introduced just for compatibility with old code.
113 /*!
114   This class contains frequantly used functionality in old code.
115   Now, you are supposed to extend existing functionality through
116   writing corresponding functors (see SVTK_Functor.h for example).
117  */
118 class SVTK_EXPORT SVTK_View : public SVTK_SignalHandler
119 {
120   Q_OBJECT;
121
122 public:
123   SVTK_View(SVTK_ViewWindow* theMainWindow);
124
125   virtual
126   ~SVTK_View();
127   
128   /*  interactive object management */
129   //! To highlight a VTK presentation with the same #SALOME_InteractiveObject
130   void
131   highlight(const Handle(SALOME_InteractiveObject)& IObject, 
132             bool highlight, 
133             bool immediatly = true);
134
135   //! To unhighlight all VTK presentations
136   void
137   unHighlightAll();
138
139   //! Try to find a SALOME_InteractiveObject in the view that corresponds to the entry
140   Handle(SALOME_InteractiveObject) 
141   FindIObject(const char* Entry);
142
143   //! Check, if the viewer contains a presentatin with defined #SALOME_InteractiveObject
144   bool
145   isInViewer(const Handle(SALOME_InteractiveObject)& IObject);
146
147   //! Check, if a presentatin with defined #SALOME_InteractiveObject is visible
148   bool
149   isVisible(const Handle(SALOME_InteractiveObject)& IObject);
150
151   void
152   rename(const Handle(SALOME_InteractiveObject)& IObject, 
153          const QString& newName);
154   
155   //----------------------------------------------------------------------------
156   // Displaymode management
157   //! Get current display mode (obsolete)
158   int 
159   GetDisplayMode();
160
161   //! Set current display mode
162   void
163   SetDisplayMode(int);
164
165   //! Switch representation wireframe/shading
166   void
167   SetDisplayMode(const Handle(SALOME_InteractiveObject)& IObject, 
168                  int theMode);
169
170   //! Change all actors to wireframe
171   void 
172   ChangeRepresentationToWireframe();
173
174   //! Change all actors to surface
175   void
176   ChangeRepresentationToSurface();
177
178   //! Change all actors to surface with edges
179   void
180   ChangeRepresentationToSurfaceWithEdges();
181
182   //! Change to wireframe a list of vtkactor
183   void
184   ChangeRepresentationToWireframe(vtkActorCollection* theListofActors);
185
186   //! Change to surface a list of vtkactor
187   void
188   ChangeRepresentationToSurface(vtkActorCollection* theListofActors);
189
190   //! Change to surface with edges a list of vtkactor
191   void
192   ChangeRepresentationToSurfaceWithEdges(vtkActorCollection* theListofActors);
193
194   //! Change transparency
195   void
196   SetTransparency(const Handle(SALOME_InteractiveObject)& theIObject,
197                   float trans);
198
199   //! Get current transparency
200   float 
201   GetTransparency(const Handle(SALOME_InteractiveObject)& theIObject);
202
203   //! Change color
204   void
205   SetColor(const Handle(SALOME_InteractiveObject)& theIObject,
206            const QColor& theColor);
207
208   //! Get current color
209   QColor
210   GetColor(const Handle(SALOME_InteractiveObject)& theIObject);
211
212   //! Change material
213   void
214   SetMaterial(const Handle(SALOME_InteractiveObject)& theIObject,
215               vtkProperty* thePropF);
216
217   //! Get current material
218   vtkProperty* 
219   GetMaterial(const Handle(SALOME_InteractiveObject)& theIObject);
220
221   //----------------------------------------------------------------------------
222   // Erase Display functions
223   //! To erase all existing VTK presentations
224   void
225   EraseAll();
226
227   //! To display all existing VTK presentations
228   void
229   DisplayAll();
230
231   //! To remove from the view all existing VTK presentations
232   void
233   RemoveAll( const bool immediatly );
234
235   //! To erase VTK presentation with defined #SALOME_InteractiveObject
236   void
237   Erase(const Handle(SALOME_InteractiveObject)& IObject, 
238         bool immediatly = true);
239   void
240   Remove(const Handle(SALOME_InteractiveObject)& IObject, 
241          bool immediatly = true);
242
243   //! To display VTK presentation with defined #SALOME_InteractiveObject
244   void
245   Display(const Handle(SALOME_InteractiveObject)& IObject, 
246           bool immediatly = true);
247
248   //! To display VTK presentation with defined #SALOME_InteractiveObject and erase all anothers
249   void
250   DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject);
251
252   //! To display the VTK presentation
253   void
254   Display(SALOME_Actor* SActor, 
255           bool immediatly = true);
256
257   //! To erase the VTK presentation
258   void
259   Erase(SALOME_Actor* SActor, 
260         bool immediatly = true);
261
262   //! To remove the VTK presentation
263   void
264   Remove(SALOME_Actor* SActor, 
265          bool updateViewer = true);
266
267   //! Collect objects visible in viewer
268   void
269   GetVisible( SALOME_ListIO& theList );
270
271   //----------------------------------------------------------------------------
272   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
273   void
274   SetSelectionProp(const double& theRed = 1, 
275                    const double& theGreen = 1,
276                    const double& theBlue = 0, 
277                    const int& theWidth = 5);
278
279   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
280   void
281   SetPreselectionProp(const double& theRed = 0, 
282                       const double& theGreen = 1,
283                       const double& theBlue = 1, 
284                       const int& theWidth = 5);
285
286   //! Redirect the request to #SVTK_Renderer::SetPreselectionProp
287   void
288   SetSelectionTolerance(const double& theTolNodes = 0.025, 
289                         const double& theTolCell = 0.001,
290                         const double& theTolObjects = 0.025);
291
292  protected:  
293   int myDisplayMode;
294 };
295
296 #ifdef WIN32
297 #pragma warning( default:4251 )
298 #endif
299
300 #endif