]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_ViewTools.h
Salome HOME
Update translations
[modules/visu.git] / src / VISUGUI / VisuGUI_ViewTools.h
1 // Copyright (C) 2007-2011  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 //  VISU VISUGUI : GUI of VISU component
24 //  File   : VisuGUI_Tools.h
25 //  Author : Sergey Anikin
26 //  Module : VISU
27 //
28 #ifndef VisuGUI_ViewTools_HeaderFile
29 #define VisuGUI_ViewTools_HeaderFile
30
31 #include "VisuGUI.h"
32
33 #include "VisuGUI_Tools.h"
34
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_Table_i.hh"
37 #include "VISU_PointMap3d_i.hh"
38 #include "VISU_ViewManager_i.hh"
39
40 #include "VISU_Actor.h"
41
42 #include "SalomeApp_Module.h"
43 #include "SalomeApp_Application.h"
44
45 //#include "VVTK_ViewModel.h"
46 //#include "VVTK_ViewWindow.h"
47
48 #include "SVTK_Functor.h"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
51
52 #include "SPlot2d_ViewModel.h"
53
54 #include "VTKViewer_Algorithm.h"
55
56 #include "SUIT_Session.h"
57 #include "SUIT_Desktop.h"
58 #include "SUIT_MessageBox.h"
59 #include "SUIT_ViewManager.h"
60 #include "SUIT_ViewWindow.h"
61
62 #include "SALOME_ListIO.hxx"
63 #include "SALOME_ListIteratorOfListIO.hxx"
64
65 #include <vtkActorCollection.h>
66 #include <vtkRenderer.h>
67
68 //class VVTK_Viewer;
69
70 namespace VISU 
71 {
72   /*! Return active view window, if it instantiates TViewer::TViewWindow class,
73    *  overwise find or create corresponding view window, make it active and return it.
74    *  \note Active VVTK_ViewWindow can be returned by request GetViewWindow<SVTK_Viewer>(),
75    *        because VVTK_ViewWindow inherits SVTK_ViewWindow.
76    */
77   template<class TViewer>
78   inline
79   typename TViewer::TViewWindow*
80   GetViewWindow(VisuGUI* theModule)
81   {
82     typedef typename TViewer::TViewWindow TViewWindow;
83     if (SalomeApp_Application* anApp = theModule->getApp()) {
84       if (TViewWindow* aView = dynamic_cast<TViewWindow*>(anApp->desktop()->activeWindow()))
85         return aView;
86     }
87     SUIT_ViewManager* aViewManager =
88       theModule->getViewManager(TViewer::Type(), /*create = */true);
89     if (aViewManager) {
90       if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
91         if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)) {
92           aViewWindow->raise();
93           aViewWindow->setFocus();
94           return aView;
95         }
96       }
97     }
98     return NULL;
99   }
100
101   /*! Return active view window, if it instantiates TViewWindow class, overwise return NULL.
102    *  \note Active VVTK_ViewWindow can be returned by request GetActiveViewWindow<SVTK_ViewWindow>(),
103    *        because VVTK_ViewWindow inherits SVTK_ViewWindow.
104    */
105   template<class TViewWindow>
106   inline
107   TViewWindow*
108   GetActiveViewWindow(const SalomeApp_Module* theModule = NULL)
109   {
110     SalomeApp_Application* anApp = NULL;
111     if (theModule)
112       anApp = theModule->getApp();
113     else
114       anApp = dynamic_cast<SalomeApp_Application*>
115         (SUIT_Session::session()->activeApplication());
116
117     if (anApp)
118       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager())
119         if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView())
120           return dynamic_cast<TViewWindow*>(aViewWindow);
121
122     return NULL;
123   }
124
125
126   //---------------------------------------------------------------
127   VISU_Actor*
128   PublishInView(VisuGUI* theModule,
129                 Prs3d_i* thePrs,
130                 SVTK_ViewWindow* theViewWindow,
131                 const bool theIsHighlight = false);  
132
133
134   //---------------------------------------------------------------
135   VISU_Actor*
136   UpdateViewer(VisuGUI* theModule,
137                VISU::Prs3d_i* thePrs,
138                bool theDispOnly = false,
139                const bool theIsHighlight = false);
140
141
142   //---------------------------------------------------------------
143   template<class TViewer>
144   inline
145   void
146   OnEraseAll(VisuGUI* theModule)
147   {
148     typedef typename TViewer::TViewWindow TViewWindow;
149     if (TViewWindow* aViewWindow = GetActiveViewWindow<TViewWindow>(theModule)) {
150       aViewWindow->unHighlightAll();
151       if (vtkRenderer *aRen = aViewWindow->getRenderer()) {
152         VTK::ActorCollectionCopy aCopy(aRen->GetActors());
153         vtkActorCollection *aCollection = aCopy.GetActors();
154         aCollection->InitTraversal();
155         while (vtkActor *anAct = aCollection->GetNextActor()) {
156           if (anAct->GetVisibility() > 0)
157             if (SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)) {
158               anActor->VisibilityOff();
159             }
160         }
161         aViewWindow->Repaint();
162       }
163     }
164   }
165
166   template<>
167   inline
168   void
169   OnEraseAll<SPlot2d_Viewer>(VisuGUI* theModule)
170   {
171     if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false))
172       aPlot2d->EraseAll();
173   }
174
175
176   //---------------------------------------------------------------
177   void
178   ErasePrs3d(VisuGUI* theModule,
179              VISU::Prs3d_i* thePrs,
180              bool theDoRepaint = true);
181
182   void
183   ErasePrs(VisuGUI* theModule,
184            Base_i* theBase, 
185            bool theDoRepaintVW);
186 }
187
188 #endif