Salome HOME
Allow saving groups with non-ascii names.
authoreap <eap@opencascade.com>
Thu, 23 Aug 2018 15:10:56 +0000 (18:10 +0300)
committereap <eap@opencascade.com>
Thu, 23 Aug 2018 15:10:56 +0000 (18:10 +0300)
+ Fix UTF8-invalid group names present in MED file

src/Driver/CMakeLists.txt
src/Driver/Driver_Document.cxx [deleted file]
src/Driver/Driver_Document.h [deleted file]
src/Driver/Driver_Mesh.cxx
src/Driver/Driver_Mesh.h
src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx
src/SMESHGUI/SMESHGUI.cxx

index d4a1d5c0a21dc4b13b5eae866fb43e80f11e1a44..586e88e0ef6a6a98639d557bedfd148e025729bd 100644 (file)
@@ -47,7 +47,6 @@ SET(_link_LIBRARIES
 
 # header files / no moc processing
 SET(MeshDriver_HEADERS
 
 # header files / no moc processing
 SET(MeshDriver_HEADERS
-  Driver_Document.h
   Driver_Mesh.h
   Driver_SMDS_Mesh.h
   Driver_SMESHDS_Mesh.h
   Driver_Mesh.h
   Driver_SMDS_Mesh.h
   Driver_SMESHDS_Mesh.h
@@ -57,7 +56,6 @@ SET(MeshDriver_HEADERS
 
 # sources / static
 SET(MeshDriver_SOURCES
 
 # sources / static
 SET(MeshDriver_SOURCES
-  Driver_Document.cxx
   Driver_Mesh.cxx
   Driver_SMDS_Mesh.cxx
   Driver_SMESHDS_Mesh.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 (file)
index 3312fc9..0000000
+++ /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 (file)
index 1857cb6..0000000
+++ /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 <string>
-
-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
index 38cdcc778c430767c2c89848eb803f18d5a0195e..d3fc4d9ebe301a683a1e22985d40606974a9d0b0 100644 (file)
@@ -101,3 +101,41 @@ SMESH_ComputeErrorPtr Driver_Mesh::GetError()
   }
   return SMESH_ComputeError::New( myStatus == DRS_OK ? int(COMPERR_OK) : int(myStatus), msg );
 }
   }
   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<const unsigned char* >( 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;
+}
index d368336409fa369789fb62b9d4862ba21887f5ed..164be49132590f477f3825a2eba412fe0e9fd466 100644 (file)
@@ -75,6 +75,8 @@ class MESHDRIVER_EXPORT Driver_Mesh
   std::string myMeshName;
   int         myMeshId;
 
   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;
   Status addMessage(const std::string& msg, const bool isFatal=false);
   std::vector< std::string > myErrorMessages;
   Status                     myStatus;
index a1a5cfcc7106b8b358d78c1f272cd51747da9d31..362874425a1428fc38efa13e0fd4d08130a15e86 100644 (file)
@@ -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 )
             }
             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;
           }
           aFamily->SetId( aFamId );
           myFamilies[aFamId] = aFamily;
index 80951c8006752b8d8d5995637bf8440d2ddf40ce..35e2c4850859bdc09d4b07bd8e6c24179925fe7c 100644 (file)
@@ -7131,7 +7131,7 @@ bool SMESHGUI::renameObject( const QString& entry, const QString& name) {
 
           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
           if( !aGroupObject->_is_nil() ) {
 
           SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(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) );
           }
             if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
               anActor->setName( qUtf8Printable(name) );
           }