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