1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ProfileInterpolateDlg.h"
25 #include "HYDROGUI_Tool.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_ObjComboBox.h"
28 #include "HYDROGUI_OCCSelector.h"
30 #include <OCCViewer_ViewPort3d.h>
31 #include <OCCViewer_Utilities.h>
32 #include <OCCViewer_ViewManager.h>
33 #include <OCCViewer_ViewFrame.h>
34 #include <LightApp_Application.h>
36 #include <SUIT_Tools.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_ResourceMgr.h>
46 #include <QGridLayout>
48 #include <HYDROData_Stream.h>
49 #include <HYDROData_Profile.h>
51 HYDROGUI_ProfileInterpolateDlg::HYDROGUI_ProfileInterpolateDlg( HYDROGUI_Module* theModule, const QString& theTitle )
52 : HYDROGUI_ViewerDlg( theModule, theTitle )
54 QWidget* main = new QGroupBox( mainFrame() );
55 QGridLayout* base = new QGridLayout( main );
59 base->addWidget( new QLabel( tr( "RIVER_OBJECT" ), main ), 0, 0, 1, 1 );
60 base->addWidget( myRiver = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_STREAM, main ), 0, 1, 1, 1 );
62 base->addWidget( new QLabel( tr( "INTERPOLATOR" ), main ), 1, 0, 1, 1 );
63 base->addWidget( myIntrp = new QComboBox( main ), 1, 1, 1, 1 );
65 base->addWidget( new QLabel( tr( "DESCRIPTION" ), main ), 2, 0, 1, 1 );
66 base->addWidget( myDescr = new QTextEdit( main ), 2, 1, 1, 1 );
67 myDescr->setReadOnly( true );
69 base->addWidget( new QLabel( tr( "PROFILE_1" ), main ), 3, 0, 1, 1 );
70 base->addWidget( myProfileStart = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_PROFILE, main ), 3, 1, 1, 1 );
71 myProfileStart->setObjectFilter( this );
73 base->addWidget( new QLabel( tr( "PROFILE_2" ), main ), 4, 0, 1, 1 );
74 base->addWidget( myProfileFinish = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_PROFILE, main ), 4, 1, 1, 1 );
75 myProfileFinish->setObjectFilter( this );
77 base->addWidget( new QLabel( tr( "NUMBER_OF_PROFILES" ), main ), 5, 0, 1, 1 );
78 base->addWidget( myProfileNumber = new QSpinBox( main ), 5, 1, 1, 1 );
79 myProfileNumber->setRange( 1, 1000 );
81 base->addWidget( new QLabel( tr( "PARAMETERS" ), main ), 6, 0, 1, 1 );
82 base->addWidget( myParams = new QLineEdit( main ), 6, 1, 1, 1 );
84 connect( myRiver, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onRiverChanged( const QString& ) ) );
85 connect( myIntrp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onInterpolatorIndexChanged( int ) ) );
87 connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) );
88 connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) );
90 connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileStartChanged( const QString& ) ) );
91 connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) );
93 connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) );
94 connect( myParams, SIGNAL( editingFinished() ), this, SIGNAL( onParametersEditingFinished() ) );
96 new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() );
101 HYDROGUI_ProfileInterpolateDlg::~HYDROGUI_ProfileInterpolateDlg()
105 QString HYDROGUI_ProfileInterpolateDlg::interpolator() const
107 return myIntrp->currentText();
110 void HYDROGUI_ProfileInterpolateDlg::setInterpolator( const QString& theInterp )
112 int idx = myIntrp->findText( theInterp );
114 myIntrp->setCurrentIndex( idx );
117 void HYDROGUI_ProfileInterpolateDlg::setInterpolators( const QStringList& theList )
120 myIntrp->addItems( theList );
123 QString HYDROGUI_ProfileInterpolateDlg::interpolatorDescription() const
125 return myDescr->toPlainText();
128 void HYDROGUI_ProfileInterpolateDlg::setInterpolatorDescription( const QString& theText )
130 myDescr->setText( theText );
133 QString HYDROGUI_ProfileInterpolateDlg::interpolatorParameters() const
135 return myParams->text();
138 void HYDROGUI_ProfileInterpolateDlg::setInterpolatorParameters( const QString& theLine )
140 myParams->setText( theLine );
143 QString HYDROGUI_ProfileInterpolateDlg::river() const
145 return myRiver->selectedObject();
148 void HYDROGUI_ProfileInterpolateDlg::setRiver( const QString& theName )
150 myRiver->setSectedObject( theName );
153 QString HYDROGUI_ProfileInterpolateDlg::profileStart() const
155 return myProfileStart->selectedObject();
158 void HYDROGUI_ProfileInterpolateDlg::setProfileStart( const QString& theName )
160 myProfileStart->setSectedObject( theName );
163 QString HYDROGUI_ProfileInterpolateDlg::profileFinish() const
165 return myProfileFinish->selectedObject();
168 void HYDROGUI_ProfileInterpolateDlg::setProfileFinish( const QString& theName )
170 myProfileFinish->setSectedObject( theName );
173 int HYDROGUI_ProfileInterpolateDlg::profileNumber() const
175 return myProfileNumber->value();
178 void HYDROGUI_ProfileInterpolateDlg::setProfileNumber( int theNum )
180 myProfileNumber->setValue( theNum );
183 bool HYDROGUI_ProfileInterpolateDlg::isActive( HYDROGUI_ObjComboBox* selector ) const
185 return selector == activeProfile();
188 bool HYDROGUI_ProfileInterpolateDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
190 if ( theEntity.IsNull() )
194 if ( theEntity->GetKind() == KIND_PROFILE )
196 if ( myRiverProfiles.isEmpty() )
198 Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), river(), KIND_STREAM ) );
199 if ( !aStream.IsNull() )
201 HYDROData_SequenceOfObjects aProfiles = aStream->GetProfiles();
202 HYDROGUI_ProfileInterpolateDlg* that = (HYDROGUI_ProfileInterpolateDlg*)this;
203 for ( int i = aProfiles.Lower(); i <= aProfiles.Upper(); i++ )
204 that->myRiverProfiles.insert( aProfiles.Value( i )->GetName() );
207 res = myRiverProfiles.contains( theEntity->GetName() );
212 void HYDROGUI_ProfileInterpolateDlg::reset()
214 myRiverProfiles.clear();
217 myProfileStart->reset();
218 myProfileFinish->reset();
223 void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished()
225 emit interpolatorParametersChanged( myParams->text() );
228 void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName )
230 myRiverProfiles.clear();
232 myProfileStart->reset();
233 myProfileFinish->reset();
237 emit riverChanged( theName );
240 void HYDROGUI_ProfileInterpolateDlg::onInterpolatorIndexChanged( int theIdx )
242 emit interpolatorChanged( myIntrp->itemText( theIdx ) );
245 void HYDROGUI_ProfileInterpolateDlg::onProfileChanged( const QString& )
250 void HYDROGUI_ProfileInterpolateDlg::updateState()
252 setApplyEnabled( !river().isEmpty() && !profileStart().isEmpty() && !profileFinish().isEmpty() && profileStart() != profileFinish() );
255 HYDROGUI_ObjComboBox* HYDROGUI_ProfileInterpolateDlg::activeProfile() const
257 HYDROGUI_ObjComboBox* profile = myProfileFinish;
258 if ( myProfileStart->selectedObject().isEmpty() )
259 profile = myProfileStart;
260 else if ( myProfileFinish->selectedObject().isEmpty() )
261 profile = myProfileFinish;
262 else if ( SUIT_Tools::isParent( myProfileStart->parentWidget()->focusWidget(), myProfileStart ) )
263 profile = myProfileStart;
264 else if ( SUIT_Tools::isParent( myProfileFinish->parentWidget()->focusWidget(), myProfileFinish ) )
265 profile = myProfileFinish;