Salome HOME
patch for install error on Linux
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeBathymetry.cxx
index 2abb2879632f8d0ad5276e1458cfc88a5af9d0c7..e8e7941b670df5490036037941cc70b95161a62b 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include <HYDROGUI_ShapeBathymetry.h>
 #include <HYDROGUI_OCCDisplayer.h>
+#include <HYDROGUI_BathymetryPrs.h>
 #include <HYDROData_Bathymetry.h>
 
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_PointCloud.hxx>
-#include <AIS_Drawer.hxx>
 #include <Aspect_ColorScale.hxx>
 #include <Prs3d_PointAspect.hxx>
 
@@ -37,11 +32,12 @@ HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer*
 : HYDROGUI_Shape( theContext, theBathymetry, theZLayer ),
   myDisplayer( theDisplayer )
 {
+  setDisplayMode( AIS_PointCloud::DM_Points );
 }
 
 HYDROGUI_ShapeBathymetry::~HYDROGUI_ShapeBathymetry()
 {
-  myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( true );
 }
 
 void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivateSelection )
@@ -52,7 +48,7 @@ void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivate
 
   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
 
-  if ( !aBath.IsNull() )
+  if ( !aBath.IsNull() && !aBath->GetAltitudePoints().empty())
   {
     buildShape();
     updateShape( false, false );
@@ -67,18 +63,19 @@ Handle_AIS_InteractiveObject HYDROGUI_ShapeBathymetry::createShape() const
   Handle_HYDROData_Bathymetry aBath = Handle_HYDROData_Bathymetry::DownCast( getObject() );
   if( !aBath.IsNull() )
   {
-    Handle_AIS_PointCloud aPntCloud = new AIS_PointCloud();
-    aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 1.0));
+    Handle_AIS_PointCloud aPntCloud = new HYDROGUI_BathymetryPrs();
+    aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox );
+    aPntCloud->Attributes()->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_WHITE, 2.0));
 
     const HYDROData_Bathymetry::AltitudePoints& aBathPoints = aBath->GetAltitudePoints();
-    int aLower = aBathPoints.Lower();
-    int anUpper = aBathPoints.Upper();
+    int aLower = 0;
+    int anUpper = (int)aBathPoints.size()-1;
 
     HYDROGUI_ShapeBathymetry* aThat = const_cast<HYDROGUI_ShapeBathymetry*>( this );
     aThat->myCoords = new TColgp_HArray1OfPnt( aLower, anUpper );
     aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper );
     for( int i=aLower; i<=anUpper; i++ )
-      aThat->myCoords->SetValue( i, aBathPoints.Value( i ) );
+      aThat->myCoords->SetValue( i, gp_Pnt( aBathPoints[i].X, aBathPoints[i].Y, aBathPoints[i].Z ) );
 
     return aPntCloud;
   }
@@ -107,6 +104,8 @@ void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
 
 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(Aspect_ColorScale)& theColorScale )
 {
+  if (!myCoords)
+    return;
   for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
   {
     double z = myCoords->Value( i ).Z();
@@ -125,8 +124,7 @@ void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( isShown != theState );
   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
-  if( isChanged )
-    myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( isChanged );
 }
 
 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
@@ -134,8 +132,7 @@ void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
-  if( isChanged )
-    myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( isChanged );
 }
 
 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
@@ -143,8 +140,7 @@ void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::display( theIsUpdateViewer );
-  if( isChanged )
-    myDisplayer->SetToUpdateColorScale();
+  setToUpdateColorScale( isChanged );
 }
 
 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
@@ -152,6 +148,13 @@ void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
   bool isShown = getContext()->IsDisplayed( getAISObject() );
   bool isChanged = ( isShown  );
   HYDROGUI_Shape::erase( theIsUpdateViewer );
-  if( isChanged )
+  setToUpdateColorScale( isChanged );
+}
+
+void HYDROGUI_ShapeBathymetry::setToUpdateColorScale( bool isChanged )
+{
+#ifndef LIGHT_MODE
+  if( isChanged && myDisplayer )
     myDisplayer->SetToUpdateColorScale();
+#endif
 }