Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_ViewTools.h
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  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 //
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_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_MessageBox.h"
57 #include "SUIT_ViewManager.h"
58 #include "SUIT_ViewWindow.h"
59
60 #include "SALOME_ListIO.hxx"
61 #include "SALOME_ListIteratorOfListIO.hxx"
62
63 #include <vtkActorCollection.h>
64 #include <vtkRenderer.h>
65
66 class VVTK_Viewer;
67
68 namespace VISU 
69 {
70   /*! Return active view window, if it instantiates TViewer::TViewWindow class,
71    *  overwise find or create corresponding view window, make it active and return it.
72    *  \note Active VVTK_ViewWindow can be returned by request GetViewWindow<SVTK_Viewer>(),
73    *        because VVTK_ViewWindow inherits SVTK_ViewWindow.
74    */
75   template<class TViewer>
76   inline
77   typename TViewer::TViewWindow*
78   GetViewWindow(VisuGUI* theModule)
79   {
80     typedef typename TViewer::TViewWindow TViewWindow;
81     if (SalomeApp_Application* anApp = theModule->getApp()) {
82       if (TViewWindow* aView = dynamic_cast<TViewWindow*>(anApp->desktop()->activeWindow()))
83         return aView;
84     }
85     SUIT_ViewManager* aViewManager =
86       theModule->getViewManager(TViewer::Type(), /*create = */true);
87     if (aViewManager) {
88       if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
89         if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)) {
90           aViewWindow->raise();
91           aViewWindow->setFocus();
92           return aView;
93         }
94       }
95     }
96     return NULL;
97   }
98
99   /*! Return active view window, if it instantiates TViewWindow class, overwise return NULL.
100    *  \note Active VVTK_ViewWindow can be returned by request GetActiveViewWindow<SVTK_ViewWindow>(),
101    *        because VVTK_ViewWindow inherits SVTK_ViewWindow.
102    */
103   template<class TViewWindow>
104   inline
105   TViewWindow*
106   GetActiveViewWindow(const SalomeApp_Module* theModule = NULL)
107   {
108     SalomeApp_Application* anApp = NULL;
109     if (theModule)
110       anApp = theModule->getApp();
111     else
112       anApp = dynamic_cast<SalomeApp_Application*>
113         (SUIT_Session::session()->activeApplication());
114
115     if (anApp)
116       if (SUIT_ViewManager* aViewManager = anApp->activeViewManager())
117         if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView())
118           return dynamic_cast<TViewWindow*>(aViewWindow);
119
120     return NULL;
121   }
122
123
124   //---------------------------------------------------------------
125   VISU_Actor*
126   PublishInView(VisuGUI* theModule,
127                 Prs3d_i* thePrs,
128                 SVTK_ViewWindow* theViewWindow,
129                 const bool theIsHighlight = false);  
130
131
132   //---------------------------------------------------------------
133   VISU_Actor*
134   UpdateViewer(VisuGUI* theModule,
135                VISU::Prs3d_i* thePrs,
136                bool theDispOnly = false,
137                const bool theIsHighlight = false);
138
139
140   //---------------------------------------------------------------
141   template<class TViewer>
142   inline
143   void
144   OnEraseAll(VisuGUI* theModule)
145   {
146     typedef typename TViewer::TViewWindow TViewWindow;
147     if (TViewWindow* aViewWindow = GetActiveViewWindow<TViewWindow>(theModule)) {
148       aViewWindow->unHighlightAll();
149       if (vtkRenderer *aRen = aViewWindow->getRenderer()) {
150         vtkActorCollection *aCollection = aRen->GetActors();
151         aCollection->InitTraversal();
152         while (vtkActor *anAct = aCollection->GetNextActor()) {
153           if (anAct->GetVisibility() > 0)
154             if (SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)) {
155               anActor->VisibilityOff();
156             }
157         }
158         aViewWindow->Repaint();
159       }
160     }
161   }
162
163   template<>
164   inline
165   void
166   OnEraseAll<SPlot2d_Viewer>(VisuGUI* theModule)
167   {
168     if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false))
169       aPlot2d->EraseAll();
170   }
171
172
173   //---------------------------------------------------------------
174   void
175   ErasePrs3d(VisuGUI* theModule,
176              VISU::Prs3d_i* thePrs,
177              bool theDoRepaint = true);
178
179   void
180   ErasePrs(VisuGUI* theModule,
181            Base_i* theBase, 
182            bool theDoRepaintVW);
183 }
184
185 #endif