From d0dddc3ca2a60e5dd20432a407d6da23091e138e Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 12 May 2017 17:11:00 +0300 Subject: [PATCH] Ubuntu problem correction: zero deflection was used because of another system local. The conversion string->double is corrected like in SALOME kernel conversion is performed. --- src/Config/Config_PropManager.cpp | 18 +++++++++++++++--- src/Config/Config_PropManager.h | 5 +++++ src/GeomValidators/CMakeLists.txt | 2 ++ src/GeomValidators/GeomValidators_Positive.cpp | 5 +++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Config/Config_PropManager.cpp b/src/Config/Config_PropManager.cpp index 205f9b503..a1e2e6b03 100644 --- a/src/Config/Config_PropManager.cpp +++ b/src/Config/Config_PropManager.cpp @@ -8,7 +8,6 @@ std::vector stringToRGB(const std::string& theColor); int stringToInteger(const std::string& theInt); -double stringToDouble(const std::string& theDouble); bool stringToBoolean(const std::string& theInt); Config_Properties Config_PropManager::myProps; @@ -176,10 +175,23 @@ int stringToInteger(const std::string& theInt) return atoi(theInt.c_str()); } -double stringToDouble(const std::string& theDouble) +double Config_PropManager::stringToDouble(const std::string& theDouble) { + std::string aStr = theDouble; + + // change locale and convert "," to "." if exists + std::string aCurLocale = setlocale(LC_NUMERIC, 0); + setlocale(LC_NUMERIC, "C"); + int dotpos = (int)aStr.find(','); + if (dotpos != std::string::npos) + aStr.replace(dotpos, 1, "."); + char* p; - return strtod(theDouble.c_str(), &p); + double aValue = strtod(aStr.c_str(), &p); + + // restore locale + setlocale(LC_NUMERIC, aCurLocale.c_str()); + return aValue; } bool stringToBoolean(const std::string& theBoolean) diff --git a/src/Config/Config_PropManager.h b/src/Config/Config_PropManager.h index 8ae5cf84c..e4ed9aaa9 100644 --- a/src/Config/Config_PropManager.h +++ b/src/Config/Config_PropManager.h @@ -61,6 +61,11 @@ class Config_PropManager //! Returns boolean by given section and name CONFIG_EXPORT static bool boolean(const std::string& theSection, const std::string& theName); + //! Returns convertion of the string to double value. Temporary changes locale to process + //! values contained "," or "." separator. + //! \param theDouble a value to be converted + //! \return double result or zero + CONFIG_EXPORT static double stringToDouble(const std::string& theDouble); private: CONFIG_EXPORT static Config_Properties myProps; ///< List of all stored properties diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index f7f7d29e0..db014d5c9 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -44,6 +44,7 @@ SET(PROJECT_SOURCES SET(PROJECT_LIBRARIES ModelAPI Events + Config GeomAPI ) @@ -54,6 +55,7 @@ TARGET_LINK_LIBRARIES(GeomValidators ${PROJECT_LIBRARIES}) INCLUDE_DIRECTORIES( ${CAS_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/Config ${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomDataAPI diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index 6737f289a..1690b116e 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -6,6 +6,7 @@ #include "GeomValidators_Positive.h" +#include #include #include @@ -34,8 +35,8 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, if(theArguments.size() == 1) { std::list::const_iterator anIt = theArguments.begin(); char *aErr; - double aValue = strtod((*anIt).c_str(), &aErr); - if(*aErr == 0) { + double aValue = Config_PropManager::stringToDouble((*anIt).c_str()); + if(aValue != 0) { // very probably ok aMinValue = aValue; } -- 2.39.2