Salome HOME
some bug fixes
[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
40 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
41 : HYDROGUI_InputPanel( theModule, theTitle )
42 {
43   // Stream name
44   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
45
46   myObjectName = new QLineEdit( myObjectNameGroup );
47
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 );
53
54   // Stream parameters
55   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
56
57   myAxes = new QComboBox( aParamGroup );
58   myAxes->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
59   myDDZ = new QDoubleSpinBox( aParamGroup );
60   myDDZ->setRange( 0.01, 100 );
61   myDDZ->setSingleStep( 0.1 );
62   myDDZ->setValue( 0.1 );
63   myDDZ->setDecimals( 2 );
64   mySpatialStep = new QDoubleSpinBox( aParamGroup );
65   mySpatialStep->setRange( 0.1, 100 );
66   mySpatialStep->setSingleStep( 0.1 );
67   mySpatialStep->setValue( 1 );
68   mySpatialStep->setDecimals( 2 );
69
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 );
78
79   myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
80   myProfiles->setHiddenObjectsShown(true);
81   myProfiles->setVisibilityIconShown(false);
82   myProfiles->setContentsMargins(QMargins());
83   myProfiles->setOrderingEnabled( false );
84  
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();
93  
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 );
100   
101   aParamGroup->setLayout( aParamLayout );
102
103   // Common
104   addWidget( myObjectNameGroup );
105   addWidget( aParamGroup );
106   addStretch();
107
108   // Create selector
109   if ( module() ) {
110     HYDROGUI_ListSelector* aListSelector = 
111 #ifdef LIGHT_MODE
112       new HYDROGUI_ListSelector( myProfiles, 0 );
113 #else
114       new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
115 #endif
116     aListSelector->setAutoBlock( true );
117   }
118
119   // Connect signals and slots
120   connect( myAxes, SIGNAL( currentIndexChanged( const QString & ) ), this, SIGNAL( AxisChanged( const QString& ) ) );
121   connect( myAddButton, SIGNAL( clicked() ), this, SIGNAL( AddProfiles() ) );
122   connect( myRemoveButton, SIGNAL( clicked() ), this, SLOT( onRemoveProfiles() ) );
123   connect( myDDZ, SIGNAL( valueChanged (double) ), this, SLOT (onDDZValueChanged(double)));
124   connect( mySpatialStep, SIGNAL( valueChanged (double) ), this, SLOT (onSSValueChanged(double)));
125 }
126
127 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
128 {
129 }
130
131 void HYDROGUI_StreamDlg::reset()
132 {
133   bool isBlocked = blockSignals( true );
134
135   myObjectName->clear();
136
137   myAxes->clear();
138   myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
139   myAddButton->setEnabled( true );
140   myRemoveButton->setEnabled( true );
141
142   blockSignals( isBlocked );
143 }
144
145 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
146 {
147   myObjectName->setText( theName );
148 }
149
150 QString HYDROGUI_StreamDlg::getObjectName() const
151 {
152   return myObjectName->text();
153 }
154
155 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
156 {
157   bool isBlocked = blockSignals( true );
158
159   myAxes->clear();
160   myAxes->addItems( theAxises );
161
162   blockSignals( isBlocked );
163 }
164
165 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
166 {
167   bool isBlocked = blockSignals( true );
168
169   int aNewId = myAxes->findText( theName );
170   if ( aNewId != myAxes->currentIndex() ) {
171     myAxes->setCurrentIndex( aNewId );
172   }
173   //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
174
175   blockSignals( isBlocked );
176 }
177
178 QString HYDROGUI_StreamDlg::getAxisName() const
179 {
180   return myAxes->currentText();
181 }
182
183 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
184 {
185   bool isBlocked = blockSignals( true );
186
187   myProfiles->setUpdatesEnabled( false );
188   
189   HYDROGUI_ListModel::Object2VisibleList aProfiles;
190 #ifndef LIGHT_MODE
191   foreach ( const QString& aProfileName, theProfiles )
192   {
193     Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( 
194       HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
195     if ( !anObject.IsNull() )
196     {
197       aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
198     }
199   }
200 #endif
201
202   myProfiles->setObjects( aProfiles );
203
204
205   myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
206
207   myProfiles->setUpdatesEnabled( true );
208
209   blockSignals( isBlocked );
210 }
211
212 void HYDROGUI_StreamDlg::onRemoveProfiles()
213 {
214   QStringList aSelectedProfiles = myProfiles->getSelectedNames();
215
216   emit RemoveProfiles( aSelectedProfiles );
217 }
218
219 void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
220 {
221   emit DDZValueChanged( d );
222 }
223
224 void HYDROGUI_StreamDlg::onSSValueChanged(double d)
225 {
226   emit SSValueChanged( d );
227 }
228
229
230 void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
231 {
232   myDDZ->setValue( theDDZ );
233 }
234
235 double HYDROGUI_StreamDlg::getDDZ() const
236 {
237   return myDDZ->value();
238 }
239
240 void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
241 {
242   mySpatialStep->setValue( theSpatialStep );
243 }
244
245 double HYDROGUI_StreamDlg::getSpatialStep() const
246 {
247   return mySpatialStep->value();
248 }
249
250 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (int theInd, QColor theColor)
251 {
252   myProfiles->setBackgroundColor(theInd, theColor);
253 }
254
255 QColor HYDROGUI_StreamDlg::getBackgroundColorForProfileList (int theInd) const
256 {
257   return myProfiles->getBackgroundColor(theInd);
258 }
259
260 void HYDROGUI_StreamDlg::clearAllBackgroundColorsForProfileList ()
261 {
262   myProfiles->clearAllBackgroundColors();
263 }
264