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 <SelectMgr_SequenceOfOwner.hxx>
25 #include <StdPrs_WFShape.hxx>
26 #include <StdSelect_BRepOwner.hxx>
27 #include <TopoDS_Face.hxx>
31 const Quantity_Color EDGES_COLOR = Quantity_NOC_SLATEGRAY;
32 const int HILIGHT_ISO_NB = 10;
34 IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
35 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
37 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
38 : AIS_ColoredShape( theMap->GetShape() )
40 SetLandCoverMap( theMap );
41 SetAutoHilight( Standard_False );
42 SetHilightAttributes( EDGES_COLOR );
45 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
49 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
54 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
60 void HYDROGUI_LandCoverMapPrs::UpdateColors()
62 SetMaterial( Graphic3d_NOM_PLASTIC );
63 if( myLCMap.IsNull() )
65 Set( TopoDS_Shape() );
69 Set( myLCMap->GetShape() );
70 HYDROData_LandCoverMap::Explorer anIt( myLCMap );
71 for( ; anIt.More(); anIt.Next() )
73 TopoDS_Face aFace = anIt.Face();
74 QString aStricklerType = anIt.StricklerType();
75 Quantity_Color aColor = GetColor( aStricklerType );
76 SetCustomColor( aFace, aColor );
77 SetCustomWidth( aFace, 1.0 );
79 SetTransparency( myLCMap->GetTransparency() );
82 Handle(AIS_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
87 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(AIS_ColorScale)& theColorScale )
89 myColorScale = theColorScale;
90 double aMin = 0, aMax = 0;
91 if( myTable.IsNull() )
93 //TODO: go through all Strickler tables in the document to get the global range
96 myTable->GetCoefficientRange( aMin, aMax );
98 myColorScale->SetRange( aMin, aMax );
102 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
107 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
112 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
114 Quantity_Color aResult;
116 if( !myColorScale.IsNull() && !myTable.IsNull() )
118 double aCoeff = myTable->Get( theStricklerType, 0.0 );
119 Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
123 return Quantity_Color();
126 QColor aColor = HYDROData_Document::Document( myLCMap->Label())->GetAssociatedColor(theStricklerType, myTable);
128 if (aColor.isValid())
129 return HYDROData_Tool::toOccColor(aColor);
131 return Quantity_Color();
134 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
135 const Handle(Prs3d_Presentation)& thePresentation,
136 const Standard_Integer theMode )
138 thePresentation->Clear();
140 myDrawer->UIsoAspect()->SetNumber( 0 );
141 myDrawer->VIsoAspect()->SetNumber( 0 );
142 myDrawer->LineAspect()->SetColor( EDGES_COLOR );
143 myDrawer->FaceBoundaryAspect()->SetColor( EDGES_COLOR );
144 myDrawer->FreeBoundaryAspect()->SetColor( EDGES_COLOR );
150 AIS_ColoredShape::Compute( thePresentationManager, thePresentation, theMode );
154 if( theMode==AIS_Shaded )
155 StdPrs_WFShape::Add( thePresentation, Shape(), myDrawer );
158 void HYDROGUI_LandCoverMapPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
159 const SelectMgr_SequenceOfOwner& theOwners )
161 Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePresentationManager );
163 SetHilightAttributes( EDGES_COLOR );
165 for( int i=1, n=theOwners.Length(); i<=n; i++ )
167 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast( theOwners.Value( i ) );
168 if( !anOwner.IsNull() )
169 StdPrs_WFShape::Add( aSelectPrs, anOwner->Shape(), HilightAttributes() );
172 HilightAttributes()->UIsoAspect()->SetNumber( 0 );
173 HilightAttributes()->VIsoAspect()->SetNumber( 0 );
175 aSelectPrs->SetDisplayPriority( 9 );
176 aSelectPrs->Display();
179 void HYDROGUI_LandCoverMapPrs::SetHilightAttributes( const Quantity_Color& theEdgesColor )
181 HilightAttributes()->UIsoAspect()->SetNumber( HILIGHT_ISO_NB );
182 HilightAttributes()->UIsoAspect()->SetColor( theEdgesColor );
183 HilightAttributes()->VIsoAspect()->SetNumber( HILIGHT_ISO_NB );
184 HilightAttributes()->VIsoAspect()->SetColor( theEdgesColor );
185 HilightAttributes()->LineAspect()->SetColor( theEdgesColor );
186 HilightAttributes()->FaceBoundaryAspect()->SetColor( theEdgesColor );
187 HilightAttributes()->FreeBoundaryAspect()->SetColor( theEdgesColor );