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 <AIS_Drawer.hxx>
30 #include <Aspect_ColorScale.hxx>
31 #include <Prs3d_PointAspect.hxx>
33 HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer* theDisplayer,
34 const Handle(AIS_InteractiveContext)& theContext,
35 const Handle_HYDROData_Bathymetry& theBathymetry,
37 : HYDROGUI_Shape( theContext, theBathymetry, theZLayer ),
38 myDisplayer( theDisplayer )
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->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0));
73 const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
74 int aLower = aBathPoints.Lower();
75 int anUpper = aBathPoints.Upper();
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 ) );
86 return Handle_AIS_InteractiveObject();
89 void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
93 if( myCoords.IsNull() )
97 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
99 double aValue = myCoords->Value( i ).Z();
100 if( isFirst || aValue < theMin )
102 if( isFirst || aValue > theMax )
108 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
110 for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
112 double z = myCoords->Value( i ).Z();
113 Quantity_Color aColor;
114 theColorScale->FindColor( z, aColor );
115 myColors->SetValue( i, aColor );
117 Handle_AIS_PointCloud aPntCloud = Handle_AIS_PointCloud::DownCast( getAISObject() );
118 aPntCloud->SetPoints( myCoords, myColors );
119 getContext()->Redisplay( aPntCloud, Standard_False );
122 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
123 const bool theIsUpdateViewer )
125 bool isShown = getContext()->IsDisplayed( getAISObject() );
126 bool isChanged = ( isShown != theState );
127 HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
129 myDisplayer->SetToUpdateColorScale();
132 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
134 bool isShown = getContext()->IsDisplayed( getAISObject() );
135 bool isChanged = ( !isShown );
136 HYDROGUI_Shape::displayShape( theIsUpdateViewer );
138 myDisplayer->SetToUpdateColorScale();
141 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
143 bool isShown = getContext()->IsDisplayed( getAISObject() );
144 bool isChanged = ( !isShown );
145 HYDROGUI_Shape::display( theIsUpdateViewer );
147 myDisplayer->SetToUpdateColorScale();
150 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
152 bool isShown = getContext()->IsDisplayed( getAISObject() );
153 bool isChanged = ( isShown );
154 HYDROGUI_Shape::erase( theIsUpdateViewer );
156 myDisplayer->SetToUpdateColorScale();