Salome HOME
refs #455: not clear presentation
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeBathymetry.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <HYDROGUI_ShapeBathymetry.h>
24 #include <HYDROGUI_OCCDisplayer.h>
25 #include <HYDROGUI_BathymetryPrs.h>
26 #include <HYDROData_Bathymetry.h>
27
28 #include <AIS_InteractiveContext.hxx>
29 #include <AIS_Drawer.hxx>
30 #include <Aspect_ColorScale.hxx>
31 #include <Prs3d_PointAspect.hxx>
32
33 HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer*                theDisplayer,
34                                                     const Handle(AIS_InteractiveContext)& theContext,
35                                                     const Handle_HYDROData_Bathymetry&    theBathymetry,
36                                                     const int                             theZLayer )
37 : HYDROGUI_Shape( theContext, theBathymetry, theZLayer ),
38   myDisplayer( theDisplayer )
39 {
40 }
41
42 HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry()
43 {
44   myDisplayer->SetToUpdateColorScale();
45 }
46
47 void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection )
48 {
49   setIsToUpdate( false );
50
51   // Try to retrieve information from object
52
53   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
54
55   if ( !aBath.IsNull() )
56   {
57     buildShape();
58     updateShape( false, false );
59   }
60
61   HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
62 }
63
64
65 Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const
66 {
67   Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() );
68   if( !aBath.IsNull() )
69   {
70     Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs();
71     aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0));
72
73     const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
74     int aLower = aBathPoints.Lower();
75     int anUpper = aBathPoints.Upper();
76
77     HYDROGUI_ShapeBathymetry* aThat = const_cast<HYDROGUI_ShapeBathymetry*>( this );
78     aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
79     aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper );
80     for( int i=aLower; i<=anUpper; i++ )
81       aThat->myCoords->SetValue( i, aBathPoints.Value( i ) );
82
83     return aPntCloud;
84   }
85   else
86     return Handle_AIS_InteractiveObject();
87 }
88
89 void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
90 {
91   theMin = 0;
92   theMax = 0;
93   if( myCoords.IsNull() )
94     return;
95
96   bool isFirst = true;
97   for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
98   {
99     double aValue = myCoords->Value( i ).Z();
100     if( isFirst || aValue < theMin )
101       theMin = aValue;
102     if( isFirst || aValue > theMax )
103       theMax = aValue;
104     isFirst = false;
105   }
106 }
107
108 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
109 {
110   for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
111   {
112     double z = myCoords->Value( i ).Z();
113     Quantity_Color aColor;
114     theColorScale->FindColor( z, aColor );
115     myColors->SetValue( i, aColor );
116   }
117   Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() );
118   aPntCloud->SetPoints( myCoords, myColors );
119   getContext()->Redisplay( aPntCloud, Standard_False );
120 }
121
122 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
123                                            const bool theIsUpdateViewer )
124 {
125   bool isShown = getContext()->IsDisplayed( getAISObject() );
126   bool isChanged = ( isShown != theState );
127   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
128   if( isChanged )
129     myDisplayer->SetToUpdateColorScale();
130 }
131
132 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
133 {
134   bool isShown = getContext()->IsDisplayed( getAISObject() );
135   bool isChanged = ( !isShown  );
136   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
137   if( isChanged )
138     myDisplayer->SetToUpdateColorScale();
139 }
140
141 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
142 {
143   bool isShown = getContext()->IsDisplayed( getAISObject() );
144   bool isChanged = ( !isShown  );
145   HYDROGUI_Shape::display( theIsUpdateViewer );
146   if( isChanged )
147     myDisplayer->SetToUpdateColorScale();
148 }
149
150 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
151 {
152   bool isShown = getContext()->IsDisplayed( getAISObject() );
153   bool isChanged = ( isShown  );
154   HYDROGUI_Shape::erase( theIsUpdateViewer );
155   if( isChanged )
156     myDisplayer->SetToUpdateColorScale();
157 }