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 <Prs3d_IsoAspect.hxx>
25 #include <Prs3d_LineAspect.hxx>
26 #include <Prs3d_ShadingAspect.hxx>
27 #include <Graphic3d_AspectFillArea3d.hxx>
28 #include <Select3D_SensitiveBox.hxx>
29 #include <StdPrs_ShadedShape.hxx>
30 #include <StdPrs_WFShape.hxx>
31 #include <StdSelect.hxx>
32 #include <StdSelect_BRepOwner.hxx>
33 #include <StdSelect_BRepSelectionTool.hxx>
34 #include <TopoDS_Face.hxx>
38 IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_Shape )
39 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_Shape )
41 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
42 : AIS_Shape( TopoDS_Shape() )
44 SetLandCoverMap( theMap );
47 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
51 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
56 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
59 Set( theMap->GetShape() );
62 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
67 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
69 myColorScale = theColorScale;
72 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
77 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
82 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
84 Quantity_Color aResult;
86 if( !myColorScale.IsNull() && !myTable.IsNull() )
88 double aCoeff = myTable->Get( theStricklerType, 0.0 );
89 Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
93 return Quantity_Color();
96 if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
98 QColor aColor = myTable->GetColor( theStricklerType );
99 return HYDROData_Tool::toOccColor( aColor );
102 HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
103 for( ; anIt.More(); anIt.Next() )
105 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
106 if( aTable->HasType( theStricklerType ) )
108 QColor aColor = myTable->GetColor( theStricklerType );
109 return HYDROData_Tool::toOccColor( aColor );
113 return Quantity_Color();
116 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
117 const Handle(Prs3d_Presentation)& thePresentation,
118 const Standard_Integer theMode )
120 if( myLCMap.IsNull() )
123 thePresentation->Clear();
124 SetMaterial( Graphic3d_NOM_PLASTIC );
126 Quantity_Color anEdgeColor = Quantity_NOC_WHITE;
127 myDrawer->LineAspect()->SetColor( anEdgeColor );
128 myDrawer->FaceBoundaryAspect()->SetColor( anEdgeColor );
129 myDrawer->FreeBoundaryAspect()->SetColor( anEdgeColor );
130 myDrawer->UIsoAspect()->SetNumber( 0 );
131 myDrawer->VIsoAspect()->SetNumber( 0 );
138 bool isShaded = theMode==AIS_Shaded;
139 HYDROData_LandCoverMap::Iterator anIt( myLCMap );
140 for( ; anIt.More(); anIt.Next() )
142 TopoDS_Face aFace = anIt.Face();
145 QString aStricklerType = anIt.StricklerType();
146 Quantity_Color aColor = GetColor( aStricklerType );
147 Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d();
148 Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC );
149 aMaterialAspect.SetColor( aColor );
150 anAspect->SetFrontMaterial( aMaterialAspect );
151 anAspect->SetBackMaterial( aMaterialAspect );
153 Handle(Graphic3d_AspectFillArea3d) aGlobalAspect = myDrawer->ShadingAspect()->Aspect();
154 myDrawer->ShadingAspect()->SetAspect( anAspect );
155 StdPrs_ShadedShape::Add( thePresentation, aFace, myDrawer );
156 myDrawer->ShadingAspect()->SetAspect( aGlobalAspect );
158 StdPrs_WFShape::Add( thePresentation, aFace, myDrawer );
162 StdPrs_WFShape::Add( thePresentation, aFace, myDrawer );
172 void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
173 const Standard_Integer theMode )
175 if( myLCMap.IsNull() )
180 theSelection->Clear();
181 Bnd_Box B = BoundingBox();
182 Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this );
183 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B );
184 theSelection->Add( aSensitiveBox );
188 Standard_Real aDeflection = Prs3d::GetDeflection( myLCMap->GetShape(), myDrawer );
189 HYDROData_LandCoverMap::Iterator anIt( myLCMap );
190 for( ; anIt.More(); anIt.Next() )
192 StdSelect_BRepSelectionTool::Load( theSelection,
197 myDrawer->HLRAngle(),
198 myDrawer->IsAutoTriangulation());
200 StdSelect::SetDrawerForBRepOwner( theSelection, myDrawer );