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 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
41 : HYDROGUI_InputPanel( theModule, theTitle )
44 myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
46 myObjectName = new QLineEdit( myObjectNameGroup );
48 QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
49 aNameLayout->setMargin( 5 );
50 aNameLayout->setSpacing( 5 );
51 aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
52 aNameLayout->addWidget( myObjectName );
55 QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
57 myAxes = new QComboBox( aParamGroup );
58 myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
59 myDDZ = new QDoubleSpinBox( aParamGroup );
60 myDDZ->setRange( 1E-2, 100 );
61 myDDZ->setSingleStep( 1E-2 );
62 myDDZ->setValue( 0.1 );
63 myDDZ->setDecimals( 2 );
64 mySpatialStep = new QDoubleSpinBox( aParamGroup );
65 mySpatialStep->setRange( 1E-2, 100 );
66 mySpatialStep->setSingleStep( 1.0 );
67 mySpatialStep->setValue( 1 );
68 mySpatialStep->setDecimals( 2 );
70 QGridLayout* aParam1Layout = new QGridLayout();
71 aParam1Layout->setMargin( 0 );
72 aParam1Layout->addWidget( new QLabel( tr( "STREAM_HYDRAULIC_AXIS" ) ), 0, 0 );
73 aParam1Layout->addWidget( myAxes, 0, 1 );
74 aParam1Layout->addWidget( new QLabel( tr( "STREAM_DDZ" ) ), 1, 0 );
75 aParam1Layout->addWidget( myDDZ, 1, 1 );
76 aParam1Layout->addWidget( new QLabel( tr( "STREAM_SPATIAL_STEP" ) ), 2, 0 );
77 aParam1Layout->addWidget( mySpatialStep, 2, 1 );
79 myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
80 myProfiles->setHiddenObjectsShown(true);
81 myProfiles->setVisibilityIconShown(false);
82 myProfiles->setContentsMargins(QMargins());
83 myProfiles->setOrderingEnabled( false );
85 myAddButton = new QPushButton( aParamGroup );
86 myAddButton->setText( tr("ADD") );
87 myRemoveButton = new QPushButton( aParamGroup );
88 myRemoveButton->setText( tr("REMOVE") );
89 QBoxLayout* aButtonsLayout = new QHBoxLayout();
90 aButtonsLayout->addWidget( myAddButton );
91 aButtonsLayout->addWidget( myRemoveButton );
92 aButtonsLayout->addStretch();
94 QBoxLayout* aParamLayout = new QVBoxLayout();
95 aParamLayout->setMargin( 5 );
96 aParamLayout->setSpacing( 5 );
97 aParamLayout->addLayout( aParam1Layout );
98 aParamLayout->addWidget( myProfiles );
99 aParamLayout->addLayout( aButtonsLayout );
103 aParamGroup->setLayout( aParamLayout );
106 addWidget( myObjectNameGroup );
107 addWidget( aParamGroup );
112 HYDROGUI_ListSelector* aListSelector =
114 new HYDROGUI_ListSelector( myProfiles, 0 );
116 new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
118 aListSelector->setAutoBlock( true );
121 // Connect signals and slots
122 connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) );
123 connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
124 connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
125 connect( myDDZ, SIGNAL( valueChanged (double) ), this, SLOT (onDDZValueChanged(double)));
126 connect( mySpatialStep, SIGNAL( valueChanged (double) ), this, SLOT (onSSValueChanged(double)));
129 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
133 void HYDROGUI_StreamDlg::reset()
135 bool isBlocked = blockSignals( true );
137 myObjectName->clear();
140 myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
141 myAddButton->setEnabled( true );
142 myRemoveButton->setEnabled( true );
144 blockSignals( isBlocked );
147 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
149 myObjectName->setText( theName );
152 QString HYDROGUI_StreamDlg::getObjectName() const
154 return myObjectName->text();
157 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
159 bool isBlocked = blockSignals( true );
162 myAxes->addItems( theAxises );
164 blockSignals( isBlocked );
167 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
169 bool isBlocked = blockSignals( true );
171 int aNewId = myAxes->findText( theName );
172 if ( aNewId != myAxes->currentIndex() ) {
173 myAxes->setCurrentIndex( aNewId );
175 //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
177 blockSignals( isBlocked );
180 QString HYDROGUI_StreamDlg::getAxisName() const
182 return myAxes->currentText();
185 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
187 bool isBlocked = blockSignals( true );
189 myProfiles->setUpdatesEnabled( false );
191 HYDROGUI_ListModel::Object2VisibleList aProfiles;
193 foreach ( const QString& aProfileName, theProfiles )
195 Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast(
196 HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
197 if ( !anObject.IsNull() )
199 aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
204 myProfiles->setObjects( aProfiles );
206 myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
208 myProfiles->setUpdatesEnabled( true );
210 blockSignals( isBlocked );
213 void HYDROGUI_StreamDlg::onRemoveProfiles()
215 QStringList aSelectedProfiles = myProfiles->getSelectedNames();
217 emit RemoveProfiles( aSelectedProfiles );
220 void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
222 emit DDZValueChanged( d );
225 void HYDROGUI_StreamDlg::onSSValueChanged(double d)
227 emit SSValueChanged( d );
231 void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
233 myDDZ->setValue( theDDZ );
236 double HYDROGUI_StreamDlg::getDDZ() const
238 return myDDZ->value();
241 void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
243 mySpatialStep->setValue( theSpatialStep );
246 double HYDROGUI_StreamDlg::getSpatialStep() const
248 return mySpatialStep->value();