Salome HOME
refs #662: the tests for land cover presentations
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverMapPrs.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
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>
26 #include <QColor>
27 #include <QString>
28
29 IMPLEMENT_STANDARD_HANDLE( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
30 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
31
32 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
33   : AIS_ColoredShape( theMap->GetShape() )
34 {
35   SetLandCoverMap( theMap );
36 }
37
38 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
39 {
40 }
41
42 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
43 {
44   return myLCMap;
45 }
46
47 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
48 {
49   myLCMap = theMap;
50   UpdateColors();
51 }
52
53 void HYDROGUI_LandCoverMapPrs::UpdateColors()
54 {
55   Set( myLCMap->GetShape() );
56   SetMaterial( Graphic3d_NOM_PLASTIC );
57   HYDROData_LandCoverMap::Iterator anIt( myLCMap );
58   for( ; anIt.More(); anIt.Next() )
59   {
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 );
65   }
66 }
67
68 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
69 {
70   return myColorScale;
71 }
72
73 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
74 {
75   myColorScale = theColorScale;
76   double aMin = 0, aMax = 0;
77   if( myTable.IsNull() )
78   {
79     //TODO: go through all Strickler tables in the document to get the global range
80   }
81   else
82     myTable->GetCoefficientRange( aMin, aMax );
83
84   myColorScale->SetRange( aMin, aMax );
85   UpdateColors();
86 }
87
88 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
89 {
90   return myTable;
91 }
92
93 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
94 {
95   myTable = theTable;
96 }
97
98 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
99 {
100   Quantity_Color aResult;
101
102   if( !myColorScale.IsNull() && !myTable.IsNull() )
103   {
104     double aCoeff = myTable->Get( theStricklerType, 0.0 );
105     Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
106     if( isOK )
107       return aResult;
108     else
109       return Quantity_Color();
110   }
111
112   if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
113   {
114     QColor aColor = myTable->GetColor( theStricklerType );
115     return HYDROData_Tool::toOccColor( aColor );
116   }
117
118   HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
119   for( ; anIt.More(); anIt.Next() )
120   {
121     Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
122     if( aTable->HasType( theStricklerType ) )
123     {
124       QColor aColor = aTable->GetColor( theStricklerType );
125       return HYDROData_Tool::toOccColor( aColor );
126     }
127   }
128
129   return Quantity_Color();
130 }
131
132 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
133                                         const Handle(Prs3d_Presentation)& thePresentation,
134                                         const Standard_Integer theMode )
135 {
136   thePresentation->Clear();
137
138   Quantity_Color anEdgeColor = Quantity_NOC_WHITE;
139
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 );
145
146   switch( theMode )
147   {
148   case AIS_WireFrame:
149   case AIS_Shaded:
150     AIS_ColoredShape::Compute( thePresentationManager, thePresentation, theMode );
151     break;
152   }
153
154   if( theMode==AIS_Shaded )
155     StdPrs_WFDeflectionShape::Add( thePresentation, Shape(), myDrawer );
156 }
157