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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <HYDROGUI_ShapeBathymetry.h>
20 #include <HYDROGUI_OCCDisplayer.h>
21 #include <HYDROGUI_BathymetryPrs.h>
22 #include <HYDROData_Bathymetry.h>
24 #include <AIS_InteractiveContext.hxx>
25 #include <Aspect_ColorScale.hxx>
26 #include <Prs3d_PointAspect.hxx>
28 HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer* theDisplayer,
29 const Handle(AIS_InteractiveContext)& theContext,
30 const Handle_HYDROData_Bathymetry& theBathymetry,
32 : HYDROGUI_Shape( theContext, theBathymetry, theZLayer ),
33 myDisplayer( theDisplayer )
35 setDisplayMode( AIS_PointCloud::DM_Points );
38 HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry()
40 setToUpdateColorScale( true );
43 void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection )
45 setIsToUpdate( false );
47 // Try to retrieve information from object
49 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
51 if ( !aBath.IsNull() )
54 updateShape( false, false );
57 HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
61 Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const
63 Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() );
66 Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs();
67 aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox );
68 aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0));
70 const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
72 int anUpper = (int)aBathPoints.size()-1;
74 HYDROGUI_ShapeBathymetry* aThat = const_cast<HYDROGUI_ShapeBathymetry*>( this );
75 aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
76 aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper );
77 for( int i=aLower; i<=anUpper; i++ )
78 aThat->myCoords->SetValue( i, gp_Pnt( aBathPoints[i].X, aBathPoints[i].Y, aBathPoints[i].Z ) );
83 return Handle_AIS_InteractiveObject();
86 void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
90 if( myCoords.IsNull() )
94 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
96 double aValue = myCoords->Value( i ).Z();
97 if( isFirst || aValue < theMin )
99 if( isFirst || aValue > theMax )
105 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
107 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
109 double z = myCoords->Value( i ).Z();
110 Quantity_Color aColor;
111 theColorScale->FindColor( z, aColor );
112 myColors->SetValue( i, aColor );
114 Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() );
115 aPntCloud->SetPoints( myCoords, myColors );
116 getContext()->Redisplay( aPntCloud, Standard_False );
119 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
120 const bool theIsUpdateViewer )
122 bool isShown = getContext()->IsDisplayed( getAISObject() );
123 bool isChanged = ( isShown != theState );
124 HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
125 setToUpdateColorScale( isChanged );
128 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
130 bool isShown = getContext()->IsDisplayed( getAISObject() );
131 bool isChanged = ( !isShown );
132 HYDROGUI_Shape::displayShape( theIsUpdateViewer );
133 setToUpdateColorScale( isChanged );
136 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
138 bool isShown = getContext()->IsDisplayed( getAISObject() );
139 bool isChanged = ( !isShown );
140 HYDROGUI_Shape::display( theIsUpdateViewer );
141 setToUpdateColorScale( isChanged );
144 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
146 bool isShown = getContext()->IsDisplayed( getAISObject() );
147 bool isChanged = ( isShown );
148 HYDROGUI_Shape::erase( theIsUpdateViewer );
149 setToUpdateColorScale( isChanged );
152 void HYDROGUI_ShapeBathymetry::setToUpdateColorScale( bool isChanged )
155 if( isChanged && myDisplayer )
156 myDisplayer->SetToUpdateColorScale();