1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <HYDROGUI_ShapeBathymetry.h>
24 #include <HYDROGUI_OCCDisplayer.h>
25 #include <HYDROGUI_BathymetryPrs.h>
26 #include <HYDROData_Bathymetry.h>
28 #include <AIS_InteractiveContext.hxx>
29 #include <Aspect_ColorScale.hxx>
30 #include <Prs3d_PointAspect.hxx>
32 HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer* theDisplayer,
33 const Handle(AIS_InteractiveContext)& theContext,
34 const Handle_HYDROData_Bathymetry& theBathymetry,
36 : HYDROGUI_Shape( theContext, theBathymetry, theZLayer ),
37 myDisplayer( theDisplayer )
39 setDisplayMode( AIS_PointCloud::DM_Points );
42 HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry()
44 myDisplayer->SetToUpdateColorScale();
47 void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection )
49 setIsToUpdate( false );
51 // Try to retrieve information from object
53 Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
55 if ( !aBath.IsNull() )
58 updateShape( false, false );
61 HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
65 Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const
67 Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() );
70 Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs();
71 aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox );
72 aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0));
74 const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
75 int aLower = aBathPoints.Lower();
76 int anUpper = aBathPoints.Upper();
78 HYDROGUI_ShapeBathymetry* aThat = const_cast<HYDROGUI_ShapeBathymetry*>( this );
79 aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
80 aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper );
81 for( int i=aLower; i<=anUpper; i++ )
82 aThat->myCoords->SetValue( i, aBathPoints.Value( i ) );
87 return Handle_AIS_InteractiveObject();
90 void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
94 if( myCoords.IsNull() )
98 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
100 double aValue = myCoords->Value( i ).Z();
101 if( isFirst || aValue < theMin )
103 if( isFirst || aValue > theMax )
109 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
111 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
113 double z = myCoords->Value( i ).Z();
114 Quantity_Color aColor;
115 theColorScale->FindColor( z, aColor );
116 myColors->SetValue( i, aColor );
118 Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() );
119 aPntCloud->SetPoints( myCoords, myColors );
120 getContext()->Redisplay( aPntCloud, Standard_False );
123 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
124 const bool theIsUpdateViewer )
126 bool isShown = getContext()->IsDisplayed( getAISObject() );
127 bool isChanged = ( isShown != theState );
128 HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
130 myDisplayer->SetToUpdateColorScale();
133 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
135 bool isShown = getContext()->IsDisplayed( getAISObject() );
136 bool isChanged = ( !isShown );
137 HYDROGUI_Shape::displayShape( theIsUpdateViewer );
139 myDisplayer->SetToUpdateColorScale();
142 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
144 bool isShown = getContext()->IsDisplayed( getAISObject() );
145 bool isChanged = ( !isShown );
146 HYDROGUI_Shape::display( theIsUpdateViewer );
148 myDisplayer->SetToUpdateColorScale();
151 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
153 bool isShown = getContext()->IsDisplayed( getAISObject() );
154 bool isChanged = ( isShown );
155 HYDROGUI_Shape::erase( theIsUpdateViewer );
157 myDisplayer->SetToUpdateColorScale();