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