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_PrsZoneDriver.h"
31 #include "HYDROGUI_Tool.h"
33 #include <GraphicsView_Viewer.h>
34 #include <GraphicsView_ViewPort.h>
36 HYDROGUI_Displayer::HYDROGUI_Displayer( HYDROGUI_Module* theModule )
37 : HYDROGUI_AbstractDisplayer( theModule )
41 HYDROGUI_Displayer::~HYDROGUI_Displayer()
45 void HYDROGUI_Displayer::SetToUpdate( const HYDROData_SequenceOfObjects& theObjs,
46 const int theViewerId )
48 GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
52 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
56 GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
57 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
59 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
63 if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
64 aPrs->setIsToUpdate( true );
68 void HYDROGUI_Displayer::EraseAll( const int theViewerId )
70 GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
74 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
78 GraphicsView_ObjectListIterator anIter( HYDROGUI_Tool::GetPrsList( aViewPort ) );
79 while( anIter.hasNext() )
81 if( GraphicsView_Object* anObject = anIter.next() )
83 aViewPort->removeItem( anObject );
89 void HYDROGUI_Displayer::Erase( const HYDROData_SequenceOfObjects& theObjs,
90 const int theViewerId )
92 GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
96 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
100 HYDROGUI_DataModel* aModel = (HYDROGUI_DataModel*)module()->dataModel();
103 GraphicsView_ObjectList anObjectList = HYDROGUI_Tool::GetPrsList( aViewPort );
104 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
106 // the object may be null or dead
107 const Handle(HYDROData_Entity)& anObj = theObjs.Value( i );
108 if( HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList ) )
110 aViewPort->removeItem( aPrs );
117 void HYDROGUI_Displayer::Display( const HYDROData_SequenceOfObjects& theObjs,
118 const int theViewerId,
119 const bool theIsForced,
120 const bool theDoFitAll)
122 GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
126 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
130 bool anIsDisplayed = false;
131 GraphicsView_ObjectList anObjectList = aViewPort->getObjects();
132 for( int i = 1, n = theObjs.Length(); i <= n; i++ )
134 Handle(HYDROData_Entity) anObj = theObjs.Value( i );
138 HYDROGUI_Prs* aPrs = HYDROGUI_Tool::GetPresentation( anObj, anObjectList );
140 bool anIsInserted = ( aPrs != 0 );
141 if( !aPrs || aPrs->getIsToUpdate() || theIsForced )
143 if( HYDROGUI_PrsDriver* aDriver = getDriver( anObj ) )
145 if( aDriver->Update( anObj, aPrs ) && aPrs && !anIsInserted )
146 aViewPort->addItem( aPrs );
152 bool anIsVisible = module()->isObjectVisible( (size_t)aViewer, anObj );
153 aPrs->setVisible( anIsVisible );
157 aViewPort->onBoundingRectChanged(); // specific of HYDRO module
164 void HYDROGUI_Displayer::purgeObjects( const int theViewerId )
166 GraphicsView_Viewer* aViewer = module()->getViewer( theViewerId );
170 GraphicsView_ViewPort* aViewPort = aViewer->getActiveViewPort();
174 GraphicsView_ObjectListIterator anIter( HYDROGUI_Tool::GetPrsList( aViewPort ) );
175 while( anIter.hasNext() )
177 if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
179 Handle(HYDROData_Entity) anObject = aPrs->getObject();
180 if( !anObject.IsNull() && anObject->IsRemoved() )
182 aViewPort->removeItem( aPrs );
189 HYDROGUI_PrsDriver* HYDROGUI_Displayer::getDriver( const Handle(HYDROData_Entity)& theObj )
191 HYDROGUI_PrsDriver* aDriver = NULL;
192 ObjectKind aKind = theObj->GetKind();
193 PrsDriversMap::iterator anIter = myPrsDriversMap.find( aKind );
194 if( anIter != myPrsDriversMap.end() )
195 aDriver = anIter.value();
201 aDriver = new HYDROGUI_PrsImageDriver();
204 aDriver = new HYDROGUI_PrsPolylineDriver();
207 aDriver = new HYDROGUI_PrsZoneDriver();
214 myPrsDriversMap[ aKind ] = aDriver;
220 QString HYDROGUI_Displayer::GetType() const
222 return GraphicsView_Viewer::Type();