Salome HOME
refs #1327: implementation of the scaling operations
authorasl <asl@opencascade.com>
Thu, 28 Sep 2017 14:58:34 +0000 (17:58 +0300)
committerasl <asl@opencascade.com>
Thu, 28 Sep 2017 14:58:34 +0000 (17:58 +0300)
src/HYDROGUI/HYDROGUI_BathymetryOp.cxx
src/HYDROGUI/HYDROGUI_BathymetryOp.h
src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx
src/HYDROGUI/HYDROGUI_BathymetryPrs.h
src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx
src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h
src/HYDROGUI/HYDROGUI_Operations.cxx
src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx
src/HYDRO_tests/test_HYDROGUI_BathymetryPrs.cxx

index 787053cf5a3a5dfe4266cb27eefa45e25a250853..cee53f3ec05fb13de152fd1f77972905a7e36869 100644 (file)
 //
 
 #include <HYDROGUI_BathymetryOp.h>
+#include <HYDROGUI_Operations.h>
+#include <HYDROGUI_BathymetryPrs.h>
+#include <HYDROGUI_ShapeBathymetry.h>
+#include <HYDROGUI_Module.h>
+#include <LightApp_Application.h>
+#include <OCCViewer_ViewManager.h>
+#include <OCCViewer_ViewWindow.h>
+#include <QtxDoubleSpinBox.h>
+#include <SUIT_Desktop.h>
+#include <QLayout>
+#include <QPushButton>
+
+HYDROGUI_BathymetryLimitsDlg::HYDROGUI_BathymetryLimitsDlg( QWidget* theParent )
+  : QDialog( 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 );
+
+  myMin = new QtxDoubleSpinBox( this );
+  myMax = new QtxDoubleSpinBox( this );
+
+  layout->addWidget( myMin, 0, 1 );
+  layout->addWidget( myMax, 1, 1 );
+
+  QFrame* aBtnFrame = new QFrame( this );
+  QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnFrame );
+  layout->addWidget( aBtnFrame, 2, 0, 1, 2 );
+
+  QPushButton* ok = new QPushButton( tr( "OK" ), 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() ) );
+}
+
+HYDROGUI_BathymetryLimitsDlg::~HYDROGUI_BathymetryLimitsDlg()
+{
+}
+
+double HYDROGUI_BathymetryLimitsDlg::GetMin() const
+{
+  return myMin->value();
+}
+
+double HYDROGUI_BathymetryLimitsDlg::GetMax() const
+{
+  return myMax->value();
+}
+
+void HYDROGUI_BathymetryLimitsDlg::SetMinMax( double theMin, double theMax )
+{
+  myMin->setValue( theMin );
+  myMax->setValue( theMax );
+}
+
+
+
+
 
 HYDROGUI_BathymetryOp::HYDROGUI_BathymetryOp( HYDROGUI_Module* theModule, int theMode )
 : HYDROGUI_Operation( theModule ), myMode( theMode )
@@ -28,12 +91,101 @@ HYDROGUI_BathymetryOp::~HYDROGUI_BathymetryOp()
 {
 }
 
+Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule );
+QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule );
+
 void HYDROGUI_BathymetryOp::startOperation()
 {
-  //TODO
+  activate( true );
+}
+
+void HYDROGUI_BathymetryOp::commitOperation()
+{
+  activate( false );
 }
 
 void HYDROGUI_BathymetryOp::abortOperation()
 {
-  //TODO
+  activate( false );
+}
+
+OCCViewer_ViewWindow* HYDROGUI_BathymetryOp::activeViewWindow() const
+{
+  LightApp_Application* app = module()->getApp();
+  OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>
+    ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
+  return dynamic_cast<OCCViewer_ViewWindow*>( mgr->getActiveView() );
+}
+
+void HYDROGUI_BathymetryOp::activate( bool isActivate )
+{
+QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
+
+  switch( myMode )
+  {
+  case BathymetryTextId:
+    {
+      foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+        bath->GetShape()->TextLabels( isActivate );
+      break;
+    }
+
+  case BathymetryRescaleSelectionId:
+    {
+      if( isActivate )
+        foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+          bath->GetShape()->RescaleBySelection();
+      commit();
+      break;
+    }
+
+  case BathymetryRescaleVisibleId:
+    {
+      if( isActivate )
+        foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+          bath->GetShape()->RescaleByVisible( activeViewWindow() );
+      commit();
+      break;
+    }
+
+  case BathymetryRescaleUserId:
+    {
+      if( isActivate )
+      {
+        double min=0, max=0, lmin=0, lmax=0;
+        bool first = true;
+        foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+        {
+          bath->GetShape()->GetRange( lmin, lmax );
+          if( first || lmin < min )
+            min = lmin;
+          if( first || lmax > max )
+            max = lmax;
+          first = false;
+        }
+
+        HYDROGUI_BathymetryLimitsDlg dlg( module()->getApp()->desktop() );
+        dlg.SetMinMax( min, max );
+        if( dlg.exec()==QDialog::Accepted )
+        {
+          min = dlg.GetMin();
+          max = dlg.GetMax();
+          foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+            bath->GetShape()->Rescale( min, max );
+          commit();
+        }
+        else
+          abort();
+        break;
+      }
+    }
+
+  case BathymetryRescaleDefaultId:
+    {
+      if( isActivate )
+        foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+          bath->GetShape()->RescaleDefault();
+      break;
+    }
+  }
 }
index 7855f84f6658c89a00aeedef0c08a0be15a9414a..b85ecd196da992ddd2ac3edd82a8683ac99ef047 100644 (file)
 #define HYDROGUI_BATHYMETRY_OP_H
 
 #include <HYDROGUI_Operation.h>
+#include <QDialog.h>
+
+class OCCViewer_ViewWindow;
+class QtxDoubleSpinBox;
 
 class HYDROGUI_BathymetryOp : public HYDROGUI_Operation
 {
@@ -32,10 +36,30 @@ public:
 
 protected:
   virtual void startOperation();
+  virtual void commitOperation();
   virtual void abortOperation();
 
+  void activate( bool );
+  OCCViewer_ViewWindow* activeViewWindow() const;
+
 private:
   int myMode;
 };
 
+
+class HYDROGUI_BathymetryLimitsDlg : public QDialog
+{
+public:
+  HYDROGUI_BathymetryLimitsDlg( QWidget* theParent );
+  virtual ~HYDROGUI_BathymetryLimitsDlg();
+
+  double GetMin() const;
+  double GetMax() const;
+  void SetMinMax( double, double );
+
+private:
+  QtxDoubleSpinBox* myMin;
+  QtxDoubleSpinBox* myMax;
+};
+
 #endif
index 1334896f578f2d79008f9043460feb2898485fbe..63d04939820a11689b5c9ff7dc527804ebbec7fa 100644 (file)
@@ -28,7 +28,8 @@
 
 const int BATH_HIGHLIGHT_MODE = 10;
 
-HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs()
+HYDROGUI_BathymetryPrs::HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* theShape )
+  : myShape( theShape )
 {
   SetHilightMode( BATH_HIGHLIGHT_MODE );
   SetAutoHilight( Standard_True );
@@ -38,6 +39,11 @@ HYDROGUI_BathymetryPrs::~HYDROGUI_BathymetryPrs()
 {
 }
 
+HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
+{
+  return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
+}
+
 void HYDROGUI_BathymetryPrs::UpdateBound()
 {
   Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
index 6af696db4fc9962b4b8ed3a96b935aa076f602a6..1f5e0df124cc49f1ea20e80e74f99a203f9d46ed 100644 (file)
 #include <Bnd_Box.hxx>
 #include <QList>
 
+class HYDROGUI_ShapeBathymetry;
+
 class HYDROGUI_BathymetryPrs : public AIS_PointCloud
 {
 public:
-  HYDROGUI_BathymetryPrs();
+  HYDROGUI_BathymetryPrs( const HYDROGUI_ShapeBathymetry* );
   virtual ~HYDROGUI_BathymetryPrs();
 
   virtual void SetPoints( const Handle(TColgp_HArray1OfPnt)&     theCoords,
@@ -47,6 +49,8 @@ public:
 
   void SetTextLabels( const QList<int>& );
 
+  HYDROGUI_ShapeBathymetry* GetShape() const;
+
 protected:
   virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
                         const Handle(Prs3d_Presentation)& thePresentation,
@@ -58,6 +62,7 @@ protected:
   void AddPoint( const Handle(Graphic3d_ArrayOfPoints)&, const Handle(SelectMgr_EntityOwner)& );
 
 private:
+  const HYDROGUI_ShapeBathymetry* myShape;
   Bnd_Box myBound;
   QList<int> myTextIndices;
 };
index 2fc0fc9c730539dbe6c4a6cb73cb55928b7be0a5..76d4dcc0b1bfe1d7a50c72c7dfdb9263b92cf798 100644 (file)
@@ -20,6 +20,7 @@
 #include <HYDROGUI_BathymetrySelectionOp.h>
 #include <HYDROGUI_Module.h>
 #include <HYDROGUI_BathymetryPrs.h>
+#include <HYDROGUI_BathymetryOp.h>
 #include <OCCViewer_ViewManager.h>
 #include <LightApp_Application.h>
 
@@ -42,18 +43,25 @@ void HYDROGUI_BathymetrySelectionOp::abortOperation()
   activateSelection( false );
 }
 
-void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
+bool HYDROGUI_BathymetrySelectionOp::isValid( SUIT_Operation* theOtherOp ) const
 {
-  if( myIsActive==isActive )
-    return;
+  HYDROGUI_BathymetryOp* aBathOp = dynamic_cast<HYDROGUI_BathymetryOp*>( theOtherOp );
+  return ( aBathOp != 0 );
+}
 
-  LightApp_Application* app = module()->getApp();
+Handle(AIS_InteractiveContext) getContext( HYDROGUI_Module* theModule )
+{
+  LightApp_Application* app = theModule->getApp();
   OCCViewer_ViewManager* mgr = dynamic_cast<OCCViewer_ViewManager*>
     ( app->getViewManager( OCCViewer_Viewer::Type(), true ) );
   Handle(AIS_InteractiveContext) ctx = mgr->getOCCViewer()->getAISContext();
+  return ctx;
+}
 
-
+QList<Handle(HYDROGUI_BathymetryPrs)> getShownBathymetries( HYDROGUI_Module* theModule )
+{
   QList<Handle(HYDROGUI_BathymetryPrs)> baths;
+  Handle(AIS_InteractiveContext) ctx = getContext( theModule );
 
   AIS_ListOfInteractive objs;
   ctx->DisplayedObjects( objs );
@@ -64,13 +72,25 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
     if( !bath.IsNull() )
       baths.append( bath );
   }
+  return baths;
+}
+
+void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
+{
+  if( myIsActive==isActive )
+    return;
 
+  Handle(AIS_InteractiveContext) ctx = getContext( module() );
+  QList<Handle(HYDROGUI_BathymetryPrs)> baths = getShownBathymetries( module() );
   if( isActive )
   {
     const int aSelectionMode = 1;
     ctx->OpenLocalContext( Standard_True );
     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
+    {
       ctx->Activate( bath, aSelectionMode, Standard_True );
+      bath->SetAutoHilight( Standard_False );
+    }
     ctx->UpdateCurrentViewer();
   }
   else
@@ -78,6 +98,7 @@ void HYDROGUI_BathymetrySelectionOp::activateSelection( bool isActive )
     foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
     {
       bath->ClearSelected();
+      bath->SetAutoHilight( Standard_True );
       ctx->Deactivate( bath );
     }
     ctx->CloseLocalContext( -1, Standard_True );
index 227e582edba788795222be05a3f127f5478838d4..3d88280b6185a5fa6ced05716328d793e4d3e4ef 100644 (file)
@@ -30,6 +30,8 @@ public:
   HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule );
   virtual ~HYDROGUI_BathymetrySelectionOp();
 
+  virtual bool isValid( SUIT_Operation* theOtherOp ) const;
+
 protected:
   virtual void startOperation();
   virtual void abortOperation();
index 75ca6f832714174cb3a11b9d1b622a7eed06100a..cb4ad5206aa6e97c5b283a71cd056a69152bcabe 100644 (file)
@@ -801,5 +801,13 @@ void HYDROGUI_Module::onBathymetrySelection()
 
 void HYDROGUI_Module::onBathymetryText()
 {
-  //TODO
+  QAction* a = qobject_cast<QAction*>( sender() );
+  if( !a )
+    return;
+
+  bool isChecked = a->isChecked();
+  if( isChecked )
+    startOperation( BathymetryTextId );
+  else
+    operation( BathymetryTextId )->abort();
 }
index 75542ee3be2fe53bbf5e461d2e8ac94e1bfb9f2f..da2a12b726cc5a9c1a0975430d800e5f5267a318 100644 (file)
@@ -70,7 +70,7 @@ Handle(AIS_InteractiveObject) HYDROGUI_ShapeBathymetry::createShape() const
   Handle(HYDROData_Bathymetry) aBath = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
   if( !aBath.IsNull() )
   {
-    aPntCloud = new HYDROGUI_BathymetryPrs();
+    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));
 
