From 6074577ddf7ed43a22093a51d50d53b99adaea5e Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 28 Sep 2017 17:58:34 +0300 Subject: [PATCH] refs #1327: implementation of the scaling operations --- src/HYDROGUI/HYDROGUI_BathymetryOp.cxx | 156 +++++++++++++++++- src/HYDROGUI/HYDROGUI_BathymetryOp.h | 24 +++ src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx | 8 +- src/HYDROGUI/HYDROGUI_BathymetryPrs.h | 7 +- .../HYDROGUI_BathymetrySelectionOp.cxx | 31 +++- src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h | 2 + src/HYDROGUI/HYDROGUI_Operations.cxx | 10 +- src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx | 7 +- .../test_HYDROGUI_BathymetryPrs.cxx | 21 +++ 9 files changed, 254 insertions(+), 12 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx index 787053cf..cee53f3e 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetryOp.cxx @@ -18,6 +18,69 @@ // #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +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 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 + ( app->getViewManager( OCCViewer_Viewer::Type(), true ) ); + return dynamic_cast( mgr->getActiveView() ); +} + +void HYDROGUI_BathymetryOp::activate( bool isActivate ) +{ +QList 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; + } + } } diff --git a/src/HYDROGUI/HYDROGUI_BathymetryOp.h b/src/HYDROGUI/HYDROGUI_BathymetryOp.h index 7855f84f..b85ecd19 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryOp.h +++ b/src/HYDROGUI/HYDROGUI_BathymetryOp.h @@ -21,6 +21,10 @@ #define HYDROGUI_BATHYMETRY_OP_H #include +#include + +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 diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx index 1334896f..63d04939 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.cxx @@ -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( myShape ); +} + void HYDROGUI_BathymetryPrs::UpdateBound() { Handle(Graphic3d_ArrayOfPoints) points = GetPoints(); diff --git a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h index 6af696db..1f5e0df1 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetryPrs.h +++ b/src/HYDROGUI/HYDROGUI_BathymetryPrs.h @@ -24,10 +24,12 @@ #include #include +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& ); + 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 myTextIndices; }; diff --git a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx index 2fc0fc9c..76d4dcc0 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx +++ b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -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( 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 ( app->getViewManager( OCCViewer_Viewer::Type(), true ) ); Handle(AIS_InteractiveContext) ctx = mgr->getOCCViewer()->getAISContext(); + return ctx; +} - +QList getShownBathymetries( HYDROGUI_Module* theModule ) +{ QList 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 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 ); diff --git a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h index 227e582e..3d88280b 100644 --- a/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h +++ b/src/HYDROGUI/HYDROGUI_BathymetrySelectionOp.h @@ -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(); diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 75ca6f83..cb4ad520 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -801,5 +801,13 @@ void HYDROGUI_Module::onBathymetrySelection() void HYDROGUI_Module::onBathymetryText() { - //TODO + QAction* a = qobject_cast( sender() ); + if( !a ) + return; + + bool isChecked = a->isChecked(); + if( isChecked ) + startOperation( BathymetryTextId ); + else + operation( BathymetryTextId )->abort(); } diff --git a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx index 75542ee3..da2a12b7 100644 --- a/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx +++ b/src/HYDROGUI/HYDROGUI_ShapeBathymetry.cxx @@ -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 selection = selected(); + QList selection; + if( isOn ) + selection = selected(); + getContext()->ClearSelected(); prs->SetTextLabels( selection ); getAISObject()->Redisplay(); diff --git a/src/HYDRO_tests/test_HYDROGUI_BathymetryPrs.cxx b/src/HYDRO_tests/test_HYDROGUI_BathymetryPrs.cxx index 7d2b8b7c..47f4cec2 100644 --- a/src/HYDRO_tests/test_HYDROGUI_BathymetryPrs.cxx +++ b/src/HYDRO_tests/test_HYDROGUI_BathymetryPrs.cxx @@ -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(); -- 2.30.2