Usage of Unicode characters as names of parameters.
} else if (PyFloat_Check($input) || PyLong_Check($input)) {
temp = std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>(ModelHighAPI_Selection(), ModelHighAPI_Double(PyFloat_AsDouble($input)));
} else if (PyUnicode_Check($input)) {
- temp = std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>(ModelHighAPI_Selection(), ModelHighAPI_Double(PyUnicode_AsUTF8($input)));
+ Py_ssize_t size;
+ temp = std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>(ModelHighAPI_Selection(), ModelHighAPI_Double(PyUnicode_AsWideCharString($input, &size)));
} else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
temp = std::pair<ModelHighAPI_Selection, ModelHighAPI_Double>($1->first, $1->second);
} else {
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()
const std::list<ModelHighAPI_Selection>& 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_
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
-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) {
}
}
-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) {
}
}
-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) {
}
}
-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();
}
}
void GeomData_Point::setUsedParameters(int theComponent,
- const std::set<std::string>& theUsedParameters)
+ const std::set<std::wstring>& theUsedParameters)
{
assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
myExpression[theComponent]->setUsedParameters(theUsedParameters);
}
-std::set<std::string> GeomData_Point::usedParameters(int theComponent) const
+std::set<std::wstring> GeomData_Point::usedParameters(int theComponent) const
{
assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
return myExpression[theComponent]->usedParameters();
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);
/// Defines the used parameters
GEOMDATA_EXPORT virtual void setUsedParameters(int theComponent,
- const std::set<std::string>& theUsedParameters);
+ const std::set<std::wstring>& theUsedParameters);
/// Returns the used parameters
- GEOMDATA_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const;
+ GEOMDATA_EXPORT virtual std::set<std::wstring> usedParameters(int theComponent) const;
protected:
/// Initializes attributes
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
}
}
-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();
}
}
void GeomData_Point2D::setUsedParameters(int theComponent,
- const std::set<std::string>& theUsedParameters)
+ const std::set<std::wstring>& theUsedParameters)
{
assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
myExpression[theComponent]->setUsedParameters(theUsedParameters);
}
-std::set<std::string> GeomData_Point2D::usedParameters(int theComponent) const
+std::set<std::wstring> GeomData_Point2D::usedParameters(int theComponent) const
{
assert(theComponent >= 0 && theComponent < NUM_COMPONENTS);
return myExpression[theComponent]->usedParameters();
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);
/// Defines the used parameters
GEOMDATA_EXPORT virtual void setUsedParameters(int theComponent,
- const std::set<std::string>& theUsedParameters);
+ const std::set<std::wstring>& theUsedParameters);
/// Returns the used parameters
- GEOMDATA_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const;
+ GEOMDATA_EXPORT virtual std::set<std::wstring> usedParameters(int theComponent) const;
protected:
/// Initializes attributes
%module GeomDataAPI
%{
#include "GeomDataAPI_swig.h"
+
+ #define SWIGPY_UNICODE_ARG(obj) ((PyObject*) (obj))
%}
// import other modules
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,
/// Defines the used parameters
GEOMDATAAPI_EXPORT virtual void setUsedParameters(int theComponent,
- const std::set<std::string>& theUsedParameters) = 0;
+ const std::set<std::wstring>& theUsedParameters) = 0;
/// Returns the used parameters
- GEOMDATAAPI_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const = 0;
+ GEOMDATAAPI_EXPORT virtual std::set<std::wstring> usedParameters(int theComponent) const = 0;
/// Returns the type of this class of attributes
static std::string typeId()
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,
/// Defines the used parameters
GEOMDATAAPI_EXPORT virtual void setUsedParameters(int theComponent,
- const std::set<std::string>& theUsedParameters) = 0;
+ const std::set<std::wstring>& theUsedParameters) = 0;
/// Returns the used parameters
- GEOMDATAAPI_EXPORT virtual std::set<std::string> usedParameters(int theComponent) const = 0;
+ GEOMDATAAPI_EXPORT virtual std::set<std::wstring> usedParameters(int theComponent) const = 0;
/// Appends the delta values to point
GEOMDATAAPI_EXPORT void move(const double theDeltaX, const double theDeltaY);
${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}
Events
Config
ModelAPI
+ Locale
${PyInterp}
${PYTHON_LIBRARIES}
)
#include <Events_InfoMessage.h>
+#include <Locale_Convert.h>
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefList.h>
//------------------------------------------------------------------------------
// 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);
return sstream.str();
}
-std::set<std::string> toSet(const std::list<std::string>& theContainer)
+std::set<std::wstring> toSet(const std::list<std::wstring>& theContainer)
{
- return std::set<std::string>(theContainer.begin(), theContainer.end());
+ return std::set<std::wstring>(theContainer.begin(), theContainer.end());
}
//------------------------------------------------------------------------------
std::shared_ptr<ModelAPI_ParameterEvalMessage> aMsg =
std::dynamic_pointer_cast<ModelAPI_ParameterEvalMessage>(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<std::shared_ptr<ModelAPI_ResultParameter> > aParamsList;
double aResult = evaluate(aParam, anExp, anError, aParamsList, true);
}
double InitializationPlugin_EvalListener::evaluate(FeaturePtr theParameter,
- const std::string& theExpression, std::string& theError,
+ const std::wstring& theExpression, std::string& theError,
std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
const bool theIsParameter)
{
- std::list<std::string> anExprParams = myInterp->compile(theExpression);
+ std::list<std::wstring> anExprParams = myInterp->compile(theExpression);
// find expression's params in the model
- std::list<std::string> aContext;
- std::list<std::string>::iterator it = anExprParams.begin();
+ std::list<std::wstring> aContext;
+ std::list<std::wstring>::iterator it = anExprParams.begin();
for ( ; it != anExprParams.end(); it++) {
double aValue;
ResultParameterPtr aParamRes;
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);
if (isValid)
anAttribute->setCalculatedValue(aValue);
anAttribute->setUsedParameters(isValid ?
- toSet(myInterp->compile(anAttribute->text())) : std::set<std::string>());
+ toSet(myInterp->compile(anAttribute->text())) : std::set<std::wstring>());
anAttribute->setExpressionInvalid(!isValid);
anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError);
} else
if (isValid)
anAttribute->setCalculatedValue(aValue);
anAttribute->setUsedParameters(isValid ?
- toSet(myInterp->compile(anAttribute->text())) : std::set<std::string>());
+ toSet(myInterp->compile(anAttribute->text())) : std::set<std::wstring>());
anAttribute->setExpressionInvalid(!isValid);
anAttribute->setExpressionError(anAttribute->text().empty() ? "" : anError);
} else
if (aMessage->attribute()->attributeType() == GeomDataAPI_Point::typeId()) {
AttributePointPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point>(aMessage->attribute());
- std::string aText[] = {
+ std::wstring aText[] = {
anAttribute->textX(),
anAttribute->textY(),
anAttribute->textZ()
bool isValid = anError.empty();
if (isValid) aCalculatedValue[i] = aValue;
anAttribute->setUsedParameters(i,
- isValid ? toSet(myInterp->compile(aText[i])) : std::set<std::string>());
+ isValid ? toSet(myInterp->compile(aText[i])) : std::set<std::wstring>());
anAttribute->setExpressionInvalid(i, !isValid);
anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError);
}
if (aMessage->attribute()->attributeType() == GeomDataAPI_Point2D::typeId()) {
AttributePoint2DPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aMessage->attribute());
- std::string aText[] = {
+ std::wstring aText[] = {
anAttribute->textX(),
anAttribute->textY()
};
bool isValid = anError.empty();
if (isValid) aCalculatedValue[i] = aValue;
anAttribute->setUsedParameters(i,
- isValid ? toSet(myInterp->compile(aText[i])) : std::set<std::string>());
+ isValid ? toSet(myInterp->compile(aText[i])) : std::set<std::wstring>());
anAttribute->setExpressionInvalid(i, !isValid);
anAttribute->setExpressionError(i, aText[i].empty() ? "" : anError);
}
protected:
/// Evaluates theExpression and returns its value.
double evaluate(std::shared_ptr<ModelAPI_Feature> theParameter,
- const std::string& theExpression, std::string& theError,
+ const std::wstring& theExpression, std::string& theError,
std::list<std::shared_ptr<ModelAPI_ResultParameter> >& theParamsList,
const bool theIsParameter = false);
#include <InitializationPlugin_PyInterp.h>
+#include <Locale_Convert.h>
+
#include <string>
#include <stdexcept>
#include <clocale>
// 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<std::pair<int, int> >
-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
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
}
-std::list<std::string> InitializationPlugin_PyInterp::compile(const std::string& theExpression)
+std::list<std::wstring> InitializationPlugin_PyInterp::compile(const std::wstring& theExpression)
{
PyLockWrapper lck; // Acquire GIL until the end of the method
- std::list<std::string> aResult;
+ std::list<std::wstring> 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);
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);
}
return aResult;
}
-void InitializationPlugin_PyInterp::extendLocalContext(const std::list<std::string>& theParameters)
+void InitializationPlugin_PyInterp::extendLocalContext(const std::list<std::wstring>& theParameters)
{
PyLockWrapper lck; // Acquire GIL until the end of the method
if (theParameters.empty())
return;
- std::list<std::string>::const_iterator it = theParameters.begin();
+ std::list<std::wstring>::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);
}
}
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(),
"<string>", Py_eval_input, &aFlags);
if(!anExprCode) {
theError = errorMessage();
virtual ~InitializationPlugin_PyInterp();
/// Returns a list of positions for theName in theExpression.
- std::list<std::pair<int, int> > positions(const std::string& theExpression,
- const std::string& theName);
+ std::list<std::pair<int, int> > positions(const std::wstring& theExpression,
+ const std::wstring& theName);
/// Compiles theExpression and returns a list of parameters used in theExpression.
- std::list<std::string> compile(const std::string& theExpression);
+ std::list<std::wstring> compile(const std::wstring& theExpression);
/// Extends local context with the list of parameters.
- void extendLocalContext(const std::list<std::string>& theParameters);
+ void extendLocalContext(const std::list<std::wstring>& 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);
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);
}
}
-std::string Model_AttributeDouble::text()
+std::wstring Model_AttributeDouble::text()
{
return myExpression->text();
}
return myExpression->error();
}
-void Model_AttributeDouble::setUsedParameters(const std::set<std::string>& theUsedParameters)
+void Model_AttributeDouble::setUsedParameters(const std::set<std::wstring>& theUsedParameters)
{
myExpression->setUsedParameters(theUsedParameters);
}
-std::set<std::string> Model_AttributeDouble::usedParameters() const
+std::set<std::wstring> Model_AttributeDouble::usedParameters() const
{
return myExpression->usedParameters();
}
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);
MODEL_EXPORT virtual std::string expressionError();
/// Defines the used parameters
- MODEL_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters);
+ MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters);
/// Returns the used parameters
- MODEL_EXPORT virtual std::set<std::string> usedParameters() const;
+ MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const;
protected:
/// Initializes attributes
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);
}
}
-std::string Model_AttributeInteger::text()
+std::wstring Model_AttributeInteger::text()
{
return myExpression->text();
}
return myExpression->error();
}
-void Model_AttributeInteger::setUsedParameters(const std::set<std::string>& theUsedParameters)
+void Model_AttributeInteger::setUsedParameters(const std::set<std::wstring>& theUsedParameters)
{
myExpression->setUsedParameters(theUsedParameters);
}
-std::set<std::string> Model_AttributeInteger::usedParameters() const
+std::set<std::wstring> Model_AttributeInteger::usedParameters() const
{
return myExpression->usedParameters();
}
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);
MODEL_EXPORT virtual std::string expressionError();
/// Defines the used parameters
- MODEL_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters);
+ MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters);
/// Returns the used parameters
- MODEL_EXPORT virtual std::set<std::string> usedParameters() const;
+ MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const;
protected:
/// Initializes attributes
}
}
-std::set<std::string> set_union(const std::set<std::string>& theLeft,
- const std::set<std::string>& theRight)
+std::set<std::wstring> set_union(const std::set<std::wstring>& theLeft,
+ const std::set<std::wstring>& theRight)
{
- std::set<std::string> aResult;
+ std::set<std::wstring> aResult;
aResult.insert(theLeft.begin(), theLeft.end());
aResult.insert(theRight.begin(), theRight.end());
return aResult;
}
-std::set<std::string> usedParameters(const AttributePointPtr& theAttribute)
+std::set<std::wstring> usedParameters(const AttributePointPtr& theAttribute)
{
- std::set<std::string> anUsedParameters;
+ std::set<std::wstring> anUsedParameters;
for (int aComponent = 0; aComponent < 3; ++aComponent)
anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
return anUsedParameters;
}
-std::set<std::string> usedParameters(const AttributePoint2DPtr& theAttribute)
+std::set<std::wstring> usedParameters(const AttributePoint2DPtr& theAttribute)
{
- std::set<std::string> anUsedParameters;
+ std::set<std::wstring> anUsedParameters;
for (int aComponent = 0; aComponent < 2; ++aComponent)
anUsedParameters = set_union(anUsedParameters, theAttribute->usedParameters(aComponent));
return anUsedParameters;
}
-std::list<ResultParameterPtr> findVariables(const std::set<std::string>& theParameters,
+std::list<ResultParameterPtr> findVariables(const std::set<std::wstring>& theParameters,
const DocumentPtr& theDocument)
{
std::list<ResultParameterPtr> aResult;
- std::set<std::string>::const_iterator aParamIt = theParameters.cbegin();
+ std::set<std::wstring>::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
} else if (aType == ModelAPI_AttributeInteger::typeId()) { // integer attribute
AttributeIntegerPtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttr);
- std::set<std::string> anUsedParameters = anAttribute->usedParameters();
+ std::set<std::wstring> anUsedParameters = anAttribute->usedParameters();
std::list<ResultParameterPtr> 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<ModelAPI_AttributeDouble>(anAttr);
- std::set<std::string> anUsedParameters = anAttribute->usedParameters();
+ std::set<std::wstring> anUsedParameters = anAttribute->usedParameters();
std::list<ResultParameterPtr> 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<GeomDataAPI_Point>(anAttr);
- std::set<std::string> anUsedParameters = usedParameters(anAttribute);
+ std::set<std::wstring> anUsedParameters = usedParameters(anAttribute);
std::list<ResultParameterPtr> 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<GeomDataAPI_Point2D>(anAttr);
- std::set<std::string> anUsedParameters = usedParameters(anAttribute);
+ std::set<std::wstring> anUsedParameters = usedParameters(anAttribute);
std::list<ResultParameterPtr> aParameters =
findVariables(anUsedParameters, owner()->document());
aReferenced.insert(aReferenced.end(), aParameters.begin(), aParameters.end());
#include "Model_Expression.h"
+#include <Locale_Convert.h>
+
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
}
}
-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()));
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)
return TCollection_AsciiString(myError->Get()).ToCString();
}
-void Model_Expression::setUsedParameters(const std::set<std::string>& theUsedParameters)
+void Model_Expression::setUsedParameters(const std::set<std::wstring>& theUsedParameters)
{
myUsedParameters->Clear();
- std::set<std::string>::const_iterator anIt = theUsedParameters.begin();
+ std::set<std::wstring>::const_iterator anIt = theUsedParameters.begin();
for (; anIt != theUsedParameters.end(); ++anIt)
myUsedParameters->Append(TCollection_ExtendedString(anIt->c_str()));
}
-std::set<std::string> Model_Expression::usedParameters() const
+std::set<std::wstring> Model_Expression::usedParameters() const
{
- std::set<std::string> aResult;
+ std::set<std::wstring> 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;
}
{
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);
MODEL_EXPORT virtual std::string error();
/// Defines the used parameters (by the parameters listener)
- MODEL_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters);
+ MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters);
/// Returns the used parameters
- MODEL_EXPORT virtual std::set<std::string> usedParameters() const;
+ MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const;
protected:
/// Initializes attributes
{
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();
};
};
/// Defines the used parameters (by the parameters listener)
- MODEL_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters) {
+ MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters) {
Model_Expression::setUsedParameters(theUsedParameters);
};
/// Returns the used parameters
- MODEL_EXPORT virtual std::set<std::string> usedParameters() const {
+ MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const {
return Model_Expression::usedParameters();
};
{
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();
};
};
/// Defines the used parameters (by the parameters listener)
- MODEL_EXPORT virtual void setUsedParameters(const std::set<std::string>& theUsedParameters) {
+ MODEL_EXPORT virtual void setUsedParameters(const std::set<std::wstring>& theUsedParameters) {
Model_Expression::setUsedParameters(theUsedParameters);
};
/// Returns the used parameters
- MODEL_EXPORT virtual std::set<std::string> usedParameters() const {
+ MODEL_EXPORT virtual std::set<std::wstring> usedParameters() const {
return Model_Expression::usedParameters();
};
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;
/// Defines the used parameters
MODELAPI_EXPORT virtual
- void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
+ void setUsedParameters(const std::set<std::wstring>& theUsedParameters) = 0;
/// Returns the used parameters
- MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
+ MODELAPI_EXPORT virtual std::set<std::wstring> usedParameters() const = 0;
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string typeId()
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;
/// Defines the used parameters
MODELAPI_EXPORT virtual
- void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
+ void setUsedParameters(const std::set<std::wstring>& theUsedParameters) = 0;
/// Returns the used parameters
- MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
+ MODELAPI_EXPORT virtual std::set<std::wstring> usedParameters() const = 0;
/// Returns the type of this class of attributes
MODELAPI_EXPORT static std::string typeId()
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;
/// 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<std::pair<int, int> > myPositions; ///< computation result: start-end position indices
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<ModelAPI_ComputePositionsMessage>
- 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<ModelAPI_ComputePositionsMessage> aMessage =
std::shared_ptr<ModelAPI_ComputePositionsMessage>(
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<std::pair<int, int> >& thePositions);
/// Returns the results of processing: position start and end indices
#include "ModelAPI_Expression.h"
+#include <Locale_Convert.h>
+
ModelAPI_Expression::ModelAPI_Expression()
{
}
+
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;
}
}
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;
/// Defines the used parameters (by the parameters listener)
MODELAPI_EXPORT virtual
- void setUsedParameters(const std::set<std::string>& theUsedParameters) = 0;
+ void setUsedParameters(const std::set<std::wstring>& theUsedParameters) = 0;
/// Returns the used parameters
- MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
+ MODELAPI_EXPORT virtual std::set<std::wstring> 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();
// 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
}
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<ModelAPI_ResultParameter>(aParamObj);
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();
*/
MODELAPI_EXPORT bool findVariable(const std::shared_ptr<ModelAPI_Document>& theDocument,
std::shared_ptr<ModelAPI_Feature> theSearcher,
- const std::string& theName, double& outValue,
+ const std::wstring& theName, double& outValue,
std::shared_ptr<ModelAPI_ResultParameter>& theParam);
/*!
* theSearcher must be located later in the history than the found variable.
*/
MODELAPI_EXPORT bool findVariable(std::shared_ptr<ModelAPI_Feature> theSearcher,
- const std::string& theName,
+ const std::wstring& theName,
double& outValue, std::shared_ptr<ModelAPI_ResultParameter>& theParam,
const std::shared_ptr<ModelAPI_Document>& theDocument = std::shared_ptr<ModelAPI_Document>());
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 {
temp = ModelHighAPI_Integer(static_cast<int>(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 {
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 {
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 {
{
}
-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)
{
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();
}
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();
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;
};
//--------------------------------------------------------------------------------------
{
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;
}
{
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;
}
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt)
{
- std::string aText = theAttrInt->text();
+ std::string aText = Locale::Convert::toString(theAttrInt->text());
if (aText.empty())
*myDumpStorage << theAttrInt->value();
else
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal)
{
- std::string aText = theAttrReal->text();
+ std::string aText = Locale::Convert::toString(theAttrReal->text());
if (aText.empty())
*myDumpStorage << theAttrReal->value();
else
if (anAttr->text().empty())
aResult<<anAttr->value();
else
- aResult<<anAttr->text();
+ aResult << Locale::Convert::toString(anAttr->text());
} else if (aType == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttr);
if (anAttr->id() == "ConstraintValue") {
double aVal = anAttr->value();
dumpArray(aResult, &aVal, 1, aPrecision);
} else
- aResult<<anAttr->text();
+ aResult << Locale::Convert::toString(anAttr->text());
} else if (aType == ModelAPI_AttributeBoolean::typeId()) {
AttributeBooleanPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(theAttr);
// do not dump internal flags of ConstraintAngle
{
}
-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)
{
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();
}
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();
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;
};
//--------------------------------------------------------------------------------------
GeomAPI
GeomDataAPI
GeomAlgoAPI
+ Locale
${QT_LIBRARIES}
${OpenCASCADE_FoundationClasses_LIBRARIES}
${OpenCASCADE_Visualization_LIBRARIES}
${PROJECT_SOURCE_DIR}/src/GeomDataAPI
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+ ${PROJECT_SOURCE_DIR}/src/Locale
${SUIT_INCLUDE}
)
double& outValue) const
{
ResultParameterPtr aParam;
- return ModelAPI_Tools::findVariable(FeaturePtr(), theName.toStdString(), outValue, aParam);
+ return ModelAPI_Tools::findVariable(FeaturePtr(), theName.toStdWString(), outValue, aParam);
}
/*!
// 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
aReal->setExpressionError("");
aReal->setExpressionInvalid(false);
}
- aReal->setText("");
+ aReal->setText(L"");
aReal->setValue(mySpinBox->value());
}
updateObject(myFeature);
{
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 {
#include <ModuleBase_WidgetExprEditor.h>
#include <ModuleBase_Tools.h>
+#include <Locale_Convert.h>
+
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Validator.h>
AttributeStringPtr aStringAttr = aData->string(attributeID());
QString aWidgetValue = myEditor->toPlainText();
- aStringAttr->setValue(aWidgetValue.toStdString());
+ aStringAttr->setValue(aWidgetValue.toStdWString());
updateObject(myFeature);
// Try to get the value
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);
// 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
anAttribute->setExpressionError("");
anAttribute->setExpressionInvalid(false);
}
- anAttribute->setText("");
+ anAttribute->setText(L"");
anAttribute->setValue(mySpinBox->value());
}
updateObject(myFeature);
{
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();
#include <ModuleBase_Tools.h>
#include <ModuleBase_IconFactory.h>
+#include <Locale_Convert.h>
+
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
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;
}
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;
#include <QLabel>
-#define ERR_STRING "ERROR"
+#define ERR_STRING L"ERROR"
ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
ModuleBase_IWorkshop* theWorkshop,
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('=')) {
}
aText = aText.split('=').at(0);
}
- return aText.toStdString();
+ return aText.toStdWString();
}
//********************************************************************
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);
}
aAttr->setText(aXText, aYText, aZText);
} else {
- aAttr->setText("", "", "");
+ aAttr->setText(L"", L"", L"");
aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
}
} else {
AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(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 {
//------------------------------------------------------------------------------
// 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;
}
}
}
-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<ModelAPI_ComputePositionsMessage> aMsg =
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<int>& aColOffsets = ritLine->second;
std::list<int>::const_reverse_iterator ritOffset = aColOffsets.rbegin();
void ParametersPlugin_EvalListener::renameInParameter(
std::shared_ptr<ParametersPlugin_Parameter> theParameter,
- const std::string& theOldName,
- const std::string& theNewName)
+ const std::wstring& theOldName,
+ const std::wstring& theNewName)
{
std::shared_ptr<ModelAPI_AttributeString> 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);
void ParametersPlugin_EvalListener::renameInAttribute(
std::shared_ptr<ModelAPI_Attribute> 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<ModelAPI_AttributeInteger>(theAttribute);
- std::string anExpressionString = anAttribute->text();
+ std::wstring anExpressionString = anAttribute->text();
anExpressionString = renameInPythonExpression(anExpressionString,
theOldName, theNewName);
anAttribute->setText(anExpressionString);
if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr anAttribute =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
- std::string anExpressionString = anAttribute->text();
+ std::wstring anExpressionString = anAttribute->text();
anExpressionString = renameInPythonExpression(anExpressionString,
theOldName, theNewName);
anAttribute->setText(anExpressionString);
if (theAttribute->attributeType() == GeomDataAPI_Point::typeId()) {
AttributePointPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point>(theAttribute);
- std::string anExpressionString[3] = {
+ std::wstring anExpressionString[3] = {
anAttribute->textX(),
anAttribute->textY(),
anAttribute->textZ()
if (theAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) {
AttributePoint2DPtr anAttribute =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
- std::string anExpressionString[2] = {
+ std::wstring anExpressionString[2] = {
anAttribute->textX(),
anAttribute->textY()
};
void ParametersPlugin_EvalListener::renameInDependents(
std::shared_ptr<ModelAPI_ResultParameter> theResultParameter,
- const std::string& theOldName,
- const std::string& theNewName)
+ const std::wstring& theOldName,
+ const std::wstring& theNewName)
{
std::set<std::shared_ptr<ModelAPI_Attribute> > anAttributes =
theResultParameter->data()->refsToMe();
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(
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);
}
{
/// 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<ParametersPlugin_Parameter*, std::string> myOldNames;
+ std::map<ParametersPlugin_Parameter*, std::wstring> myOldNames;
public:
PARAMETERSPLUGIN_EXPORT ParametersPlugin_EvalListener();
PARAMETERSPLUGIN_EXPORT virtual ~ParametersPlugin_EvalListener();
void processReplaceParameterEvent(const std::shared_ptr<Events_Message>& 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<ParametersPlugin_Parameter> 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<ModelAPI_Attribute> 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<ModelAPI_ResultParameter> theResultParameter,
- const std::string& theOldName,
- const std::string& theNewName);
+ const std::wstring& theOldName,
+ const std::wstring& theNewName);
};
#endif /* SRC_PARAMETERSPLUGIN_PARAMETERSPLUGIN_EVALLISTENER_H_ */
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);
// update the depended expressions
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
if (aParam->document() != aRootDoc) {
- std::list<std::string> aNames; // collect names in the root document that must be checked
+ std::list<std::wstring> aNames; // collect names in the root document that must be checked
aNames.push_back(aName);
if (anOldName != aName) {
aNames.push_back(anOldName);
}
- std::list<std::string>::iterator aNIter = aNames.begin();
+ std::list<std::wstring>::iterator aNIter = aNames.begin();
for (; aNIter != aNames.end(); aNIter++) {
double aValue;
ResultParameterPtr aRootParam;
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);
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<ModelAPI_Feature>(data()->owner());
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
if (aId == ModelAPI_AttributeDouble::typeId()) {
AttributeDoublePtr aDouble =
std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(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<ModelAPI_AttributeInteger>(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<GeomDataAPI_Point> aPnt =
std::dynamic_pointer_cast<GeomDataAPI_Point>(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());
std::shared_ptr<GeomDataAPI_Point2D> aPnt =
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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());
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
+#include <Locale_Convert.h>
+
#include <GeomDataAPI_Point2D.h>
#include <GeomAPI_Angle2d.h>
}
#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);
}
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();
}
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());
}
}
struct Length {
AttributePtr myPoints[2];
- std::string myValueText;
+ std::wstring myValueText;
double myValueDouble;
GeomPnt2dPtr myFlyoutPoint;
int myLocationType;
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)
SketcherPrs_Mirror.h
SketcherPrs_Transformation.h
SketcherPrs_Angle.h
- SketcherPrs_Offset.h
+ SketcherPrs_Offset.h
)
SET(PROJECT_SOURCES
SketcherPrs_Mirror.cpp
SketcherPrs_Transformation.cpp
SketcherPrs_Angle.cpp
- SketcherPrs_Offset.cpp
+ SketcherPrs_Offset.cpp
)
SET(PROJECT_LIBRARIES
GeomAPI
GeomDataAPI
Events
+ Locale
${OpenCASCADE_FoundationClasses_LIBRARIES}
${OpenCASCADE_ModelingAlgorithms_LIBRARIES}
${OpenCASCADE_Visualization_LIBRARIES}
${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}
#include <Events_Loop.h>
+#include <Locale_Convert.h>
+
#include <AIS_Dimension.hxx>
#include <TCollection_ExtendedString.hxx>
{
myDoubleValue = theAttributeValue->value();
myHasParameters = theAttributeValue->usedParameters().size() > 0;
- myTextValue = theAttributeValue->text();
+ myTextValue = Locale::Convert::toString(theAttributeValue->text());
}
SketcherPrs_DimensionStyle::SketcherPrs_DimensionStyle()
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));