Salome HOME
Corrections of examples path after install with scbi
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ChannelDlg.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_ChannelDlg.h"
20
21 #include "HYDROGUI_Tool.h"
22
23 #include <QComboBox>
24 #include <QGroupBox>
25 #include <QLabel>
26 #include <QLayout>
27 #include <QLineEdit>
28 #include <QCheckBox>
29 #include <QtxDoubleSpinBox.h>
30 #include <QRadioButton>
31
32 HYDROGUI_ChannelDlg::HYDROGUI_ChannelDlg( HYDROGUI_Module* theModule, const QString& theTitle )
33 : HYDROGUI_InputPanel( theModule, theTitle )
34 {
35   // Channel name
36   myObjectNameGroup = new QGroupBox( tr( "CHANNEL_NAME" ), mainFrame() );
37
38   myObjectName = new QLineEdit( myObjectNameGroup );
39
40   QBoxLayout* aNameLayout = new QHBoxLayout( myObjectNameGroup );
41   aNameLayout->setMargin( 5 );
42   aNameLayout->setSpacing( 5 );
43   aNameLayout->addWidget( new QLabel( tr( "NAME" ), myObjectNameGroup ) );
44   aNameLayout->addWidget( myObjectName );
45
46   // Channel parameters
47   QGroupBox* aParamGroup = new QGroupBox( tr( "CHANNEL_PARAMETERS" ), mainFrame() );
48
49   //myGuideLines = new HYDROGUI_ObjComboSelector( theModule, KIND_POLYLINE, aParamGroup );
50   myGuideLines = new QComboBox( aParamGroup );
51   myGuideLines->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
52
53   //myProfiles = new HYDROGUI_ObjComboSelector( theModule, KIND_PROFILE, aParamGroup );
54   myProfiles = new QComboBox( aParamGroup );
55   myProfiles->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
56
57   myEquiDistance = new QtxDoubleSpinBox( aParamGroup );
58   myEquiDistance->setRange( 0.01, 9999 );
59   myEquiDistance->setValue( 1.0 );
60   myEquiDistance->setSingleStep( 1.0 );
61
62   //for digue
63   myLCVal = new QtxDoubleSpinBox( aParamGroup );
64   myLCVal->setRange( 0.0, 999999 );
65   myLCVal->setValue( 50 );
66   myLCVal->setSingleStep( 0.1 );
67
68   myDeltaZVal = new QtxDoubleSpinBox( aParamGroup );
69   myDeltaZVal->setRange( 0.0, 999999 );
70   myDeltaZVal->setValue( 5.0 );
71   myDeltaZVal->setSingleStep( 0.1 );
72
73   myCoteZVal = new QtxDoubleSpinBox( aParamGroup );
74   myCoteZVal->setRange( 0.0, 999999 );
75   myCoteZVal->setValue( 1.0 );
76   myCoteZVal->setSingleStep( 0.1 );
77   //END for digue
78
79   myInvertDirection = new QCheckBox(aParamGroup);
80   myInvertDirection->setChecked(false);
81
82   myProfileLabel = new QLabel( tr( "CHANNEL_PROFILE" ), aParamGroup);
83
84   myProfileModeButton = new QRadioButton( tr( "VIA_PROFILE" ), myObjectNameGroup );
85   myProfileModeButton2 = new QRadioButton( tr( "PREDEF" ), myObjectNameGroup );
86
87   QGridLayout* aParamsLayout = new QGridLayout( aParamGroup );
88   aParamsLayout->setMargin( 5 );
89   aParamsLayout->setSpacing( 5 );
90   aParamsLayout->addWidget( new QLabel( tr( "CHANNEL_GUIDE_LINE" ), aParamGroup ), 0, 0 );
91   aParamsLayout->addWidget( myGuideLines, 0, 1 );
92     
93   aParamsLayout->addWidget( myProfileModeButton, 1, 0 );
94   aParamsLayout->addWidget( myProfileModeButton2, 1, 1 );
95
96   aParamsLayout->addWidget( myProfileLabel, 2, 0 );
97   aParamsLayout->addWidget( myProfiles, 2, 1 );
98
99   myLCValLabel = new QLabel( tr( "LC_VALUE" ), aParamGroup);
100   myDeltaZValLabel = new QLabel( tr( "DELTAZ_VALUE" ), aParamGroup);
101   myCoteZValLabel = new QLabel( tr( "COTEZ_VALUE" ), aParamGroup);
102
103   aParamsLayout->addWidget( myLCValLabel, 3, 0 );
104   aParamsLayout->addWidget( myLCVal, 3, 1 );
105   aParamsLayout->addWidget( myDeltaZValLabel, 4, 0 );
106   aParamsLayout->addWidget( myDeltaZVal, 4, 1 );
107   aParamsLayout->addWidget( myCoteZValLabel, 5, 0 );
108   aParamsLayout->addWidget( myCoteZVal, 5, 1 );
109
110   aParamsLayout->addWidget( new QLabel( tr( "EQUI_DISTANCE" ), aParamGroup ), 6, 0 );
111   aParamsLayout->addWidget( myEquiDistance, 6, 1 );
112   aParamsLayout->addWidget( new QLabel( tr( "INVERT_DIRECTION" ), aParamGroup ), 7, 0 );
113   aParamsLayout->addWidget( myInvertDirection, 7, 1 );
114
115   // Common
116   addWidget( myObjectNameGroup );
117   addWidget( aParamGroup );
118
119   addStretch();
120
121   // Connect signals and slots
122   connect( myGuideLines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onChannelDefChanged() ) );
123   connect( myProfiles, SIGNAL(  currentIndexChanged( int ) ), this, SLOT( onChannelDefChanged() ) );
124   
125   connect( myLCVal, SIGNAL( valueChanged( double ) ), this, SLOT( onChannelDefChanged() ) );
126   connect( myDeltaZVal, SIGNAL(  valueChanged( double ) ), this, SLOT( onChannelDefChanged() ) );
127   connect( myCoteZVal, SIGNAL( valueChanged( double ) ), this, SLOT( onChannelDefChanged() ) );
128
129   connect( myProfileModeButton, SIGNAL( toggled( bool ) ), this, SLOT( onProfileModeChanged( bool ) ) );
130   myProfileModeButton->setChecked(true);
131 }
132
133 HYDROGUI_ChannelDlg::~HYDROGUI_ChannelDlg()
134 {
135 }
136
137 void HYDROGUI_ChannelDlg::reset()
138 {
139   bool isBlocked = blockSignals( true );
140
141   myObjectName->clear();
142
143   myGuideLines->clear();
144   myProfiles->clear();
145
146   blockSignals( isBlocked );
147
148   onChannelDefChanged();
149 }
150
151 void HYDROGUI_ChannelDlg::setObjectName( const QString& theName )
152 {
153   myObjectName->setText( theName );
154 }
155
156 QString HYDROGUI_ChannelDlg::getObjectName() const
157 {
158   return myObjectName->text();
159 }
160
161 void HYDROGUI_ChannelDlg::setGuideLineNames( const QStringList& theGuideLines )
162 {
163   bool isBlocked = blockSignals( true );
164
165   myGuideLines->clear();
166   myGuideLines->addItems( theGuideLines );
167
168   blockSignals( isBlocked );
169 }
170
171 void HYDROGUI_ChannelDlg::setGuideLineName( const QString& theGuideLine )
172 {
173   int aNewIdx = myGuideLines->findText( theGuideLine );
174   if ( aNewIdx != myGuideLines->currentIndex() )
175   {
176     myGuideLines->setCurrentIndex( aNewIdx );
177   }
178   else
179   {
180     onChannelDefChanged();
181   }
182 }
183
184 QString HYDROGUI_ChannelDlg::getGuideLineName() const
185 {
186   return myGuideLines->currentText();
187 }
188
189 void HYDROGUI_ChannelDlg::setProfileNames( const QStringList& theProfiles )
190 {
191   bool isBlocked = blockSignals( true );
192
193   myProfiles->clear();
194   myProfiles->addItems( theProfiles );
195
196   blockSignals( isBlocked );
197 }
198
199 void HYDROGUI_ChannelDlg::setProfileName( const QString& theProfile )
200 {
201   int aNewIdx = myProfiles->findText( theProfile );
202   if ( aNewIdx != myProfiles->currentIndex() )
203   {
204     myProfiles->setCurrentIndex( aNewIdx );
205   }
206   else
207   {
208     onChannelDefChanged();
209   }
210 }
211
212 QString HYDROGUI_ChannelDlg::getProfileName() const
213 {
214   return myProfiles->currentText();
215 }
216
217 void HYDROGUI_ChannelDlg::onChannelDefChanged()
218 {
219   if ( signalsBlocked() )
220     return;
221
222   emit CreatePreview();
223 }
224
225 void HYDROGUI_ChannelDlg::onProfileModeChanged(bool mode)
226 {
227   if ( signalsBlocked() )
228     return;
229   if (mode)
230   {
231     myProfiles->setVisible(true);
232     myProfileLabel->setVisible(true);
233     myLCValLabel->setVisible(false);
234     myLCVal->setVisible(false);
235     myDeltaZValLabel->setVisible(false);
236     myDeltaZVal->setVisible(false);
237     myCoteZValLabel->setVisible(false);
238     myCoteZVal->setVisible(false);
239   }
240   else
241   {
242     myProfiles->setVisible(false);
243     myProfileLabel->setVisible(false);
244     myLCValLabel->setVisible(true);
245     myLCVal->setVisible(true);
246     myDeltaZValLabel->setVisible(true);
247     myDeltaZVal->setVisible(true);
248     myCoteZValLabel->setVisible(true);
249     myCoteZVal->setVisible(true);
250   }
251   emit CreatePreview();
252 }
253
254 bool HYDROGUI_ChannelDlg::getProfileMode()
255 {
256   return myProfileModeButton->isChecked();
257 }
258
259 void HYDROGUI_ChannelDlg::setProfileMode(bool mode)
260 {
261   myProfileModeButton->setChecked(mode);
262   myProfileModeButton2->setChecked(!mode);
263 }
264
265 double HYDROGUI_ChannelDlg::getEquiDistance() const
266 {
267   return myEquiDistance->value();
268 }
269
270 void HYDROGUI_ChannelDlg::setEquiDistance( double theValue )
271 {
272   myEquiDistance->setValue( theValue );
273 }
274
275 bool HYDROGUI_ChannelDlg::getInvertDirection() const
276 {
277   return myInvertDirection->isChecked();
278 }
279
280 void HYDROGUI_ChannelDlg::setInvertDirection( bool isChecked )
281 {
282   myInvertDirection->setChecked(isChecked);
283 }
284
285 double HYDROGUI_ChannelDlg::getLCValue() const
286 {
287   return myLCVal->value();
288 }
289
290 void  HYDROGUI_ChannelDlg::setLCValue( double val )
291 {
292   myLCVal->setValue( val );
293 }  
294
295 double HYDROGUI_ChannelDlg::getDeltaZValue() const
296 {
297   return myDeltaZVal->value();
298 }
299
300 void HYDROGUI_ChannelDlg::setDeltaZValue( double val )
301 {
302   myDeltaZVal->setValue( val );
303 }
304 double HYDROGUI_ChannelDlg::getCoteZValue() const
305 {
306   return myCoteZVal->value();
307 }
308
309 void HYDROGUI_ChannelDlg::setCoteZValue( double val )
310 {
311   myCoteZVal->setValue( val );
312 }