Salome HOME
cleaning some comments
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeBathymetry.cxx
index f211ae56480fbbd0e4e27861ffc0750604c24af5..a6de2d915509941d23825af2618fac74c0cf06e5 100644 (file)
@@ -20,6 +20,7 @@
 #include <HYDROGUI_OCCDisplayer.h>
 #include <HYDROGUI_BathymetryPrs.h>
 #include <HYDROData_Bathymetry.h>
+#include <HYDROGUI_Tool.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_ColorScale.hxx>
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
 #include <V3d_View.hxx>
+#include <QTime>
+#include <utilities.h>
+
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
 
 HYDROGUI_ShapeBathymetry::HYDROGUI_ShapeBathymetry( HYDROGUI_OCCDisplayer*                theDisplayer,
                                                     const Handle(AIS_InteractiveContext)& theContext,
@@ -65,6 +71,7 @@ void HYDROGUI_ShapeBathymetry::update( bool theIsUpdateViewer, bool isDeactivate
 
 QList<Handle(AIS_InteractiveObject)> HYDROGUI_ShapeBathymetry::createShape() const
 {
+  DEBTRACE("createShape");
   QList<Handle(AIS_InteractiveObject)> shapes;
 
   Handle(AIS_InteractiveObject) aPntCloud;
@@ -94,6 +101,7 @@ QList<Handle(AIS_InteractiveObject)> HYDROGUI_ShapeBathymetry::createShape() con
 
 void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale)& theColorScale )
 {
+  DEBTRACE("UpdateWithColorScale");
   if (!myCoords || getAISObjects().isEmpty())
     return;
 
@@ -171,7 +179,7 @@ void HYDROGUI_ShapeBathymetry::GetRange( double& theMin, double& theMax ) const
 {
   if( !myRangeInitialized )
   {
-    HYDROGUI_ShapeBathymetry* that = 
+    HYDROGUI_ShapeBathymetry* that =
       const_cast<HYDROGUI_ShapeBathymetry*>( this );
     that->RescaleDefault();
     that->myRangeInitialized = true;
@@ -183,7 +191,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();
@@ -192,8 +200,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 );
@@ -202,37 +218,36 @@ 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;
-  selected.reserve( myCoords->Size() );
+  DEBTRACE("selected");
+  QVector<int> selected;
 
-  Handle(AIS_InteractiveContext) c = getContext();
-  if( !c.IsNull() )
-  {
-    Handle(AIS_LocalContext) lc = c->LocalContext();
-    if( !lc.IsNull() )
-    {
-      for( lc->InitSelected(); lc->MoreSelected(); lc->NextSelected() )
-      {
-        Handle(HYDROGUI_BathymetryPointOwner) anOwner = 
-          Handle(HYDROGUI_BathymetryPointOwner)::DownCast( lc->SelectedOwner() );
-        if( anOwner )
-          selected.append( anOwner->GetIndex() );
-      }
-    }
-  }
+  // HYDROGUI_BathymetryPrs::ClearSelected() called before: Nothing left...
+
+  Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] );
+  if (!aPntCloud.IsNull())
+    selected = aPntCloud->getSelectedPoints();
+  DEBTRACE("selected " << selected.size());
   return selected;
 }
 
 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
@@ -241,21 +256,23 @@ 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 );
   setToUpdateColorScale( true );
 
   if( !getAISObjects().isEmpty() )
-    getAISObjects()[0]->Redisplay();
+  {
+    getContext()->RecomputePrsOnly( getAISObjects()[0], true );
+  }
 }
 
 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() )
@@ -282,8 +299,9 @@ void HYDROGUI_ShapeBathymetry::Build()
   buildShape();
 }
 
-void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn )
+void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn, bool isUpdateCurrentViewer )
 {
+  DEBTRACE("TextLabels " << isOn << " " << isUpdateCurrentViewer);
   if( getAISObjects().isEmpty() )
     return;
 
@@ -291,11 +309,13 @@ void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn )
   if( prs.IsNull() )
     return;
 
-  QList<int> selection;
+  QVector<int> selection;
   if( isOn )
     selection = selected();
 
-  getContext()->ClearSelected();
+
   prs->SetTextLabels( selection );
-  prs->Redisplay();
+  getContext()->RecomputePrsOnly( prs, Standard_False, Standard_False );
+  if( isUpdateCurrentViewer )
+  getContext()->UpdateCurrentViewer();
 }