1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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),
45 //============================================================================
46 /*! Function : ~SALOMEDSImpl_ScalarVariable()
49 //============================================================================
50 SALOMEDSImpl_ScalarVariable::~SALOMEDSImpl_ScalarVariable(){}
52 //============================================================================
56 //============================================================================
57 bool SALOMEDSImpl_ScalarVariable::setValue(const double theValue)
60 if(myValue == theValue)
67 //============================================================================
71 //============================================================================
72 bool SALOMEDSImpl_ScalarVariable::setStringValue(const std::string& theValue)
75 if(myStrValue == theValue)
78 myStrValue = theValue;
82 //============================================================================
83 /*! Function : getValue()
86 //============================================================================
87 double SALOMEDSImpl_ScalarVariable::getValue() const
92 //============================================================================
93 /*! Function : getStringValue()
96 //============================================================================
97 std::string SALOMEDSImpl_ScalarVariable::getStringValue() const
102 //============================================================================
103 /*! Function : Save()
106 //============================================================================
107 std::string SALOMEDSImpl_ScalarVariable::Save() const{
108 Kernel_Utils::Localizer loc;
113 case SALOMEDSImpl_GenericVariable::REAL_VAR:
115 sprintf(buffer, "%.64e", myValue);
118 case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
119 case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
121 sprintf(buffer, "%d", (int)myValue);
124 case SALOMEDSImpl_GenericVariable::STRING_VAR:
126 sprintf(buffer, "%s", myStrValue.c_str());
131 return std::string(buffer);
134 //============================================================================
135 /*! Function : SaveToScript()
138 //============================================================================
139 std::string SALOMEDSImpl_ScalarVariable::SaveToScript() const
141 Kernel_Utils::Localizer loc;
146 case SALOMEDSImpl_GenericVariable::REAL_VAR:
148 sprintf(buffer, "%g", myValue);
151 case SALOMEDSImpl_GenericVariable::INTEGER_VAR:
153 sprintf(buffer, "%d", (int)myValue);
156 case SALOMEDSImpl_GenericVariable::BOOLEAN_VAR:
158 sprintf(buffer, "%s", ((bool)myValue) ? "True" : "False");
161 case SALOMEDSImpl_GenericVariable::STRING_VAR:
163 sprintf(buffer, "\"%s\"", myStrValue.c_str());
168 return std::string(buffer);
171 //============================================================================
172 /*! Function : SaveType()
175 //============================================================================
176 std::string SALOMEDSImpl_ScalarVariable::SaveType() const{
178 sprintf(buffer, "%d", (int)Type());
179 return std::string(buffer);
182 //============================================================================
183 /*! Function : Load()
186 //============================================================================
187 void SALOMEDSImpl_ScalarVariable::Load(const std::string& theStrValue)
189 Kernel_Utils::Localizer loc;
191 std::string strCopy = theStrValue;
192 if ( Type() == SALOMEDSImpl_GenericVariable::STRING_VAR ) {
193 #ifdef OLDSTUDY_COMPATIBILITY
194 if (strCopy.size() > 1 && strCopy[0] == '\"' && strCopy[strCopy.size()-1] == '\"')
195 strCopy = strCopy.substr(1, strCopy.size()-2);
196 #endif // OLDSTUDY_COMPATIBILITY
197 setStringValue( strCopy );
200 #ifdef OLDSTUDY_COMPATIBILITY
201 int dotpos = strCopy.find(',');
202 if (dotpos != std::string::npos)
203 strCopy.replace(dotpos, 1, ".");
204 #endif // OLDSTUDY_COMPATIBILITY
205 double aValue = atof(strCopy.c_str());