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_PrsPolylineDriver.h"
30 #include "HYDROGUI_Tool.h"
32 #include <GraphicsView_Viewer.h>
33 #include <GraphicsView_ViewPort.h>
35 HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule )
36 : myModule( theModule )
40 HYDROGUI_Displayer::~HYDROGUI_Displayer()
44 void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
45 const int theViewerId )
47 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
51 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
55 GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
56 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
58 Handle(HYDROData_Object) anObj = theObjs.Value( i );
62 if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
63 aPrs->setIsToUpdate( true );
67 void HYDROGUI_Displayer::UpdateAll( const int theViewerId,
69 const bool theIsForced )
72 EraseAll( theViewerId );
73 DisplayAll( theViewerId, theIsForced );
76 void HYDROGUI_Displayer::EraseAll( const int theViewerId )
78 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
82 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
86 GraphicsView_ObjectListIterator anIter( HYDROGUI_Tool::GetPrsList( aViewPort ) );
87 while( anIter.hasNext() )
89 if( GraphicsView_Object* anObject = anIter.next() )
91 aViewPort->removeItem( anObject );
97 void HYDROGUI_Displayer::DisplayAll( const int theViewerId,
98 const bool theIsForced )
100 HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
103 HYDROData_SequenceOfObjects aSeq;
104 HYDROGUI_Tool::GetPrsSubObjects( aModel, theViewerId, aSeq );
105 Update( aSeq, theViewerId, theIsForced );
109 void HYDROGUI_Displayer::Update( const HYDROData_SequenceOfObjects& theObjs,
110 const int theViewerId,
111 const bool theIsForced )
113 // First of all, kill all bad presentations
114 purgeObjects( theViewerId );
116 // Now dig in the data model
117 HYDROData_SequenceOfObjects anObjectsToErase, anObjectsToDisplay;
119 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
121 const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
123 anObjectsToErase.Append( anObj );
125 anObjectsToDisplay.Append( anObj );
128 if( anObjectsToErase.Length() )
129 Erase( anObjectsToErase, theViewerId );
130 if( anObjectsToDisplay.Length() )
131 Display( anObjectsToDisplay, theViewerId, theIsForced );
134 void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
135 const int theViewerId )
137 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
141 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
145 HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)myModule->dataModel();
148 GraphicsView_ObjectList anObjectList = HYDROGUI_Tool::GetPrsList( aViewPort );
149 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
151 // the object may be null or dead
152 const Handle(HYDROData_Object)& anObj = theObjs.Value( i );
153 if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
155 aViewPort->removeItem( aPrs );
162 void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
163 const int theViewerId,
164 const bool theIsForced )
166 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
170 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
174 bool anIsDisplayed = false;
175 GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
176 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
178 Handle(HYDROData_Object) anObj = theObjs.Value( i );
182 HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList );
184 bool anIsInserted = ( aPrs != 0 );
185 if( !aPrs || aPrs->getIsToUpdate() || theIsForced )
187 if( HYDROGUI_PrsDriver* aDriver = getDriver( anObj ) )
189 if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
190 aViewPort->addItem( aPrs );
196 bool anIsVisible = anObj->GetVisibility();
197 aPrs->setVisible( anIsVisible );
204 void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
206 GraphicsView_Viewer* aViewer = myModule->getViewer( theViewerId );
210 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
214 GraphicsView_ObjectListIterator anIter( HYDROGUI_Tool::GetPrsList( aViewPort ) );
215 while( anIter.hasNext() )
217 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
219 Handle(HYDROData_Object) anObject = aPrs->getObject();
220 if( !anObject.IsNull() && anObject->IsRemoved() )
222 aViewPort->removeItem( aPrs );
229 HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Object)& theObj )
231 HYDROGUI_PrsDriver* aDriver = NULL;
232 ObjectKind aKind = theObj->GetKind();
233 PrsDriversMap::iterator anIter = myPrsDriversMap.find( aKind );
234 if( anIter != myPrsDriversMap.end() )
235 aDriver = anIter.value();
241 aDriver = new HYDROGUI_PrsImageDriver();
242 myPrsDriversMap[ aKind ] = aDriver;
245 aDriver = new HYDROGUI_PrsPolylineDriver();
246 myPrsDriversMap[ aKind ] = aDriver;