@@ -269,7 +269,10 @@ void HYDROGUI_ShapeBathymetry::TextLabels( bool isOn )
   if( prs.IsNull() )
     return;
 
-  QList<int> selection = selected();
+  QList<int> selection;
+  if( isOn )
+    selection = selected();
+
   getContext()->ClearSelected();
   prs->SetTextLabels( selection );
   getAISObject()->Redisplay();
index 7d2b8b7c0b466c2d12bf06684877807c167a4332..47f4cec2cd5ae06bf9ce9b46f54a024eb99f3fc7 100644 (file)
@@ -42,6 +42,7 @@ void test_HYDROGUI_BathymetryPrs::createBathPrs()
 {
   myBathPrs = new HYDROGUI_ShapeBathymetry( 0, TestViewer::context(), myBath );
   myBathPrs->Build();
+  myBathPrs->getAISObject()->SetAutoHilight( Standard_False );
 
   double min, max;
   myBathPrs->GetRange( min, max );
@@ -112,6 +113,10 @@ void test_HYDROGUI_BathymetryPrs::test_selection()
   TestViewer::setKey( "bathy_selection" );
   CPPUNIT_ASSERT_IMAGES
 
+  select( 5, 5, 6, 6 );
+  TestViewer::setKey( "bathy_prs" );
+  CPPUNIT_ASSERT_IMAGES
+
   //QTest::qWait( 50000 );
 
   aDoc->Close();
@@ -253,6 +258,22 @@ void test_HYDROGUI_BathymetryPrs::test_text_presentation()
   TestViewer::setKey( "bathy_text_labels" );
   CPPUNIT_ASSERT_IMAGES;
 
+  // Disable text labels
+  myBathPrs->TextLabels( false );
+  vp->fitAll();
+  qApp->processEvents();
+  TestViewer::setKey( "bathy_prs" );
+  CPPUNIT_ASSERT_IMAGES;
+
+  // Special case: flag=false + non-empty selection
+  select( x1, y1, x2, y2 );
+  myBathPrs->TextLabels( false );
+  vp->fitAll();
+  qApp->processEvents();
+  TestViewer::setKey( "bathy_prs" );
+  CPPUNIT_ASSERT_IMAGES;
+
+
   //QTest::qWait( 50000 );
 
   aDoc->Close();