Salome HOME
debug stream profiles linear interpolator
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ProfileInterpolateDlg.cxx
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_ProfileInterpolateDlg.h"
20
21 #include "HYDROGUI_Tool2.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_ObjComboBox.h"
24 #include "HYDROGUI_OCCSelector.h"
25
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>
31
32 #include <SUIT_Tools.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35
36 #include <QLabel>
37 #include <QSpinBox>
38 #include <QLineEdit>
39 #include <QTextEdit>
40 #include <QGroupBox>
41 #include <QComboBox>
42 #include <QGridLayout>
43
44 #include <HYDROData_Stream.h>
45 #include <HYDROData_Profile.h>
46
47 HYDROGUI_ProfileInterpolateDlg::HYDROGUI_ProfileInterpolateDlg( HYDROGUI_Module* theModule, const QString& theTitle )
48     : HYDROGUI_ViewerDlg( theModule, theTitle, false )
49 {
50     QWidget* main = new QGroupBox( mainFrame() );
51     QGridLayout* base = new QGridLayout( main );
52
53     addWidget( main );
54
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 );
57
58     base->addWidget( new QLabel( tr( "INTERPOLATOR" ), main ), 1, 0, 1, 1 );
59     base->addWidget( myIntrp = new QComboBox( main ), 1, 1, 1, 1 );
60
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 );
64
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 );
68
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 );
72
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 );
76
77     base->addWidget( new QLabel( tr( "PARAMETERS" ), main ), 6, 0, 1, 1 );
78     base->addWidget( myParams = new QLineEdit( main ), 6, 1, 1, 1 );
79
80     connect( myRiver, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onRiverChanged( const QString& ) ) );
81     connect( myIntrp, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onInterpolatorIndexChanged( int ) ) );
82
83     connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) );
84     connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SLOT( onProfileChanged( const QString& ) ) );
85
86     connect( myProfileStart, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileStartChanged( const QString& ) ) );
87     connect( myProfileFinish, SIGNAL( objectSelected( const QString& ) ), this, SIGNAL( profileFinishChanged( const QString& ) ) );
88
89     connect( myProfileNumber, SIGNAL( valueChanged( int ) ), this, SIGNAL( profileNumberChanged( int ) ) );
90     connect( myParams, SIGNAL( editingFinished() ), this, SLOT( onParametersEditingFinished() ) );
91
92     new HYDROGUI_OCCSelector( module(), viewer(), selectionMgr() );
93
94     updateState();
95 }
96
97 HYDROGUI_ProfileInterpolateDlg::~HYDROGUI_ProfileInterpolateDlg()
98 {
99 }
100
101 QString HYDROGUI_ProfileInterpolateDlg::interpolator() const
102 {
103     return myIntrp->currentText();
104 }
105
106 void HYDROGUI_ProfileInterpolateDlg::setInterpolator( const QString& theInterp )
107 {
108     int idx = myIntrp->findText( theInterp );
109     if ( idx >= 0 )
110         myIntrp->setCurrentIndex( idx );
111 }
112
113 void HYDROGUI_ProfileInterpolateDlg::setInterpolators( const QStringList& theList )
114 {
115     myIntrp->clear();
116     myIntrp->addItems( theList );
117 }
118
119 QString HYDROGUI_ProfileInterpolateDlg::interpolatorDescription() const
120 {
121     return myDescr->toPlainText();
122 }
123
124 void HYDROGUI_ProfileInterpolateDlg::setInterpolatorDescription( const QString& theText )
125 {
126     myDescr->setText( theText );
127 }
128
129 QString HYDROGUI_ProfileInterpolateDlg::interpolatorParameters() const
130 {
131     return myParams->text();
132 }
133
134 void HYDROGUI_ProfileInterpolateDlg::setInterpolatorParameters( const QString& theLine )
135 {
136     myParams->setText( theLine );
137 }
138
139 QString HYDROGUI_ProfileInterpolateDlg::river() const
140 {
141     return myRiver->selectedObject();
142 }
143
144 void HYDROGUI_ProfileInterpolateDlg::setRiver( const QString& theName )
145 {
146     myRiver->setSelectedObject( theName );
147 }
148
149 QString HYDROGUI_ProfileInterpolateDlg::profileStart() const
150 {
151     return myProfileStart->selectedObject();
152 }
153
154 void HYDROGUI_ProfileInterpolateDlg::setProfileStart( const QString& theName )
155 {
156     myProfileStart->setSelectedObject( theName );
157 }
158
159 QString HYDROGUI_ProfileInterpolateDlg::profileFinish() const
160 {
161     return myProfileFinish->selectedObject();
162 }
163
164 void HYDROGUI_ProfileInterpolateDlg::setProfileFinish( const QString& theName )
165 {
166     myProfileFinish->setSelectedObject( theName );
167 }
168
169 int HYDROGUI_ProfileInterpolateDlg::profileNumber() const
170 {
171     return myProfileNumber->value();
172 }
173
174 void HYDROGUI_ProfileInterpolateDlg::setProfileNumber( int theNum )
175 {
176     myProfileNumber->setValue( theNum );
177 }
178
179 bool HYDROGUI_ProfileInterpolateDlg::isActive( HYDROGUI_ObjComboBox* selector ) const
180 {
181     return selector == activeProfile();
182 }
183
184 bool HYDROGUI_ProfileInterpolateDlg::isOk( const Handle(HYDROData_Entity)& theEntity ) const
185 {
186     if ( theEntity.IsNull() )
187         return false;
188
189     bool res = true;
190     if ( theEntity->GetKind() == KIND_PROFILE )
191     {
192         if ( myRiverProfiles.isEmpty() )
193         {
194             Handle(HYDROData_Stream) aStream = Handle(HYDROData_Stream)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), river(), KIND_STREAM ) );
195             if ( !aStream.IsNull() )
196             {
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() );
201             }
202         }
203         res = myRiverProfiles.contains( theEntity->GetName() );
204     }
205     return res;
206 }
207
208 void HYDROGUI_ProfileInterpolateDlg::reset()
209 {
210     myRiverProfiles.clear();
211
212     myRiver->reset();
213     myProfileStart->reset();
214     myProfileFinish->reset();
215     myParams->clear();
216     myDescr->clear();
217 }
218
219 void HYDROGUI_ProfileInterpolateDlg::onParametersEditingFinished()
220 {
221     emit interpolatorParametersChanged( myParams->text() );
222 }
223
224 void HYDROGUI_ProfileInterpolateDlg::onRiverChanged( const QString& theName )
225 {
226     myRiverProfiles.clear();
227
228     myProfileStart->reset();
229     myProfileFinish->reset();
230
231     updateState();
232
233     emit riverChanged( theName );
234 }
235
236 void HYDROGUI_ProfileInterpolateDlg::onInterpolatorIndexChanged( int theIdx )
237 {
238     emit interpolatorChanged( myIntrp->itemText( theIdx ) );
239 }
240
241 void HYDROGUI_ProfileInterpolateDlg::onProfileChanged( const QString& )
242 {
243     updateState();
244 }
245
246 void HYDROGUI_ProfileInterpolateDlg::updateState()
247 {
248     setApplyEnabled( !river().isEmpty() && !profileStart().isEmpty() && !profileFinish().isEmpty() && profileStart() != profileFinish() );
249 }
250
251 HYDROGUI_ObjComboBox* HYDROGUI_ProfileInterpolateDlg::activeProfile() const
252 {
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;
262     return profile;
263 }