1 // Copyright (C) 2007-2008 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Tools.h
24 // Author : Sergey Anikin
27 #ifndef VisuGUI_ViewTools_HeaderFile
28 #define VisuGUI_ViewTools_HeaderFile
32 #include "VisuGUI_Tools.h"
34 #include "VISU_Prs3d_i.hh"
35 #include "VISU_Table_i.hh"
36 #include "VISU_PointMap3d_i.hh"
37 #include "VISU_ViewManager_i.hh"
39 #include "VISU_Actor.h"
41 #include "SalomeApp_Module.h"
42 #include "SalomeApp_Application.h"
44 //#include "VVTK_ViewModel.h"
45 //#include "VVTK_ViewWindow.h"
47 #include "SVTK_Functor.h"
48 #include "SVTK_ViewModel.h"
49 #include "SVTK_ViewWindow.h"
51 #include "SPlot2d_ViewModel.h"
53 #include "VTKViewer_Algorithm.h"
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"
61 #include "SALOME_ListIO.hxx"
62 #include "SALOME_ListIteratorOfListIO.hxx"
64 #include <vtkActorCollection.h>
65 #include <vtkRenderer.h>
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.
76 template<class TViewer>
78 typename TViewer::TViewWindow*
79 GetViewWindow(VisuGUI* theModule)
81 typedef typename TViewer::TViewWindow TViewWindow;
82 if (SalomeApp_Application* anApp = theModule->getApp()) {
83 if (TViewWindow* aView = dynamic_cast<TViewWindow*>(anApp->desktop()->activeWindow()))
86 SUIT_ViewManager* aViewManager =
87 theModule->getViewManager(TViewer::Type(), /*create = */true);
89 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()) {
90 if (TViewWindow* aView = dynamic_cast<TViewWindow*>(aViewWindow)) {
92 aViewWindow->setFocus();
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.
104 template<class TViewWindow>
107 GetActiveViewWindow(const SalomeApp_Module* theModule = NULL)
109 SalomeApp_Application* anApp = NULL;
111 anApp = theModule->getApp();
113 anApp = dynamic_cast<SalomeApp_Application*>
114 (SUIT_Session::session()->activeApplication());
117 if (SUIT_ViewManager* aViewManager = anApp->activeViewManager())
118 if (SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView())
119 return dynamic_cast<TViewWindow*>(aViewWindow);
125 //---------------------------------------------------------------
127 PublishInView(VisuGUI* theModule,
129 SVTK_ViewWindow* theViewWindow,
130 const bool theIsHighlight = false);
133 //---------------------------------------------------------------
135 UpdateViewer(VisuGUI* theModule,
136 VISU::Prs3d_i* thePrs,
137 bool theDispOnly = false,
138 const bool theIsHighlight = false);
141 //---------------------------------------------------------------
142 template<class TViewer>
145 OnEraseAll(VisuGUI* theModule)
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();
159 aViewWindow->Repaint();
167 OnEraseAll<SPlot2d_Viewer>(VisuGUI* theModule)
169 if (SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false))
174 //---------------------------------------------------------------
176 ErasePrs3d(VisuGUI* theModule,
177 VISU::Prs3d_i* thePrs,
178 bool theDoRepaint = true);
181 ErasePrs(VisuGUI* theModule,
183 bool theDoRepaintVW);