From: Artem Zhidkov Date: Mon, 29 Jun 2020 19:57:14 +0000 (+0300) Subject: Task #3237: Allow usage of accented characters in ObjectBrowser X-Git-Tag: V9_6_0a1~60^2~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cfbcedf4020c69d1a92f4d0f52032893732630b0;p=modules%2Fshaper.git Task #3237: Allow usage of accented characters in ObjectBrowser * Code cleanup * Add unit test with utf-8. --- diff --git a/src/Locale/CMakeLists.txt b/src/Locale/CMakeLists.txt index aab6541bd..ec83f609b 100644 --- a/src/Locale/CMakeLists.txt +++ b/src/Locale/CMakeLists.txt @@ -18,6 +18,7 @@ # INCLUDE(Common) +INCLUDE(UnitTest) INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} @@ -41,3 +42,7 @@ ADD_LIBRARY(Locale SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) TARGET_LINK_LIBRARIES(Locale ${PROJECT_LIBRARIES}) INSTALL(TARGETS Locale DESTINATION ${SHAPER_INSTALL_BIN}) + +ADD_UNIT_TESTS( + TestUTF8.py +) diff --git a/src/Locale/Locale_Convert.cpp b/src/Locale/Locale_Convert.cpp index f3263d8e4..580888347 100644 --- a/src/Locale/Locale_Convert.cpp +++ b/src/Locale/Locale_Convert.cpp @@ -21,35 +21,10 @@ #include -////// To support old types of GCC (less than 5.0), check the wide-string conversion is working -////#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L) && \ -//// (__cplusplus >= 201402L || !defined(__GLIBCXX__) || \ -//// (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE > 4)) -////#define HAVE_WORKING_WIDESTRING 1 -////#else -////#define HAVE_WORKING_WIDESTRING 0 -////#endif -//// -////#if HAVE_WORKING_WIDESTRING -////#include -////#endif - namespace Locale { std::string Convert::toString(const std::wstring& theWStr) { -////#if HAVE_WORKING_WIDESTRING -//// static std::wstring_convert > aConvertor; -//// return aConvertor.to_bytes(theWStr); -////#else -//// char* aBuf = new char[2 * (theWStr.size() + 1)]; -//// size_t aNbChars = std::wcstombs(aBuf, theWStr.c_str(), theWStr.size()); -//// if (aNbChars != (size_t)-1) -//// aBuf[aNbChars] = '\0'; -//// std::string aStr(aBuf); -//// delete[] aBuf; -//// return aStr; -////#endif return boost::locale::conv::utf_to_utf(theWStr); } @@ -60,18 +35,6 @@ namespace Locale std::wstring Convert::toWString(const std::string& theStr) { -////#if HAVE_WORKING_WIDESTRING -//// static std::wstring_convert > aConvertor; -//// return aConvertor.from_bytes(theStr); -////#else -//// wchar_t* aBuf = new wchar_t[theStr.size() + 1]; -//// size_t aNbWChars = std::mbstowcs(aBuf, theStr.c_str(), theStr.size()); -//// if (aNbWChars != (size_t)-1) -//// aBuf[aNbWChars] = L'\0'; -//// std::wstring aWStr(aBuf); -//// delete[] aBuf; -//// return aWStr; -////#endif return boost::locale::conv::utf_to_utf(theStr); } diff --git a/src/Locale/Test/TestUTF8.py b/src/Locale/Test/TestUTF8.py new file mode 100644 index 000000000..488bcd001 --- /dev/null +++ b/src/Locale/Test/TestUTF8.py @@ -0,0 +1,63 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() + +### Create Part +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +### Create Box +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Box_1.setName("boîte") +Box_1.result().setName("boîte") + +### Create Sphere +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10) +Sphere_1.setName("sphère") +Sphere_1.result().setName("sphère") + +### Create Shell +Shell_1_objects = [model.selection("FACE", "boîte/Left"), + model.selection("FACE", "boîte/Back"), + model.selection("FACE", "boîte/Bottom")] +Shell_1 = model.addShell(Part_1_doc, Shell_1_objects) + +### Create Cut +Cut_1 = model.addCut(Part_1_doc, [model.selection("SHELL", "boîte")], [model.selection("COMPOUND", "all-in-sphère")], keepSubResults = True) +Cut_1.result().subResult(0).setName("Cut_1_1_1") +Cut_1.result().subResult(1).setName("Cut_1_1_2") +Cut_1.result().subResult(2).setName("Cut_1_1_3") + +model.end() + +from GeomAPI import * + +model.testNbResults(Cut_1, 1) +model.testNbSubResults(Cut_1, [3]) +model.testNbSubShapes(Cut_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(Cut_1, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(Cut_1, GeomAPI_Shape.EDGE, [9]) +model.testNbSubShapes(Cut_1, GeomAPI_Shape.VERTEX, [18]) +model.testResultsVolumes(Cut_1, [64.38055098]) + +assert(model.checkPythonDump())