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_StreamDlg.h"
20 #include "HYDROGUI_ListSelector.h"
21 #include "HYDROGUI_OrderedListWidget.h"
22 #include <HYDROData_Profile.h>
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool2.h"
27 #include <LightApp_Application.h>
28 #include <LightApp_SelectionMgr.h>
36 #include <QListWidget>
37 #include <QPushButton>
38 #include <QDoubleSpinBox>
40 #include <QRadioButton>
42 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
43 : HYDROGUI_InputPanel( theModule, theTitle )
46 myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
48 myObjectName = new QLineEdit( myObjectNameGroup );
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 );
57 QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
59 myAxes = new QComboBox( aParamGroup );
60 myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
62 myLeftBanks = new QComboBox( aParamGroup );
63 myLeftBanks->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
65 myRightBanks = new QComboBox( aParamGroup );
66 myRightBanks->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
68 myProfilePoints = new QSpinBox();
69 myProfilePoints->setRange(3, 99999);
70 myProfilePoints->setValue(100);
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, 100 );
79 mySpatialStep->setSingleStep( 0.1 );
80 mySpatialStep->setValue( 1 );
81 mySpatialStep->setDecimals( 2 );
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);
90 QGridLayout* aParam1Layout = new QGridLayout();
92 aParam1Layout->addWidget( myModeButton, 0, 0 );
93 aParam1Layout->addWidget( myModeButton2, 0, 1 );
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 );
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" ) );
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 );
116 myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
117 myProfiles->setHiddenObjectsShown(true);
118 myProfiles->setVisibilityIconShown(false);
119 myProfiles->setContentsMargins(QMargins());
120 myProfiles->setOrderingEnabled( false );
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();
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 );
138 aParamGroup->setLayout( aParamLayout );
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 );
149 addWidget( myObjectNameGroup );
150 addWidget( aParamGroup );
151 addWidget( aWarnGroup );
156 HYDROGUI_ListSelector* aListSelector =
158 new HYDROGUI_ListSelector( myProfiles, 0 );
160 new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
162 aListSelector->setAutoBlock( true );
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)));
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)));
176 connect( myModeButton, SIGNAL( toggled( bool ) ), this, SIGNAL( ModeChanged( bool ) ) );
177 connect( myModeButton, SIGNAL( toggled( bool ) ), this, SLOT( ModeChangedDlg( bool ) ) );
179 ModeChangedDlg(true);
181 //myModeButton->setChecked(false);
184 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
188 void HYDROGUI_StreamDlg::reset()
190 bool isBlocked = blockSignals( true );
192 myObjectName->clear();
195 myLeftBanks->clear();
196 myRightBanks->clear();
198 myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
200 myAddButton->setEnabled( true );
201 myRemoveButton->setEnabled( true );
203 blockSignals( isBlocked );
206 QList<Handle(HYDROData_Entity)> HYDROGUI_StreamDlg::getProfiles()
208 return myProfiles->getObjects();
211 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
213 myObjectName->setText( theName );
216 QString HYDROGUI_StreamDlg::getObjectName() const
218 return myObjectName->text();
221 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
223 bool isBlocked = blockSignals( true );
226 myAxes->addItems( theAxises );
228 blockSignals( isBlocked );
231 void HYDROGUI_StreamDlg::setLeftBankNames( const QStringList& theBanks )
233 bool isBlocked = blockSignals( true );
235 myLeftBanks->clear();
236 myLeftBanks->addItems( theBanks );
238 blockSignals( isBlocked );
241 void HYDROGUI_StreamDlg::setRightBankNames( const QStringList& theBanks )
243 bool isBlocked = blockSignals( true );
245 myRightBanks->clear();
246 myRightBanks->addItems( theBanks );
248 blockSignals( isBlocked );
251 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
253 bool isBlocked = blockSignals( true );
255 int aNewId = myAxes->findText( theName );
256 if ( aNewId != myAxes->currentIndex() ) {
257 myAxes->setCurrentIndex( aNewId );
259 //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
261 blockSignals( isBlocked );
264 void HYDROGUI_StreamDlg::setLeftBankName( const QString& theName )
266 bool isBlocked = blockSignals( true );
268 int aNewId = myLeftBanks->findText( theName );
269 if ( aNewId != myLeftBanks->currentIndex() ) {
270 myLeftBanks->setCurrentIndex( aNewId );
272 //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
274 blockSignals( isBlocked );
277 void HYDROGUI_StreamDlg::setRightBankName( const QString& theName )
279 bool isBlocked = blockSignals( true );
281 int aNewId = myRightBanks->findText( theName );
282 if ( aNewId != myRightBanks->currentIndex() ) {
283 myRightBanks->setCurrentIndex( aNewId );
285 //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
287 blockSignals( isBlocked );
291 QString HYDROGUI_StreamDlg::getAxisName() const
293 return myAxes->currentText();
296 QString HYDROGUI_StreamDlg::getLeftBankName() const
298 return myLeftBanks->currentText();
301 QString HYDROGUI_StreamDlg::getRightBankName() const
303 return myRightBanks->currentText();
306 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
308 bool isBlocked = blockSignals( true );
310 myProfiles->setUpdatesEnabled( false );
312 HYDROGUI_ListModel::Object2VisibleList aProfiles;
314 foreach ( const QString& aProfileName, theProfiles )
316 Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast(
317 HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
318 if ( !anObject.IsNull() )
320 aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
325 myProfiles->setObjects( aProfiles );
328 myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
330 myProfiles->setUpdatesEnabled( true );
332 blockSignals( isBlocked );
335 void HYDROGUI_StreamDlg::onRemoveProfiles()
337 QStringList aSelectedProfiles = myProfiles->getSelectedNames();
339 emit RemoveProfiles( aSelectedProfiles );
342 void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
344 emit DDZValueChanged( d );
347 void HYDROGUI_StreamDlg::onSSValueChanged(double d)
349 emit SSValueChanged( d );
353 void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
355 myDDZ->setValue( theDDZ );
358 double HYDROGUI_StreamDlg::getDDZ() const
360 return myDDZ->value();
363 void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
365 mySpatialStep->setValue( theSpatialStep );
368 double HYDROGUI_StreamDlg::getSpatialStep() const
370 return mySpatialStep->value();
373 void HYDROGUI_StreamDlg::setNbProfilePoints( const int theNbPoints )
375 myProfilePoints->setValue( theNbPoints );
378 int HYDROGUI_StreamDlg::getNbProfilePoints() const
380 return myProfilePoints->value();
384 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (int theInd, QColor theColor)
386 myProfiles->setBackgroundColor(theInd, theColor);
389 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (QString name, QColor theColor)
391 myProfiles->setBackgroundColor(name, theColor);
394 QColor HYDROGUI_StreamDlg::getBackgroundColorForProfileList (int theInd) const
396 return myProfiles->getBackgroundColor(theInd);
399 void HYDROGUI_StreamDlg::clearAllBackgroundColorsForProfileList ()
401 myProfiles->clearAllBackgroundColors();
404 void HYDROGUI_StreamDlg::addWarning( const QString& theWarnMess )
406 myWarnText->append( theWarnMess );
409 void HYDROGUI_StreamDlg::clearWarnings()
415 void HYDROGUI_StreamDlg::ModeChangedDlg(bool mode)
417 //if ( signalsBlocked() )
421 myProfilePoints->setVisible(false);
422 myProfilePointsLabel->setVisible(false);
424 myLeftBanks->setVisible(false);
425 myLeftBanksLabel->setVisible(false);
427 myRightBanks->setVisible(false);
428 myRightBanksLabel->setVisible(false);
430 myDDZ->setVisible(true);
431 myDDZLabel->setVisible(true);
435 myProfilePoints->setVisible(true);
436 myProfilePointsLabel->setVisible(true);
438 myLeftBanks->setVisible(true);
439 myLeftBanksLabel->setVisible(true);
441 myRightBanks->setVisible(true);
442 myRightBanksLabel->setVisible(true);
444 myDDZ->setVisible(false);
445 myDDZLabel->setVisible(false);
450 int HYDROGUI_StreamDlg::getMode()
452 bool isCh = myModeButton->isChecked();
456 void HYDROGUI_StreamDlg::setMode(int mode)
458 bool checkState = mode == 0;
459 myModeButton->setChecked(checkState);
460 myModeButton2->setChecked(!checkState);