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_Displayer.h"
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Prs.h"
28 #include "HYDROGUI_PrsImageDriver.h"
29 #include "HYDROGUI_Tool.h"
31 #include <GraphicsView_Viewer.h>
32 #include <GraphicsView_ViewPort.h>
34 HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule )
35 : myModule( theModule )
39 HYDROGUI_Displayer::~HYDROGUI_Displayer()
43 void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
44 const int theViewerId )
46 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
50 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
54 GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
55 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
57 Handle(HYDROData_Object) anObj = theObjs.Value( i );
61 if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
62 aPrs->setIsToUpdate( true );
66 void HYDROGUI_Displayer::UpdateAll( const int theViewerId,
68 const bool theIsForced )
71 EraseAll( theViewerId );
72 DisplayAll( theViewerId, theIsForced );
75 void HYDROGUI_Displayer::EraseAll( const int theViewerId )
77 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
81 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
85 GraphicsView_ObjectListIterator anIter( HYDROGUI_Tool::GetPrsList( aViewPort ) );
86 while( anIter.hasNext() )
88 if( GraphicsView_Object* anObject = anIter.next() )
90 aViewPort->removeItem( anObject );
96 void HYDROGUI_Displayer::DisplayAll( const int theViewerId,
97 const bool theIsForced )
99 HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
102 HYDROData_SequenceOfObjects aSeq;
103 HYDROGUI_Tool::GetPrsSubObjects( aModel, theViewerId, aSeq );
104 Update( aSeq, theViewerId, theIsForced );
108 void HYDROGUI_Displayer::Update( const HYDROData_SequenceOfObjects& theObjs,
109 const int theViewerId,
110 const bool theIsForced )
112 // First of all, kill all bad presentations
113 purgeObjects( theViewerId );
115 // Now dig in the data model
116 HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay;
118 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
120 const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
122 anObjectsToErase.Append( anObj );
124 anObjectsToDisplay.Append( anObj );
127 if( anObjectsToErase.Length() )
128 Erase( anObjectsToErase, theViewerId );
129 if( anObjectsToDisplay.Length() )
130 Display( anObjectsToDisplay, theViewerId, theIsForced );
133 void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
134 const int theViewerId )
136 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
140 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
144 HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
147 GraphicsView_ObjectList anObjectList = HYDROGUI_Tool::GetPrsList( aViewPort );
148 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
150 // the object may be null or dead
151 const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
152 if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
154 aViewPort->removeItem( aPrs );
161 void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
162 const int theViewerId,
163 const bool theIsForced )
165 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
169 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
173 bool anIsDisplayed = false;
174 GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
175 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
177 Handle(HYDROData_Object) anObj = theObjs.Value( i );
181 HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList );
183 bool anIsInserted = ( aPrs != 0 );
184 if( !aPrs || aPrs->getIsToUpdate() || theIsForced )
186 if( HYDROGUI_PrsDriver* aDriver = getDriver( anObj ) )
188 if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
189 aViewPort->addItem( aPrs );
195 bool anIsVisible = anObj->GetVisibility();
196 aPrs->setVisible( anIsVisible );
203 void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
205 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
209 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
213 GraphicsView_ObjectListIterator anIter( HYDROGUI_Tool::GetPrsList( aViewPort ) );
214 while( anIter.hasNext() )
216 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
218 Handle(HYDROData_Object) anObject = aPrs->getObject();
219 if( !anObject.IsNull() && anObject->IsRemoved() )
221 aViewPort->removeItem( aPrs );
228 HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object)& theObj )
230 HYDROGUI_PrsDriver* aDriver = NULL;
231 ObjectKind aKind = theObj->GetKind();
232 PrsDriversMap::iterator anIter = myPrsDriversMap.find( aKind );
233 if( anIter != myPrsDriversMap.end() )
234 aDriver = anIter.value();
240 aDriver = new HYDROGUI_PrsImageDriver();
241 myPrsDriversMap[ aKind ] = aDriver;