Salome HOME
PAL7705: Support for string parameters of hypothesis added in GUI
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_aParameter.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_aParameter.cxx
25 //  Module : SMESH
26 //  $Header$
27
28 #include "SMESHGUI_aParameter.h"
29   
30 #include <qspinbox.h>
31 #include <qvalidator.h>
32 #include <qtextedit.h>
33
34 #include "QAD_SpinBoxDbl.h"
35
36 #include <utilities.h>
37
38 SMESHGUI_aParameter::~SMESHGUI_aParameter() {}
39
40 //=================================================================================
41 // class    : SMESHGUI_intParameter
42 // purpose  :
43 //=================================================================================
44 SMESHGUI_intParameter::SMESHGUI_intParameter(const int      theInitValue,
45                                              const QString& theLabel,
46                                              const int      theBottom,   
47                                              const int      theTop)
48      :SMESHGUI_aParameter(theLabel),
49        _top(theTop), _bottom(theBottom), _initValue( theInitValue )
50 {
51 }
52 SMESHGUI_aParameter::Type SMESHGUI_intParameter::GetType() const
53 {
54   return SMESHGUI_aParameter::INT;
55 }
56 bool SMESHGUI_intParameter::GetNewInt( int & theValue ) const
57 {
58   theValue = _newValue;
59   return _newValue != _initValue;
60 }
61 bool SMESHGUI_intParameter::GetNewDouble( double & Value ) const
62 {
63   return false;
64 }
65 bool SMESHGUI_intParameter::GetNewText( QString & Value ) const
66 {
67   return false;
68 }
69 void SMESHGUI_intParameter::InitializeWidget( QWidget* theQWidget) const
70 {
71   QSpinBox * aSpin = dynamic_cast< QSpinBox *>( theQWidget );
72   if ( aSpin ) {
73     aSpin->setMinValue( _bottom );
74     aSpin->setMaxValue( _top );
75     aSpin->setValue( _initValue );
76   }
77 }
78 void SMESHGUI_intParameter::TakeValue( QWidget* theQWidget)
79 {
80   QSpinBox * aSpin = dynamic_cast< QSpinBox *>( theQWidget );
81   if ( aSpin )
82     _newValue = aSpin->value();
83 }
84 //=================================================================================
85 // class    : SMESHGUI_doubleParameter
86 // purpose  :
87 //=================================================================================
88 SMESHGUI_doubleParameter::SMESHGUI_doubleParameter(const double   theInitValue,
89                                                    const QString& theLabel,
90                                                    const double   theBottom,   
91                                                    const double   theTop,
92                                                    const double   theStep,
93                                                    const int      theDecimals)
94      :SMESHGUI_aParameter( theLabel ),
95        _top( theTop ), _bottom( theBottom ), _step( theStep ),
96        _initValue( theInitValue ), _decimals( theDecimals )
97 {
98 }
99 SMESHGUI_aParameter::Type SMESHGUI_doubleParameter::GetType() const
100 {
101   return SMESHGUI_aParameter::DOUBLE;
102 }
103 bool SMESHGUI_doubleParameter::GetNewInt( int & theValue ) const
104 {
105   return false;
106 }
107 bool SMESHGUI_doubleParameter::GetNewDouble( double & Value ) const
108 {
109   Value = _newValue;
110   return _newValue != _initValue;
111 }
112 bool SMESHGUI_doubleParameter::GetNewText( QString & Value ) const
113 {
114   return false;
115 }
116 void SMESHGUI_doubleParameter::InitializeWidget( QWidget* theQWidget) const
117 {
118   QAD_SpinBoxDbl * aSpin = dynamic_cast< QAD_SpinBoxDbl *>( theQWidget );
119   if ( aSpin ) {
120     aSpin->setRange( _bottom, _top );
121     ((QDoubleValidator*)(aSpin->validator()))->setRange( _bottom, _top, _decimals );
122     aSpin->setValue( _initValue );
123     aSpin->setLineStep( _step );
124   }
125 }
126 void SMESHGUI_doubleParameter::TakeValue( QWidget* theQWidget)
127 {
128   QAD_SpinBoxDbl * aSpin = dynamic_cast< QAD_SpinBoxDbl *>( theQWidget );
129   if ( aSpin )
130     _newValue = aSpin->value();
131 }
132
133 //=================================================================================
134 // class    : SMESHGUI_strParameter
135 // purpose  :
136 //=================================================================================
137 SMESHGUI_strParameter::SMESHGUI_strParameter(const QString& theInitValue,
138                                              const QString& theLabel)
139      :SMESHGUI_aParameter(theLabel),
140       _initValue( theInitValue )
141 {
142   MESSAGE("SMESHGUI_strParameter::SMESHGUI_strParameter")
143 }
144 SMESHGUI_aParameter::Type SMESHGUI_strParameter::GetType() const
145 {
146   return SMESHGUI_aParameter::TEXT;
147 }
148 bool SMESHGUI_strParameter::GetNewInt( int & theValue ) const
149 {
150   return false;
151 }
152 bool SMESHGUI_strParameter::GetNewDouble( double & Value ) const
153 {
154   return false;
155 }
156 bool SMESHGUI_strParameter::GetNewText( QString & theValue ) const
157 {
158   theValue = _newValue;
159   return _newValue != _initValue;
160 }
161 void SMESHGUI_strParameter::InitializeWidget( QWidget* theQWidget) const
162 {
163   MESSAGE("SMESHGUI_strParameter::InitializeWidget")
164   QTextEdit * anEdit = dynamic_cast< QTextEdit *>( theQWidget );
165   if ( anEdit ) {
166     anEdit->setText( _initValue );
167   }
168 }
169 void SMESHGUI_strParameter::TakeValue( QWidget* theQWidget)
170 {
171   MESSAGE("SMESHGUI_strParameter::TakeValue")
172   QTextEdit * anEdit = dynamic_cast< QTextEdit *>( theQWidget );
173   if ( anEdit )
174     _newValue = anEdit->text();
175 }