]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_LandCoverMapPrs.cxx
Salome HOME
Merge branch 'BR_H2018_2' of https://codev-tuleap.cea.fr/plugins/git/salome/hydro...
[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 <SelectMgr_SequenceOfOwner.hxx>
25 #include <StdPrs_WFShape.hxx>
26 #include <StdSelect_BRepOwner.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <QColor>
29 #include <QString>
30
31 const Quantity_Color EDGES_COLOR = Quantity_NOC_SLATEGRAY;
32 const int HILIGHT_ISO_NB = 10;
33
34 IMPLEMENT_STANDARD_RTTIEXT( HYDROGUI_LandCoverMapPrs, AIS_ColoredShape )
35
36 HYDROGUI_LandCoverMapPrs::HYDROGUI_LandCoverMapPrs( const Handle(HYDROData_LandCoverMap)& theMap )
37   : AIS_ColoredShape( theMap->GetShape() )
38 {
39   SetLandCoverMap( theMap );
40   SetAutoHilight( Standard_False );
41   SetHilightAttributes( EDGES_COLOR );
42 }
43
44 HYDROGUI_LandCoverMapPrs::~HYDROGUI_LandCoverMapPrs()
45 {
46 }
47
48 Handle(HYDROData_LandCoverMap) HYDROGUI_LandCoverMapPrs::GetLandCoverMap() const
49 {
50   return myLCMap;
51 }
52
53 void HYDROGUI_LandCoverMapPrs::SetLandCoverMap( const Handle(HYDROData_LandCoverMap)& theMap )
54 {
55   myLCMap = theMap;
56   UpdateColors();
57 }
58
59 void HYDROGUI_LandCoverMapPrs::UpdateColors()
60 {
61   SetMaterial( Graphic3d_NOM_PLASTIC );
62   if( myLCMap.IsNull() )
63   {
64     Set( TopoDS_Shape() );
65     return;
66   }
67   
68   Set( myLCMap->GetShape() );
69   HYDROData_LandCoverMap::Explorer anIt( myLCMap );
70   for( ; anIt.More(); anIt.Next() )
71   {
72     TopoDS_Face aFace = anIt.Face();
73     QString aStricklerType = anIt.StricklerType();
74     Quantity_Color aColor = GetColor( aStricklerType );
75     SetCustomColor( aFace, aColor );
76     SetCustomWidth( aFace, 1.0 );
77   } 
78   SetTransparency( myLCMap->GetTransparency() );
79 }
80
81 Handle(AIS_ColorScale) HYDROGUI_LandCoverMapPrs::GetColorScale() const
82 {
83   return myColorScale;
84 }
85
86 void HYDROGUI_LandCoverMapPrs::SetColorScale( const Handle(AIS_ColorScale)& theColorScale )
87 {
88   myColorScale = theColorScale;
89   double aMin = 0, aMax = 0;
90   if( myTable.IsNull() )
91   {
92     //TODO: go through all Strickler tables in the document to get the global range
93   }
94   else
95     myTable->GetCoefficientRange( aMin, aMax );
96
97   myColorScale->SetRange( aMin, aMax );
98   UpdateColors();
99 }
100
101 Handle(HYDROData_StricklerTable) HYDROGUI_LandCoverMapPrs::GetTable() const
102 {
103   return myTable;
104 }
105
106 void HYDROGUI_LandCoverMapPrs::SetTable( const Handle(HYDROData_StricklerTable)& theTable )
107 {
108   myTable = theTable;
109 }
110
111 Quantity_Color HYDROGUI_LandCoverMapPrs::GetColor( const QString& theStricklerType ) const
112 {
113   Quantity_Color aResult;
114
115   if( !myColorScale.IsNull() && !myTable.IsNull() )
116   {
117     double aCoeff = myTable->Get( theStricklerType, 0.0 );
118     Standard_Boolean isOK = myColorScale->FindColor( aCoeff, aResult );
119     if( isOK )
120       return aResult;
121     else
122       return Quantity_Color();
123   }
124
125   QColor aColor = HYDROData_Document::Document( myLCMap->Label())->GetAssociatedColor(theStricklerType, myTable);
126
127   if (aColor.isValid())
128     return HYDROData_Tool::toOccColor(aColor);
129   else
130     return Quantity_Color();
131 }
132
133 void HYDROGUI_LandCoverMapPrs::Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
134                                         const Handle(Prs3d_Presentation)& thePresentation,
135                                         const Standard_Integer theMode )
136 {
137   thePresentation->Clear();
138
139   myDrawer->UIsoAspect()->SetNumber( 0 );
140   myDrawer->VIsoAspect()->SetNumber( 0 );
141   myDrawer->LineAspect()->SetColor( EDGES_COLOR );
142   myDrawer->FaceBoundaryAspect()->SetColor( EDGES_COLOR );
143   myDrawer->FreeBoundaryAspect()->SetColor( EDGES_COLOR );
144
145   switch( theMode )
146   {
147   case AIS_WireFrame:
148   case AIS_Shaded:
149     AIS_ColoredShape::Compute( thePresentationManager, thePresentation, theMode );
150     break;
151   }
152
153   if( theMode==AIS_Shaded )
154     StdPrs_WFShape::Add( thePresentation, Shape(), myDrawer );
155 }
156
157 void HYDROGUI_LandCoverMapPrs::HilightSelected( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
158                                                 const SelectMgr_SequenceOfOwner& theOwners )
159 {
160   Handle(Prs3d_Presentation) aSelectPrs = GetSelectPresentation( thePresentationManager );
161
162   SetHilightAttributes( EDGES_COLOR );
163
164   for( int i=1, n=theOwners.Length(); i<=n; i++ )
165   {
166     Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast( theOwners.Value( i ) );
167     if( !anOwner.IsNull() )
168       StdPrs_WFShape::Add( aSelectPrs, anOwner->Shape(), HilightAttributes() );
169   }
170
171   HilightAttributes()->UIsoAspect()->SetNumber( 0 );
172   HilightAttributes()->VIsoAspect()->SetNumber( 0 );
173
174   aSelectPrs->SetDisplayPriority( 9 );
175   aSelectPrs->Display();
176 }
177
178 void HYDROGUI_LandCoverMapPrs::SetHilightAttributes( const Quantity_Color& theEdgesColor )
179 {
180   if (HilightAttributes().IsNull())
181     AIS_ColoredShape::SetHilightAttributes(new Prs3d_Drawer());
182   HilightAttributes()->UIsoAspect()->SetNumber( HILIGHT_ISO_NB );
183   HilightAttributes()->UIsoAspect()->SetColor( theEdgesColor );
184   HilightAttributes()->VIsoAspect()->SetNumber( HILIGHT_ISO_NB );
185   HilightAttributes()->VIsoAspect()->SetColor( theEdgesColor );
186   HilightAttributes()->LineAspect()->SetColor( theEdgesColor );
187   HilightAttributes()->FaceBoundaryAspect()->SetColor( theEdgesColor );
188   HilightAttributes()->FreeBoundaryAspect()->SetColor( theEdgesColor );
189 }