Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ShapeBathymetry.cxx
index 35e8362aee08b5aa3b660e2081ecde63a3aad8bc..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,
@@ -94,7 +96,7 @@ QList<Handle(AIS_InteractiveObject)> HYDROGUI_ShapeBathymetry::createShape() con
 
 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++ )
@@ -108,7 +110,7 @@ void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale
     theColorScale->FindColor( z, aColor );
     myColors->SetValue( i, aColor );
   }
-  Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObject()[0] );
+  Handle(HYDROGUI_BathymetryPrs) aPntCloud = Handle(HYDROGUI_BathymetryPrs)::DownCast( getAISObjects()[0] );
   aPntCloud->SetPoints( myCoords, myColors );
   getContext()->RecomputePrsOnly( aPntCloud, Standard_True );
   getContext()->RecomputeSelectionOnly( aPntCloud );
@@ -117,6 +119,9 @@ void HYDROGUI_ShapeBathymetry::UpdateWithColorScale( const Handle(AIS_ColorScale
 void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
                                            const bool theIsUpdateViewer )
 {
+  if( getAISObjects().isEmpty() )
+    return;
+
   bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( isShown != theState );
   HYDROGUI_Shape::setVisible( theState, theIsUpdateViewer );
@@ -125,6 +130,9 @@ void HYDROGUI_ShapeBathymetry::setVisible( const bool theState,
 
 void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
 {
+  if( getAISObjects().isEmpty() )
+    return;
+
   bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::displayShape( theIsUpdateViewer );
@@ -133,6 +141,9 @@ void HYDROGUI_ShapeBathymetry::displayShape( const bool theIsUpdateViewer )
 
 void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
 {
+  if( getAISObjects().isEmpty() )
+    return;
+
   bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( !isShown  );
   HYDROGUI_Shape::display( theIsUpdateViewer );
@@ -141,6 +152,9 @@ void HYDROGUI_ShapeBathymetry::display( const bool theIsUpdateViewer )
 
 void HYDROGUI_ShapeBathymetry::erase( const bool theIsUpdateViewer )
 {
+  if( getAISObjects().isEmpty() )
+    return;
+
   bool isShown = getContext()->IsDisplayed( getAISObjects()[0] );
   bool isChanged = ( isShown  );
   HYDROGUI_Shape::erase( theIsUpdateViewer );
@@ -171,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();
@@ -180,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 );
@@ -190,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() )
   {
@@ -210,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() );
       }
     }
@@ -220,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
@@ -229,19 +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 );
   setToUpdateColorScale( true );
-  getAISObject()->Redisplay();
+
+  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() )
@@ -268,17 +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;
+  QVector<int> selection;
   if( isOn )
     selection = selected();
 
-  getContext()->ClearSelected();
+
+  //getContext()->ClearSelected(true);
   prs->SetTextLabels( selection );
-  getAISObject()->Redisplay();
+  getContext()->RecomputePrsOnly( prs, Standard_False, Standard_False );
+  //prs->Redisplay();
+  if( isUpdateCurrentViewer )
+  getContext()->UpdateCurrentViewer();
 }