//
#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 )
{
}
+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;
+ }
+ }
}
#define HYDROGUI_BATHYMETRY_OP_H
#include <HYDROGUI_Operation.h>
+#include <QDialog.h>
+
+class OCCViewer_ViewWindow;
+class QtxDoubleSpinBox;
class HYDROGUI_BathymetryOp : public HYDROGUI_Operation
{
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
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 );
{
}
+HYDROGUI_ShapeBathymetry* HYDROGUI_BathymetryPrs::GetShape() const
+{
+ return const_cast<HYDROGUI_ShapeBathymetry*>( myShape );
+}
+
void HYDROGUI_BathymetryPrs::UpdateBound()
{
Handle(Graphic3d_ArrayOfPoints) points = GetPoints();
#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,
void SetTextLabels( const QList<int>& );
+ HYDROGUI_ShapeBathymetry* GetShape() const;
+
protected:
virtual void Compute( const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
const Handle(Prs3d_Presentation)& thePresentation,
void AddPoint( const Handle(Graphic3d_ArrayOfPoints)&, const Handle(SelectMgr_EntityOwner)& );
private:
+ const HYDROGUI_ShapeBathymetry* myShape;
Bnd_Box myBound;
QList<int> myTextIndices;
};
#include <HYDROGUI_BathymetrySelectionOp.h>
#include <HYDROGUI_Module.h>
#include <HYDROGUI_BathymetryPrs.h>
+#include <HYDROGUI_BathymetryOp.h>
#include <OCCViewer_ViewManager.h>
#include <LightApp_Application.h>
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 );
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
foreach( Handle(HYDROGUI_BathymetryPrs) bath, baths )
{
bath->ClearSelected();
+ bath->SetAutoHilight( Standard_True );
ctx->Deactivate( bath );
}
ctx->CloseLocalContext( -1, Standard_True );
HYDROGUI_BathymetrySelectionOp( HYDROGUI_Module* theModule );
virtual ~HYDROGUI_BathymetrySelectionOp();
+ virtual bool isValid( SUIT_Operation* theOtherOp ) const;
+
protected:
virtual void startOperation();
virtual void abortOperation();
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();
}
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));
if( prs.IsNull() )
return;
- QList<int> selection = selected();
+ QList<int> selection;
+ if( isOn )
+ selection = selected();
+
getContext()->ClearSelected();
prs->SetTextLabels( selection );
getAISObject()->Redisplay();
{
myBathPrs = new HYDROGUI_ShapeBathymetry( 0, TestViewer::context(), myBath );
myBathPrs->Build();
+ myBathPrs->getAISObject()->SetAutoHilight( Standard_False );
double min, max;
myBathPrs->GetRange( min, max );
TestViewer::setKey( "bathy_selection" );
CPPUNIT_ASSERT_IMAGES
+ select( 5, 5, 6, 6 );
+ TestViewer::setKey( "bathy_prs" );
+ CPPUNIT_ASSERT_IMAGES
+
//QTest::qWait( 50000 );
aDoc->Close();
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();