Salome HOME
lot 10 - warnings for DTM - untested
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_BathymetryOp.cxx
index cee53f3ec05fb13de152fd1f77972905a7e36869..b0d6eff7baaaeefb08c8d1d20685e69296fd706b 100644 (file)
 #include <HYDROGUI_BathymetryPrs.h>
 #include <HYDROGUI_ShapeBathymetry.h>
 #include <HYDROGUI_Module.h>
+#include <HYDROGUI_OCCDisplayer.h>
 #include <LightApp_Application.h>
 #include <OCCViewer_ViewManager.h>
 #include <OCCViewer_ViewWindow.h>
 #include <QtxDoubleSpinBox.h>
 #include <SUIT_Desktop.h>
+#include <SUIT_SelectionMgr.h>
 #include <QLayout>
 #include <QPushButton>
+#include <QApplication>
 
 HYDROGUI_BathymetryLimitsDlg::HYDROGUI_BathymetryLimitsDlg( QWidget* theParent )
   : QDialog( theParent )
@@ -36,11 +39,13 @@ HYDROGUI_BathymetryLimitsDlg::HYDROGUI_BathymetryLimitsDlg( QWidget* theParent )
   QGridLayout* layout = new QGridLayout();
   setLayout( layout );
 
-  layout->addWidget( new QLabel( tr( "MIN_VALUE" ) ), 0, 0 );
-  layout->addWidget( new QLabel( tr( "MAX_VALUE" ) ), 1, 0 );
+  layout->addWidget( new QLabel( tr( "Min value" ) ), 0, 0 );
+  layout->addWidget( new QLabel( tr( "Max value" ) ), 1, 0 );
 
   myMin = new QtxDoubleSpinBox( this );
+  myMin->setRange( -1000, 1000 );
   myMax = new QtxDoubleSpinBox( this );
+  myMax->setRange( -1000, 1000 );
 
   layout->addWidget( myMin, 0, 1 );
   layout->addWidget( myMax, 1, 1 );
@@ -50,12 +55,12 @@ HYDROGUI_BathymetryLimitsDlg::HYDROGUI_BathymetryLimitsDlg( QWidget* theParent )
   layout->addWidget( aBtnFrame, 2, 0, 1, 2 );
 
   QPushButton* ok = new QPushButton( tr( "OK" ), this );
-  QPushButton* cancel = new QPushButton( tr( "CANCEL" ), this );
+  QPushButton* cancel = new QPushButton( tr( "Cancel" ), this );
   aBtnLayout->addWidget( ok );
   aBtnLayout->addWidget( cancel );
 
   connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
-  connect( ok, SIGNAL( clicked() ), this, SLOT( reject() ) );
+  connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
 }
 
 HYDROGUI_BathymetryLimitsDlg::~HYDROGUI_BathymetryLimitsDlg()
@@ -83,7 +88,7 @@ void HYDROGUI_BathymetryLimitsDlg::SetMinMax( double theMin, double theMax )
 
 
 HYDROGUI_BathymetryOp::HYDROGUI_BathymetryOp( HYDROGUI_Module* theModule, int theMode )
-: HYDROGUI_Operation( theModule ), myMode( theMode )
+: HYDROGUI_Operation( theModule ), myMode( theMode ), myIsActivate( false )
 {
 }
 
@@ -91,6 +96,7 @@ HYDROGUI_BathymetryOp::~HYDROGUI_BathymetryOp()
 {
 }
 
+OCCViewer_Viewer* getViewer( HYDROGUI_Module* theModule );
 Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule );
 QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule );
 
@@ -101,6 +107,7 @@ void HYDROGUI_BathymetryOp::startOperation()
 
 void HYDROGUI_BathymetryOp::commitOperation()
 {
+  //if( myMode!=BathymetryTextId )
   activate( false );
 }
 
@@ -119,22 +126,38 @@ OCCViewer_ViewWindow* HYDROGUI_BathymetryOp::activeViewWindow() const
 
 void HYDROGUI_BathymetryOp::activate( bool isActivate )
 {
-QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
+  if( myIsActivate==isActivate )
+    return;
+
+  myIsActivate = isActivate;
+  QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
+  bool isUpdateCS = false;
+
+  if( myMode!=BathymetryRescaleUserId )
+    qApp->setOverrideCursor( Qt::WaitCursor );
 
   switch( myMode )
   {
   case BathymetryTextId:
     {
       foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
-        bath->GetShape()->TextLabels( isActivate );
+        bath->GetShape()->TextLabels( isActivate, bath==baths.last() );
+      //commit();
+      if( isActivate )
+        connect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
+      else
+        disconnect( selectionMgr(), SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ) );
       break;
     }
 
   case BathymetryRescaleSelectionId:
     {
       if( isActivate )
+      {
         foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
           bath->GetShape()->RescaleBySelection();
+        isUpdateCS = true;
+      }
       commit();
       break;
     }
@@ -142,8 +165,11 @@ QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
   case BathymetryRescaleVisibleId:
     {
       if( isActivate )
+      {
         foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
           bath->GetShape()->RescaleByVisible( activeViewWindow() );
+        isUpdateCS = true;
+      }
       commit();
       break;
     }
@@ -168,10 +194,14 @@ QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
         dlg.SetMinMax( min, max );
         if( dlg.exec()==QDialog::Accepted )
         {
+          qApp->setOverrideCursor( Qt::WaitCursor );
+
           min = dlg.GetMin();
           max = dlg.GetMax();
           foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
             bath->GetShape()->Rescale( min, max );
+
+          isUpdateCS = true;
           commit();
         }
         else
@@ -183,9 +213,33 @@ QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
   case BathymetryRescaleDefaultId:
     {
       if( isActivate )
+      {
         foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
           bath->GetShape()->RescaleDefault();
+        isUpdateCS = true;
+      }
+      commit();
       break;
     }
   }
+
+  if( isUpdateCS )
+    module()->getOCCDisplayer()->UpdateColorScale( getViewer( module() ) );
+
+  qApp->restoreOverrideCursor();
+}
+
+void HYDROGUI_BathymetryOp::onSelectionChanged()
+{
+  QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
+  bool isUpdateCS = false;
+
+  qApp->setOverrideCursor( Qt::WaitCursor );
+  if( myMode==BathymetryTextId )
+  {
+    foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+      bath->GetShape()->TextLabels( true, bath==baths.last() );
+  }
+
+  qApp->restoreOverrideCursor();
 }