1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ProfileInterpolateDlg.h"
21 #include "HYDROGUI_Tool2.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_ObjComboBox.h"
24 #include "HYDROGUI_OCCSelector.h"
26 #include <OCCViewer_ViewPort3d.h>
27 #include <OCCViewer_Utilities.h>
28 #include <OCCViewer_ViewManager.h>
29 #include <OCCViewer_ViewFrame.h>
30 #include <LightApp_Application.h>
32 #include <SUIT_Tools.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
42 #include <QGridLayout>
44 #include <HYDROData_Stream.h>
45 #include <HYDROData_Profile.h>
47 HYDROGUI_ProfileInterpolateDlg::HYDROGUI_ProfileInterpolateDlg( HYDROGUI_Module* theModule, const QString& theTitle )
48 : HYDROGUI_ViewerDlg( theModule, theTitle, false )
50 QWidget* main = new QGroupBox( mainFrame() );
51 QGridLayout* base = new QGridLayout( main );
55 base->addWidget( new QLabel( tr( "STREAM_OBJECT" ), main ), 0, 0, 1, 1 );
56 base->addWidget( myRiver = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_STREAM, main ), 0, 1, 1, 1 );
58 base->addWidget( new QLabel( tr( "INTERPOLATOR" ), main ), 1, 0, 1, 1 );
59 base->addWidget( myIntrp = new QComboBox( main ), 1, 1, 1, 1 );
61 base->addWidget( new QLabel( tr( "DESCRIPTION" ), main ), 2, 0, 1, 1 );
62 base->addWidget( myDescr = new QTextEdit( main ), 2, 1, 1, 1 );
63 myDescr->setReadOnly( true );
65 base->addWidget( new QLabel( tr( "PROFILE_1" ), main ), 3, 0, 1, 1 );
66 base->addWidget( myProfileStart = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_PROFILE, main ), 3, 1, 1, 1 );
67 myProfileStart->setObjectFilter( this );
69 base->addWidget( new QLabel( tr( "PROFILE_2" ), main ), 4, 0, 1, 1 );
70 base->addWidget( myProfileFinish = new HYDROGUI_ObjComboBox( theModule, QString::null, KIND_PROFILE, main ), 4, 1, 1, 1 );
71 myProfileFinish->setObjectFilter( this );
73 base->addWidget( new QLabel( tr( "NUMBER_OF_PROFILES" ), main ), 5, 0, 1, 1 );
74 base->addWidget( myProfileNumber = new QSpinBox( main ), 5, 1, 1, 1 );
75 myProfileNumber->setRange( 1, 1000 );
77 base->addWidget( new QLabel( tr( "PARAMETERS" ), main ), 6, 0, 1, 1 );
78 base->addWidget( myParams = new QLineEdit( main ), 6, 1, 1, 1 );
80 connect( myRiver, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onRiverChanged( const QString& ) ) );
81 connect( myIntrp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onInterpolatorIndexChanged( int ) ) );
83 connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) );
84 connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) );
86 connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileStartChanged( const QString& ) ) );
87 connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) );
89 connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) );
90 connect( myParams, SIGNAL( editingFinished() ), this, SIGNAL( onParametersEditingFinished() ) );
92 new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() );
97 HYDROGUI_ProfileInterpolateDlg::~HYDROGUI_ProfileInterpolateDlg()
101 QString HYDROGUI_ProfileInterpolateDlg::interpolator() const
103 return myIntrp->currentText();
106 void HYDROGUI_ProfileInterpolateDlg::setInterpolator( const QString& theInterp )
108 int idx = myIntrp->findText( theInterp );
110 myIntrp->setCurrentIndex( idx );
113 void HYDROGUI_ProfileInterpolateDlg::setInterpolators( const QStringList& theList )
116 myIntrp->addItems( theList );
119 QString HYDROGUI_ProfileInterpolateDlg::interpolatorDescription() const
121 return myDescr->toPlainText();
124 void HYDROGUI_ProfileInterpolateDlg::setInterpolatorDescription( const QString& theText )
126 myDescr->setText( theText );
129 QString HYDROGUI_ProfileInterpolateDlg::interpolatorParameters() const
131 return myParams->text();
134 void HYDROGUI_ProfileInterpolateDlg::setInterpolatorParameters( const QString& theLine )
136 myParams->setText( theLine );
139 QString HYDROGUI_ProfileInterpolateDlg::river() const
141 return myRiver->selectedObject();
144 void HYDROGUI_ProfileInterpolateDlg::setRiver( const QString& theName )
146 myRiver->setSelectedObject( theName );
149 QString HYDROGUI_ProfileInterpolateDlg::profileStart() const
151 return myProfileStart->selectedObject();
154 void HYDROGUI_ProfileInterpolateDlg::setProfileStart( const QString& theName )
156 myProfileStart->setSelectedObject( theName );
159 QString HYDROGUI_ProfileInterpolateDlg::profileFinish() const
161 return myProfileFinish->selectedObject();
164 void HYDROGUI_ProfileInterpolateDlg::setProfileFinish( const QString& theName )
166 myProfileFinish->setSelectedObject( theName );
169 int HYDROGUI_ProfileInterpolateDlg::profileNumber() const
171 return myProfileNumber->value();
174 void HYDROGUI_ProfileInterpolateDlg::setProfileNumber( int theNum )
176 myProfileNumber->setValue( theNum );
179 bool HYDROGUI_ProfileInterpolateDlg::isActive( HYDROGUI_ObjComboBox* selector ) const
181 return selector == activeProfile();
184 bool HYDROGUI_ProfileInterpolateDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
186 if ( theEntity.IsNull() )
190 if ( theEntity->GetKind() == KIND_PROFILE )
192 if ( myRiverProfiles.isEmpty() )
194 Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), river(), KIND_STREAM ) );
195 if ( !aStream.IsNull() )
197 HYDROData_SequenceOfObjects aProfiles = aStream->GetProfiles();
198 HYDROGUI_ProfileInterpolateDlg* that = (HYDROGUI_ProfileInterpolateDlg*)this;
199 for ( int i = aProfiles.Lower(); i <= aProfiles.Upper(); i++ )
200 that->myRiverProfiles.insert( aProfiles.Value( i )->GetName() );
203 res = myRiverProfiles.contains( theEntity->GetName() );
208 void HYDROGUI_ProfileInterpolateDlg::reset()
210 myRiverProfiles.clear();
213 myProfileStart->reset();
214 myProfileFinish->reset();
219 void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished()
221 emit interpolatorParametersChanged( myParams->text() );
224 void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName )
226 myRiverProfiles.clear();
228 myProfileStart->reset();
229 myProfileFinish->reset();
233 emit riverChanged( theName );
236 void HYDROGUI_ProfileInterpolateDlg::onInterpolatorIndexChanged( int theIdx )
238 emit interpolatorChanged( myIntrp->itemText( theIdx ) );
241 void HYDROGUI_ProfileInterpolateDlg::onProfileChanged( const QString& )
246 void HYDROGUI_ProfileInterpolateDlg::updateState()
248 setApplyEnabled( !river().isEmpty() && !profileStart().isEmpty() && !profileFinish().isEmpty() && profileStart() != profileFinish() );
251 HYDROGUI_ObjComboBox* HYDROGUI_ProfileInterpolateDlg::activeProfile() const
253 HYDROGUI_ObjComboBox* profile = myProfileFinish;
254 if ( myProfileStart->selectedObject().isEmpty() )
255 profile = myProfileStart;
256 else if ( myProfileFinish->selectedObject().isEmpty() )
257 profile = myProfileFinish;
258 else if ( SUIT_Tools::isParent( myProfileStart->parentWidget()->focusWidget(), myProfileStart ) )
259 profile = myProfileStart;
260 else if ( SUIT_Tools::isParent( myProfileFinish->parentWidget()->focusWidget(), myProfileFinish ) )
261 profile = myProfileFinish;