-// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 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
// 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
#include "HYDROGUI_ProfileInterpolateDlg.h"
-#include "HYDROGUI_Module.h"
#include "HYDROGUI_Tool.h"
-#include "HYDROGUI_AISTrihedron.h"
-
-#include <CurveCreator_Widget.h>
-#include <CurveCreator_ICurve.hxx>
-#include <CurveCreator_Utils.hxx>
+#include "HYDROGUI_Module.h"
+#include "HYDROGUI_ObjComboBox.h"
+#include "HYDROGUI_OCCSelector.h"
#include <OCCViewer_ViewPort3d.h>
#include <OCCViewer_Utilities.h>
#include <OCCViewer_ViewFrame.h>
#include <LightApp_Application.h>
+#include <SUIT_Tools.h>
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
-#include <QGroupBox>
-#include <QHBoxLayout>
#include <QLabel>
+#include <QSpinBox>
#include <QLineEdit>
-#include <QMouseEvent>
+#include <QTextEdit>
+#include <QGroupBox>
+#include <QComboBox>
+#include <QGridLayout>
+
+#include <HYDROData_Stream.h>
+#include <HYDROData_Profile.h>
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<OCCViewer_ViewFrame*>( 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 );
+
+ 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 );
- myCoordLabel = new QLabel( this );
- QHBoxLayout* aCoordLayout = new QHBoxLayout();
- aCoordLayout->addWidget( myCoordLabel );
- aCoordLayout->addStretch();
+ 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 );
- addLayout( aCoordLayout );
+ 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<int> aSections;
- aSections << 0;
- myEditorWidget->setSelectedSections( aSections );
+QString HYDROGUI_ProfileInterpolateDlg::interpolatorParameters() const
+{
+ return myParams->text();
}
-QList<int> 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->setSectedObject( 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<QBoxLayout*>( myAddElementBox->layout() );
- anAddElementLayout->addWidget( theWidget );
+void HYDROGUI_ProfileInterpolateDlg::setProfileStart( const QString& theName )
+{
+ myProfileStart->setSectedObject( 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->setSectedObject( theName );
+}
- QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
- anAddElementLayout->removeWidget( theWidget );
+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();
+}
- theWidget->hide();
- myAddElementBox->hide();
+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;
}
-void HYDROGUI_ProfileInterpolateDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
+void HYDROGUI_ProfileInterpolateDlg::reset()
{
- OCCViewer_ViewWindow* anOCCViewWindow =
- dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
- if ( anOCCViewWindow && anOCCViewWindow->getViewPort() ) {
- gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint(
- theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() );
+ myRiverProfiles.clear();
- // 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 ) );
- }
+ myRiver->reset();
+ myProfileStart->reset();
+ myProfileFinish->reset();
+ myParams->clear();
+ myDescr->clear();
+}
+
+void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished()
+{
+ emit interpolatorParametersChanged( myParams->text() );
}
-bool HYDROGUI_ProfileInterpolateDlg::eventFilter( QObject* theObj, QEvent* theEvent )
+void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName )
{
- if ( theObj->inherits( "OCCViewer_ViewPort" ) )
- {
- if ( theEvent->type() == QEvent::Leave )
- myCoordLabel->clear();
+ myRiverProfiles.clear();
- return false;
- }
+ myProfileStart->reset();
+ myProfileFinish->reset();
- return HYDROGUI_InputPanel::eventFilter( theObj, theEvent );
+ updateState();
+
+ emit riverChanged( theName );
+}
+
+void HYDROGUI_ProfileInterpolateDlg::onInterpolatorIndexChanged( int theIdx )
+{
+ emit interpolatorChanged( myIntrp->itemText( theIdx ) );
+}
+
+void HYDROGUI_ProfileInterpolateDlg::onProfileChanged( const QString& )
+{
+ updateState();
+}
+
+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;
}