Allow saving groups with non-ascii names.

+ Fix UTF8-invalid group names present in MED file
This commit is contained in:
eap 2018-08-23 18:10:56 +03:00
parent 2f529dcd26
commit 8af480d893
7 changed files with 42 additions and 92 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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<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;
}

View File

@ -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;

View 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 )
aFamily->AddGroupName(aGroupName);
aFamily->AddGroupName( fixUTF8( aGroupName ));
}
aFamily->SetId( aFamId );
myFamilies[aFamId] = aFamily;

View 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() ) {
aGroupObject->SetName( qPrintable(name) );
aGroupObject->SetName( qUtf8Printable(name) );
if ( SMESH_Actor *anActor = SMESH::FindActorByEntry( qPrintable(entry) ) )
anActor->setName( qUtf8Printable(name) );
}