1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_Tools.h
25 // Author : Sergey Anikin
28 #ifndef VisuGUI_ViewTools_HeaderFile
29 #define VisuGUI_ViewTools_HeaderFile
33 #include "VisuGUI_Tools.h"
35 #include "VISU_Prs3d_i.hh"
36 #include "VISU_Table_i.hh"
37 #include "VISU_PointMap3d_i.hh"
38 #include "VISU_ViewManager_i.hh"
40 #include "VISU_Actor.h"
42 #include "SalomeApp_Module.h"
43 #include "SalomeApp_Application.h"
45 //#include "VVTK_ViewModel.h"
46 //#include "VVTK_ViewWindow.h"
48 #include "SVTK_Functor.h"
49 #include "SVTK_ViewModel.h"
50 #include "SVTK_ViewWindow.h"
52 #include "SPlot2d_ViewModel.h"
54 #include "VTKViewer_Algorithm.h"
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"
62 #include "SALOME_ListIO.hxx"
63 #include "SALOME_ListIteratorOfListIO.hxx"
65 #include <vtkActorCollection.h>
66 #include <vtkRenderer.h>
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.
77 template<class TViewer>
79 typename TViewer::TViewWindow*
80 GetViewWindow(VisuGUI* theModule)
82 typedef typename TViewer::TViewWindow TViewWindow;
83 if (SalomeApp_Application* anApp = theModule->getApp()) {
84 if (TViewWindow* aView = dynamic_cast<TViewWindow*>(anApp->desktop()->activeWindow()))
87 SUIT_ViewManager* aViewManager =
88 theModule->getViewManager(TViewer::Type(), /*create = */true);
90 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
91 if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)) {
93 aViewWindow->setFocus();
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.
105 template<class TViewWindow>
108 GetActiveViewWindow(const SalomeApp_Module* theModule = NULL)
110 SalomeApp_Application* anApp = NULL;
112 anApp = theModule->getApp();
114 anApp = dynamic_cast<SalomeApp_Application*>
115 (SUIT_Session::session()->activeApplication());
118 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager())
119 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView())
120 return dynamic_cast<TViewWindow*>(aViewWindow);
126 //---------------------------------------------------------------
128 PublishInView(VisuGUI* theModule,
130 SVTK_ViewWindow* theViewWindow,
131 const bool theIsHighlight = false);
134 //---------------------------------------------------------------
136 UpdateViewer(VisuGUI* theModule,
137 VISU::Prs3d_i* thePrs,
138 bool theDispOnly = false,
139 const bool theIsHighlight = false);
142 //---------------------------------------------------------------
143 template<class TViewer>
146 OnEraseAll(VisuGUI* theModule)
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();
161 aViewWindow->Repaint();
169 OnEraseAll<SPlot2d_Viewer>(VisuGUI* theModule)
171 if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false))
176 //---------------------------------------------------------------
178 ErasePrs3d(VisuGUI* theModule,
179 VISU::Prs3d_i* thePrs,
180 bool theDoRepaint = true);
183 ErasePrs(VisuGUI* theModule,
185 bool theDoRepaintVW);