Salome HOME
0128a7a311d846db9a83011603ebd4ec165a0ab5
[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.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>
31 #include <QColor>
32 #include <QString>
33
34 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
35 {
36   return myLCMap;
37 }
38
39 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
40 {
41   myLCMap = theMap;
42 }
43
44 Handle(Aspect_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
45 {
46   return myColorScale;
47 }
48
49 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(Aspect_ColorScale)& theColorScale )
50 {
51   myColorScale = theColorScale;
52 }
53
54 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
55 {
56   return myTable;
57 }
58
59 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
60 {
61   myTable = theTable;
62 }
63
64 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
65 {
66   Quantity_Color aResult;
67
68   if( !myColorScale.IsNull() && !myTable.IsNull() )
69   {
70     double aCoeff = myTable->Get( theStricklerType, 0.0 );
71     Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
72     if( isOK )
73       return aResult;
74     else
75       return Quantity_Color();
76   }
77
78   if( !myTable.IsNull() && myTable->HasType( theStricklerType ) )
79   {
80     QColor aColor = myTable->GetColor( theStricklerType );
81     return HYDROData_Tool::toOccColor( aColor );
82   }
83
84   HYDROData_Iterator anIt( HYDROData_Document::Document( myLCMap->Label() ), KIND_STRICKLER_TABLE );
85   for( ; anIt.More(); anIt.Next() )
86   {
87     Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( anIt.Current() );
88     if( aTable->HasType( theStricklerType ) )
89     {
90       QColor aColor = myTable->GetColor( theStricklerType );
91       return HYDROData_Tool::toOccColor( aColor );
92     }
93   }
94
95   return Quantity_Color();
96 }
97
98 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
99                                         const Handle(Prs3d_Presentation)& thePresentation,
100                                         const Standard_Integer theMode )
101 {
102   if( myLCMap.IsNull() )
103     return;
104
105   switch( theMode )
106   {
107   case AIS_WireFrame:
108   case AIS_Shaded:
109     {
110       bool isShaded = theMode==AIS_Shaded;
111       HYDROData_LandCoverMap::Iterator anIt( myLCMap );
112       for( ; anIt.More(); anIt.Next() )
113       {
114         TopoDS_Face aFace = anIt.Face();
115         QString aStricklerType = anIt.StricklerType();
116         Quantity_Color aColor = GetColor( aStricklerType );
117         SetColor( aColor );
118
119         if( isShaded )
120           StdPrs_ShadedShape::Add( thePresentation, aFace, myDrawer );
121         else
122           StdPrs_WFDeflectionShape::Add( thePresentation, aFace, myDrawer );
123       }
124     }
125     break;
126   default:
127     break;
128   }
129 }
130
131 void HYDROGUI_LandCoverMapPrs::ComputeSelection( const Handle(SelectMgr_Selection)& theSelection,
132                                                  const Standard_Integer theMode )
133 {
134   if( myLCMap.IsNull() )
135     return;
136
137   if( theMode==0 )
138   {
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 );
144   }
145   else
146   {
147     Standard_Real aDeflection = Prs3d::GetDeflection( myLCMap->GetShape(), myDrawer );
148     HYDROData_LandCoverMap::Iterator anIt( myLCMap );
149     for( ; anIt.More(); anIt.Next() )
150     {
151       StdSelect_BRepSelectionTool::Load( theSelection,
152                                          this,
153                                          anIt.Face(),
154                                          TopAbs_FACE,
155                                          aDeflection,
156                                          myDrawer->HLRAngle(),
157                                          myDrawer->IsAutoTriangulation());
158     }
159     StdSelect::SetDrawerForBRepOwner( theSelection, myDrawer );
160   }
161 }