Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeBathymetry.cxx
index 76065dfc3909fa9dd00b42a53afdce6a4ddef60d..b3d390141093fd35b134e305d1bd9d1d8c234022 100644 (file)
@@ -27,6 +27,8 @@
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
 #include <V3d_View.hxx>
+#include <QTime>
+#include <utilities.h>
 
 HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer*                theDisplayer,
                                                     const Handle(AIS_InteractiveContext)& theContext,
@@ -63,15 +65,17 @@ void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivate
   HYDROGUI_Shape::update( theIsUpdateViewer, isDeactivateSelection );
 }
 
-Handle(AIS_InteractiveObject) HYDROGUI_ShapeBathymetry::createShape() const
+QList<Handle(AIS_InteractiveObject)> HYDROGUI_ShapeBathymetry::createShape() const
 {
+  QList<Handle(AIS_InteractiveObject)> shapes;
+
   Handle(AIS_InteractiveObject) aPntCloud;
 
   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
   if( !aBath.IsNull() )
   {
-    aPntCloud = new HYDROGUI_BathymetryPrs();
-    aPntCloud->SetHilightMode( AIS_PointCloud::DM_BndBox );
+    aPntCloud = new HYDROGUI_BathymetryPrs( this );
+    //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();
@@ -83,14 +87,16 @@ Handle(AIS_InteractiveObject) HYDROGUI_ShapeBathymetry::createShape() const
     aThat->myColors = new Quantity_HArray1OfColor( aLower, anUpper );
     for( int i=aLower; i<=anUpper; i++ )
       aThat->myCoords->SetValue( i, gp_Pnt( aBathPoints[i].X, aBathPoints[i].Y, aBathPoints[i].Z ) );
+
+    shapes.append( aPntCloud );
   }
 
-  return aPntCloud;
+  return shapes;
 }
 
 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale)& theColorScale )
 {
-  if (!myCoords)
+  if (!myCoords || getAISObjects().isEmpty())
     return;
 
   for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
@@ -104,15 +110,19 @@ void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale
     theColorScale->FindColor( z, aColor );
     myColors->SetValue( i, aColor );
   }
-  Handle(AIS_PointCloud) aPntCloud = Handle(AIS_PointCloud)::DownCast( getAISObject() );
+  Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] );
   aPntCloud->SetPoints( myCoords, myColors );
   getContext()->RecomputePrsOnly( aPntCloud, Standard_True );
