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>
24 #include <Select3D_SensitiveBox.hxx>
25 #include <StdPrs_ShadedShape.hxx>
26 #include <StdPrs_WFDeflectionShape.hxx>
27 #include <StdSelect.hxx>
28 #include <StdSelect_BRepOwner.hxx>
29 #include <StdSelect_BRepSelectionTool.hxx>
30 #include <TopoDS_Face.hxx>
34 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
39 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
44 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
49 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
51 myColorScale = theColorScale;
54 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
59 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
64 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
66 Quantity_Color aResult;
68 if( !myColorScale.IsNull() && !myTable.IsNull() )
70 double aCoeff = myTable->Get( theStricklerType, 0.0 );
71 Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
75 return Quantity_Color();
78 if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
80 QColor aColor = myTable->GetColor( theStricklerType );
81 return HYDROData_Tool::toOccColor( aColor );
84 HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
85 for( ; anIt.More(); anIt.Next() )
87 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
88 if( aTable->HasType( theStricklerType ) )
90 QColor aColor = myTable->GetColor( theStricklerType );
91 return HYDROData_Tool::toOccColor( aColor );
95 return Quantity_Color();
98 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
99 const Handle(Prs3d_Presentation)& thePresentation,
100 const Standard_Integer theMode )
102 if( myLCMap.IsNull() )
110 bool isShaded = theMode==AIS_Shaded;
111 HYDROData_LandCoverMap::Iterator anIt( myLCMap );
112 for( ; anIt.More(); anIt.Next() )
114 TopoDS_Face aFace = anIt.Face();
115 QString aStricklerType = anIt.StricklerType();
116 Quantity_Color aColor = GetColor( aStricklerType );
120 StdPrs_ShadedShape::Add( thePresentation, aFace, myDrawer );
122 StdPrs_WFDeflectionShape::Add( thePresentation, aFace, myDrawer );
131 void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
132 const Standard_Integer theMode )
134 if( myLCMap.IsNull() )
139 theSelection->Clear();
140 Bnd_Box B = BoundingBox();
141 Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this );
142 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B );
143 theSelection->Add( aSensitiveBox );
147 Standard_Real aDeflection = Prs3d::GetDeflection( myLCMap->GetShape(), myDrawer );
148 HYDROData_LandCoverMap::Iterator anIt( myLCMap );
149 for( ; anIt.More(); anIt.Next() )
151 StdSelect_BRepSelectionTool::Load( theSelection,
156 myDrawer->HLRAngle(),
157 myDrawer->IsAutoTriangulation());
159 StdSelect::SetDrawerForBRepOwner( theSelection, myDrawer );