1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_LandCoverMapPrs.h>
20 #include <HYDROData_Iterator.h>
21 #include <HYDROData_Tool.h>
22 #include <AIS_DisplayMode.hxx>
23 #include <Prs3d_IsoAspect.hxx>
24 #include <StdPrs_WFDeflectionShape.hxx>
25 #include <TopoDS_Face.hxx>
29 IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
30 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
32 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
33 : AIS_ColoredShape( theMap->GetShape() )
35 SetLandCoverMap( theMap );
38 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
42 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
47 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
53 void HYDROGUI_LandCoverMapPrs::UpdateColors()
55 Set( myLCMap->GetShape() );
56 SetMaterial( Graphic3d_NOM_PLASTIC );
57 HYDROData_LandCoverMap::Iterator anIt( myLCMap );
58 for( ; anIt.More(); anIt.Next() )
60 TopoDS_Face aFace = anIt.Face();
61 QString aStricklerType = anIt.StricklerType();
62 Quantity_Color aColor = GetColor( aStricklerType );
63 SetCustomColor( aFace, aColor );
64 SetCustomWidth( aFace, 1.0 );
68 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
73 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
75 myColorScale = theColorScale;
76 double aMin = 0, aMax = 0;
77 if( myTable.IsNull() )
79 //TODO: go through all Strickler tables in the document to get the global range
82 myTable->GetCoefficientRange( aMin, aMax );
84 myColorScale->SetRange( aMin, aMax );
88 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
93 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
98 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
100 Quantity_Color aResult;
102 if( !myColorScale.IsNull() && !myTable.IsNull() )
104 double aCoeff = myTable->Get( theStricklerType, 0.0 );
105 Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
109 return Quantity_Color();
112 if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
114 QColor aColor = myTable->GetColor( theStricklerType );
115 return HYDROData_Tool::toOccColor( aColor );
118 HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
119 for( ; anIt.More(); anIt.Next() )
121 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
122 if( aTable->HasType( theStricklerType ) )
124 QColor aColor = aTable->GetColor( theStricklerType );
125 return HYDROData_Tool::toOccColor( aColor );
129 return Quantity_Color();
132 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
133 const Handle(Prs3d_Presentation)& thePresentation,
134 const Standard_Integer theMode )
136 thePresentation->Clear();
138 Quantity_Color anEdgeColor = Quantity_NOC_WHITE;
140 myDrawer->UIsoAspect()->SetNumber( 0 );
141 myDrawer->VIsoAspect()->SetNumber( 0 );
142 myDrawer->LineAspect()->SetColor( anEdgeColor );
143 myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor );
144 myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor );
150 AIS_ColoredShape::Compute( thePresentationManager, thePresentation, theMode );
154 if( theMode==AIS_Shaded )
155 StdPrs_WFDeflectionShape::Add( thePresentation, Shape(), myDrawer );