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 <BRepMesh_IncrementalMesh.hxx>
24 #include <Graphic3d_ArrayOfTriangles.hxx>
25 #include <Graphic3d_AspectFillArea3d.hxx>
26 #include <Poly_Triangulation.hxx>
27 #include <Prs3d_Root.hxx>
28 #include <Select3D_SensitiveBox.hxx>
29 #include <StdSelect_BRepOwner.hxx>
30 #include <TopoDS_Face.hxx>
34 IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject )
35 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_InteractiveObject )
37 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
38 : AIS_InteractiveObject()
40 SetLandCoverMap( theMap );
43 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
47 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
52 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
57 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
62 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
64 myColorScale = theColorScale;
67 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
72 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
77 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
79 Quantity_Color aResult;
81 if( !myColorScale.IsNull() && !myTable.IsNull() )
83 double aCoeff = myTable->Get( theStricklerType, 0.0 );
84 Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
88 return Quantity_Color();
91 if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
93 QColor aColor = myTable->GetColor( theStricklerType );
94 return HYDROData_Tool::toOccColor( aColor );
97 HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
98 for( ; anIt.More(); anIt.Next() )
100 Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
101 if( aTable->HasType( theStricklerType ) )
103 QColor aColor = myTable->GetColor( theStricklerType );
104 return HYDROData_Tool::toOccColor( aColor );
108 return Quantity_Color();
111 void DrawTriangulation( const Handle(Prs3d_Presentation)& thePresentation,
112 const Handle(Poly_Triangulation)& theTriangulation,
113 const Quantity_Color& theColor )
115 const TColgp_Array1OfPnt& aNodesArray = theTriangulation->Nodes();
116 int aNbNodes = aNodesArray.Length();
118 const Poly_Array1OfTriangle& aTrianglesArray = theTriangulation->Triangles();
119 int aNbTriangles = aTrianglesArray.Length();
121 Handle( Graphic3d_ArrayOfTriangles ) anArray = new Graphic3d_ArrayOfTriangles
122 ( aNbNodes, aNbTriangles * 3, Standard_True, Standard_True, Standard_False );
124 Prs3d_Root::NewGroup( thePresentation );
125 Handle( Graphic3d_Group ) aGroup = Prs3d_Root::CurrentGroup( thePresentation );
126 Handle( Graphic3d_AspectFillArea3d ) anAspect = new Graphic3d_AspectFillArea3d();
127 Graphic3d_MaterialAspect aMaterialAspect( Graphic3d_NOM_PLASTIC );
128 aMaterialAspect.SetColor( theColor );
129 anAspect->SetFrontMaterial( aMaterialAspect );
130 anAspect->SetBackMaterial( aMaterialAspect );
134 for( i = aNodesArray.Lower(); i <= aNodesArray.Upper(); i++ )
136 anArray->AddVertex( aNodesArray( i ), theColor );
137 anArray->SetVertexNormal( i, 0, 0, 1 );
140 Standard_Integer anIndexTriangle[3] = { 0, 0, 0 };
141 for( i = aTrianglesArray.Lower(); i<= aTrianglesArray.Upper(); i++ )
143 aTrianglesArray( i ).Get( anIndexTriangle[0], anIndexTriangle[1], anIndexTriangle[2] );
144 anArray->AddEdge( anIndexTriangle[0] );
145 anArray->AddEdge( anIndexTriangle[1] );
146 anArray->AddEdge( anIndexTriangle[2] );
148 aGroup->AddPrimitiveArray( anArray );
149 //aGroup->SetGroupPrimitivesAspect( anAspect );
152 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
153 const Handle(Prs3d_Presentation)& thePresentation,
154 const Standard_Integer theMode )
156 if( myLCMap.IsNull() )
159 thePresentation->Clear();
160 const double aLinearDeflection = 1E-2;
161 BRepMesh_IncrementalMesh aMesh( myLCMap->GetShape(), aLinearDeflection );
163 bool isOK = aMesh.IsDone();
169 HYDROData_LandCoverMap::Iterator anIt( myLCMap );
170 for( ; anIt.More(); anIt.Next() )
172 TopoDS_Face aFace = anIt.Face();
173 QString aStricklerType = anIt.StricklerType();
174 Quantity_Color aColor = GetColor( aStricklerType );
176 TopLoc_Location aLocation;
177 Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation( aFace, aLocation );
178 DrawTriangulation( thePresentation, aTriangulation, aColor );
187 void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
188 const Standard_Integer theMode )
190 if( myLCMap.IsNull() )
195 /*theSelection->Clear();
196 Bnd_Box B = BoundingBox();
197 Handle(StdSelect_BRepOwner) anOwner = new StdSelect_BRepOwner( myLCMap->GetShape(), this );
198 Handle(Select3D_SensitiveBox) aSensitiveBox = new Select3D_SensitiveBox( anOwner, B );
199 theSelection->Add( aSensitiveBox );*/