1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDSImpl_ScalarVariable.cxx
21 // Author : Roman NIKOLAEV, Open CASCADE S.A.S.
24 #include "SALOMEDSImpl_ScalarVariable.hxx"
25 #include "SALOMEDSImpl_GenericVariable.hxx"
26 #include "Basics_Utils.hxx"
31 #define OLDSTUDY_COMPATIBILITY
33 //============================================================================
34 /*! Function : SALOMEDSImpl_ScalarVariable
37 //============================================================================
38 SALOMEDSImpl_ScalarVariable::
39 SALOMEDSImpl_ScalarVariable(SALOMEDSImpl_GenericVariable::VariableTypes type,
40 const std::string& theName):
41 SALOMEDSImpl_GenericVariable(type,theName)
44 //============================================================================
45 /*! Function : ~SALOMEDSImpl_ScalarVariable()
48 //============================================================================
49 SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){}
51 //============================================================================
55 //============================================================================
56 bool SALOMEDSImpl_ScalarVariable::setValue(const double theValue)
59 if(myValue == theValue)
66 //============================================================================
70 //============================================================================
71 bool SALOMEDSImpl_ScalarVariable::setStringValue(const std::string& theValue)
74 if(myStrValue == theValue)
77 myStrValue = theValue;
81 //============================================================================
82 /*! Function : getValue()
85 //============================================================================
86 double SALOMEDSImpl_ScalarVariable::getValue() const
91 //============================================================================
92 /*! Function : getStringValue()
95 //============================================================================
96 std::string SALOMEDSImpl_ScalarVariable::getStringValue() const
101 //============================================================================
102 /*! Function : Save()
105 //============================================================================
106 std::string SALOMEDSImpl_ScalarVariable::Save() const{
107 Kernel_Utils::Localizer loc;
112 case SALOMEDSImpl_GenericVariable::REAL_VAR:
114 sprintf(buffer, "%.64e", myValue);
117 case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
118 case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
120 sprintf(buffer, "%d", (int)myValue);
123 case SALOMEDSImpl_GenericVariable::STRING_VAR:
125 sprintf(buffer, "%s", myStrValue.c_str());
130 return std::string(buffer);
133 //============================================================================
134 /*! Function : SaveToScript()
137 //============================================================================
138 std::string SALOMEDSImpl_ScalarVariable::SaveToScript() const
140 Kernel_Utils::Localizer loc;
145 case SALOMEDSImpl_GenericVariable::REAL_VAR:
147 sprintf(buffer, "%g", myValue);
150 case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
152 sprintf(buffer, "%d", (int)myValue);
155 case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
157 sprintf(buffer, "%s", ((bool)myValue) ? "True" : "False");
160 case SALOMEDSImpl_GenericVariable::STRING_VAR:
162 sprintf(buffer, "\"%s\"", myStrValue.c_str());
167 return std::string(buffer);
170 //============================================================================
171 /*! Function : SaveType()
174 //============================================================================
175 std::string SALOMEDSImpl_ScalarVariable::SaveType() const{
177 sprintf(buffer, "%d", (int)Type());
178 return std::string(buffer);
181 //============================================================================
182 /*! Function : Load()
185 //============================================================================
186 void SALOMEDSImpl_ScalarVariable::Load(const std::string& theStrValue)
188 Kernel_Utils::Localizer loc;
190 std::string strCopy = theStrValue;
191 if ( Type() == SALOMEDSImpl_GenericVariable::STRING_VAR ) {
192 #ifdef OLDSTUDY_COMPATIBILITY
193 if (strCopy.size() > 1 && strCopy[0] == '\"' && strCopy[strCopy.size()-1] == '\"')
194 strCopy = strCopy.substr(1, strCopy.size()-2);
195 #endif // OLDSTUDY_COMPATIBILITY
196 setStringValue( strCopy );
199 #ifdef OLDSTUDY_COMPATIBILITY
200 int dotpos = strCopy.find(',');
201 if (dotpos != std::string::npos)
202 strCopy.replace(dotpos, 1, ".");
203 #endif // OLDSTUDY_COMPATIBILITY
204 double aValue = atof(strCopy.c_str());