+  getContext()->RecomputeSelectionOnly( aPntCloud );
 }
 
 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
                                            const bool theIsUpdateViewer )
 {
-  bool isShown = getContext()->IsDisplayed( getAISObject() );
+  if( getAISObjects().isEmpty() )
+    return;
+
+  bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( isShown != theState );
   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
   setToUpdateColorScale( isChanged );
@@ -120,7 +130,10 @@ void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
 
 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
 {
-  bool isShown = getContext()->IsDisplayed( getAISObject() );
+  if( getAISObjects().isEmpty() )
+    return;
+
+  bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
   setToUpdateColorScale( isChanged );
@@ -128,7 +141,10 @@ void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
 
 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
 {
-  bool isShown = getContext()->IsDisplayed( getAISObject() );
+  if( getAISObjects().isEmpty() )
+    return;
+
+  bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::display( theIsUpdateViewer );
   setToUpdateColorScale( isChanged );
@@ -136,7 +152,10 @@ void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
 
 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
 {
-  bool isShown = getContext()->IsDisplayed( getAISObject() );
+  if( getAISObjects().isEmpty() )
+    return;
+
+  bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( isShown  );
   HYDROGUI_Shape::erase( theIsUpdateViewer );
   setToUpdateColorScale( isChanged );
@@ -166,7 +185,7 @@ void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
 
 void HYDROGUI_ShapeBathymetry::RescaleByVisible( OCCViewer_ViewWindow* theWindow )
 {
-  QList<int> visible;
+  QVector<int> visible;
   visible.reserve( myCoords->Size() );
 
   OCCViewer_ViewPort3d* vp = theWindow->getViewPort();
@@ -175,8 +194,16 @@ void HYDROGUI_ShapeBathymetry::RescaleByVisible( OCCViewer_ViewWindow* theWindow
   int xp, yp;
   int w = vp->width();
   int h = vp->height();
+  int n = myCoords->Upper();
   bool isVisible;
-  for( int i=myCoords->Lower(), n=myCoords->Upper(); i<=n; i++ )
+
+#ifdef _DEBUG
+  MESSAGE("RescaleByVisible: " << n);
+  QTime t1;
+  t1.start();
+#endif
+
+  for( int i=myCoords->Lower(); i<=n; i++ )
   {
     gp_Pnt p = myCoords->Value( i );
     v->Convert( p.X(), p.Y(), p.Z(), xp, yp );
@@ -185,16 +212,26 @@ void HYDROGUI_ShapeBathymetry::RescaleByVisible( OCCViewer_ViewWindow* theWindow
       visible.append( i );
   }
 
+#ifdef _DEBUG
+  MESSAGE("Time after visibles search:" << t1.elapsed());
+#endif
+
   //TODO: question: empty visible part produce empty bathymetry or complete bathymetry?
   // For now "complete" is implemented
   Rescale( visible, visible.isEmpty() );
+
+#ifdef _DEBUG
+  MESSAGE("Time after rescale:" << t1.elapsed());
+#endif
 }
 
-QList<int> HYDROGUI_ShapeBathymetry::selected() const
+QVector<int> HYDROGUI_ShapeBathymetry::selected() const
 {
-  QList<int> selected;
+  QVector<int> selected;
   selected.reserve( myCoords->Size() );
 
+  Handle(AIS_InteractiveObject) obj = getAISObjects().first();
+
   Handle(AIS_InteractiveContext) c = getContext();
   if( !c.IsNull() )
   {
@@ -205,7 +242,7 @@ QList<int> HYDROGUI_ShapeBathymetry::selected() const
       {
         Handle(HYDROGUI_BathymetryPointOwner) anOwner = 
           Handle(HYDROGUI_BathymetryPointOwner)::DownCast( lc->SelectedOwner() );
-        if( anOwner )
+        if( !anOwner.IsNull() && anOwner->Selectable()==obj )
           selected.append( anOwner->GetIndex() );
       }
     }
@@ -215,7 +252,7 @@ QList<int> HYDROGUI_ShapeBathymetry::selected() const
 
 void HYDROGUI_ShapeBathymetry::RescaleBySelection()
 {
-  QList<int> selection = selected();
+  QVector<int> selection = selected();
 
   //TODO: question: empty selection produce empty bathymetry or complete bathymetry?
   // For now "complete" is implemented
@@ -224,18 +261,24 @@ void HYDROGUI_ShapeBathymetry::RescaleBySelection()
 
 void HYDROGUI_ShapeBathymetry::Rescale( double theMin, double theMax )
 {
-  getContext()->ClearSelected();
+  getContext()->ClearSelected(true);
   myMin = qMin( theMin, theMax );
   myMax = qMax( theMin, theMax );
-  getAISObject()->Redisplay();
+  setToUpdateColorScale( true );
+
+  if( !getAISObjects().isEmpty() )
+  {
+    getContext()->RecomputePrsOnly( getAISObjects()[0], true );
+    //getAISObjects()[0]->Redisplay();
+}
 }
 
 void HYDROGUI_ShapeBathymetry::RescaleDefault()
 {
-  Rescale( QList<int>(), true );
+  Rescale( QVector<int>(), true );
 }
 
-void HYDROGUI_ShapeBathymetry::Rescale( const QList<int>& theIndices, bool isForcedAll )
+void HYDROGUI_ShapeBathymetry::Rescale( const QVector<int>& theIndices, bool isForcedAll )
 {
   double aMin = 0, aMax = 0;
   if( !myCoords.IsNull() )
@@ -262,14 +305,24 @@ void HYDROGUI_ShapeBathymetry::Build()
   buildShape();
 }
 
-void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn )
+void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn, bool isUpdateCurrentViewer )
 {
-  Handle(HYDROGUI_BathymetryPrs) prs = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObject() );
+  if( getAISObjects().isEmpty() )
+    return;
+
+  Handle(HYDROGUI_BathymetryPrs) prs = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] );
   if( prs.IsNull() )
     return;
 
-  QList<int> selection = selected();
-  getContext()->ClearSelected();
+  QVector<int> selection;
+  if( isOn )
+    selection = selected();
+
+
+  //getContext()->ClearSelected(true);
   prs->SetTextLabels( selection );
-  getAISObject()->Redisplay();
+  getContext()->RecomputePrsOnly( prs, Standard_False, Standard_False );
+  //prs->Redisplay();
+  if( isUpdateCurrentViewer )
+  getContext()->UpdateCurrentViewer();
 }