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_OCCDisplayer.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28 #include "HYDROGUI_Shape.h"
30 #include <AIS_InteractiveContext.hxx>
31 #include <AIS_ListIteratorOfListOfInteractive.hxx>
32 #include <AIS_ListOfInteractive.hxx>
34 #include <OCCViewer_ViewManager.h>
35 #include <OCCViewer_ViewModel.h>
36 #include <OCCViewer_ViewWindow.h>
38 #include <QApplication>
40 HYDROGUI_OCCDisplayer::HYDROGUI_OCCDisplayer( HYDROGUI_Module* theModule )
41 : myModule( theModule )
45 HYDROGUI_OCCDisplayer::~HYDROGUI_OCCDisplayer()
49 void HYDROGUI_OCCDisplayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
50 const int theViewerId )
52 OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId );
56 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
58 Handle(HYDROData_Object) anObj = theObjs.Value( i );
62 HYDROGUI_Shape* anObjShape = myModule->getObjectShape( (size_t)aViewer, anObj );
66 anObjShape->setIsToUpdate( true );
70 void HYDROGUI_OCCDisplayer::UpdateAll( const int theViewerId,
72 const bool theIsForced )
75 EraseAll( theViewerId );
77 DisplayAll( theViewerId, theIsForced );
80 void HYDROGUI_OCCDisplayer::EraseAll( const int theViewerId )
82 OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId );
86 myModule->removeViewShapes( (size_t)aViewer );
89 void HYDROGUI_OCCDisplayer::DisplayAll( const int theViewerId,
90 const bool theIsForced )
92 HYDROData_SequenceOfObjects aSeq;
93 HYDROGUI_Tool::GetPrsSubObjects( myModule, aSeq );
94 Update( aSeq, theViewerId, theIsForced );
97 void HYDROGUI_OCCDisplayer::Update( const HYDROData_SequenceOfObjects& theObjs,
98 const int theViewerId,
99 const bool theIsForced )
101 // First of all, kill all bad presentations
102 purgeObjects( theViewerId );
104 // Now dig in the data model
105 HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay;
107 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
109 const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
111 anObjectsToErase.Append( anObj );
113 anObjectsToDisplay.Append( anObj );
116 if( anObjectsToErase.Length() )
117 Erase( anObjectsToErase, theViewerId );
118 if( anObjectsToDisplay.Length() )
119 Display( anObjectsToDisplay, theViewerId, theIsForced );
122 void HYDROGUI_OCCDisplayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
123 const int theViewerId )
125 OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId );
129 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
131 Handle(HYDROData_Object) anObj = theObjs.Value( i );
135 myModule->removeObjectShape( (size_t)aViewer, anObj );
139 HYDROGUI_Shape* HYDROGUI_OCCDisplayer::createShape( const int theViewerId,
140 const Handle(AIS_InteractiveContext)& theContext,
141 const Handle(HYDROData_Object)& theObject )
143 HYDROGUI_Shape* aResShape = NULL;
144 if ( theContext.IsNull() || theObject.IsNull() )
147 ObjectKind anObjectKind = theObject->GetKind();
148 if ( anObjectKind != KIND_POLYLINE &&
149 anObjectKind != KIND_ZONE )
152 aResShape = new HYDROGUI_Shape( theContext, theObject );
153 myModule->setObjectShape( theViewerId, theObject, aResShape );
158 void HYDROGUI_OCCDisplayer::Display( const HYDROData_SequenceOfObjects& theObjs,
159 const int theViewerId,
160 const bool theIsForced )
162 OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId );
166 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
170 for ( int i = 1, n = theObjs.Length(); i <= n; i++ )
172 Handle(HYDROData_Object) anObj = theObjs.Value( i );
173 if ( anObj.IsNull() || anObj->IsRemoved() )
176 HYDROGUI_Shape* anObjShape = myModule->getObjectShape( (size_t)aViewer, anObj );
178 if ( !anObjShape || anObjShape->getIsToUpdate() || theIsForced )
181 anObjShape = createShape( (size_t)aViewer, aCtx, anObj );
184 anObjShape->update( false );
189 bool anIsVisible = myModule->isObjectVisible( (size_t)aViewer, anObj );
190 anObjShape->setVisible( anIsVisible, false );
194 OCCViewer_ViewManager* aViewManager
195 = ::qobject_cast<OCCViewer_ViewManager*>( aViewer->getViewManager() );
198 OCCViewer_ViewWindow* aViewWindow =
199 ::qobject_cast<OCCViewer_ViewWindow*>( aViewManager->getActiveView() );
202 QApplication::processEvents(); //Process the draw events for viewer
203 aViewWindow->onFitAll();
208 void HYDROGUI_OCCDisplayer::purgeObjects( const int theViewerId )
210 OCCViewer_Viewer* aViewer = myModule->getOCCViewer( theViewerId );
214 Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
218 AIS_ListOfInteractive aDisplayedObjects;
219 aCtx->DisplayedObjects( aDisplayedObjects );
221 AIS_ListIteratorOfListOfInteractive aListIter( aDisplayedObjects );
222 for ( ; aListIter.More(); aListIter.Next() )
224 Handle(AIS_InteractiveObject) aPrsObj = aListIter.Value();
225 if ( aPrsObj.IsNull() )
228 Handle(HYDROData_Object) anOwnerObj =
229 Handle(HYDROData_Object)::DownCast( aPrsObj->GetOwner() );
230 if ( !anOwnerObj.IsNull() && anOwnerObj->IsRemoved() )
231 myModule->removeObjectShape( (size_t)aViewer, anOwnerObj );