Salome HOME
improve test h003 h008 h016
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_StreamDlg.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_StreamDlg.h"
20 #include "HYDROGUI_ListSelector.h"
21 #include "HYDROGUI_OrderedListWidget.h"
22 #include <HYDROData_Profile.h>
23
24 #ifndef LIGHT_MODE
25   #include "HYDROGUI_Module.h"
26   #include "HYDROGUI_Tool2.h"
27   #include <LightApp_Application.h>
28   #include <LightApp_SelectionMgr.h>
29 #endif
30
31 #include <QComboBox>
32 #include <QGroupBox>
33 #include <QLabel>
34 #include <QLayout>
35 #include <QLineEdit>
36 #include <QListWidget>
37 #include <QPushButton>
38 #include <QDoubleSpinBox>
39 #include <QTextEdit>
40 #include <QRadioButton>
41
42 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
43 : HYDROGUI_InputPanel( theModule, theTitle )
44 {
45   // Stream name
46   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
47
48   myObjectName = new QLineEdit( myObjectNameGroup );
49
50   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
51   aNameLayout->setMargin( 5 );
52   aNameLayout->setSpacing( 5 );
53   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
54   aNameLayout->addWidget( myObjectName );
55
56   // Stream parameters
57   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
58
59   myAxes = new QComboBox( aParamGroup );
60   myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
61
62   myLeftBanks = new QComboBox( aParamGroup );
63   myLeftBanks->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
64
65   myRightBanks = new QComboBox( aParamGroup );
66   myRightBanks->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
67
68   myProfilePoints = new QSpinBox();
69   myProfilePoints->setRange(3, 99999);
70   myProfilePoints->setValue(100);
71
72   myDDZ = new QDoubleSpinBox( aParamGroup );
73   myDDZ->setRange( 0.01, 100 );
74   myDDZ->setSingleStep( 0.1 );
75   myDDZ->setValue( 0.1 );
76   myDDZ->setDecimals( 2 );
77   mySpatialStep = new QDoubleSpinBox( aParamGroup );
78   mySpatialStep->setRange( 0.1, 9999 );
79   mySpatialStep->setSingleStep( 0.1 );
80   mySpatialStep->setValue( 1 );
81   mySpatialStep->setDecimals( 2 );
82   
83   myModeButton = new QRadioButton( tr( "VIA_DTM" ), myObjectNameGroup );
84   myModeButton->setAutoExclusive(true);
85   myModeButton2 = new QRadioButton( tr( "VIA_LISM" ), myObjectNameGroup );
86   myModeButton2->setAutoExclusive(true);
87   myModeButton->setChecked(true);
88   myModeButton2->setChecked(false);
89   
90   QGridLayout* aParam1Layout = new QGridLayout();
91
92   aParam1Layout->addWidget( myModeButton, 0, 0 );
93   aParam1Layout->addWidget( myModeButton2, 0, 1 );
94
95   myDDZLabel = new QLabel( tr( "STREAM_DDZ" ) );
96   aParam1Layout->setMargin( 0 );
97   aParam1Layout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ), 1, 0 );
98   aParam1Layout->addWidget( myAxes, 1, 1 );
99   aParam1Layout->addWidget( myDDZLabel, 2, 0 );
100   aParam1Layout->addWidget( myDDZ, 2, 1 );
101   aParam1Layout->addWidget( new QLabel( tr( "STREAM_SPATIAL_STEP" ) ), 3, 0 );
102   aParam1Layout->addWidget( mySpatialStep, 3, 1 );
103
104   ///line. intr method widgets
105   myLeftBanksLabel = new QLabel( tr( "STREAM_LEFT_BANK" ) );
106   myRightBanksLabel = new QLabel( tr( "STREAM_RIGHT_BANK" ) );
107   myProfilePointsLabel =  new QLabel( tr( "STREAM_PROFILE_POINTS" ) );
108
109   aParam1Layout->addWidget( myLeftBanksLabel, 4, 0 );
110   aParam1Layout->addWidget( myLeftBanks, 4, 1 );
111   aParam1Layout->addWidget( myRightBanksLabel, 5, 0 );
112   aParam1Layout->addWidget( myRightBanks, 5, 1 );
113   aParam1Layout->addWidget( myProfilePointsLabel, 6, 0 );
114   aParam1Layout->addWidget( myProfilePoints, 6, 1 );
115
116   myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
117   myProfiles->setHiddenObjectsShown(true);
118   myProfiles->setVisibilityIconShown(false);
119   myProfiles->setContentsMargins(QMargins());
120   myProfiles->setOrderingEnabled( false );
121  
122   myAddButton = new QPushButton( aParamGroup );
123   myAddButton->setText( tr("ADD") );
124   myRemoveButton = new QPushButton( aParamGroup );
125   myRemoveButton->setText( tr("REMOVE") );
126   QBoxLayout* aButtonsLayout = new QHBoxLayout();
127   aButtonsLayout->addWidget( myAddButton );
128   aButtonsLayout->addWidget( myRemoveButton );
129   aButtonsLayout->addStretch();
130  
131   QBoxLayout* aParamLayout = new QVBoxLayout();
132   aParamLayout->setMargin( 5 );
133   aParamLayout->setSpacing( 5 );
134   aParamLayout->addLayout( aParam1Layout );
135   aParamLayout->addWidget( myProfiles );
136   aParamLayout->addLayout( aButtonsLayout );
137   
138   aParamGroup->setLayout( aParamLayout );
139
140   // Warnings
141   QGroupBox* aWarnGroup = new QGroupBox( tr( "STREAM_WARNINGS" ), mainFrame() );
142   myWarnText = new QTextEdit(); 
143   myWarnText->setReadOnly(true);
144   QBoxLayout* aWarnLayout = new QVBoxLayout();
145   aWarnLayout->addWidget( myWarnText );  
146   aWarnGroup->setLayout( aWarnLayout );
147
148   // Common
149   addWidget( myObjectNameGroup );
150   addWidget( aParamGroup );
151   addWidget( aWarnGroup );
152   addStretch();
153
154   // Create selector
155   if ( module() ) {
156     HYDROGUI_ListSelector* aListSelector = 
157 #ifdef LIGHT_MODE
158       new HYDROGUI_ListSelector( myProfiles, 0 );
159 #else
160       new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
161 #endif
162     aListSelector->setAutoBlock( true );
163   }
164
165   // Connect signals and slots
166   connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) );
167   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
168   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
169   connect( myDDZ, SIGNAL( valueChanged (double) ), this, SLOT (onDDZValueChanged(double)));
170   connect( mySpatialStep, SIGNAL( valueChanged (double) ), this, SLOT (onSSValueChanged(double)));
171   ///
172   connect( myLeftBanks, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( LeftBankChanged( const QString& ) ) );
173   connect( myRightBanks, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( RightBankChanged( const QString& ) ) );
174   connect( myProfilePoints, SIGNAL( valueChanged (int) ), this, SIGNAL (ProfilePointsChanged(int)));
175
176   connect( myModeButton, SIGNAL( toggled( bool ) ), this, SIGNAL( ModeChanged( bool ) ) );
177   connect( myModeButton, SIGNAL( toggled( bool ) ), this, SLOT( ModeChangedDlg( bool ) ) );
178
179   ModeChangedDlg(true);
180
181   //myModeButton->setChecked(false);
182 }
183
184 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
185 {
186 }
187
188 void HYDROGUI_StreamDlg::reset()
189 {
190   bool isBlocked = blockSignals( true );
191
192   myObjectName->clear();
193
194   myAxes->clear();
195   myLeftBanks->clear();
196   myRightBanks->clear();
197
198   myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
199
200   myAddButton->setEnabled( true );
201   myRemoveButton->setEnabled( true );
202
203   blockSignals( isBlocked );
204 }
205
206 QList<Handle(HYDROData_Entity)> HYDROGUI_StreamDlg::getProfiles()
207 {
208   return myProfiles->getObjects();
209 }
210
211 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
212 {
213   myObjectName->setText( theName );
214 }
215
216 QString HYDROGUI_StreamDlg::getObjectName() const
217 {
218   return myObjectName->text();
219 }
220
221 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
222 {
223   bool isBlocked = blockSignals( true );
224
225   myAxes->clear();
226   myAxes->addItems( theAxises );
227
228   blockSignals( isBlocked );
229 }
230
231 void HYDROGUI_StreamDlg::setLeftBankNames( const QStringList& theBanks )
232 {
233   bool isBlocked = blockSignals( true );
234
235   myLeftBanks->clear();
236   myLeftBanks->addItems( theBanks );
237
238   blockSignals( isBlocked );
239 }
240
241 void HYDROGUI_StreamDlg::setRightBankNames( const QStringList& theBanks )
242 {
243   bool isBlocked = blockSignals( true );
244
245   myRightBanks->clear();
246   myRightBanks->addItems( theBanks );
247
248   blockSignals( isBlocked );
249 }
250
251 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
252 {
253   bool isBlocked = blockSignals( true );
254
255   int aNewId = myAxes->findText( theName );
256   if ( aNewId != myAxes->currentIndex() ) {
257     myAxes->setCurrentIndex( aNewId );
258   }
259   //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
260
261   blockSignals( isBlocked );
262 }
263
264 void HYDROGUI_StreamDlg::setLeftBankName( const QString& theName )
265 {
266   bool isBlocked = blockSignals( true );
267
268   int aNewId = myLeftBanks->findText( theName );
269   if ( aNewId != myLeftBanks->currentIndex() ) {
270     myLeftBanks->setCurrentIndex( aNewId );
271   }
272   //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
273
274   blockSignals( isBlocked );
275 }
276
277 void HYDROGUI_StreamDlg::setRightBankName( const QString& theName )
278 {
279   bool isBlocked = blockSignals( true );
280
281   int aNewId = myRightBanks->findText( theName );
282   if ( aNewId != myRightBanks->currentIndex() ) {
283     myRightBanks->setCurrentIndex( aNewId );
284   }
285   //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
286
287   blockSignals( isBlocked );
288 }
289
290
291 QString HYDROGUI_StreamDlg::getAxisName() const
292 {
293   return myAxes->currentText();
294 }
295
296 QString HYDROGUI_StreamDlg::getLeftBankName() const
297 {
298   return myLeftBanks->currentText();
299 }
300
301 QString HYDROGUI_StreamDlg::getRightBankName() const
302 {
303   return myRightBanks->currentText();
304 }
305
306 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
307 {
308   bool isBlocked = blockSignals( true );
309
310   myProfiles->setUpdatesEnabled( false );
311   
312   HYDROGUI_ListModel::Object2VisibleList aProfiles;
313 #ifndef LIGHT_MODE
314   foreach ( const QString& aProfileName, theProfiles )
315   {
316     Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( 
317       HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
318     if ( !anObject.IsNull() )
319     {
320       aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
321     }
322   }
323 #endif
324
325   myProfiles->setObjects( aProfiles );
326
327
328   myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
329
330   myProfiles->setUpdatesEnabled( true );
331
332   blockSignals( isBlocked );
333 }
334
335 void HYDROGUI_StreamDlg::onRemoveProfiles()
336 {
337   QStringList aSelectedProfiles = myProfiles->getSelectedNames();
338
339   emit RemoveProfiles( aSelectedProfiles );
340 }
341
342 void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
343 {
344   emit DDZValueChanged( d );
345 }
346
347 void HYDROGUI_StreamDlg::onSSValueChanged(double d)
348 {
349   emit SSValueChanged( d );
350 }
351
352
353 void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
354 {
355   myDDZ->setValue( theDDZ );
356 }
357
358 double HYDROGUI_StreamDlg::getDDZ() const
359 {
360   return myDDZ->value();
361 }
362
363 void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
364 {
365   mySpatialStep->setValue( theSpatialStep );
366 }
367
368 double HYDROGUI_StreamDlg::getSpatialStep() const
369 {
370   return mySpatialStep->value();
371 }
372
373 void HYDROGUI_StreamDlg::setNbProfilePoints( const int theNbPoints )
374 {
375   myProfilePoints->setValue( theNbPoints );
376 }
377
378 int HYDROGUI_StreamDlg::getNbProfilePoints() const
379 {
380   return myProfilePoints->value();
381 }
382
383
384 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (int theInd, QColor theColor)
385 {
386   myProfiles->setBackgroundColor(theInd, theColor);
387 }
388
389 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (QString name, QColor theColor)
390 {
391   myProfiles->setBackgroundColor(name, theColor);
392 }
393
394 QColor HYDROGUI_StreamDlg::getBackgroundColorForProfileList (int theInd) const
395 {
396   return myProfiles->getBackgroundColor(theInd);
397 }
398
399 void HYDROGUI_StreamDlg::clearAllBackgroundColorsForProfileList ()
400 {
401   myProfiles->clearAllBackgroundColors();
402 }
403
404 void HYDROGUI_StreamDlg::addWarning( const QString& theWarnMess )
405 {
406   myWarnText->append( theWarnMess );
407 }
408
409 void HYDROGUI_StreamDlg::clearWarnings()
410 {
411   myWarnText->clear();
412 }
413
414
415 void HYDROGUI_StreamDlg::ModeChangedDlg(bool mode)
416 {
417   //if ( signalsBlocked() )
418   //  return;
419   if (mode)
420   {
421     myProfilePoints->setVisible(false);
422     myProfilePointsLabel->setVisible(false);
423
424     myLeftBanks->setVisible(false);
425     myLeftBanksLabel->setVisible(false);
426
427     myRightBanks->setVisible(false);
428     myRightBanksLabel->setVisible(false);
429
430     myDDZ->setVisible(true);
431     myDDZLabel->setVisible(true);
432   }
433   else
434   {
435     myProfilePoints->setVisible(true);
436     myProfilePointsLabel->setVisible(true);
437
438     myLeftBanks->setVisible(true);
439     myLeftBanksLabel->setVisible(true);
440
441     myRightBanks->setVisible(true);
442     myRightBanksLabel->setVisible(true);
443
444     myDDZ->setVisible(false);
445     myDDZLabel->setVisible(false);
446   }
447
448 }
449
450 int HYDROGUI_StreamDlg::getMode()
451 {
452   bool isCh = myModeButton->isChecked();
453   return isCh ? 0 : 1;
454 }
455
456 void HYDROGUI_StreamDlg::setMode(int mode)
457 {
458   bool checkState = mode == 0;
459   myModeButton->setChecked(checkState);
460   myModeButton2->setChecked(!checkState);
461 }
462
463
464