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