From: eap Date: Thu, 23 Aug 2018 15:10:56 +0000 (+0300) Subject: Allow saving groups with non-ascii names. X-Git-Tag: SHAPER_V9_1_0RC1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=8af480d8934d988fbefe45f08ffd868d43f7cf28 Allow saving groups with non-ascii names. + Fix UTF8-invalid group names present in MED file --- diff --git a/src/Driver/CMakeLists.txt b/src/Driver/CMakeLists.txt index d4a1d5c0a..586e88e0e 100644 --- a/src/Driver/CMakeLists.txt +++ b/src/Driver/CMakeLists.txt @@ -47,7 +47,6 @@ SET(_link_LIBRARIES # header files / no moc processing SET(MeshDriver_HEADERS - Driver_Document.h Driver_Mesh.h Driver_SMDS_Mesh.h Driver_SMESHDS_Mesh.h @@ -57,7 +56,6 @@ SET(MeshDriver_HEADERS # sources / static SET(MeshDriver_SOURCES - Driver_Document.cxx Driver_Mesh.cxx Driver_SMDS_Mesh.cxx Driver_SMESHDS_Mesh.cxx diff --git a/src/Driver/Driver_Document.cxx b/src/Driver/Driver_Document.cxx deleted file mode 100644 index 3312fc9b5..000000000 --- a/src/Driver/Driver_Document.cxx +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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 -// - -#include "Driver_Document.h" - -Driver_Document::Driver_Document(): - myDocument(NULL) -{} - - -void Driver_Document::SetFile(const std::string& theFileName) -{ - myFile = theFileName; -} - - -void Driver_Document::SetDocument(SMESHDS_Document * theDocument) -{ - myDocument = theDocument; -} diff --git a/src/Driver/Driver_Document.h b/src/Driver/Driver_Document.h deleted file mode 100644 index 1857cb62b..000000000 --- a/src/Driver/Driver_Document.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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 -// - -#ifndef _INCLUDE_DRIVER_DOCUMENT -#define _INCLUDE_DRIVER_DOCUMENT - -#include "Driver_Mesh.h" - -#include - -class SMESHDS_Document; - -class MESHDRIVER_EXPORT Driver_Document -{ - public: - Driver_Document(); - virtual ~Driver_Document(){} - - virtual void Perform() = 0; - void SetFile(const std::string& theFileName); - void SetDocument(SMESHDS_Document *theDocument); - - protected: - SMESHDS_Document * myDocument; - std::string myFile; - -}; - - -#endif diff --git a/src/Driver/Driver_Mesh.cxx b/src/Driver/Driver_Mesh.cxx index 38cdcc778..d3fc4d9eb 100644 --- a/src/Driver/Driver_Mesh.cxx +++ b/src/Driver/Driver_Mesh.cxx @@ -101,3 +101,41 @@ SMESH_ComputeErrorPtr Driver_Mesh::GetError() } return SMESH_ComputeError::New( myStatus == DRS_OK ? int(COMPERR_OK) : int(myStatus), msg ); } + +//================================================================================ +/*! + * \brief Assure a string is UTF-8 valid by replacing invalid chars + */ +//================================================================================ + +std::string Driver_Mesh::fixUTF8(const std::string & str ) +{ + std::string fixed = str; + const unsigned char* s = reinterpret_cast( fixed.data() ); + + for ( size_t i = 0; i < fixed.size(); ++i ) + { + if ( s[i] < 128 ) + continue; // latin + + bool invalid = false; + + // how many bytes follow? + int len = 0; + if (s[i] >> 5 == 0b110 ) len = 1; + else if (s[i] >> 4 == 0b1110 ) len = 2; + else if (s[i] >> 3 == 0b11110) len = 3; + else + invalid = true; + + // check the bytes + for ( int j = 0; j < len && !invalid; ++j ) + invalid = ( s[i+j+1] >> 6 != 0b10 ); + + if ( invalid ) + fixed[i] = '?'; + else + i += len; + } + return fixed; +} diff --git a/src/Driver/Driver_Mesh.h b/src/Driver/Driver_Mesh.h index d36833640..164be4913 100644 --- a/src/Driver/Driver_Mesh.h +++ b/src/Driver/Driver_Mesh.h @@ -75,6 +75,8 @@ class MESHDRIVER_EXPORT Driver_Mesh std::string myMeshName; int myMeshId; + static std::string fixUTF8(const std::string & s ); + Status addMessage(const std::string& msg, const bool isFatal=false); std::vector< std::string > myErrorMessages; Status myStatus; diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index a1a5cfcc7..362874425 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -156,7 +156,7 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() } if(MYDEBUG) MESSAGE(aGroupName); if ( strncmp( aGroupName.c_str(), NIG_GROUP_PREFIX, strlen(NIG_GROUP_PREFIX) ) != 0 ) - aFamily->AddGroupName(aGroupName); + aFamily->AddGroupName( fixUTF8( aGroupName )); } aFamily->SetId( aFamId ); myFamilies[aFamId] = aFamily; diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 80951c800..35e2c4850 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -7131,7 +7131,7 @@ bool SMESHGUI::renameObject( const QString& entry, const QString& name) { SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface(IObject); if( !aGroupObject->_is_nil() ) { - aGroupObject->SetName( qPrintable(name) ); + aGroupObject->SetName( qUtf8Printable(name) ); if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) ) anActor->setName( qUtf8Printable(name) ); }