Salome HOME
Initial merge of branch 'BR_HYDRO_IMPS_2016' into BR_PORTING_OCCT_7
[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
41 HYDROGUI_StreamDlg::HYDROGUI_StreamDlg( HYDROGUI_Module* theModule, const QString& theTitle )
42 : HYDROGUI_InputPanel( theModule, theTitle )
43 {
44   // Stream name
45   myObjectNameGroup = new QGroupBox( tr( "STREAM_NAME" ), mainFrame() );
46
47   myObjectName = new QLineEdit( myObjectNameGroup );
48
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 );
54
55   // Stream parameters
56   QGroupBox* aParamGroup = new QGroupBox( tr( "STREAM_PARAMETERS" ), mainFrame() );
57
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 );
70
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 );
79
80   myProfiles = new HYDROGUI_OrderedListWidget( aParamGroup, 0 );
81   myProfiles->setHiddenObjectsShown(true);
82   myProfiles->setVisibilityIconShown(false);
83   myProfiles->setContentsMargins(QMargins());
84   myProfiles->setOrderingEnabled( false );
85  
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();
94  
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 );
101   
102   aParamGroup->setLayout( aParamLayout );
103
104   // Warnings
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 );
111
112   // Common
113   addWidget( myObjectNameGroup );
114   addWidget( aParamGroup );
115   addWidget( aWarnGroup );
116   addStretch();
117
118   // Create selector
119   if ( module() ) {
120     HYDROGUI_ListSelector* aListSelector = 
121 #ifdef LIGHT_MODE
122       new HYDROGUI_ListSelector( myProfiles, 0 );
123 #else
124       new HYDROGUI_ListSelector( myProfiles, module()->getApp()->selectionMgr() );
125 #endif
126     aListSelector->setAutoBlock( true );
127   }
128
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)));
135 }
136
137 HYDROGUI_StreamDlg::~HYDROGUI_StreamDlg()
138 {
139 }
140
141 void HYDROGUI_StreamDlg::reset()
142 {
143   bool isBlocked = blockSignals( true );
144
145   myObjectName->clear();
146
147   myAxes->clear();
148   myProfiles->setObjects( HYDROGUI_ListModel::Object2VisibleList() );
149   myAddButton->setEnabled( true );
150   myRemoveButton->setEnabled( true );
151
152   blockSignals( isBlocked );
153 }
154
155 void HYDROGUI_StreamDlg::setObjectName( const QString& theName )
156 {
157   myObjectName->setText( theName );
158 }
159
160 QString HYDROGUI_StreamDlg::getObjectName() const
161 {
162   return myObjectName->text();
163 }
164
165 void HYDROGUI_StreamDlg::setAxisNames( const QStringList& theAxises )
166 {
167   bool isBlocked = blockSignals( true );
168
169   myAxes->clear();
170   myAxes->addItems( theAxises );
171
172   blockSignals( isBlocked );
173 }
174
175 void HYDROGUI_StreamDlg::setAxisName( const QString& theName )
176 {
177   bool isBlocked = blockSignals( true );
178
179   int aNewId = myAxes->findText( theName );
180   if ( aNewId != myAxes->currentIndex() ) {
181     myAxes->setCurrentIndex( aNewId );
182   }
183   //myAddButton->setEnabled( myAxes->currentIndex() > -1 );
184
185   blockSignals( isBlocked );
186 }
187
188 QString HYDROGUI_StreamDlg::getAxisName() const
189 {
190   return myAxes->currentText();
191 }
192
193 void HYDROGUI_StreamDlg::setProfiles( const QStringList& theProfiles )
194 {
195   bool isBlocked = blockSignals( true );
196
197   myProfiles->setUpdatesEnabled( false );
198   
199   HYDROGUI_ListModel::Object2VisibleList aProfiles;
200 #ifndef LIGHT_MODE
201   foreach ( const QString& aProfileName, theProfiles )
202   {
203     Handle(HYDROData_Profile) anObject = Handle(HYDROData_Profile)::DownCast( 
204       HYDROGUI_Tool::FindObjectByName( module(), aProfileName ) );
205     if ( !anObject.IsNull() )
206     {
207       aProfiles.append( HYDROGUI_ListModel::Object2Visible( anObject, true ) );
208     }
209   }
210 #endif
211
212   myProfiles->setObjects( aProfiles );
213
214
215   myRemoveButton->setEnabled( myProfiles->getObjects().count() > 0 );
216
217   myProfiles->setUpdatesEnabled( true );
218
219   blockSignals( isBlocked );
220 }
221
222 void HYDROGUI_StreamDlg::onRemoveProfiles()
223 {
224   QStringList aSelectedProfiles = myProfiles->getSelectedNames();
225
226   emit RemoveProfiles( aSelectedProfiles );
227 }
228
229 void HYDROGUI_StreamDlg::onDDZValueChanged(double d)
230 {
231   emit DDZValueChanged( d );
232 }
233
234 void HYDROGUI_StreamDlg::onSSValueChanged(double d)
235 {
236   emit SSValueChanged( d );
237 }
238
239
240 void HYDROGUI_StreamDlg::setDDZ( const double theDDZ )
241 {
242   myDDZ->setValue( theDDZ );
243 }
244
245 double HYDROGUI_StreamDlg::getDDZ() const
246 {
247   return myDDZ->value();
248 }
249
250 void HYDROGUI_StreamDlg::setSpatialStep( const double theSpatialStep )
251 {
252   mySpatialStep->setValue( theSpatialStep );
253 }
254
255 double HYDROGUI_StreamDlg::getSpatialStep() const
256 {
257   return mySpatialStep->value();
258 }
259
260 void HYDROGUI_StreamDlg::setBackgroundColorForProfileList (int theInd, QColor theColor)
261 {
262   myProfiles->setBackgroundColor(theInd, theColor);
263 }
264
265 QColor HYDROGUI_StreamDlg::getBackgroundColorForProfileList (int theInd) const
266 {
267   return myProfiles->getBackgroundColor(theInd);
268 }
269
270 void HYDROGUI_StreamDlg::clearAllBackgroundColorsForProfileList ()
271 {
272   myProfiles->clearAllBackgroundColors();
273 }
274
275 void HYDROGUI_StreamDlg::addWarning( const QString& theWarnMess )
276 {
277   myWarnText->append( theWarnMess );
278 }
279
280 void HYDROGUI_StreamDlg::clearWarnings()
281 {
282   myWarnText->clear();
283 }
284