1 // Copyright (C) 2007-2013 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 #include "HYDROGUI_VTKPrsDisplayer.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_VTKPrs.h"
28 #include "HYDROGUI_VTKPrsBathymetryDriver.h"
29 #include "HYDROGUI_Tool.h"
31 #include <SVTK_ViewModel.h>
32 #include <SVTK_ViewWindow.h>
33 #include <SALOME_ListIO.hxx>
34 #include <SALOME_ListIteratorOfListIO.hxx>
35 #include <SALOME_InteractiveObject.hxx>
36 #include <SUIT_ViewManager.h>
37 #include <SUIT_Accel.h>
41 HYDROGUI_VTKPrsDisplayer::HYDROGUI_VTKPrsDisplayer( HYDROGUI_Module* theModule )
42 : HYDROGUI_AbstractDisplayer( theModule ), myDriver( NULL )
46 HYDROGUI_VTKPrsDisplayer::~HYDROGUI_VTKPrsDisplayer()
50 void HYDROGUI_VTKPrsDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
51 const int theViewerId )
53 SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
56 HYDROGUI_VTKPrs* anObjShape;
57 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
59 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
62 anObjShape = module()->getObjectVTKPrs( (size_t)aViewer, anObj );
65 anObjShape->setIsToUpdate( true );
72 void HYDROGUI_VTKPrsDisplayer::EraseAll( const int theViewerId )
74 SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
77 aViewer->EraseAll( true );
78 module()->removeViewVTKPrs( (size_t)aViewer );
82 void HYDROGUI_VTKPrsDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
83 const int theViewerId )
85 SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
88 HYDROGUI_VTKPrs* aPrs;
89 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
91 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
95 aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj );
98 aViewer->Erase( aPrs, true );
100 if ( anObj->IsRemoved() )
102 module()->removeObjectVTKPrs( (size_t)aViewer, anObj );
108 void HYDROGUI_VTKPrsDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
109 const int theViewerId,
110 const bool theIsForced,
111 const bool theDoFitAll)
113 SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
116 bool isChanged = false;
117 HYDROGUI_VTKPrs* aPrs;
118 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
120 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
121 if( !anObj.IsNull() )
123 bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj );
124 aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anObj );
126 bool anIsInserted = ( aPrs != 0 );
127 if( anIsVisible && ( !aPrs || aPrs->getIsToUpdate() || theIsForced ) )
129 if( HYDROGUI_VTKPrsDriver* aDriver = getDriver( anObj ) )
131 if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
133 module()->setObjectVTKPrs( (size_t)aViewer, anObj, aPrs );
142 aViewer->Display( aPrs );
146 aViewer->Erase( aPrs );
155 // Repaint is done inside OnFitAll()
156 aViewer->getViewManager()->getActiveView()->onAccelAction( SUIT_Accel::ZoomFit );
158 else if ( isChanged )
165 void HYDROGUI_VTKPrsDisplayer::purgeObjects( const int theViewerId )
167 SVTK_Viewer* aViewer = module()->getVTKViewer( theViewerId );
170 SALOME_ListIO aListIO;
171 aViewer->GetVisible( aListIO );
173 HYDROGUI_VTKPrs* aPrs;
174 SALOME_ListIteratorOfListIO anIter( aListIO );
175 for( ; anIter.More(); anIter.Next() )
177 Handle(SALOME_InteractiveObject) aPrsObj = anIter.Value();
178 if ( !aPrsObj.IsNull() )
180 Handle(HYDROData_Entity) anOwnerObj =
181 module()->getDataModel()->objectByEntry( aPrsObj->getEntry() );
182 if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() )
184 aPrs = module()->getObjectVTKPrs( (size_t)aViewer, anOwnerObj );
187 aViewer->Erase( aPrs );
189 module()->removeObjectVTKPrs( (size_t)aViewer, anOwnerObj );
196 HYDROGUI_VTKPrsDriver* HYDROGUI_VTKPrsDisplayer::getDriver( const Handle(HYDROData_Entity)& theObj )
198 HYDROGUI_VTKPrsDriver* aDriver = NULL;
199 ObjectKind aKind = theObj->GetKind();
200 if( theObj->GetKind() == KIND_BATHYMETRY )
204 myDriver = new HYDROGUI_VTKPrsBathymetryDriver();
212 QString HYDROGUI_VTKPrsDisplayer::GetType() const
214 return SVTK_Viewer::Type();