X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ProfileInterpolateDlg.cxx;h=add3b8bb55537cd04b741006c4f1358ed000779d;hb=39a306b77b32044c89bf6cef4445d5bfdea43149;hp=04e6ceebc78697a337e9af61d4efd1499f3321e5;hpb=575363a8b27efeb72d97631bcf9644486b14f2dd;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx b/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx index 04e6ceeb..add3b8bb 100644 --- a/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ProfileInterpolateDlg.cxx @@ -1,12 +1,8 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// +// Copyright (C) 2014-2015 EDF-R&D // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,13 +18,10 @@ #include "HYDROGUI_ProfileInterpolateDlg.h" -#include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" -#include "HYDROGUI_AISTrihedron.h" - -#include -#include -#include +#include "HYDROGUI_Module.h" +#include "HYDROGUI_ObjComboBox.h" +#include "HYDROGUI_OCCSelector.h" #include #include @@ -36,205 +29,235 @@ #include #include +#include #include #include -#include -#include #include +#include #include -#include +#include +#include +#include +#include + +#include +#include HYDROGUI_ProfileInterpolateDlg::HYDROGUI_ProfileInterpolateDlg( HYDROGUI_Module* theModule, const QString& theTitle ) -: HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL) -{ - QHBoxLayout* aNameLayout = new QHBoxLayout(); - QLabel* aNameLabel = new QLabel(tr("PROFILE_NAME_TLT"), this); - aNameLayout->addWidget(aNameLabel); - myName = new QLineEdit(this); - aNameLayout->addWidget(myName); - - addLayout(aNameLayout); - - int anActionFlags = - CurveCreator_Widget::DisableNewSection | CurveCreator_Widget::DisableDetectionMode | - CurveCreator_Widget::DisableClosedSection; - QStringList aCoordTitles; - aCoordTitles << tr( "U_TITLE" ) << tr( "Z_TITLE" ); - myEditorWidget = new CurveCreator_Widget( this, NULL, anActionFlags, aCoordTitles ); - addWidget( myEditorWidget, 3 ); - - myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), this ); - addWidget( myAddElementBox, 2 ); - - QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox ); - anAddElementLayout->setMargin( 0 ); - anAddElementLayout->setSpacing( 5 ); - - myViewManager = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 ); - OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( false ); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - aViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT, - aResMgr->backgroundValue( "OCCViewer", "xz_background", aViewer->background(OCCViewer_ViewFrame::TOP_LEFT) ) ); - aViewer->setBackground( OCCViewer_ViewFrame::TOP_RIGHT, - aResMgr->backgroundValue( "OCCViewer", "yz_background", aViewer->background(OCCViewer_ViewFrame::TOP_RIGHT) ) ); - aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT, - aResMgr->backgroundValue( "OCCViewer", "xy_background", aViewer->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) ); - aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT, - aResMgr->backgroundValue( "OCCViewer", "background", aViewer->background(OCCViewer_ViewFrame::MAIN_VIEW) ) ); - - aViewer->setTrihedronSize( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ), - aResMgr->booleanValue( "3DViewer", "relative_size", aViewer->trihedronRelative() )); - aViewer->setInteractionStyle( aResMgr->integerValue( "3DViewer", "navigation_mode", aViewer->interactionStyle() ) ); - aViewer->setZoomingStyle( aResMgr->integerValue( "3DViewer", "zooming_mode", aViewer->zoomingStyle() ) ); - aViewer->enablePreselection( aResMgr->booleanValue( "OCCViewer", "enable_preselection", aViewer->isPreselectionEnabled() ) ); - aViewer->enableSelection( aResMgr->booleanValue( "OCCViewer", "enable_selection", aViewer->isSelectionEnabled() ) ); - - myViewManager->setViewModel( aViewer );// custom view model, which extends SALOME_View interface - SUIT_ViewWindow* aViewWin = myViewManager->createViewWindow(); - aViewer->setStaticTrihedronDisplayed( false ); - Handle(AIS_Trihedron) aTrihedron = HYDROGUI_AISTrihedron::createTrihedron( - aResMgr->doubleValue( "3DViewer", "trihedron_size", - aViewer->trihedronSize() )); - Handle(AIS_InteractiveContext) anAISContext = aViewer->getAISContext(); - if ( !anAISContext.IsNull() ) { - anAISContext->Display( aTrihedron ); - anAISContext->Deactivate( aTrihedron ); - } - - addWidget( aViewWin, 4 ); - myEditorWidget->setOCCViewer( aViewer ); - - connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) ); - connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) ); - connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) ); - - myAddElementBox->hide(); - - // Coordinates - connect( myViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ), - this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) ); - if ( aViewWin ) { - OCCViewer_ViewFrame* aViewFrame = dynamic_cast( aViewWin ); - if ( aViewFrame && aViewFrame->getViewPort() ) { - aViewFrame->getViewPort()->installEventFilter( this ); - } - } + : HYDROGUI_ViewerDlg( theModule, theTitle ) +{ + QWidget* main = new QGroupBox( mainFrame() ); + QGridLayout* base = new QGridLayout( main ); + + addWidget( main ); + + base->addWidget( new QLabel( tr( "STREAM_OBJECT" ), main ), 0, 0, 1, 1 ); + base->addWidget( myRiver = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_STREAM, main ), 0, 1, 1, 1 ); + + base->addWidget( new QLabel( tr( "INTERPOLATOR" ), main ), 1, 0, 1, 1 ); + base->addWidget( myIntrp = new QComboBox( main ), 1, 1, 1, 1 ); + + base->addWidget( new QLabel( tr( "DESCRIPTION" ), main ), 2, 0, 1, 1 ); + base->addWidget( myDescr = new QTextEdit( main ), 2, 1, 1, 1 ); + myDescr->setReadOnly( true ); + + base->addWidget( new QLabel( tr( "PROFILE_1" ), main ), 3, 0, 1, 1 ); + base->addWidget( myProfileStart = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_PROFILE, main ), 3, 1, 1, 1 ); + myProfileStart->setObjectFilter( this ); - myCoordLabel = new QLabel( this ); - QHBoxLayout* aCoordLayout = new QHBoxLayout(); - aCoordLayout->addWidget( myCoordLabel ); - aCoordLayout->addStretch(); + base->addWidget( new QLabel( tr( "PROFILE_2" ), main ), 4, 0, 1, 1 ); + base->addWidget( myProfileFinish = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_PROFILE, main ), 4, 1, 1, 1 ); + myProfileFinish->setObjectFilter( this ); - addLayout( aCoordLayout ); + base->addWidget( new QLabel( tr( "NUMBER_OF_PROFILES" ), main ), 5, 0, 1, 1 ); + base->addWidget( myProfileNumber = new QSpinBox( main ), 5, 1, 1, 1 ); + myProfileNumber->setRange( 1, 1000 ); + + base->addWidget( new QLabel( tr( "PARAMETERS" ), main ), 6, 0, 1, 1 ); + base->addWidget( myParams = new QLineEdit( main ), 6, 1, 1, 1 ); + + connect( myRiver, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onRiverChanged( const QString& ) ) ); + connect( myIntrp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onInterpolatorIndexChanged( int ) ) ); + + connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) ); + connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) ); + + connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileStartChanged( const QString& ) ) ); + connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) ); + + connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) ); + connect( myParams, SIGNAL( editingFinished() ), this, SIGNAL( onParametersEditingFinished() ) ); + + new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() ); + + updateState(); } HYDROGUI_ProfileInterpolateDlg::~HYDROGUI_ProfileInterpolateDlg() { - delete myViewManager; } -void HYDROGUI_ProfileInterpolateDlg::reset() +QString HYDROGUI_ProfileInterpolateDlg::interpolator() const { - myEditorWidget->reset(); - myEditorWidget->setActionMode( CurveCreator_Widget::AdditionMode ); + return myIntrp->currentText(); } -Handle(AIS_InteractiveContext) HYDROGUI_ProfileInterpolateDlg::getAISContext() +void HYDROGUI_ProfileInterpolateDlg::setInterpolator( const QString& theInterp ) { - OCCViewer_Viewer* aViewer = (OCCViewer_Viewer*)myViewManager->getViewModel(); - return aViewer ? aViewer->getAISContext() : 0; + int idx = myIntrp->findText( theInterp ); + if ( idx >= 0 ) + myIntrp->setCurrentIndex( idx ); } -void HYDROGUI_ProfileInterpolateDlg::setProfileName( const QString& theName ) +void HYDROGUI_ProfileInterpolateDlg::setInterpolators( const QStringList& theList ) { - myName->setText(theName); + myIntrp->clear(); + myIntrp->addItems( theList ); } -QString HYDROGUI_ProfileInterpolateDlg::getProfileName() const +QString HYDROGUI_ProfileInterpolateDlg::interpolatorDescription() const { - return myName->text(); + return myDescr->toPlainText(); } -void HYDROGUI_ProfileInterpolateDlg::setProfile( CurveCreator_ICurve* theProfile ) +void HYDROGUI_ProfileInterpolateDlg::setInterpolatorDescription( const QString& theText ) { - myEditorWidget->setCurve( theProfile ); + myDescr->setText( theText ); +} - // select the single section by default - QList aSections; - aSections << 0; - myEditorWidget->setSelectedSections( aSections ); +QString HYDROGUI_ProfileInterpolateDlg::interpolatorParameters() const +{ + return myParams->text(); } -QList HYDROGUI_ProfileInterpolateDlg::getSelectedSections() +void HYDROGUI_ProfileInterpolateDlg::setInterpolatorParameters( const QString& theLine ) { - return myEditorWidget->getSelectedSections(); + myParams->setText( theLine ); } -/** - * Redirect the delete action to editor widget - */ -void HYDROGUI_ProfileInterpolateDlg::deleteSelected() +QString HYDROGUI_ProfileInterpolateDlg::river() const { - myEditorWidget->removeSelected(); + return myRiver->selectedObject(); } -/** - * Checks whether there are some to delete - */ -bool HYDROGUI_ProfileInterpolateDlg::deleteEnabled() +void HYDROGUI_ProfileInterpolateDlg::setRiver( const QString& theName ) { - return myEditorWidget->removeEnabled(); + myRiver->setSelectedObject( theName ); } -void HYDROGUI_ProfileInterpolateDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit ) +QString HYDROGUI_ProfileInterpolateDlg::profileStart() const { - myEditorWidget->setEnabled( false ); + return myProfileStart->selectedObject(); +} - myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) ); - QBoxLayout* anAddElementLayout = dynamic_cast( myAddElementBox->layout() ); - anAddElementLayout->addWidget( theWidget ); +void HYDROGUI_ProfileInterpolateDlg::setProfileStart( const QString& theName ) +{ + myProfileStart->setSelectedObject( theName ); +} - theWidget->show(); - myAddElementBox->show(); +QString HYDROGUI_ProfileInterpolateDlg::profileFinish() const +{ + return myProfileFinish->selectedObject(); } -void HYDROGUI_ProfileInterpolateDlg::processFinishedSubOperation( QWidget* theWidget ) +void HYDROGUI_ProfileInterpolateDlg::setProfileFinish( const QString& theName ) { - myEditorWidget->setEnabled( true ); + myProfileFinish->setSelectedObject( theName ); +} + +int HYDROGUI_ProfileInterpolateDlg::profileNumber() const +{ + return myProfileNumber->value(); +} + +void HYDROGUI_ProfileInterpolateDlg::setProfileNumber( int theNum ) +{ + myProfileNumber->setValue( theNum ); +} + +bool HYDROGUI_ProfileInterpolateDlg::isActive( HYDROGUI_ObjComboBox* selector ) const +{ + return selector == activeProfile(); +} + +bool HYDROGUI_ProfileInterpolateDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const +{ + if ( theEntity.IsNull() ) + return false; + + bool res = true; + if ( theEntity->GetKind() == KIND_PROFILE ) + { + if ( myRiverProfiles.isEmpty() ) + { + Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), river(), KIND_STREAM ) ); + if ( !aStream.IsNull() ) + { + HYDROData_SequenceOfObjects aProfiles = aStream->GetProfiles(); + HYDROGUI_ProfileInterpolateDlg* that = (HYDROGUI_ProfileInterpolateDlg*)this; + for ( int i = aProfiles.Lower(); i <= aProfiles.Upper(); i++ ) + that->myRiverProfiles.insert( aProfiles.Value( i )->GetName() ); + } + } + res = myRiverProfiles.contains( theEntity->GetName() ); + } + return res; +} - QBoxLayout* anAddElementLayout = dynamic_cast( myAddElementBox->layout() ); - anAddElementLayout->removeWidget( theWidget ); +void HYDROGUI_ProfileInterpolateDlg::reset() +{ + myRiverProfiles.clear(); - theWidget->hide(); - myAddElementBox->hide(); + myRiver->reset(); + myProfileStart->reset(); + myProfileFinish->reset(); + myParams->clear(); + myDescr->clear(); } -void HYDROGUI_ProfileInterpolateDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent ) +void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished() { - OCCViewer_ViewWindow* anOCCViewWindow = - dynamic_cast(theViewWindow); - if ( anOCCViewWindow && anOCCViewWindow->getViewPort() ) { - gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( - theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() ); + emit interpolatorParametersChanged( myParams->text() ); +} + +void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName ) +{ + myRiverProfiles.clear(); + + myProfileStart->reset(); + myProfileFinish->reset(); + + updateState(); - // Show the coordinates - QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), true ); - QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), true ); - myCoordLabel->setText( tr("UZ_COORDINATES_INFO").arg( aX ).arg( anY ) ); - } + emit riverChanged( theName ); } -bool HYDROGUI_ProfileInterpolateDlg::eventFilter( QObject* theObj, QEvent* theEvent ) +void HYDROGUI_ProfileInterpolateDlg::onInterpolatorIndexChanged( int theIdx ) { - if ( theObj->inherits( "OCCViewer_ViewPort" ) ) - { - if ( theEvent->type() == QEvent::Leave ) - myCoordLabel->clear(); + emit interpolatorChanged( myIntrp->itemText( theIdx ) ); +} - return false; - } +void HYDROGUI_ProfileInterpolateDlg::onProfileChanged( const QString& ) +{ + updateState(); +} - return HYDROGUI_InputPanel::eventFilter( theObj, theEvent ); +void HYDROGUI_ProfileInterpolateDlg::updateState() +{ + setApplyEnabled( !river().isEmpty() && !profileStart().isEmpty() && !profileFinish().isEmpty() && profileStart() != profileFinish() ); +} + +HYDROGUI_ObjComboBox* HYDROGUI_ProfileInterpolateDlg::activeProfile() const +{ + HYDROGUI_ObjComboBox* profile = myProfileFinish; + if ( myProfileStart->selectedObject().isEmpty() ) + profile = myProfileStart; + else if ( myProfileFinish->selectedObject().isEmpty() ) + profile = myProfileFinish; + else if ( SUIT_Tools::isParent( myProfileStart->parentWidget()->focusWidget(), myProfileStart ) ) + profile = myProfileStart; + else if ( SUIT_Tools::isParent( myProfileFinish->parentWidget()->focusWidget(), myProfileFinish ) ) + profile = myProfileFinish; + return profile; }