From: Artem Zhidkov Date: Wed, 29 Jul 2020 21:08:59 +0000 (+0300) Subject: Issue #3237: Allow usage of accented characters in ObjectBrowser X-Git-Tag: V9_6_0a1~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ae3e12ab08ba2c98c74c9f4b93812faace2af798;p=modules%2Fshaper.git Issue #3237: Allow usage of accented characters in ObjectBrowser Usage of Unicode characters as names of parameters. --- diff --git a/src/FeaturesAPI/FeaturesAPI.i b/src/FeaturesAPI/FeaturesAPI.i index d98babe2e..b76fd2dc4 100644 --- a/src/FeaturesAPI/FeaturesAPI.i +++ b/src/FeaturesAPI/FeaturesAPI.i @@ -183,7 +183,8 @@ } else if (PyFloat_Check($input) || PyLong_Check($input)) { temp = std::pair(ModelHighAPI_Selection(), ModelHighAPI_Double(PyFloat_AsDouble($input))); } else if (PyUnicode_Check($input)) { - temp = std::pair(ModelHighAPI_Selection(), ModelHighAPI_Double(PyUnicode_AsUTF8($input))); + Py_ssize_t size; + temp = std::pair(ModelHighAPI_Selection(), ModelHighAPI_Double(PyUnicode_AsWideCharString($input, &size))); } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { temp = std::pair($1->first, $1->second); } else { diff --git a/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp b/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp index 86558686c..2d90446a4 100644 --- a/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp +++ b/src/FeaturesAPI/FeaturesAPI_MultiRotation.cpp @@ -156,8 +156,8 @@ MultiRotationPtr addMultiRotation(const std::shared_ptr& theP if (theNumber.string().empty()) { // rotate for the whole circle double aStepVal = theStep.value(); - std::string aStepStr = theStep.string(); - std::ostringstream aStepValAsStr; + std::wstring aStepStr = theStep.string(); + std::wostringstream aStepValAsStr; aStepValAsStr << aStepVal; ModelHighAPI_Integer aNumber = aStepStr == aStepValAsStr.str() diff --git a/src/FeaturesAPI/FeaturesAPI_MultiRotation.h b/src/FeaturesAPI/FeaturesAPI_MultiRotation.h index eb3b81ae4..92aa64b92 100644 --- a/src/FeaturesAPI/FeaturesAPI_MultiRotation.h +++ b/src/FeaturesAPI/FeaturesAPI_MultiRotation.h @@ -109,7 +109,7 @@ MultiRotationPtr addMultiRotation(const std::shared_ptr& theP const std::list& theMainObjects, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theStep, - const ModelHighAPI_Integer& theNumber = ModelHighAPI_Integer(""), + const ModelHighAPI_Integer& theNumber = ModelHighAPI_Integer(L""), const bool keepSubResults = false); #endif // FEATURESAPI_MULTIROTATION_H_ diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index 02b516f20..0f46fc169 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -85,7 +85,7 @@ void GeomData_Point::setX(const double theX) setCalculatedValue(theX, 0, 0); } else if (x() != theX) { myExpression[0]->setValue(theX); - myExpression[0]->setText(""); // uninitialize the text + myExpression[0]->setText(L""); // uninitialize the text owner()->data()->sendAttributeUpdated(this); } } @@ -96,7 +96,7 @@ void GeomData_Point::setY(const double theY) setCalculatedValue(0, theY, 0); } else if (y() != theY) { myExpression[1]->setValue(theY); - myExpression[1]->setText(""); // uninitialize the text + myExpression[1]->setText(L""); // uninitialize the text owner()->data()->sendAttributeUpdated(this); } } @@ -108,7 +108,7 @@ void GeomData_Point::setZ(const double theZ) } else if (z() != theZ) { myExpression[2]->setValue(theZ); - myExpression[2]->setText(""); // uninitialize the text + myExpression[2]->setText(L""); // uninitialize the text owner()->data()->sendAttributeUpdated(this); } } @@ -120,9 +120,9 @@ std::shared_ptr GeomData_Point::pnt() return aResult; } -void GeomData_Point::setText(const std::string& theX, - const std::string& theY, - const std::string& theZ) +void GeomData_Point::setText(const std::wstring& theX, + const std::wstring& theY, + const std::wstring& theZ) { if (!myIsInitialized || textX() != theX || textY() != theY || textZ() != theZ) { myExpression[0]->setText(theX); @@ -134,10 +134,10 @@ void GeomData_Point::setText(const std::string& theX, } } -void GeomData_Point::setTextX(const std::string& theX) +void GeomData_Point::setTextX(const std::wstring& theX) { if (!myIsInitialized) { - static const std::string aDefaultText = "0"; + static const std::wstring aDefaultText = L"0"; setText(theX, aDefaultText, aDefaultText); } else if (textX() != theX) { @@ -148,10 +148,10 @@ void GeomData_Point::setTextX(const std::string& theX) } } -void GeomData_Point::setTextY(const std::string& theY) +void GeomData_Point::setTextY(const std::wstring& theY) { if (!myIsInitialized) { - static const std::string aDefaultText = "0"; + static const std::wstring aDefaultText = L"0"; setText(aDefaultText, theY, aDefaultText); } else if (textY() != theY) { @@ -162,10 +162,10 @@ void GeomData_Point::setTextY(const std::string& theY) } } -void GeomData_Point::setTextZ(const std::string& theZ) +void GeomData_Point::setTextZ(const std::wstring& theZ) { if (!myIsInitialized) { - static const std::string aDefaultText = "0"; + static const std::wstring aDefaultText = L"0"; setText(aDefaultText, aDefaultText, theZ); } else if (textZ() != theZ) { @@ -176,15 +176,15 @@ void GeomData_Point::setTextZ(const std::string& theZ) } } -std::string GeomData_Point::textX() +std::wstring GeomData_Point::textX() { return myExpression[0]->text(); } -std::string GeomData_Point::textY() +std::wstring GeomData_Point::textY() { return myExpression[1]->text(); } -std::string GeomData_Point::textZ() +std::wstring GeomData_Point::textZ() { return myExpression[2]->text(); } @@ -216,13 +216,13 @@ std::string GeomData_Point::expressionError(int theComponent) } void GeomData_Point::setUsedParameters(int theComponent, - const std::set& theUsedParameters) + const std::set& theUsedParameters) { assert(theComponent >= 0 && theComponent < NUM_COMPONENTS); myExpression[theComponent]->setUsedParameters(theUsedParameters); } -std::set GeomData_Point::usedParameters(int theComponent) const +std::set GeomData_Point::usedParameters(int theComponent) const { assert(theComponent >= 0 && theComponent < NUM_COMPONENTS); return myExpression[theComponent]->usedParameters(); diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index 72f7211c9..b59e225a1 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -63,22 +63,22 @@ class GeomData_Point : public GeomDataAPI_Point void setCalculatedValue(const double theX, const double theY, const double theZ); /// Defines the text values - GEOMDATA_EXPORT virtual void setText(const std::string& theX, - const std::string& theY, - const std::string& theZ); + GEOMDATA_EXPORT virtual void setText(const std::wstring& theX, + const std::wstring& theY, + const std::wstring& theZ); /// Defines the X text value - GEOMDATA_EXPORT virtual void setTextX(const std::string& theX); + GEOMDATA_EXPORT virtual void setTextX(const std::wstring& theX); /// Defines the Y text value - GEOMDATA_EXPORT virtual void setTextY(const std::string& theY); + GEOMDATA_EXPORT virtual void setTextY(const std::wstring& theY); /// Defines the Z text value - GEOMDATA_EXPORT virtual void setTextZ(const std::string& theZ); + GEOMDATA_EXPORT virtual void setTextZ(const std::wstring& theZ); /// Returns the X text value - GEOMDATA_EXPORT virtual std::string textX(); + GEOMDATA_EXPORT virtual std::wstring textX(); /// Returns the Y text value - GEOMDATA_EXPORT virtual std::string textY(); + GEOMDATA_EXPORT virtual std::wstring textY(); /// Returns the Z text value - GEOMDATA_EXPORT virtual std::string textZ(); + GEOMDATA_EXPORT virtual std::wstring textZ(); /// Allows to set expression (text) as invalid (by the parameters listener) GEOMDATA_EXPORT virtual void setExpressionInvalid(int, const bool theFlag); @@ -94,10 +94,10 @@ class GeomData_Point : public GeomDataAPI_Point /// Defines the used parameters GEOMDATA_EXPORT virtual void setUsedParameters(int theComponent, - const std::set& theUsedParameters); + const std::set& theUsedParameters); /// Returns the used parameters - GEOMDATA_EXPORT virtual std::set usedParameters(int theComponent) const; + GEOMDATA_EXPORT virtual std::set usedParameters(int theComponent) const; protected: /// Initializes attributes diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 031a846bd..ee9c77cac 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -86,8 +86,8 @@ std::shared_ptr GeomData_Point2D::pnt() return aResult; } -void GeomData_Point2D::setText(const std::string& theX, - const std::string& theY) +void GeomData_Point2D::setText(const std::wstring& theX, + const std::wstring& theY) { if (!myIsInitialized && theX.empty() && theY.empty()) return; // empty strings are not good initializers @@ -100,11 +100,11 @@ void GeomData_Point2D::setText(const std::string& theX, } } -std::string GeomData_Point2D::textX() +std::wstring GeomData_Point2D::textX() { return myExpression[0]->text(); } -std::string GeomData_Point2D::textY() +std::wstring GeomData_Point2D::textY() { return myExpression[1]->text(); } @@ -136,13 +136,13 @@ std::string GeomData_Point2D::expressionError(int theComponent) } void GeomData_Point2D::setUsedParameters(int theComponent, - const std::set& theUsedParameters) + const std::set& theUsedParameters) { assert(theComponent >= 0 && theComponent < NUM_COMPONENTS); myExpression[theComponent]->setUsedParameters(theUsedParameters); } -std::set GeomData_Point2D::usedParameters(int theComponent) const +std::set GeomData_Point2D::usedParameters(int theComponent) const { assert(theComponent >= 0 && theComponent < NUM_COMPONENTS); return myExpression[theComponent]->usedParameters(); diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h index 36c83e5e2..245a57185 100644 --- a/src/GeomData/GeomData_Point2D.h +++ b/src/GeomData/GeomData_Point2D.h @@ -53,12 +53,12 @@ class GeomData_Point2D : public GeomDataAPI_Point2D GEOMDATA_EXPORT virtual void setCalculatedValue(const double theX, const double theY); /// Defines the text values - GEOMDATA_EXPORT virtual void setText(const std::string& theX, - const std::string& theY); + GEOMDATA_EXPORT virtual void setText(const std::wstring& theX, + const std::wstring& theY); /// Returns the text values - GEOMDATA_EXPORT virtual std::string textX(); - GEOMDATA_EXPORT virtual std::string textY(); + GEOMDATA_EXPORT virtual std::wstring textX(); + GEOMDATA_EXPORT virtual std::wstring textY(); /// Allows to set expression (text) as invalid (by the parameters listener) GEOMDATA_EXPORT virtual void setExpressionInvalid(int, const bool theFlag); @@ -74,10 +74,10 @@ class GeomData_Point2D : public GeomDataAPI_Point2D /// Defines the used parameters GEOMDATA_EXPORT virtual void setUsedParameters(int theComponent, - const std::set& theUsedParameters); + const std::set& theUsedParameters); /// Returns the used parameters - GEOMDATA_EXPORT virtual std::set usedParameters(int theComponent) const; + GEOMDATA_EXPORT virtual std::set usedParameters(int theComponent) const; protected: /// Initializes attributes diff --git a/src/GeomDataAPI/GeomDataAPI.i b/src/GeomDataAPI/GeomDataAPI.i index af9295f81..62c094994 100644 --- a/src/GeomDataAPI/GeomDataAPI.i +++ b/src/GeomDataAPI/GeomDataAPI.i @@ -21,6 +21,8 @@ %module GeomDataAPI %{ #include "GeomDataAPI_swig.h" + + #define SWIGPY_UNICODE_ARG(obj) ((PyObject*) (obj)) %} // import other modules diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index d345dbf94..da810ccfe 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -62,23 +62,23 @@ class GeomDataAPI_Point : public ModelAPI_Attribute GEOMDATAAPI_EXPORT virtual void setZ(const double theZ) = 0; /// Defines the text values - GEOMDATAAPI_EXPORT virtual void setText(const std::string& theX, - const std::string& theY, - const std::string& theZ) = 0; + GEOMDATAAPI_EXPORT virtual void setText(const std::wstring& theX, + const std::wstring& theY, + const std::wstring& theZ) = 0; /// Defines the X text value - GEOMDATAAPI_EXPORT virtual void setTextX(const std::string& theX) = 0; + GEOMDATAAPI_EXPORT virtual void setTextX(const std::wstring& theX) = 0; /// Defines the Y text value - GEOMDATAAPI_EXPORT virtual void setTextY(const std::string& theY) = 0; + GEOMDATAAPI_EXPORT virtual void setTextY(const std::wstring& theY) = 0; /// Defines the Z text value - GEOMDATAAPI_EXPORT virtual void setTextZ(const std::string& theZ) = 0; + GEOMDATAAPI_EXPORT virtual void setTextZ(const std::wstring& theZ) = 0; /// Returns the text value for X - GEOMDATAAPI_EXPORT virtual std::string textX() = 0; + GEOMDATAAPI_EXPORT virtual std::wstring textX() = 0; /// Returns the text value for Y - GEOMDATAAPI_EXPORT virtual std::string textY() = 0; + GEOMDATAAPI_EXPORT virtual std::wstring textY() = 0; /// Returns the text value for Z - GEOMDATAAPI_EXPORT virtual std::string textZ() = 0; + GEOMDATAAPI_EXPORT virtual std::wstring textZ() = 0; /// Point component (x,y,z) enum PointComponent { C_X = 0, @@ -101,10 +101,10 @@ class GeomDataAPI_Point : public ModelAPI_Attribute /// Defines the used parameters GEOMDATAAPI_EXPORT virtual void setUsedParameters(int theComponent, - const std::set& theUsedParameters) = 0; + const std::set& theUsedParameters) = 0; /// Returns the used parameters - GEOMDATAAPI_EXPORT virtual std::set usedParameters(int theComponent) const = 0; + GEOMDATAAPI_EXPORT virtual std::set usedParameters(int theComponent) const = 0; /// Returns the type of this class of attributes static std::string typeId() diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h index 845de75ab..db6f737ca 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point2D.h +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.h @@ -52,13 +52,13 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute GEOMDATAAPI_EXPORT virtual void setCalculatedValue(const double theX, const double theY) = 0; /// Defines the text values - GEOMDATAAPI_EXPORT virtual void setText(const std::string& theX, - const std::string& theY) = 0; + GEOMDATAAPI_EXPORT virtual void setText(const std::wstring& theX, + const std::wstring& theY) = 0; /// Returns the text value for X - GEOMDATAAPI_EXPORT virtual std::string textX() = 0; + GEOMDATAAPI_EXPORT virtual std::wstring textX() = 0; /// Returns the text value for Y - GEOMDATAAPI_EXPORT virtual std::string textY() = 0; + GEOMDATAAPI_EXPORT virtual std::wstring textY() = 0; /// Point component (x,y) enum PointComponent { C_X = 0, @@ -80,10 +80,10 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute /// Defines the used parameters GEOMDATAAPI_EXPORT virtual void setUsedParameters(int theComponent, - const std::set& theUsedParameters) = 0; + const std::set& theUsedParameters) = 0; /// Returns the used parameters - GEOMDATAAPI_EXPORT virtual std::set usedParameters(int theComponent) const = 0; + GEOMDATAAPI_EXPORT virtual std::set usedParameters(int theComponent) const = 0; /// Appends the delta values to point GEOMDATAAPI_EXPORT void move(const double theDeltaX, const double theDeltaY); diff --git a/src/InitializationPlugin/CMakeLists.txt b/src/InitializationPlugin/CMakeLists.txt index 38c871a2b..a9518f877 100644 --- a/src/InitializationPlugin/CMakeLists.txt +++ b/src/InitializationPlugin/CMakeLists.txt @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events ${PROJECT_SOURCE_DIR}/src/ModelAPI ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/Locale ${PROJECT_SOURCE_DIR}/src/ParametersPlugin ${SUIT_INCLUDE} ${PYTHON_INCLUDE_DIR} @@ -48,6 +49,7 @@ SET(PROJECT_LIBRARIES Events Config ModelAPI + Locale ${PyInterp} ${PYTHON_LIBRARIES} ) diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index 6e5e7d29c..1245e4abf 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -25,6 +25,8 @@ #include +#include + #include #include #include @@ -46,9 +48,9 @@ //------------------------------------------------------------------------------ // Tools -std::string toStdString(double theValue) +std::wstring toString(double theValue) { - std::ostringstream sstream; + std::wostringstream sstream; // write value in scientific format with 16 digits, // thus, not check the dot position sstream.precision(16); @@ -56,9 +58,9 @@ std::string toStdString(double theValue) return sstream.str(); } -std::set toSet(const std::list& theContainer) +std::set toSet(const std::list& theContainer) { - return std::set(theContainer.begin(), theContainer.end()); + return std::set(theContainer.begin(), theContainer.end()); } //------------------------------------------------------------------------------ @@ -91,7 +93,10 @@ void InitializationPlugin_EvalListener::processEvent( std::shared_ptr aMsg = std::dynamic_pointer_cast(theMessage); FeaturePtr aParam = aMsg->parameter(); - std::string anExp = aParam->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value(); + AttributeStringPtr anExprAttr = aParam->string(ParametersPlugin_Parameter::EXPRESSION_ID()); + std::wstring anExp = anExprAttr->isUValue() ? + Locale::Convert::toWString(anExprAttr->valueU()) : + Locale::Convert::toWString(anExprAttr->value()); std::string anError; std::list > aParamsList; double aResult = evaluate(aParam, anExp, anError, aParamsList, true); @@ -104,14 +109,14 @@ void InitializationPlugin_EvalListener::processEvent( } double InitializationPlugin_EvalListener::evaluate(FeaturePtr theParameter, - const std::string& theExpression, std::string& theError, + const std::wstring& theExpression, std::string& theError, std::list >& theParamsList, const bool theIsParameter) { - std::list anExprParams = myInterp->compile(theExpression); + std::list anExprParams = myInterp->compile(theExpression); // find expression's params in the model - std::list aContext; - std::list::iterator it = anExprParams.begin(); + std::list aContext; + std::list::iterator it = anExprParams.begin(); for ( ; it != anExprParams.end(); it++) { double aValue; ResultParameterPtr aParamRes; @@ -124,7 +129,7 @@ double InitializationPlugin_EvalListener::evaluate(FeaturePtr theParameter, if (theIsParameter) theParamsList.push_back(aParamRes); - aContext.push_back(*it + "=" + toStdString(aValue)); + aContext.push_back(*it + L"=" + toString(aValue)); } myInterp->extendLocalContext(aContext); double result = myInterp->evaluate(theExpression, theError); @@ -150,7 +155,7 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( if (isValid) anAttribute->setCalculatedValue(aValue); anAttribute->setUsedParameters(isValid ? - toSet(myInterp->compile(anAttribute->text())) : std::set()); + toSet(myInterp->compile(anAttribute->text())) : std::set()); anAttribute->setExpressionInvalid(!isValid); anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError); } else @@ -163,14 +168,14 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( if (isValid) anAttribute->setCalculatedValue(aValue); anAttribute->setUsedParameters(isValid ? - toSet(myInterp->compile(anAttribute->text())) : std::set()); + toSet(myInterp->compile(anAttribute->text())) : std::set()); anAttribute->setExpressionInvalid(!isValid); anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError); } else if (aMessage->attribute()->attributeType() == GeomDataAPI_Point::typeId()) { AttributePointPtr anAttribute = std::dynamic_pointer_cast(aMessage->attribute()); - std::string aText[] = { + std::wstring aText[] = { anAttribute->textX(), anAttribute->textY(), anAttribute->textZ() @@ -186,7 +191,7 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; anAttribute->setUsedParameters(i, - isValid ? toSet(myInterp->compile(aText[i])) : std::set()); + isValid ? toSet(myInterp->compile(aText[i])) : std::set()); anAttribute->setExpressionInvalid(i, !isValid); anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError); } @@ -197,7 +202,7 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( if (aMessage->attribute()->attributeType() == GeomDataAPI_Point2D::typeId()) { AttributePoint2DPtr anAttribute = std::dynamic_pointer_cast(aMessage->attribute()); - std::string aText[] = { + std::wstring aText[] = { anAttribute->textX(), anAttribute->textY() }; @@ -211,7 +216,7 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( bool isValid = anError.empty(); if (isValid) aCalculatedValue[i] = aValue; anAttribute->setUsedParameters(i, - isValid ? toSet(myInterp->compile(aText[i])) : std::set()); + isValid ? toSet(myInterp->compile(aText[i])) : std::set()); anAttribute->setExpressionInvalid(i, !isValid); anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError); } diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.h b/src/InitializationPlugin/InitializationPlugin_EvalListener.h index 5b6f3d7be..756b335ec 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.h +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.h @@ -51,7 +51,7 @@ class InitializationPlugin_EvalListener : public Events_Listener protected: /// Evaluates theExpression and returns its value. double evaluate(std::shared_ptr theParameter, - const std::string& theExpression, std::string& theError, + const std::wstring& theExpression, std::string& theError, std::list >& theParamsList, const bool theIsParameter = false); diff --git a/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp b/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp index 0e07f9696..675e30190 100644 --- a/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp +++ b/src/InitializationPlugin/InitializationPlugin_PyInterp.cpp @@ -19,6 +19,8 @@ #include +#include + #include #include #include @@ -44,17 +46,17 @@ const char* aSearchCode = // make the expression be correct for the python interpreter even for the // beta=alfa*2 expressions -static std::string adjustExpression(const std::string& theExpression) { - std::string anExpression = theExpression; - if (!anExpression.empty() && anExpression.back() == '=') { +static std::wstring adjustExpression(const std::wstring& theExpression) { + std::wstring anExpression = theExpression; + if (!anExpression.empty() && anExpression.back() == L'=') { anExpression = anExpression.substr(0, anExpression.length() - 1); } return anExpression; } std::list > -InitializationPlugin_PyInterp::positions(const std::string& theExpression, - const std::string& theName) +InitializationPlugin_PyInterp::positions(const std::wstring& theExpression, + const std::wstring& theName) { PyLockWrapper lck; // Acquire GIL until the end of the method @@ -64,10 +66,11 @@ InitializationPlugin_PyInterp::positions(const std::string& theExpression, PyObject* aContext = PyDict_New(); PyDict_SetItemString(aContext, "__builtins__", PyEval_GetBuiltins()); - std::string anExpression = adjustExpression(theExpression); + std::wstring anExpression = adjustExpression(theExpression); // extend aContext with variables - PyDict_SetItemString(aContext, "expression", PyUnicode_FromString(anExpression.c_str())); - PyDict_SetItemString(aContext, "name", PyUnicode_FromString(theName.c_str())); + PyDict_SetItemString(aContext, "expression", + PyUnicode_FromWideChar(anExpression.c_str(), anExpression.size())); + PyDict_SetItemString(aContext, "name", PyUnicode_FromWideChar(theName.c_str(), theName.size())); PyDict_SetItemString(aContext, "positions", Py_BuildValue("[]")); // run the search code @@ -93,21 +96,21 @@ InitializationPlugin_PyInterp::positions(const std::string& theExpression, } -std::list InitializationPlugin_PyInterp::compile(const std::string& theExpression) +std::list InitializationPlugin_PyInterp::compile(const std::wstring& theExpression) { PyLockWrapper lck; // Acquire GIL until the end of the method - std::list aResult; + std::list aResult; PyObject *aCodeopModule = PyImport_AddModule("codeop"); if(!aCodeopModule) { // Fatal error. No way to go on. PyErr_Print(); return aResult; } // support "variable_name=" expression as "variable_name" - std::string anExpression = adjustExpression(theExpression); + std::wstring anExpression = adjustExpression(theExpression); PyObject *aCodePyObj = PyObject_CallMethod(aCodeopModule, (char*)"compile_command", (char*)"(s)", - anExpression.c_str()); + Locale::Convert::toString(anExpression).c_str()); if(!aCodePyObj || aCodePyObj == Py_None || !PyCode_Check(aCodePyObj)) { Py_XDECREF(aCodePyObj); @@ -126,7 +129,8 @@ std::list InitializationPlugin_PyInterp::compile(const std::string& for (size_t i = 0; i < params_size; i++) { PyObject* aParamObj = PyTuple_GetItem(aCodeObj->co_names, i); PyObject* aParamObjStr = PyObject_Str(aParamObj); - std::string aParamName(PyUnicode_AsUTF8(aParamObjStr)); + Py_ssize_t aSize; + std::wstring aParamName(PyUnicode_AsWideCharString(aParamObjStr, &aSize)); aResult.push_back(aParamName); Py_XDECREF(aParamObjStr); } @@ -135,14 +139,14 @@ std::list InitializationPlugin_PyInterp::compile(const std::string& return aResult; } -void InitializationPlugin_PyInterp::extendLocalContext(const std::list& theParameters) +void InitializationPlugin_PyInterp::extendLocalContext(const std::list& theParameters) { PyLockWrapper lck; // Acquire GIL until the end of the method if (theParameters.empty()) return; - std::list::const_iterator it = theParameters.begin(); + std::list::const_iterator it = theParameters.begin(); for ( ; it != theParameters.cend(); it++) { - std::string aParamValue = *it; + std::string aParamValue = Locale::Convert::toString(*it); simpleRun(aParamValue.c_str(), false); } } @@ -153,16 +157,17 @@ void InitializationPlugin_PyInterp::clearLocalContext() PyDict_Clear(_local_context); } -double InitializationPlugin_PyInterp::evaluate(const std::string& theExpression, +double InitializationPlugin_PyInterp::evaluate(const std::wstring& theExpression, std::string& theError) { // support "variable_name=" expression as "variable_name" - std::string anExpression = adjustExpression(theExpression); + std::wstring anExpression = adjustExpression(theExpression); PyLockWrapper lck; // Acquire GIL until the end of the method PyCompilerFlags aFlags = {CO_FUTURE_DIVISION}; aFlags.cf_flags = CO_FUTURE_DIVISION; - PyCodeObject* anExprCode = (PyCodeObject *) Py_CompileStringFlags(anExpression.c_str(), + PyCodeObject* anExprCode = (PyCodeObject *) Py_CompileStringFlags( + Locale::Convert::toString(anExpression).c_str(), "", Py_eval_input, &aFlags); if(!anExprCode) { theError = errorMessage(); diff --git a/src/InitializationPlugin/InitializationPlugin_PyInterp.h b/src/InitializationPlugin/InitializationPlugin_PyInterp.h index b34a8df82..163c265b2 100644 --- a/src/InitializationPlugin/InitializationPlugin_PyInterp.h +++ b/src/InitializationPlugin/InitializationPlugin_PyInterp.h @@ -39,16 +39,16 @@ class INITIALIZATIONPLUGIN_EXPORT InitializationPlugin_PyInterp : public PyInter virtual ~InitializationPlugin_PyInterp(); /// Returns a list of positions for theName in theExpression. - std::list > positions(const std::string& theExpression, - const std::string& theName); + std::list > positions(const std::wstring& theExpression, + const std::wstring& theName); /// Compiles theExpression and returns a list of parameters used in theExpression. - std::list compile(const std::string& theExpression); + std::list compile(const std::wstring& theExpression); /// Extends local context with the list of parameters. - void extendLocalContext(const std::list& theParameters); + void extendLocalContext(const std::list& theParameters); /// Clears local context. void clearLocalContext(); /// Evaluates theExpression and returns its value. - double evaluate(const std::string& theExpression, std::string& theError); + double evaluate(const std::wstring& theExpression, std::string& theError); /// Runs the string command in the python interpreter. Returns true if no error is in result. bool runString(std::string theString); diff --git a/src/Model/Model_AttributeDouble.cpp b/src/Model/Model_AttributeDouble.cpp index 2f84c69ee..f3b200492 100644 --- a/src/Model/Model_AttributeDouble.cpp +++ b/src/Model/Model_AttributeDouble.cpp @@ -61,7 +61,7 @@ double Model_AttributeDouble::value() return myExpression->value(); } -void Model_AttributeDouble::setText(const std::string& theValue) +void Model_AttributeDouble::setText(const std::wstring& theValue) { if (text() != theValue) { myExpression->setText(theValue); @@ -71,7 +71,7 @@ void Model_AttributeDouble::setText(const std::string& theValue) } } -std::string Model_AttributeDouble::text() +std::wstring Model_AttributeDouble::text() { return myExpression->text(); } @@ -97,12 +97,12 @@ std::string Model_AttributeDouble::expressionError() return myExpression->error(); } -void Model_AttributeDouble::setUsedParameters(const std::set& theUsedParameters) +void Model_AttributeDouble::setUsedParameters(const std::set& theUsedParameters) { myExpression->setUsedParameters(theUsedParameters); } -std::set Model_AttributeDouble::usedParameters() const +std::set Model_AttributeDouble::usedParameters() const { return myExpression->usedParameters(); } diff --git a/src/Model/Model_AttributeDouble.h b/src/Model/Model_AttributeDouble.h index a6fa0075a..b8c6662ba 100644 --- a/src/Model/Model_AttributeDouble.h +++ b/src/Model/Model_AttributeDouble.h @@ -47,10 +47,10 @@ class Model_AttributeDouble : public ModelAPI_AttributeDouble MODEL_EXPORT virtual void setCalculatedValue(const double theValue); /// Defines the text value - MODEL_EXPORT virtual void setText(const std::string& theText); + MODEL_EXPORT virtual void setText(const std::wstring& theText); /// Returns the text value - MODEL_EXPORT virtual std::string text(); + MODEL_EXPORT virtual std::wstring text(); /// Allows to set expression (text) as invalid (by the parameters listener) MODEL_EXPORT virtual void setExpressionInvalid(const bool theFlag); @@ -65,10 +65,10 @@ class Model_AttributeDouble : public ModelAPI_AttributeDouble MODEL_EXPORT virtual std::string expressionError(); /// Defines the used parameters - MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters); + MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters); /// Returns the used parameters - MODEL_EXPORT virtual std::set usedParameters() const; + MODEL_EXPORT virtual std::set usedParameters() const; protected: /// Initializes attributes diff --git a/src/Model/Model_AttributeInteger.cpp b/src/Model/Model_AttributeInteger.cpp index 5229faebc..d4948e139 100644 --- a/src/Model/Model_AttributeInteger.cpp +++ b/src/Model/Model_AttributeInteger.cpp @@ -55,7 +55,7 @@ int Model_AttributeInteger::value() return myExpression->value(); } -void Model_AttributeInteger::setText(const std::string& theValue) +void Model_AttributeInteger::setText(const std::wstring& theValue) { if (text() != theValue) { myExpression->setText(theValue); @@ -65,7 +65,7 @@ void Model_AttributeInteger::setText(const std::string& theValue) } } -std::string Model_AttributeInteger::text() +std::wstring Model_AttributeInteger::text() { return myExpression->text(); } @@ -91,12 +91,12 @@ std::string Model_AttributeInteger::expressionError() return myExpression->error(); } -void Model_AttributeInteger::setUsedParameters(const std::set& theUsedParameters) +void Model_AttributeInteger::setUsedParameters(const std::set& theUsedParameters) { myExpression->setUsedParameters(theUsedParameters); } -std::set Model_AttributeInteger::usedParameters() const +std::set Model_AttributeInteger::usedParameters() const { return myExpression->usedParameters(); } diff --git a/src/Model/Model_AttributeInteger.h b/src/Model/Model_AttributeInteger.h index d3c1ac087..88b3bf2f4 100644 --- a/src/Model/Model_AttributeInteger.h +++ b/src/Model/Model_AttributeInteger.h @@ -45,10 +45,10 @@ class Model_AttributeInteger : public ModelAPI_AttributeInteger MODEL_EXPORT virtual void setCalculatedValue(const int theValue); /// Defines the text value - MODEL_EXPORT virtual void setText(const std::string& theText); + MODEL_EXPORT virtual void setText(const std::wstring& theText); /// Returns the text value - MODEL_EXPORT virtual std::string text(); + MODEL_EXPORT virtual std::wstring text(); /// Allows to set expression (text) as invalid (by the parameters listener) MODEL_EXPORT virtual void setExpressionInvalid(const bool theFlag); @@ -63,10 +63,10 @@ class Model_AttributeInteger : public ModelAPI_AttributeInteger MODEL_EXPORT virtual std::string expressionError(); /// Defines the used parameters - MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters); + MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters); /// Returns the used parameters - MODEL_EXPORT virtual std::set usedParameters() const; + MODEL_EXPORT virtual std::set usedParameters() const; protected: /// Initializes attributes diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 4ca69f024..fcccca536 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -675,38 +675,38 @@ void Model_Data::updateConcealmentFlag() } } -std::set set_union(const std::set& theLeft, - const std::set& theRight) +std::set set_union(const std::set& theLeft, + const std::set& theRight) { - std::set aResult; + std::set aResult; aResult.insert(theLeft.begin(), theLeft.end()); aResult.insert(theRight.begin(), theRight.end()); return aResult; } -std::set usedParameters(const AttributePointPtr& theAttribute) +std::set usedParameters(const AttributePointPtr& theAttribute) { - std::set anUsedParameters; + std::set anUsedParameters; for (int aComponent = 0; aComponent < 3; ++aComponent) anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent)); return anUsedParameters; } -std::set usedParameters(const AttributePoint2DPtr& theAttribute) +std::set usedParameters(const AttributePoint2DPtr& theAttribute) { - std::set anUsedParameters; + std::set anUsedParameters; for (int aComponent = 0; aComponent < 2; ++aComponent) anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent)); return anUsedParameters; } -std::list findVariables(const std::set& theParameters, +std::list findVariables(const std::set& theParameters, const DocumentPtr& theDocument) { std::list aResult; - std::set::const_iterator aParamIt = theParameters.cbegin(); + std::set::const_iterator aParamIt = theParameters.cbegin(); for (; aParamIt != theParameters.cend(); ++aParamIt) { - const std::string& aName = *aParamIt; + const std::wstring& aName = *aParamIt; double aValue; ResultParameterPtr aParam; // theSearcher is not needed here: in expressions @@ -790,28 +790,28 @@ void Model_Data::referencesToObjects( } else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute AttributeIntegerPtr anAttribute = std::dynamic_pointer_cast(anAttr); - std::set anUsedParameters = anAttribute->usedParameters(); + std::set anUsedParameters = anAttribute->usedParameters(); std::list aParameters = findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == ModelAPI_AttributeDouble::typeId()) { // double attribute AttributeDoublePtr anAttribute = std::dynamic_pointer_cast(anAttr); - std::set anUsedParameters = anAttribute->usedParameters(); + std::set anUsedParameters = anAttribute->usedParameters(); std::list aParameters = findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == GeomDataAPI_Point::typeId()) { // point attribute AttributePointPtr anAttribute = std::dynamic_pointer_cast(anAttr); - std::set anUsedParameters = usedParameters(anAttribute); + std::set anUsedParameters = usedParameters(anAttribute); std::list aParameters = findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); } else if (aType == GeomDataAPI_Point2D::typeId()) { // point attribute AttributePoint2DPtr anAttribute = std::dynamic_pointer_cast(anAttr); - std::set anUsedParameters = usedParameters(anAttribute); + std::set anUsedParameters = usedParameters(anAttribute); std::list aParameters = findVariables(anUsedParameters, owner()->document()); aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end()); diff --git a/src/Model/Model_Expression.cpp b/src/Model/Model_Expression.cpp index 23b60fa7e..934e910dd 100644 --- a/src/Model/Model_Expression.cpp +++ b/src/Model/Model_Expression.cpp @@ -19,6 +19,8 @@ #include "Model_Expression.h" +#include + #include #include #include @@ -45,7 +47,7 @@ Model_Expression::Model_Expression(TDF_Label& theLabel) } } -void Model_Expression::setText(const std::string& theValue) +void Model_Expression::setText(const std::wstring& theValue) { if (text() != theValue) { myText->Set(TCollection_ExtendedString(theValue.c_str())); @@ -55,9 +57,9 @@ void Model_Expression::setText(const std::string& theValue) setError(text().empty() ? "" : "Not a double value."); } -std::string Model_Expression::text() const +std::wstring Model_Expression::text() const { - return TCollection_AsciiString(myText->Get()).ToCString(); + return Locale::Convert::toWString(myText->Get().ToExtString()); } void Model_Expression::setError(const std::string& theError) @@ -71,20 +73,20 @@ std::string Model_Expression::error() return TCollection_AsciiString(myError->Get()).ToCString(); } -void Model_Expression::setUsedParameters(const std::set& theUsedParameters) +void Model_Expression::setUsedParameters(const std::set& theUsedParameters) { myUsedParameters->Clear(); - std::set::const_iterator anIt = theUsedParameters.begin(); + std::set::const_iterator anIt = theUsedParameters.begin(); for (; anIt != theUsedParameters.end(); ++anIt) myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str())); } -std::set Model_Expression::usedParameters() const +std::set Model_Expression::usedParameters() const { - std::set aResult; + std::set aResult; TDataStd_ListIteratorOfListOfExtendedString aIt; for (aIt.Initialize(myUsedParameters->List()); aIt.More(); aIt.Next()) - aResult.insert(TCollection_AsciiString(aIt.Value()).ToCString()); + aResult.insert(Locale::Convert::toWString(aIt.Value().ToExtString())); return aResult; } diff --git a/src/Model/Model_Expression.h b/src/Model/Model_Expression.h index 53d7a5027..6ad194ee4 100644 --- a/src/Model/Model_Expression.h +++ b/src/Model/Model_Expression.h @@ -39,10 +39,10 @@ class Model_Expression : public virtual ModelAPI_Expression { public: /// Sets the text of this Expression - MODEL_EXPORT virtual void setText(const std::string& theText); + MODEL_EXPORT virtual void setText(const std::wstring& theText); /// Returns the text of this Expression - MODEL_EXPORT virtual std::string text() const; + MODEL_EXPORT virtual std::wstring text() const; /// Allows to set expression (text) error (by the parameters listener) MODEL_EXPORT virtual void setError(const std::string& theError); @@ -51,10 +51,10 @@ class Model_Expression : public virtual ModelAPI_Expression MODEL_EXPORT virtual std::string error(); /// Defines the used parameters (by the parameters listener) - MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters); + MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters); /// Returns the used parameters - MODEL_EXPORT virtual std::set usedParameters() const; + MODEL_EXPORT virtual std::set usedParameters() const; protected: /// Initializes attributes @@ -77,12 +77,12 @@ class Model_ExpressionDouble : { public: /// Sets the text of this Expression - MODEL_EXPORT virtual void setText(const std::string& theText) { + MODEL_EXPORT virtual void setText(const std::wstring& theText) { Model_Expression::setText(theText); }; /// Returns the text of this Expression - MODEL_EXPORT virtual std::string text() const { + MODEL_EXPORT virtual std::wstring text() const { return Model_Expression::text(); }; @@ -97,12 +97,12 @@ class Model_ExpressionDouble : }; /// Defines the used parameters (by the parameters listener) - MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters) { + MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters) { Model_Expression::setUsedParameters(theUsedParameters); }; /// Returns the used parameters - MODEL_EXPORT virtual std::set usedParameters() const { + MODEL_EXPORT virtual std::set usedParameters() const { return Model_Expression::usedParameters(); }; @@ -142,12 +142,12 @@ class Model_ExpressionInteger : { public: /// Sets the text of this Expression - MODEL_EXPORT virtual void setText(const std::string& theText) { + MODEL_EXPORT virtual void setText(const std::wstring& theText) { Model_Expression::setText(theText); }; /// Returns the text of this Expression - MODEL_EXPORT virtual std::string text() const { + MODEL_EXPORT virtual std::wstring text() const { return Model_Expression::text(); }; @@ -162,12 +162,12 @@ class Model_ExpressionInteger : }; /// Defines the used parameters (by the parameters listener) - MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters) { + MODEL_EXPORT virtual void setUsedParameters(const std::set& theUsedParameters) { Model_Expression::setUsedParameters(theUsedParameters); }; /// Returns the used parameters - MODEL_EXPORT virtual std::set usedParameters() const { + MODEL_EXPORT virtual std::set usedParameters() const { return Model_Expression::usedParameters(); }; diff --git a/src/ModelAPI/ModelAPI_AttributeDouble.h b/src/ModelAPI/ModelAPI_AttributeDouble.h index eae4e43b5..22cd3338c 100644 --- a/src/ModelAPI/ModelAPI_AttributeDouble.h +++ b/src/ModelAPI/ModelAPI_AttributeDouble.h @@ -43,10 +43,10 @@ class ModelAPI_AttributeDouble : public ModelAPI_Attribute MODELAPI_EXPORT virtual void setCalculatedValue(const double theValue) = 0; /// Defines the text value - MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0; + MODELAPI_EXPORT virtual void setText(const std::wstring& theText) = 0; /// Returns the text value - MODELAPI_EXPORT virtual std::string text() = 0; + MODELAPI_EXPORT virtual std::wstring text() = 0; /// Allows to set expression (text) as invalid (by the parameters listener) MODELAPI_EXPORT virtual void setExpressionInvalid(const bool theFlag) = 0; @@ -62,10 +62,10 @@ class ModelAPI_AttributeDouble : public ModelAPI_Attribute /// Defines the used parameters MODELAPI_EXPORT virtual - void setUsedParameters(const std::set& theUsedParameters) = 0; + void setUsedParameters(const std::set& theUsedParameters) = 0; /// Returns the used parameters - MODELAPI_EXPORT virtual std::set usedParameters() const = 0; + MODELAPI_EXPORT virtual std::set usedParameters() const = 0; /// Returns the type of this class of attributes MODELAPI_EXPORT static std::string typeId() diff --git a/src/ModelAPI/ModelAPI_AttributeInteger.h b/src/ModelAPI/ModelAPI_AttributeInteger.h index 54c550cbb..2b8383f4d 100644 --- a/src/ModelAPI/ModelAPI_AttributeInteger.h +++ b/src/ModelAPI/ModelAPI_AttributeInteger.h @@ -43,10 +43,10 @@ class ModelAPI_AttributeInteger : public ModelAPI_Attribute MODELAPI_EXPORT virtual void setCalculatedValue(const int theValue) = 0; /// Defines the text value - MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0; + MODELAPI_EXPORT virtual void setText(const std::wstring& theText) = 0; /// Returns the text value - MODELAPI_EXPORT virtual std::string text() = 0; + MODELAPI_EXPORT virtual std::wstring text() = 0; /// Allows to set expression (text) as invalid (by the parameters listener) MODELAPI_EXPORT virtual void setExpressionInvalid(const bool theFlag) = 0; @@ -62,10 +62,10 @@ class ModelAPI_AttributeInteger : public ModelAPI_Attribute /// Defines the used parameters MODELAPI_EXPORT virtual - void setUsedParameters(const std::set& theUsedParameters) = 0; + void setUsedParameters(const std::set& theUsedParameters) = 0; /// Returns the used parameters - MODELAPI_EXPORT virtual std::set usedParameters() const = 0; + MODELAPI_EXPORT virtual std::set usedParameters() const = 0; /// Returns the type of this class of attributes MODELAPI_EXPORT static std::string typeId() diff --git a/src/ModelAPI/ModelAPI_Events.cpp b/src/ModelAPI/ModelAPI_Events.cpp index 4bc97466a..cebf9ca79 100644 --- a/src/ModelAPI/ModelAPI_Events.cpp +++ b/src/ModelAPI/ModelAPI_Events.cpp @@ -196,18 +196,18 @@ ModelAPI_ComputePositionsMessage::ModelAPI_ComputePositionsMessage( ModelAPI_ComputePositionsMessage::~ModelAPI_ComputePositionsMessage() {} -const std::string& ModelAPI_ComputePositionsMessage::expression() const +const std::wstring& ModelAPI_ComputePositionsMessage::expression() const { return myExpression; } -const std::string& ModelAPI_ComputePositionsMessage::parameter() const +const std::wstring& ModelAPI_ComputePositionsMessage::parameter() const { return myParamName; } void ModelAPI_ComputePositionsMessage::set( - const std::string& theExpression, const std::string& theParameter) + const std::wstring& theExpression, const std::wstring& theParameter) { myExpression = theExpression; myParamName = theParameter; diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 0bfb4d53e..fccf6e240 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -356,8 +356,8 @@ class ModelAPI_ParameterEvalMessage : public Events_Message /// Message to ask compute the positions of parameters in the expression class ModelAPI_ComputePositionsMessage : public Events_Message { - std::string myExpression; ///< the expression string - std::string myParamName; ///< name of the parameter to be searched + std::wstring myExpression; ///< the expression string + std::wstring myParamName; ///< name of the parameter to be searched std::list > myPositions; ///< computation result: start-end position indices public: @@ -372,7 +372,7 @@ public: /// Useful method that creates and sends the AttributeEvalMessage event /// Returns the message, processed, with the resulting fields filled MODELAPI_EXPORT static std::shared_ptr - send(const std::string& theExpression, const std::string& theParameter, const void* theSender) + send(const std::wstring& theExpression, const std::wstring& theParameter, const void* theSender) { std::shared_ptr aMessage = std::shared_ptr( @@ -389,11 +389,11 @@ public: MODELAPI_EXPORT virtual ~ModelAPI_ComputePositionsMessage(); /// Returns an expression stored in the message - MODELAPI_EXPORT const std::string& expression() const; + MODELAPI_EXPORT const std::wstring& expression() const; /// Returns a parameter name stored in the message - MODELAPI_EXPORT const std::string& parameter() const; + MODELAPI_EXPORT const std::wstring& parameter() const; /// Sets an expression and parameter needed for computation - MODELAPI_EXPORT void set(const std::string& theExpression, const std::string& theParameter); + MODELAPI_EXPORT void set(const std::wstring& theExpression, const std::wstring& theParameter); /// Sets the results of processing MODELAPI_EXPORT void setPositions(const std::list >& thePositions); /// Returns the results of processing: position start and end indices diff --git a/src/ModelAPI/ModelAPI_Expression.cpp b/src/ModelAPI/ModelAPI_Expression.cpp index 3359e5988..026c9c0f4 100644 --- a/src/ModelAPI/ModelAPI_Expression.cpp +++ b/src/ModelAPI/ModelAPI_Expression.cpp @@ -19,6 +19,8 @@ #include "ModelAPI_Expression.h" +#include + ModelAPI_Expression::ModelAPI_Expression() { @@ -49,17 +51,23 @@ ModelAPI_ExpressionInteger::ModelAPI_ExpressionInteger() } + bool ModelAPI_Expression::isVariable(const std::string& theString) +{ + return isVariable(Locale::Convert::toWString(theString)); +} + +bool ModelAPI_Expression::isVariable(const std::wstring& theString) { if (theString.empty()) return false; try { - std::string::const_iterator it = theString.begin(); - if (!(isalpha(*it) || (*it) == '_') || it == theString.end()) + std::wstring::const_iterator it = theString.begin(); + if (!(iswalpha(*it) || (*it) == L'_') || it == theString.end()) return false; it++; for ( ; it != theString.end(); ++it ) { - if(!(isalnum(*it) || (*it) == '_')) { + if(!(iswalnum(*it) || (*it) == L'_')) { return false; } } diff --git a/src/ModelAPI/ModelAPI_Expression.h b/src/ModelAPI/ModelAPI_Expression.h index 94d768f3f..b32addf66 100644 --- a/src/ModelAPI/ModelAPI_Expression.h +++ b/src/ModelAPI/ModelAPI_Expression.h @@ -43,10 +43,10 @@ class ModelAPI_Expression MODELAPI_EXPORT virtual void setInitialized(); /// Sets the text of this Expression - MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0; + MODELAPI_EXPORT virtual void setText(const std::wstring& theText) = 0; /// Returns the text of this Expression - MODELAPI_EXPORT virtual std::string text() const = 0; + MODELAPI_EXPORT virtual std::wstring text() const = 0; /// Allows to set expression (text) as invalid (by the parameters listener) MODELAPI_EXPORT virtual void setInvalid(const bool theFlag) = 0; @@ -62,14 +62,17 @@ class ModelAPI_Expression /// Defines the used parameters (by the parameters listener) MODELAPI_EXPORT virtual - void setUsedParameters(const std::set& theUsedParameters) = 0; + void setUsedParameters(const std::set& theUsedParameters) = 0; /// Returns the used parameters - MODELAPI_EXPORT virtual std::set usedParameters() const = 0; + MODELAPI_EXPORT virtual std::set usedParameters() const = 0; /// Returns True if the given string can be defined as a name of an expression variable MODELAPI_EXPORT static bool isVariable(const std::string& theString); + /// Returns True if the given string can be defined as a name of an expression variable + MODELAPI_EXPORT static bool isVariable(const std::wstring& theString); + protected: /// Objects are created for features automatically MODELAPI_EXPORT ModelAPI_Expression(); diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index e3b007bb8..69a882af6 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -171,12 +171,11 @@ std::string getFeatureError(const FeaturePtr& theFeature) // LCOV_EXCL_STOP ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup, - const std::string& theName) + const std::wstring& theName) { - std::wstring aName = Locale::Convert::toWString(theName); for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) { ObjectPtr anObject = theDocument->object(theGroup, anIndex); - if (anObject->data()->name() == aName) + if (anObject->data()->name() == theName) return anObject; } // not found @@ -184,7 +183,7 @@ ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGro } bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher, - const std::string& theName, double& outValue, ResultParameterPtr& theParam) + const std::wstring& theName, double& outValue, ResultParameterPtr& theParam) { ObjectPtr aParamObj = objectByName(theDocument, ModelAPI_ResultParameter::group(), theName); theParam = std::dynamic_pointer_cast(aParamObj); @@ -202,7 +201,7 @@ bool findVariable(const DocumentPtr& theDocument, FeaturePtr theSearcher, return true; } -bool findVariable(FeaturePtr theSearcher, const std::string& theName, double& outValue, +bool findVariable(FeaturePtr theSearcher, const std::wstring& theName, double& outValue, ResultParameterPtr& theParam, const DocumentPtr& theDocument) { SessionPtr aSession = ModelAPI_Session::get(); diff --git a/src/ModelAPI/ModelAPI_Tools.h b/src/ModelAPI/ModelAPI_Tools.h index 27021498a..5fd96b917 100644 --- a/src/ModelAPI/ModelAPI_Tools.h +++ b/src/ModelAPI/ModelAPI_Tools.h @@ -56,7 +56,7 @@ MODELAPI_EXPORT std::string getFeatureError(const std::shared_ptr& theDocument, std::shared_ptr theSearcher, - const std::string& theName, double& outValue, + const std::wstring& theName, double& outValue, std::shared_ptr& theParam); /*! @@ -66,7 +66,7 @@ MODELAPI_EXPORT bool findVariable(const std::shared_ptr& theD * theSearcher must be located later in the history than the found variable. */ MODELAPI_EXPORT bool findVariable(std::shared_ptr theSearcher, - const std::string& theName, + const std::wstring& theName, double& outValue, std::shared_ptr& theParam, const std::shared_ptr& theDocument = std::shared_ptr()); diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index f1ec7251f..109d13bc6 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -66,7 +66,8 @@ temp = ModelHighAPI_Double(PyFloat_AsDouble($input)); $1 = &temp; } else if (PyUnicode_Check($input)) { - temp = ModelHighAPI_Double(PyUnicode_AsUTF8($input)); + Py_ssize_t size; + temp = ModelHighAPI_Double(PyUnicode_AsWideCharString($input, &size)); $1 = &temp; } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { } else { @@ -83,7 +84,8 @@ temp = ModelHighAPI_Integer(static_cast(PyLong_AsLong($input))); $1 = &temp; } else if (PyUnicode_Check($input)) { - temp = ModelHighAPI_Integer(PyUnicode_AsUTF8($input)); + Py_ssize_t size; + temp = ModelHighAPI_Integer(PyUnicode_AsWideCharString($input, &size)); $1 = &temp; } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { } else { @@ -447,7 +449,8 @@ if (PyFloat_Check(item) || PyLong_Check(item)) { temp.push_back(ModelHighAPI_Double(PyFloat_AsDouble(item))); } else if (PyUnicode_Check(item)) { - temp.push_back(ModelHighAPI_Double(PyUnicode_AsUTF8(item))); + Py_ssize_t size; + temp.push_back(ModelHighAPI_Double(PyUnicode_AsWideCharString(item, &size))); } else if ((SWIG_ConvertPtr(item, (void **)&temp_double, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { temp.push_back(*temp_double); } else { @@ -485,7 +488,8 @@ if (PyLong_Check(item)) { temp.push_back(ModelHighAPI_Integer(PyLong_AsLong(item))); } else if (PyUnicode_Check(item)) { - temp.push_back(ModelHighAPI_Integer(PyUnicode_AsUTF8(item))); + Py_ssize_t size; + temp.push_back(ModelHighAPI_Integer(PyUnicode_AsWideCharString(item, &size))); } else if ((SWIG_ConvertPtr(item, (void **)&temp_int, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { temp.push_back(*temp_int); } else { diff --git a/src/ModelHighAPI/ModelHighAPI_Double.cpp b/src/ModelHighAPI/ModelHighAPI_Double.cpp index 8b4c2f048..121e85fe4 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Double.cpp @@ -32,13 +32,13 @@ ModelHighAPI_Double::ModelHighAPI_Double(double theValue) { } -ModelHighAPI_Double::ModelHighAPI_Double(const std::string & theValue) +ModelHighAPI_Double::ModelHighAPI_Double(const std::wstring & theValue) : myVariantType(VT_STRING) , myString(theValue) { } -ModelHighAPI_Double::ModelHighAPI_Double(const char * theValue) +ModelHighAPI_Double::ModelHighAPI_Double(const wchar_t * theValue) : myVariantType(VT_STRING) , myString(theValue) { @@ -54,12 +54,12 @@ double ModelHighAPI_Double::value() const return myDouble; } -std::string ModelHighAPI_Double::string() const +std::wstring ModelHighAPI_Double::string() const { if (myVariantType == VT_STRING) return myString; - std::ostringstream anOut; + std::wostringstream anOut; anOut << myDouble; return anOut.str(); } diff --git a/src/ModelHighAPI/ModelHighAPI_Double.h b/src/ModelHighAPI/ModelHighAPI_Double.h index 02ddcd197..2811c6668 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.h +++ b/src/ModelHighAPI/ModelHighAPI_Double.h @@ -41,10 +41,10 @@ public: ModelHighAPI_Double(double theValue = 0.); /// Constructor for std::string MODELHIGHAPI_EXPORT - ModelHighAPI_Double(const std::string & theValue); + ModelHighAPI_Double(const std::wstring & theValue); /// Constructor for char * MODELHIGHAPI_EXPORT - ModelHighAPI_Double(const char * theValue); + ModelHighAPI_Double(const wchar_t * theValue); /// Destructor MODELHIGHAPI_EXPORT virtual ~ModelHighAPI_Double(); @@ -64,12 +64,12 @@ public: MODELHIGHAPI_EXPORT double value() const; /// Returns a string representation of the value - MODELHIGHAPI_EXPORT virtual std::string string() const; + MODELHIGHAPI_EXPORT virtual std::wstring string() const; private: enum VariantType { VT_DOUBLE, VT_STRING } myVariantType; double myDouble; - std::string myString; + std::wstring myString; }; //-------------------------------------------------------------------------------------- diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index c46e05119..6d8affba8 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -1144,7 +1144,11 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( { static const int aSize = 3; double aValues[aSize] = {thePoint->x(), thePoint->y(), thePoint->z()}; - std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY(), thePoint->textZ()}; + std::string aTexts[aSize] = { + Locale::Convert::toString(thePoint->textX()), + Locale::Convert::toString(thePoint->textY()), + Locale::Convert::toString(thePoint->textZ()) + }; myDumpStorage->dumpArray(aSize, aValues, aTexts); return *this; } @@ -1154,7 +1158,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( { static const int aSize = 2; double aValues[aSize] = {thePoint->x(), thePoint->y()}; - std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY()}; + std::string aTexts[aSize] = { + Locale::Convert::toString(thePoint->textX()), + Locale::Convert::toString(thePoint->textY()) + }; myDumpStorage->dumpArray(aSize, aValues, aTexts); return *this; } @@ -1206,7 +1213,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrInt) { - std::string aText = theAttrInt->text(); + std::string aText = Locale::Convert::toString(theAttrInt->text()); if (aText.empty()) *myDumpStorage << theAttrInt->value(); else @@ -1231,7 +1238,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( const std::shared_ptr& theAttrReal) { - std::string aText = theAttrReal->text(); + std::string aText = Locale::Convert::toString(theAttrReal->text()); if (aText.empty()) *myDumpStorage << theAttrReal->value(); else diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index 1493d104b..58e32136f 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -211,7 +211,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { if (anAttr->text().empty()) aResult<value(); else - aResult<text(); + aResult << Locale::Convert::toString(anAttr->text()); } else if (aType == ModelAPI_AttributeDouble::typeId()) { AttributeDoublePtr anAttr = std::dynamic_pointer_cast(theAttr); if (anAttr->id() == "ConstraintValue") { @@ -230,7 +230,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) { double aVal = anAttr->value(); dumpArray(aResult, &aVal, 1, aPrecision); } else - aResult<text(); + aResult << Locale::Convert::toString(anAttr->text()); } else if (aType == ModelAPI_AttributeBoolean::typeId()) { AttributeBooleanPtr anAttr = std::dynamic_pointer_cast(theAttr); // do not dump internal flags of ConstraintAngle diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.cpp b/src/ModelHighAPI/ModelHighAPI_Integer.cpp index ea9ecc572..6f7a9ae7b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Integer.cpp @@ -31,13 +31,13 @@ ModelHighAPI_Integer::ModelHighAPI_Integer(int theValue) { } -ModelHighAPI_Integer::ModelHighAPI_Integer(const std::string & theValue) +ModelHighAPI_Integer::ModelHighAPI_Integer(const std::wstring & theValue) : myVariantType(VT_STRING) , myString(theValue) { } -ModelHighAPI_Integer::ModelHighAPI_Integer(const char * theValue) +ModelHighAPI_Integer::ModelHighAPI_Integer(const wchar_t * theValue) : myVariantType(VT_STRING) , myString(theValue) { @@ -63,12 +63,12 @@ int ModelHighAPI_Integer::intValue() const return myInt; } -std::string ModelHighAPI_Integer::string() const +std::wstring ModelHighAPI_Integer::string() const { if (myVariantType == VT_STRING) return myString; - std::ostringstream anOut; + std::wostringstream anOut; anOut << myInt; return anOut.str(); } diff --git a/src/ModelHighAPI/ModelHighAPI_Integer.h b/src/ModelHighAPI/ModelHighAPI_Integer.h index 459c74da2..da433e1c0 100644 --- a/src/ModelHighAPI/ModelHighAPI_Integer.h +++ b/src/ModelHighAPI/ModelHighAPI_Integer.h @@ -40,10 +40,10 @@ public: ModelHighAPI_Integer(int theValue = 0); /// Constructor for std::string MODELHIGHAPI_EXPORT - ModelHighAPI_Integer(const std::string & theValue); + ModelHighAPI_Integer(const std::wstring & theValue); /// Constructor for char * MODELHIGHAPI_EXPORT - ModelHighAPI_Integer(const char * theValue); + ModelHighAPI_Integer(const wchar_t * theValue); /// Destructor MODELHIGHAPI_EXPORT virtual ~ModelHighAPI_Integer(); @@ -56,12 +56,12 @@ public: MODELHIGHAPI_EXPORT virtual int intValue() const; /// Returns a string representation of the value - MODELHIGHAPI_EXPORT virtual std::string string() const; + MODELHIGHAPI_EXPORT virtual std::wstring string() const; private: enum VariantType { VT_INT, VT_STRING } myVariantType; int myInt; - std::string myString; + std::wstring myString; }; //-------------------------------------------------------------------------------------- diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index 2f06c5f28..43b268aab 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -242,6 +242,7 @@ SET(PROJECT_LIBRARIES GeomAPI GeomDataAPI GeomAlgoAPI + Locale ${QT_LIBRARIES} ${OpenCASCADE_FoundationClasses_LIBRARIES} ${OpenCASCADE_Visualization_LIBRARIES} @@ -278,6 +279,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/GeomDataAPI ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI + ${PROJECT_SOURCE_DIR}/src/Locale ${SUIT_INCLUDE} ) diff --git a/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp index e8e5d7409..488e81c59 100644 --- a/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamIntSpinBox.cpp @@ -213,7 +213,7 @@ bool ModuleBase_ParamIntSpinBox::findVariable(const QString& theName, double& outValue) const { ResultParameterPtr aParam; - return ModelAPI_Tools::findVariable(FeaturePtr(), theName.toStdString(), outValue, aParam); + return ModelAPI_Tools::findVariable(FeaturePtr(), theName.toStdWString(), outValue, aParam); } /*! diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 37ada0461..ddc7679cf 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -172,7 +172,7 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() // Nullyfy the parameter reference without deletion of the created myParameter = FeaturePtr(); } - aReal->setText(aText.toStdString()); + aReal->setText(aText.toStdWString()); } else { // it is important to set the empty text value to the attribute before set the value // because setValue tries to calculate the attribute value according to the @@ -181,7 +181,7 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() aReal->setExpressionError(""); aReal->setExpressionInvalid(false); } - aReal->setText(""); + aReal->setText(L""); aReal->setValue(mySpinBox->value()); } updateObject(myFeature); @@ -192,9 +192,9 @@ bool ModuleBase_WidgetDoubleValue::restoreValueCustom() { DataPtr aData = myFeature->data(); AttributeDoublePtr aRef = aData->real(attributeID()); - std::string aTextRepr = aRef->text(); + std::wstring aTextRepr = aRef->text(); if (!aTextRepr.empty()) { - QString aText = QString::fromStdString(aTextRepr); + QString aText = QString::fromStdWString(aTextRepr); ModuleBase_Tools::setSpinText(mySpinBox, aText); } else { diff --git a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp index e70a75f15..3050e10e8 100644 --- a/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetExprEditor.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include #include #include @@ -268,7 +270,7 @@ bool ModuleBase_WidgetExprEditor::storeValueCustom() AttributeStringPtr aStringAttr = aData->string(attributeID()); QString aWidgetValue = myEditor->toPlainText(); - aStringAttr->setValue(aWidgetValue.toStdString()); + aStringAttr->setValue(aWidgetValue.toStdWString()); updateObject(myFeature); // Try to get the value @@ -303,8 +305,12 @@ bool ModuleBase_WidgetExprEditor::restoreValueCustom() bool isBlocked = myEditor->blockSignals(true); QTextCursor aCursor = myEditor->textCursor(); int pos = aCursor.position(); - std::string aRestoredStr = aStringAttr->value(); - myEditor->setPlainText(QString::fromStdString(aRestoredStr)); + QString aRestoredStr; + if (aStringAttr->isUValue()) + aRestoredStr = QString::fromStdWString(Locale::Convert::toWString(aStringAttr->valueU())); + else + aRestoredStr = QString::fromStdString(aStringAttr->value()); + myEditor->setPlainText(aRestoredStr); aCursor.setPosition(pos); myEditor->setTextCursor(aCursor); myEditor->blockSignals(isBlocked); diff --git a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp index 81dffa9ee..7922ecae1 100644 --- a/src/ModuleBase/ModuleBase_WidgetIntValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetIntValue.cpp @@ -160,7 +160,7 @@ bool ModuleBase_WidgetIntValue::storeValueCustom() // Nullyfy the parameter reference without deletion of the created myParameter = FeaturePtr(); } - anAttribute->setText(aText.toStdString()); + anAttribute->setText(aText.toStdWString()); } else { // it is important to set the empty text value to the attribute before set the value // because setValue tries to calculate the attribute value according to the @@ -169,7 +169,7 @@ bool ModuleBase_WidgetIntValue::storeValueCustom() anAttribute->setExpressionError(""); anAttribute->setExpressionInvalid(false); } - anAttribute->setText(""); + anAttribute->setText(L""); anAttribute->setValue(mySpinBox->value()); } updateObject(myFeature); @@ -180,9 +180,9 @@ bool ModuleBase_WidgetIntValue::restoreValueCustom() { DataPtr aData = myFeature->data(); AttributeIntegerPtr anAttribute = aData->integer(attributeID()); - std::string aTextRepr = anAttribute->text(); + std::wstring aTextRepr = anAttribute->text(); if (!aTextRepr.empty()) { - QString aText = QString::fromStdString(aTextRepr); + QString aText = QString::fromStdWString(aTextRepr); //if (aText.endsWith('=')) { // if (!myParameter.get()) { // QString aName = aText.left(aText.indexOf('=')).trimmed(); diff --git a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp index 70d19c65d..a2025b6f5 100644 --- a/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp +++ b/src/ModuleBase/ModuleBase_WidgetLineEdit.cpp @@ -21,6 +21,8 @@ #include #include +#include + #include #include #include @@ -124,7 +126,7 @@ bool ModuleBase_WidgetLineEdit::storeValueCustom() DataPtr aData = myFeature->data(); AttributeStringPtr aStringAttr = aData->string(attributeID()); QString aWidgetValue = myLineEdit->text(); - aStringAttr->setValue(aWidgetValue.toStdString()); + aStringAttr->setValue(aWidgetValue.toStdWString()); updateObject(myFeature); return true; } @@ -138,7 +140,12 @@ bool ModuleBase_WidgetLineEdit::restoreValueCustom() AttributeStringPtr aStringAttr = aData->string(attributeID()); bool isBlocked = myLineEdit->blockSignals(true); - myLineEdit->setText(QString::fromStdString(aStringAttr->value())); + QString aText; + if (aStringAttr->isUValue()) + aText = QString::fromStdWString(Locale::Convert::toWString(aStringAttr->valueU())); + else + aText = QString::fromStdString(aStringAttr->value()); + myLineEdit->setText(aText); myLineEdit->blockSignals(isBlocked); return true; diff --git a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp index 8b8d85e3e..860cf15ae 100644 --- a/src/ModuleBase/ModuleBase_WidgetPointInput.cpp +++ b/src/ModuleBase/ModuleBase_WidgetPointInput.cpp @@ -34,7 +34,7 @@ #include -#define ERR_STRING "ERROR" +#define ERR_STRING L"ERROR" ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -103,7 +103,7 @@ QList ModuleBase_WidgetPointInput::getControls() const return aList; } -std::string getParmText(ModuleBase_ParamSpinBox* theSpin, FeaturePtr& theParam) +std::wstring getParmText(ModuleBase_ParamSpinBox* theSpin, FeaturePtr& theParam) { QString aText = theSpin->text(); if (aText.contains('=')) { @@ -118,7 +118,7 @@ std::string getParmText(ModuleBase_ParamSpinBox* theSpin, FeaturePtr& theParam) } aText = aText.split('=').at(0); } - return aText.toStdString(); + return aText.toStdWString(); } //******************************************************************** @@ -128,21 +128,21 @@ bool ModuleBase_WidgetPointInput::storeValueCustom() if (aAttr.get()) { if (aAttr->isInitialized()) { if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) { - std::string aXText = getParmText(myXSpin, myXParam); + std::wstring aXText = getParmText(myXSpin, myXParam); if (aXText == ERR_STRING) { aAttr->setExpressionError(0, "Parameter cannot be created"); aAttr->setExpressionInvalid(0, true); updateObject(myFeature); return false; } - std::string aYText = getParmText(myYSpin, myYParam); + std::wstring aYText = getParmText(myYSpin, myYParam); if (aYText == ERR_STRING) { aAttr->setExpressionError(1, "Parameter cannot be created"); aAttr->setExpressionInvalid(1, true); updateObject(myFeature); return false; } - std::string aZText = getParmText(myZSpin, myZParam); + std::wstring aZText = getParmText(myZSpin, myZParam); if (aZText == ERR_STRING) { aAttr->setExpressionError(2, "Parameter cannot be created"); aAttr->setExpressionInvalid(2, true); @@ -151,7 +151,7 @@ bool ModuleBase_WidgetPointInput::storeValueCustom() } aAttr->setText(aXText, aYText, aZText); } else { - aAttr->setText("", "", ""); + aAttr->setText(L"", L"", L""); aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value()); } } else { @@ -169,26 +169,26 @@ bool ModuleBase_WidgetPointInput::restoreValueCustom() AttributePointPtr aAttr = std::dynamic_pointer_cast(attribute()); if (aAttr.get()) { if (aAttr->isInitialized()) { - std::string aXText = aAttr->textX(); + std::wstring aXText = aAttr->textX(); if (aXText.empty()) { myXSpin->setValue(aAttr->x()); } else { - myXSpin->setText(aXText.c_str()); + myXSpin->setText(QString::fromStdWString(aXText)); } - std::string aYText = aAttr->textY(); + std::wstring aYText = aAttr->textY(); if (aYText.empty()) { myYSpin->setValue(aAttr->y()); } else { - myYSpin->setText(aYText.c_str()); + myYSpin->setText(QString::fromStdWString(aYText)); } - std::string aZText = aAttr->textZ(); + std::wstring aZText = aAttr->textZ(); if (aZText.empty()) { myZSpin->setValue(aAttr->z()); } else { - myZSpin->setText(aZText.c_str()); + myZSpin->setText(QString::fromStdWString(aZText)); } } else { diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index 56cefb182..5dc61ed52 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -51,14 +51,14 @@ //------------------------------------------------------------------------------ // Tools -static std::string toStdString(double theValue) +static std::wstring toStdWString(double theValue) { - std::ostringstream sstream; + std::wostringstream sstream; sstream << theValue; - size_t aPos = sstream.str().find("."); - std::string aPnt = ""; - if (aPos == std::string::npos) - aPnt = "."; + size_t aPos = sstream.str().find(L"."); + std::wstring aPnt = L""; + if (aPos == std::wstring::npos) + aPnt = L"."; return sstream.str() + aPnt; } @@ -97,12 +97,12 @@ void ParametersPlugin_EvalListener::processEvent( } } -std::string ParametersPlugin_EvalListener::renameInPythonExpression( - const std::string& theExpression, - const std::string& theOldName, - const std::string& theNewName) +std::wstring ParametersPlugin_EvalListener::renameInPythonExpression( + const std::wstring& theExpression, + const std::wstring& theOldName, + const std::wstring& theNewName) { - std::string anExpressionString = theExpression; + std::wstring anExpressionString = theExpression; // ask interpreter to compute the positions in the expression std::shared_ptr aMsg = @@ -124,7 +124,7 @@ std::string ParametersPlugin_EvalListener::renameInPythonExpression( int aLineNo = ritLine->first - 1; size_t aLineStart = 0; for (int i = 0; i < aLineNo; ++i) - aLineStart = anExpressionString.find("\n", aLineStart) + 1; + aLineStart = anExpressionString.find(L"\n", aLineStart) + 1; const std::list& aColOffsets = ritLine->second; std::list::const_reverse_iterator ritOffset = aColOffsets.rbegin(); @@ -139,13 +139,15 @@ std::string ParametersPlugin_EvalListener::renameInPythonExpression( void ParametersPlugin_EvalListener::renameInParameter( std::shared_ptr theParameter, - const std::string& theOldName, - const std::string& theNewName) + const std::wstring& theOldName, + const std::wstring& theNewName) { std::shared_ptr anExpressionAttribute = theParameter->string(ParametersPlugin_Parameter::EXPRESSION_ID()); - std::string anExpressionString = anExpressionAttribute->value(); + std::wstring anExpressionString = anExpressionAttribute->isUValue() ? + Locale::Convert::toWString(anExpressionAttribute->valueU()) : + Locale::Convert::toWString(anExpressionAttribute->value()); anExpressionString = renameInPythonExpression(anExpressionString, theOldName, theNewName); @@ -158,13 +160,13 @@ void ParametersPlugin_EvalListener::renameInParameter( void ParametersPlugin_EvalListener::renameInAttribute( std::shared_ptr theAttribute, - const std::string& theOldName, - const std::string& theNewName) + const std::wstring& theOldName, + const std::wstring& theNewName) { if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) { AttributeIntegerPtr anAttribute = std::dynamic_pointer_cast(theAttribute); - std::string anExpressionString = anAttribute->text(); + std::wstring anExpressionString = anAttribute->text(); anExpressionString = renameInPythonExpression(anExpressionString, theOldName, theNewName); anAttribute->setText(anExpressionString); @@ -172,7 +174,7 @@ void ParametersPlugin_EvalListener::renameInAttribute( if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) { AttributeDoublePtr anAttribute = std::dynamic_pointer_cast(theAttribute); - std::string anExpressionString = anAttribute->text(); + std::wstring anExpressionString = anAttribute->text(); anExpressionString = renameInPythonExpression(anExpressionString, theOldName, theNewName); anAttribute->setText(anExpressionString); @@ -180,7 +182,7 @@ void ParametersPlugin_EvalListener::renameInAttribute( if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) { AttributePointPtr anAttribute = std::dynamic_pointer_cast(theAttribute); - std::string anExpressionString[3] = { + std::wstring anExpressionString[3] = { anAttribute->textX(), anAttribute->textY(), anAttribute->textZ() @@ -195,7 +197,7 @@ void ParametersPlugin_EvalListener::renameInAttribute( if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) { AttributePoint2DPtr anAttribute = std::dynamic_pointer_cast(theAttribute); - std::string anExpressionString[2] = { + std::wstring anExpressionString[2] = { anAttribute->textX(), anAttribute->textY() }; @@ -209,8 +211,8 @@ void ParametersPlugin_EvalListener::renameInAttribute( void ParametersPlugin_EvalListener::renameInDependents( std::shared_ptr theResultParameter, - const std::string& theOldName, - const std::string& theNewName) + const std::wstring& theOldName, + const std::wstring& theNewName) { std::set > anAttributes = theResultParameter->data()->refsToMe(); @@ -302,19 +304,18 @@ void ParametersPlugin_EvalListener::processObjectRenamedEvent( if (!isValidAttribute(aParameter->string(ParametersPlugin_Parameter::VARIABLE_ID()))) { //setParameterName(aResultParameter, aMessage->oldName()); if (myOldNames.find(aParameter.get()) == myOldNames.end()) - myOldNames[aParameter.get()] = Locale::Convert::toString(aMessage->oldName()); + myOldNames[aParameter.get()] = aMessage->oldName(); return; } - std::string anOldName = Locale::Convert::toString(aMessage->oldName()); + std::wstring anOldName = aMessage->oldName(); if (myOldNames.find(aParameter.get()) != myOldNames.end()) { anOldName = myOldNames[aParameter.get()]; myOldNames.erase(aParameter.get()); aParameter->execute(); // to enable result because of previously incorrect name } - renameInDependents(aResultParameter, anOldName, - Locale::Convert::toString(aMessage->newName())); + renameInDependents(aResultParameter, anOldName, aMessage->newName()); } void ParametersPlugin_EvalListener::processReplaceParameterEvent( @@ -337,9 +338,7 @@ void ParametersPlugin_EvalListener::processReplaceParameterEvent( return; double aRealValue = aResultParameter->data()->real(ModelAPI_ResultParameter::VALUE())->value(); - std::string aValue = toStdString(aRealValue); + std::wstring aValue = toStdWString(aRealValue); - renameInDependents(aResultParameter, - Locale::Convert::toString(aResultParameter->data()->name()), - aValue); + renameInDependents(aResultParameter, aResultParameter->data()->name(), aValue); } diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.h b/src/ParametersPlugin/ParametersPlugin_EvalListener.h index f12c5cef1..089fba80f 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.h +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.h @@ -38,7 +38,7 @@ class ParametersPlugin_EvalListener : public Events_Listener { /// map of old names, that were valid for perameres, but now parameter name is changed to invalid /// stored not shared pointers to features to avoid memory keeping on the feature delete - std::map myOldNames; + std::map myOldNames; public: PARAMETERSPLUGIN_EXPORT ParametersPlugin_EvalListener(); PARAMETERSPLUGIN_EXPORT virtual ~ParametersPlugin_EvalListener(); @@ -54,21 +54,21 @@ class ParametersPlugin_EvalListener : public Events_Listener void processReplaceParameterEvent(const std::shared_ptr& theMessage); /// Renames theOldName in theExpression by theNewName. - std::string renameInPythonExpression(const std::string& theExpression, - const std::string& theOldName, - const std::string& theNewName); + std::wstring renameInPythonExpression(const std::wstring& theExpression, + const std::wstring& theOldName, + const std::wstring& theNewName); /// Renames theOldName in the expression attribute of theParameter by theNewName. void renameInParameter(std::shared_ptr theParameter, - const std::string& theOldName, - const std::string& theNewName); + const std::wstring& theOldName, + const std::wstring& theNewName); /// Renames theOldName in the text fields of theAttribute by theNewName. void renameInAttribute(std::shared_ptr theAttribute, - const std::string& theOldName, - const std::string& theNewName); + const std::wstring& theOldName, + const std::wstring& theNewName); /// Renames theOldName in all dependents of theResultParameter by theNewName. void renameInDependents(std::shared_ptr theResultParameter, - const std::string& theOldName, - const std::string& theNewName); + const std::wstring& theOldName, + const std::wstring& theNewName); }; #endif /* SRC_PARAMETERSPLUGIN_PARAMETERSPLUGIN_EVALLISTENER_H_ */ diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp index 020103798..c7b6bd763 100644 --- a/src/ParametersPlugin/ParametersPlugin_Parameter.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Parameter.cpp @@ -75,12 +75,14 @@ void ParametersPlugin_Parameter::attributeChanged(const std::string& theID) void ParametersPlugin_Parameter::updateName() { - std::string aName = string(VARIABLE_ID())->value(); - data()->setName(Locale::Convert::toWString(aName)); + std::wstring aName = string(VARIABLE_ID())->isUValue() ? + Locale::Convert::toWString(string(VARIABLE_ID())->valueU()) : + Locale::Convert::toWString(string(VARIABLE_ID())->value()); + data()->setName(aName); ResultParameterPtr aParam = document()->createParameter(data()); - std::string anOldName = Locale::Convert::toString(aParam->data()->name()); - aParam->data()->setName(Locale::Convert::toWString(aName)); + std::wstring anOldName = aParam->data()->name(); + aParam->data()->setName(aName); setResult(aParam); @@ -88,12 +90,12 @@ void ParametersPlugin_Parameter::updateName() // update the depended expressions DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument(); if (aParam->document() != aRootDoc) { - std::list aNames; // collect names in the root document that must be checked + std::list aNames; // collect names in the root document that must be checked aNames.push_back(aName); if (anOldName != aName) { aNames.push_back(anOldName); } - std::list::iterator aNIter = aNames.begin(); + std::list::iterator aNIter = aNames.begin(); for (; aNIter != aNames.end(); aNIter++) { double aValue; ResultParameterPtr aRootParam; @@ -115,7 +117,9 @@ void ParametersPlugin_Parameter::updateName() bool ParametersPlugin_Parameter::updateExpression() { - std::string anExpression = string(EXPRESSION_ID())->value(); + std::wstring anExpression = string(EXPRESSION_ID())->isUValue() ? + Locale::Convert::toWString(string(EXPRESSION_ID())->valueU()) : + Locale::Convert::toWString(string(EXPRESSION_ID())->value()); std::string outErrorMessage; double aValue = evaluate(anExpression, outErrorMessage); @@ -139,7 +143,7 @@ void ParametersPlugin_Parameter::execute() setError("Expression error.", false); } -double ParametersPlugin_Parameter::evaluate(const std::string& /*theExpression*/, +double ParametersPlugin_Parameter::evaluate(const std::wstring& /*theExpression*/, std::string& theError) { FeaturePtr aMyPtr = std::dynamic_pointer_cast(data()->owner()); diff --git a/src/ParametersPlugin/ParametersPlugin_Parameter.h b/src/ParametersPlugin/ParametersPlugin_Parameter.h index bc4d92e47..1875e46c1 100644 --- a/src/ParametersPlugin/ParametersPlugin_Parameter.h +++ b/src/ParametersPlugin/ParametersPlugin_Parameter.h @@ -100,7 +100,7 @@ class ParametersPlugin_Parameter : public ModelAPI_Feature protected: /// Evaluates theExpression and returns its value. - double evaluate(const std::string& theExpression, std::string& theError); + double evaluate(const std::wstring& theExpression, std::string& theError); /// Updates name of the parameter void updateName(); /// Updates expression of the parameter diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index e85dc9a35..1d7c37761 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -391,21 +391,22 @@ QList ParametersPlugin_WidgetParamsMgr:: if (aId == ModelAPI_AttributeDouble::typeId()) { AttributeDoublePtr aDouble = std::dynamic_pointer_cast(aAttr); - aValNames << aDouble->text().c_str(); + aValNames << QString::fromStdWString(aDouble->text()); aValNames << QString::number(aDouble->value()); } else if (aId == ModelAPI_AttributeInteger::typeId()) { AttributeIntegerPtr aInt = std::dynamic_pointer_cast(aAttr); - aValNames << aInt->text().c_str(); + aValNames << QString::fromStdWString(aInt->text()); aValNames << QString::number(aInt->value()); } else if (aId == GeomDataAPI_Point::typeId()) { std::shared_ptr aPnt = std::dynamic_pointer_cast(aAttr); - QString aExpr = QString("%1,%2,%3").arg(aPnt->textX().c_str()). - arg(aPnt->textY().c_str()).arg(aPnt->textZ().c_str()); + QString aExpr = QString("%1,%2,%3").arg(QString::fromStdWString(aPnt->textX())). + arg(QString::fromStdWString(aPnt->textY())). + arg(QString::fromStdWString(aPnt->textZ())); aValNames << aExpr; QString aRes = QString("%1,%2,%3").arg(aPnt->x()).arg(aPnt->y()).arg(aPnt->z()); @@ -415,8 +416,8 @@ QList ParametersPlugin_WidgetParamsMgr:: std::shared_ptr aPnt = std::dynamic_pointer_cast(aAttr); - QString aExpr = QString("%1,%2").arg(aPnt->textX().c_str()). - arg(aPnt->textY().c_str()); + QString aExpr = QString("%1,%2").arg(QString::fromStdWString(aPnt->textX())). + arg(QString::fromStdWString(aPnt->textY())); aValNames << aExpr; QString aRes = QString("%1,%2").arg(aPnt->x()).arg(aPnt->y()); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index d8b7d5bca..20c25e9cd 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -28,6 +28,8 @@ #include #include +#include + #include #include @@ -322,38 +324,38 @@ double SketchPlugin_ConstraintAngle::getAngleForType(double theAngle, } #if !HAVE_WORKING_REGEX -static bool parseString(const std::string& theString, std::ostringstream* theResult) +static bool parseString(const std::wstring& theString, std::wostringstream* theResult) { // skip leading spaces size_t aLength = theString.size(); - size_t aPos = theString.find_first_not_of(' '); - if (aPos == std::string::npos) + size_t aPos = theString.find_first_not_of(L' '); + if (aPos == std::wstring::npos) return false; // first should be a value - if (theString[aPos] == '-' || theString[aPos] == '+') + if (theString[aPos] == L'-' || theString[aPos] == L'+') theResult[1] << theString[aPos++]; - while (aPos < aLength && theString[aPos] >= '0' && theString[aPos] <= '9') + while (aPos < aLength && theString[aPos] >= L'0' && theString[aPos] <= L'9') theResult[1] << theString[aPos++]; - if (theString[aPos] != ' ') { - if (theString[aPos] != '.') + if (theString[aPos] != L' ') { + if (theString[aPos] != L'.') return false; theResult[1] << theString[aPos++]; - while (aPos < aLength && theString[aPos] >= '0' && theString[aPos] <= '9') + while (aPos < aLength && theString[aPos] >= L'0' && theString[aPos] <= L'9') theResult[1] << theString[aPos++]; } // next, find the sign - aPos = theString.find_first_not_of(' ', aPos); - if (aPos == std::string::npos) + aPos = theString.find_first_not_of(L' ', aPos); + if (aPos == std::wstring::npos) return false; - if (theString[aPos] == '-' || theString[aPos] == '+') + if (theString[aPos] == L'-' || theString[aPos] == L'+') theResult[2] << theString[aPos++]; // a variable should be at the end - aPos = theString.find_first_not_of(' ', aPos); - if (aPos == std::string::npos) + aPos = theString.find_first_not_of(L' ', aPos); + if (aPos == std::wstring::npos) return false; - if (theString[aPos] != '(' || theString.back() != ')') + if (theString[aPos] != L'(' || theString.back() != L')') return false; theResult[3] << theString.substr(aPos + 1, aLength - aPos - 2); @@ -376,25 +378,25 @@ static void convertAngle(AttributeDoublePtr theAngle, } else { // process the parametric value - std::string anAngleText = theAngle->text(); + std::wstring anAngleText = theAngle->text(); #if HAVE_WORKING_REGEX - std::regex anAngleRegex("\\s*([-+]?[0-9]*\\.?[0-9]*)\\s*([-+])\\s*\\((.*)\\)$", - std::regex_constants::ECMAScript); + std::wregex anAngleRegex(L"\\s*([-+]?[0-9]*\\.?[0-9]*)\\s*([-+])\\s*\\((.*)\\)$", + std::regex_constants::ECMAScript); #endif double anAnglePrefix = 0.0; - static const char aSignPrefix[2] = { '-', '+' }; + static const wchar_t aSignPrefix[2] = { L'-', L'+' }; int aSignInd = 1; #if HAVE_WORKING_REGEX - std::smatch aResult; + std::wsmatch aResult; if (std::regex_search(anAngleText, aResult, anAngleRegex)) { #else // workaround to support old versions of GCC (less than 4.9) - std::ostringstream aResult[4]; + std::wostringstream aResult[4]; if (parseString(anAngleText, aResult)) { #endif - anAnglePrefix = std::atof(aResult[1].str().c_str()); + anAnglePrefix = std::atof(Locale::Convert::toString(aResult[1].str()).c_str()); aSignInd = aResult[2].str()[0] == aSignPrefix[0] ? 0 : 1; anAngleText = aResult[3].str(); } @@ -407,15 +409,15 @@ static void convertAngle(AttributeDoublePtr theAngle, aSignInd = 1 - aSignInd; anAnglePrefix = angleForType(anAnglePrefix, theNewType); - std::ostringstream aText; + std::wostringstream aText; bool isPrintSign = true; if (fabs(anAnglePrefix) > tolerance) aText << anAnglePrefix; else isPrintSign = aSignInd == 0; if (isPrintSign) - aText << " " << aSignPrefix[aSignInd] << " ("; - aText << anAngleText << (isPrintSign ? ")" : ""); + aText << L" " << aSignPrefix[aSignInd] << L" ("; + aText << anAngleText << (isPrintSign ? L")" : L""); theAngle->setText(aText.str()); } } diff --git a/src/SketchPlugin/SketchPlugin_Fillet.cpp b/src/SketchPlugin/SketchPlugin_Fillet.cpp index 54f6805ba..f42819919 100644 --- a/src/SketchPlugin/SketchPlugin_Fillet.cpp +++ b/src/SketchPlugin/SketchPlugin_Fillet.cpp @@ -385,7 +385,7 @@ FeaturePtr SketchPlugin_Fillet::createFilletApex(const GeomPnt2dPtr& theCoordina struct Length { AttributePtr myPoints[2]; - std::string myValueText; + std::wstring myValueText; double myValueDouble; GeomPnt2dPtr myFlyoutPoint; int myLocationType; diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index 836071aae..f6db08fec 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -65,17 +65,17 @@ namespace SketchPlugin_Tools { void clearExpressions(AttributeDoublePtr theAttribute) { - theAttribute->setText(std::string()); + theAttribute->setText(std::wstring()); } void clearExpressions(AttributePointPtr theAttribute) { - theAttribute->setText(std::string(), std::string(), std::string()); + theAttribute->setText(std::wstring(), std::wstring(), std::wstring()); } void clearExpressions(AttributePoint2DPtr theAttribute) { - theAttribute->setText(std::string(), std::string()); + theAttribute->setText(std::wstring(), std::wstring()); } void clearExpressions(AttributePtr theAttribute) diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 8a123c733..b8fde5065 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -44,7 +44,7 @@ SET(PROJECT_HEADERS SketcherPrs_Mirror.h SketcherPrs_Transformation.h SketcherPrs_Angle.h - SketcherPrs_Offset.h + SketcherPrs_Offset.h ) SET(PROJECT_SOURCES @@ -68,7 +68,7 @@ SET(PROJECT_SOURCES SketcherPrs_Mirror.cpp SketcherPrs_Transformation.cpp SketcherPrs_Angle.cpp - SketcherPrs_Offset.cpp + SketcherPrs_Offset.cpp ) SET(PROJECT_LIBRARIES @@ -78,6 +78,7 @@ SET(PROJECT_LIBRARIES GeomAPI GeomDataAPI Events + Locale ${OpenCASCADE_FoundationClasses_LIBRARIES} ${OpenCASCADE_ModelingAlgorithms_LIBRARIES} ${OpenCASCADE_Visualization_LIBRARIES} @@ -117,6 +118,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/ModelGeomAlgo ${PROJECT_SOURCE_DIR}/src/GeomAPI ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/Locale ${PROJECT_SOURCE_DIR}/src/SketchPlugin ${OpenCASCADE_INCLUDE_DIR} ${FREETYPE_INCLUDE_DIRS} diff --git a/src/SketcherPrs/SketcherPrs_DimensionStyle.cpp b/src/SketcherPrs/SketcherPrs_DimensionStyle.cpp index d79b2571d..90444ba5d 100644 --- a/src/SketcherPrs/SketcherPrs_DimensionStyle.cpp +++ b/src/SketcherPrs/SketcherPrs_DimensionStyle.cpp @@ -23,6 +23,8 @@ #include +#include + #include #include @@ -49,7 +51,7 @@ void SketcherPrs_DimensionStyle::DimensionValue::init( { myDoubleValue = theAttributeValue->value(); myHasParameters = theAttributeValue->usedParameters().size() > 0; - myTextValue = theAttributeValue->text(); + myTextValue = Locale::Convert::toString(theAttributeValue->text()); } SketcherPrs_DimensionStyle::SketcherPrs_DimensionStyle() diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index 4ca26b798..96fa5f4b8 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -194,7 +194,7 @@ bool canRename(const ObjectPtr& theObject, const QString& theName) double aValue; ResultParameterPtr aParam; if (ModelAPI_Tools::findVariable(theObject->document(), - FeaturePtr(), qPrintable(theName), aValue, aParam)) { + FeaturePtr(), theName.toStdWString(), aValue, aParam)) { const char* aKeyStr = "Selected parameter can not be renamed to: %1. " "There is a parameter with the same name. Its value is: %2."; QString aErrMsg(QObject::tr(aKeyStr).arg(theName).arg(aValue));