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>
41 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
42 : HYDROGUI_InputPanel( theModule, theTitle )
45 myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
47 myObjectName = new QLineEdit( myObjectNameGroup );
49 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
50 aNameLayout->setMargin( 5 );
51 aNameLayout->setSpacing( 5 );
52 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
53 aNameLayout->addWidget( myObjectName );
56 QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
58 myAxes = new QComboBox( aParamGroup );
59 myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
60 myDDZ = new QDoubleSpinBox( aParamGroup );
61 myDDZ->setRange( 0.01, 100 );
62 myDDZ->setSingleStep( 0.1 );
63 myDDZ->setValue( 0.1 );
64 myDDZ->setDecimals( 2 );
65 mySpatialStep = new QDoubleSpinBox( aParamGroup );
66 mySpatialStep->setRange( 0.1, 100 );
67 mySpatialStep->setSingleStep( 0.1 );
68 mySpatialStep->setValue( 1 );
69 mySpatialStep->setDecimals( 2 );
71 QGridLayout* aParam1Layout = new QGridLayout();
72 aParam1Layout->setMargin( 0 );
73 aParam1Layout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ), 0, 0 );
74 aParam1Layout->addWidget( myAxes, 0, 1 );
75 aParam1Layout->addWidget( new QLabel( tr( "STREAM_DDZ" ) ), 1, 0 );
76 aParam1Layout->addWidget( myDDZ, 1, 1 );
77 aParam1Layout->addWidget( new QLabel( tr( "STREAM_SPATIAL_STEP" ) ), 2, 0 );
78 aParam1Layout->addWidget( mySpatialStep, 2, 1 );
80 myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
81 myProfiles->setHiddenObjectsShown(true);
82 myProfiles->setVisibilityIconShown(false);
83 myProfiles->setContentsMargins(QMargins());
84 myProfiles->setOrderingEnabled( false );
86 myAddButton = new QPushButton( aParamGroup );
87 myAddButton->setText( tr("ADD") );
88 myRemoveButton = new QPushButton( aParamGroup );
89 myRemoveButton->setText( tr("REMOVE") );
90 QBoxLayout* aButtonsLayout = new QHBoxLayout();
91 aButtonsLayout->addWidget( myAddButton );
92 aButtonsLayout->addWidget( myRemoveButton );
93 aButtonsLayout->addStretch();
95 QBoxLayout* aParamLayout = new QVBoxLayout();
96 aParamLayout->setMargin( 5 );
97 aParamLayout->setSpacing( 5 );
98 aParamLayout->addLayout( aParam1Layout );
99 aParamLayout->addWidget( myProfiles );
100 aParamLayout->addLayout( aButtonsLayout );
102 aParamGroup->setLayout( aParamLayout );
105 QGroupBox* aWarnGroup = new QGroupBox( tr( "STREAM_WARNINGS" ), mainFrame() );
106 myWarnText = new QTextEdit();
107 myWarnText->setReadOnly(true);
108 QBoxLayout* aWarnLayout = new QVBoxLayout();
109 aWarnLayout->addWidget( myWarnText );
110 aWarnGroup->setLayout( aWarnLayout );
113 addWidget( myObjectNameGroup );
114 addWidget( aParamGroup );
115 addWidget( aWarnGroup );
120 HYDROGUI_ListSelector* aListSelector =
122 new HYDROGUI_ListSelector( myProfiles, 0 );
124 new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
126 aListSelector->setAutoBlock( true );
129 // Connect signals and slots
130 connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) );
131 connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
132 connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
133 connect( myDDZ, SIGNAL( valueChanged (double) ), this, SLOT (onDDZValueChanged(double)));
134 connect( mySpatialStep, SIGNAL( valueChanged (double) ), this, SLOT (onSSValueChanged(double)));
137 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
141 void HYDROGUI_StreamDlg::reset()
143 bool isBlocked = blockSignals( true );
145 myObjectName->clear();
148 myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
149 myAddButton->setEnabled( true );
150 myRemoveButton->setEnabled( true );
152 blockSignals( isBlocked );
155 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
157 myObjectName->setText( theName );
160 QString HYDROGUI_StreamDlg::getObjectName() const
162 return myObjectName->text();
165 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
167 bool isBlocked = blockSignals( true );
170 myAxes->addItems( theAxises );
172 blockSignals( isBlocked );
175 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
177 bool isBlocked = blockSignals( true );
179 int aNewId = myAxes->findText( theName );
180 if ( aNewId != myAxes->currentIndex() ) {
181 myAxes->setCurrentIndex( aNewId );
183 //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
185 blockSignals( isBlocked );
188 QString HYDROGUI_StreamDlg::getAxisName() const
190 return myAxes->currentText();
193 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
195 bool isBlocked = blockSignals( true );
197 myProfiles->setUpdatesEnabled( false );
199 HYDROGUI_ListModel::Object2VisibleList aProfiles;
201 foreach ( const QString& aProfileName, theProfiles )
203 Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast(
204 HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
205 if ( !anObject.IsNull() )
207 aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
212 myProfiles->setObjects( aProfiles );
215 myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
217 myProfiles->setUpdatesEnabled( true );
219 blockSignals( isBlocked );
222 void HYDROGUI_StreamDlg::onRemoveProfiles()
224 QStringList aSelectedProfiles = myProfiles->getSelectedNames();
226 emit RemoveProfiles( aSelectedProfiles );
229 void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
231 emit DDZValueChanged( d );
234 void HYDROGUI_StreamDlg::onSSValueChanged(double d)
236 emit SSValueChanged( d );
240 void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
242 myDDZ->setValue( theDDZ );
245 double HYDROGUI_StreamDlg::getDDZ() const
247 return myDDZ->value();
250 void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
252 mySpatialStep->setValue( theSpatialStep );
255 double HYDROGUI_StreamDlg::getSpatialStep() const
257 return mySpatialStep->value();
260 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (int theInd, QColor theColor)
262 myProfiles->setBackgroundColor(theInd, theColor);
265 QColor HYDROGUI_StreamDlg::getBackgroundColorForProfileList (int theInd) const
267 return myProfiles->getBackgroundColor(theInd);
270 void HYDROGUI_StreamDlg::clearAllBackgroundColorsForProfileList ()
272 myProfiles->clearAllBackgroundColors();
275 void HYDROGUI_StreamDlg::addWarning( const QString& theWarnMess )
277 myWarnText->append( theWarnMess );
280 void HYDROGUI_StreamDlg::clearWarnings()