1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2005 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_Tools.h
25 // Author : Sergey Anikin
28 #ifndef VisuGUI_ViewTools_HeaderFile
29 #define VisuGUI_ViewTools_HeaderFile
33 #include "SUIT_MessageBox.h"
34 #include "SUIT_ViewManager.h"
35 #include "SUIT_ViewWindow.h"
37 #include "SalomeApp_Module.h"
38 #include "SalomeApp_Application.h"
40 #include "VISU_Prs3d_i.hh"
42 #include "VVTK_ViewModel.h"
43 #include "VVTK_ViewWindow.h"
45 #include "SVTK_ViewModel.h"
46 #include "SVTK_ViewWindow.h"
48 #include "VisuGUI_Tools.h"
49 #include "VTKViewer_Algorithm.h"
50 #include "SVTK_Functor.h"
52 #include "VISU_Table_i.hh"
53 #include "VISU_ViewManager_i.hh"
54 #include "SALOME_ListIO.hxx"
55 #include "SALOME_ListIteratorOfListIO.hxx"
57 #include "SPlot2d_ViewModel.h"
59 #include "VISU_Actor.h"
61 #include <vtkActorCollection.h>
62 #include <vtkRenderer.h>
68 //---------------------------------------------------------------
69 template<class TViewer>
71 typename TViewer::TViewWindow*
72 GetViewWindow(VisuGUI* theModule,
73 const bool theIsViewCreate = false)
75 typedef typename TViewer::TViewWindow TView;
76 if(SUIT_ViewManager* aViewManager = theModule->getViewManager(TViewer::Type(),theIsViewCreate)){
77 if(SUIT_ViewWindow* aViewWindow = aViewManager->getActiveView()){
78 if(TView* aView = dynamic_cast<TView*>(aViewWindow)){
80 aViewWindow->setFocus();
89 //---------------------------------------------------------------
90 template<class TViewer>
93 PublishInView(VisuGUI* theModule,
95 const bool theIsHighlight = false,
96 const bool theIsCreateView = false)
98 typedef typename TViewer::TViewWindow TView;
99 if(TView* aView = GetViewWindow<TViewer>(theModule,theIsCreateView)){
100 QApplication::setOverrideCursor( Qt::waitCursor );
102 if(VISU_Actor* anActor = thePrs->CreateActor()){
103 aView->AddActor(anActor);
105 aView->highlight(anActor->getIO(),true);
106 aView->getRenderer()->ResetCameraClippingRange();
108 QApplication::restoreOverrideCursor();
111 } catch(std::exception& exc) {
112 QApplication::restoreOverrideCursor();
114 SUIT_MessageBox::warn1
115 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
116 QObject::tr("ERR_CANT_CREATE_ACTOR") + ": " + QObject::tr(exc.what()),
117 QObject::tr("BUT_OK"));
124 //---------------------------------------------------------------
125 template<class TViewer>
128 UpdateViewer(VisuGUI* theModule,
129 VISU::Prs3d_i* thePrs,
130 bool theDispOnly = false,
131 const bool theIsHighlight = false,
132 const bool theIsViewCreate = false)
134 typedef typename TViewer::TViewWindow TView;
135 if(TView* aView = GetViewWindow<TViewer>(theModule,theIsViewCreate)){
136 vtkRenderer *aRen = aView->getRenderer();
137 vtkActorCollection *anActColl = aRen->GetActors();
138 anActColl->InitTraversal();
139 VISU_Actor* aResActor = NULL;
140 while(vtkActor *anAct = anActColl->GetNextActor()){
141 if(VISU_Actor* anActor = dynamic_cast<VISU_Actor*>(anAct)){
142 if(VISU::Prs3d_i* aPrs3d = anActor->GetPrs3d()){
143 if(thePrs == aPrs3d){
145 thePrs->UpdateActors();
146 } catch (std::runtime_error& exc) {
148 QApplication::restoreOverrideCursor();
149 SUIT_MessageBox::warn1
150 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
151 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
152 QObject::tr("BUT_OK"));
154 thePrs->RemoveActors();
158 aResActor->VisibilityOn();
159 }else if(theDispOnly){
160 anActor->VisibilityOff();
162 }else if(theDispOnly && anActor->GetVisibility()){
163 anActor->VisibilityOff();
169 aView->highlight(aResActor->getIO(),true);
170 aView->getRenderer()->ResetCameraClippingRange();
174 return PublishInView<TViewer>(theModule,thePrs,theIsHighlight,theIsViewCreate);
180 //---------------------------------------------------------------
181 template<class TViewer>
184 OnEraseAll(VisuGUI* theModule)
186 typedef typename TViewer::TViewWindow TViewWindow;
187 if(TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule)){
188 aViewWindow->unHighlightAll();
189 if(vtkRenderer *aRen = aViewWindow->getRenderer()){
190 vtkActorCollection *aCollection = aRen->GetActors();
191 aCollection->InitTraversal();
192 while(vtkActor *anAct = aCollection->GetNextActor()){
193 if(anAct->GetVisibility() > 0)
194 if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct)){
195 anActor->VisibilityOff();
198 aViewWindow->Repaint();
206 OnEraseAll<SPlot2d_Viewer>(VisuGUI* theModule)
208 if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule,false))
213 //---------------------------------------------------------------
214 template<class TVieweWindow>
217 FindActor(TVieweWindow* theViewWindow,
218 const char* theEntry)
220 using namespace SVTK;
221 if(vtkRenderer* aRenderer = theViewWindow->getRenderer()){
222 if(vtkActorCollection* aCollection = aRenderer->GetActors()){
223 if(VISU_Actor* anActor = Find<VISU_Actor>(aCollection,TIsSameEntry<VISU_Actor>(theEntry))){
231 template<class TViewer>
234 ErasePrs3d(VisuGUI* theModule,
235 VISU::Prs3d_i* thePrs,
236 const bool thIsUpdate = true)
238 typedef typename TViewer::TViewWindow TViewWindow;
239 if(TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule)){
240 if(VISU_Actor* anActor = FindActor(aViewWindow,thePrs)){
241 anActor->VisibilityOff();
243 aViewWindow->Repaint();
250 ErasePrs(VisuGUI* theModule,
251 VISU::Base_ptr theBase,