From: Alexey Kondratyev Date: Mon, 11 Oct 2021 07:47:07 +0000 (+0300) Subject: [bos #26444] [EDF] (2021) SHAPER: Improve treatment of parameters X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2ac6d89da12ae0363f34b7b147ed7d9c914b6fdc;p=modules%2Fshaper.git [bos #26444] [EDF] (2021) SHAPER: Improve treatment of parameters Update "addParameters" to use French and Russian chars in comments. Update "importParameters" to import French and Russian chars in comments from file. Update parameter manager to use French and Russian chars in comments. --- diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 8208eba76..14ab98878 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -224,6 +224,13 @@ void fillAttribute(const std::string & theValue, theAttribute->setValue(theValue); } +//-------------------------------------------------------------------------------------- +void fillAttribute(const std::wstring & theValue, + const std::shared_ptr & theAttribute) +{ + theAttribute->setValue(theValue); +} + //-------------------------------------------------------------------------------------- void fillAttribute(const char * theValue, const std::shared_ptr & theAttribute) diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index 7f0e1c896..a476721a6 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -136,6 +136,11 @@ void fillAttribute(const std::list & theValue, MODELHIGHAPI_EXPORT void fillAttribute(const std::string & theValue, const std::shared_ptr & theAttribute); + +MODELHIGHAPI_EXPORT +void fillAttribute(const std::wstring & theValue, + const std::shared_ptr & theAttribute); + MODELHIGHAPI_EXPORT void fillAttribute(const char * theValue, const std::shared_ptr & theAttribute); diff --git a/src/ParametersAPI/ParametersAPI.i b/src/ParametersAPI/ParametersAPI.i index 6922c1f96..8d8a59c74 100644 --- a/src/ParametersAPI/ParametersAPI.i +++ b/src/ParametersAPI/ParametersAPI.i @@ -23,6 +23,11 @@ %{ #include "ParametersAPI_swig.h" + + // fix for SWIG v2.0.4 + #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj)) + + #define SWIGPY_UNICODE_ARG(obj) ((PyObject*) (obj)) %} %include "doxyhelp.i" diff --git a/src/ParametersAPI/ParametersAPI_Parameter.cpp b/src/ParametersAPI/ParametersAPI_Parameter.cpp index 27c687ad3..9079094a4 100644 --- a/src/ParametersAPI/ParametersAPI_Parameter.cpp +++ b/src/ParametersAPI/ParametersAPI_Parameter.cpp @@ -35,7 +35,7 @@ ParametersAPI_Parameter::ParametersAPI_Parameter( const std::shared_ptr & theFeature, const std::string & theName, const std::string & theExpression, - const std::string & theComment) + const std::wstring & theComment) : ModelHighAPI_Interface(theFeature) { if (initialize()) { @@ -87,7 +87,7 @@ void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const ParameterPtr addParameter(const std::shared_ptr & thePart, const std::string & theName, const std::string & theExpression, - const std::string & theComment) + const std::wstring & theComment) { std::shared_ptr aFeature = thePart->addFeature(ParametersAPI_Parameter::ID()); return ParameterPtr(new ParametersAPI_Parameter(aFeature, theName, theExpression, theComment)); diff --git a/src/ParametersAPI/ParametersAPI_Parameter.h b/src/ParametersAPI/ParametersAPI_Parameter.h index 50bb1d3b8..8295db3cc 100644 --- a/src/ParametersAPI/ParametersAPI_Parameter.h +++ b/src/ParametersAPI/ParametersAPI_Parameter.h @@ -45,7 +45,7 @@ public: explicit ParametersAPI_Parameter(const std::shared_ptr & theFeature, const std::string & theName, const std::string & theExpression, - const std::string & theComment = std::string()); + const std::wstring & theComment = std::wstring()); /// Destructor PARAMETERSAPI_EXPORT virtual ~ParametersAPI_Parameter(); @@ -80,7 +80,7 @@ PARAMETERSAPI_EXPORT ParameterPtr addParameter(const std::shared_ptr & thePart, const std::string & theName, const std::string & theExpression, - const std::string & theComment = std::string()); + const std::wstring & theComment = std::wstring()); /**\ingroup CPPHighAPI * \brief Remove Parameter feature and substitute it by the value in referred features diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index b2ca35211..3f3385ec9 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -526,7 +526,7 @@ void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor, case Col_Comment: { AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::COMMENT_ID()); - aStringAttr->setValue(aText.toStdString()); + aStringAttr->setValue(aText.toStdWString()); isModified = true; } break; diff --git a/src/PythonAPI/Test/TestInsertParameter.py b/src/PythonAPI/Test/TestInsertParameter.py index 246a07a0e..97b7e13f5 100644 --- a/src/PythonAPI/Test/TestInsertParameter.py +++ b/src/PythonAPI/Test/TestInsertParameter.py @@ -31,10 +31,10 @@ nameFile = "PythonAPI_test_parametres1.txt" aDir = os.path.join(data_dir, nameFile) -aFile = open(nameFile, 'w') +aFile = open(nameFile, 'w', encoding = "utf_8") -aFile.write("Longueur 36. # \"Comment\"\n") -aFile.write("Largeur 24. # Comment\n") +aFile.write("Longueur 36. # \"Longueur de la pièce\"\n") +aFile.write("Largeur 24. # Largeur de la pièce\n") aFile.write("Hauteur Longueur*Largeur\n") aFile.write("\n") aFile.write(" \n") diff --git a/src/PythonAPI/model/parameter/import_parameter.py b/src/PythonAPI/model/parameter/import_parameter.py index d75275dfc..cc5b21427 100644 --- a/src/PythonAPI/model/parameter/import_parameter.py +++ b/src/PythonAPI/model/parameter/import_parameter.py @@ -18,12 +18,13 @@ # from salome.shaper import model +import codecs def importParameters(theDocument, theFileName): aResult = [] try: - aFile = open(theFileName, 'r') + aFile = codecs.open(theFileName, 'r', encoding = 'utf_8_sig') except IOError: return aResult @@ -36,7 +37,7 @@ def importParameters(theDocument, theFileName): isComment = False aFirstText = aLine.split(" ")[0] - aName = aFirstText.split("#")[0] + aName = aFirstText.split("#")[0].strip() aLine = aLine.lstrip(aName) @@ -48,7 +49,7 @@ def importParameters(theDocument, theFileName): aComment = aLine if(len(aName) > 0): - aResult.append(model.addParameter(theDocument, aName.strip(), aParameter.strip(), aComment.strip())) + aResult.append(model.addParameter(theDocument, aName, aParameter.strip(), aComment.strip())) aFile.close() return aResult