Salome HOME
Merge branch 'BR_RIVER' of ssh://git.salome-platform.org/modules/hydro into BR_RIVER
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeBathymetry.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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   setDisplayMode( AIS_PointCloud::DM_Points );
41 }
42
43 HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry()
44 {
45   myDisplayer->SetToUpdateColorScale();
46 }
47
48 void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection )
49 {
50   setIsToUpdate( false );
51
52   // Try to retrieve information from object
53
54   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
55
56   if ( !aBath.IsNull() )
57   {
58     buildShape();
59     updateShape( false, false );
60   }
61
62   HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
63 }
64
65
66 Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const
67 {
68   Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() );
69   if( !aBath.IsNull() )
70   {
71     Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs();
72     aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox );
73     aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0));
74
75     const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
76     int aLower = aBathPoints.Lower();
77     int anUpper = aBathPoints.Upper();
78
79     HYDROGUI_ShapeBathymetry* aThat = const_cast<HYDROGUI_ShapeBathymetry*>( this );
80     aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
81     aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper );
82     for( int i=aLower; i<=anUpper; i++ )
83       aThat->myCoords->SetValue( i, aBathPoints.Value( i ) );
84
85     return aPntCloud;
86   }
87   else
88     return Handle_AIS_InteractiveObject();
89 }
90
91 void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
92 {
93   theMin = 0;
94   theMax = 0;
95   if( myCoords.IsNull() )
96     return;
97
98   bool isFirst = true;
99   for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
100   {
101     double aValue = myCoords->Value( i ).Z();
102     if( isFirst || aValue < theMin )
103       theMin = aValue;
104     if( isFirst || aValue > theMax )
105       theMax = aValue;
106     isFirst = false;
107   }
108 }
109
110 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
111 {
112   for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
113   {
114     double z = myCoords->Value( i ).Z();
115     Quantity_Color aColor;
116     theColorScale->FindColor( z, aColor );
117     myColors->SetValue( i, aColor );
118   }
119   Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() );
120   aPntCloud->SetPoints( myCoords, myColors );
121   getContext()->Redisplay( aPntCloud, Standard_False );
122 }
123
124 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
125                                            const bool theIsUpdateViewer )
126 {
127   bool isShown = getContext()->IsDisplayed( getAISObject() );
128   bool isChanged = ( isShown != theState );
129   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
130   if( isChanged )
131     myDisplayer->SetToUpdateColorScale();
132 }
133
134 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
135 {
136   bool isShown = getContext()->IsDisplayed( getAISObject() );
137   bool isChanged = ( !isShown  );
138   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
139   if( isChanged )
140     myDisplayer->SetToUpdateColorScale();
141 }
142
143 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
144 {
145   bool isShown = getContext()->IsDisplayed( getAISObject() );
146   bool isChanged = ( !isShown  );
147   HYDROGUI_Shape::display( theIsUpdateViewer );
148   if( isChanged )
149     myDisplayer->SetToUpdateColorScale();
150 }
151
152 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
153 {
154   bool isShown = getContext()->IsDisplayed( getAISObject() );
155   bool isChanged = ( isShown  );
156   HYDROGUI_Shape::erase( theIsUpdateViewer );
157   if( isChanged )
158     myDisplayer->SetToUpdateColorScale();
159 }