From: jfa Date: Tue, 21 Feb 2006 07:38:30 +0000 (+0000) Subject: PAL11563: Naming Policy. Add method HasDuplicatedGroupNamesMED() to check group names... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=56ee43a2eb7befa08a549ab134e465a48c8436d7;p=modules%2Fsmesh.git PAL11563: Naming Policy. Add method HasDuplicatedGroupNamesMED() to check group names on duplications before export to MED. --- diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index a48181ec5..28e4ca873 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -336,6 +336,11 @@ module SMESH SMESH_MeshEditor GetMeshEditor() raises (SALOME::SALOME_Exception); + /*! Check group names for duplications. + * Consider maximum group name length stored in MED file. + */ + boolean HasDuplicatedGroupNamesMED(); + /*! * Export Mesh to different MED Formats * @params diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index abe270cc3..a8089b04f 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -63,6 +63,9 @@ #include "Utils_ExceptHandlers.hxx" +// maximum stored group name length in MED file +#define MAX_MED_GROUP_NAME_LENGTH 80 + #ifdef _DEBUG_ static int MYDEBUG = 0; #else @@ -746,11 +749,25 @@ throw(SALOME_Exception) } //============================================================================= -/*! - * +/*! Export* methods. + * To store mesh contents on disk in different formats. */ //============================================================================= +bool SMESH_Mesh::HasDuplicatedGroupNamesMED() +{ + set aGroupNames; + for ( map::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) { + SMESH_Group* aGroup = it->second; + string aGroupName = aGroup->GetName(); + aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH); + if (!aGroupNames.insert(aGroupName).second) + return true; + } + + return false; +} + void SMESH_Mesh::ExportMED(const char *file, const char* theMeshName, bool theAutoGroups, @@ -758,6 +775,7 @@ void SMESH_Mesh::ExportMED(const char *file, throw(SALOME_Exception) { Unexpect aCatch(SalomeException); + DriverMED_W_SMESHDS_Mesh myWriter; myWriter.SetFile ( file, MED::EVersion(theVersion) ); myWriter.SetMesh ( _myMeshDS ); @@ -775,15 +793,28 @@ void SMESH_Mesh::ExportMED(const char *file, myWriter.AddGroupOfVolumes(); } + // Pass groups to writer. Provide unique group names. + set aGroupNames; + char aString [256]; + int maxNbIter = 10000; // to guarantee cycle finish for ( map::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) { SMESH_Group* aGroup = it->second; SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS(); if ( aGroupDS ) { - aGroupDS->SetStoreName( aGroup->GetName() ); + string aGroupName0 = aGroup->GetName(); + aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH); + string aGroupName = aGroupName0; + for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) { + sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str()); + aGroupName = aString; + aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH); + } + aGroupDS->SetStoreName( aGroupName.c_str() ); myWriter.AddGroup( aGroupDS ); } } + // Perform export myWriter.Perform(); } diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 5054e0038..5d4e16bae 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -150,7 +150,12 @@ public: const TopTools_ListOfShape& GetAncestors(const TopoDS_Shape& theSubShape) const; // return list of ancestors of theSubShape in the order // that lower dimention shapes come first. - + + /*! Check group names for duplications. + * Consider maximum group name length stored in MED file. + */ + bool HasDuplicatedGroupNamesMED(); + void ExportMED(const char *file, const char* theMeshName = NULL, bool theAutoGroups = true, diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 42fac7d5d..5fa53b1e5 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -132,12 +132,11 @@ public: throw (SALOME::SALOME_Exception); // --- C++ interface - void SetImpl(::SMESH_Mesh* impl); ::SMESH_Mesh& GetImpl(); // :: force no namespace here SMESH_Gen_i* GetGen() { return _gen_i; } - + int ImportUNVFile( const char* theFileName ) throw (SALOME::SALOME_Exception); @@ -150,6 +149,11 @@ public: SMESH::DriverMED_ReadStatus ImportMEDFile( const char* theFileName, const char* theMeshName ) throw (SALOME::SALOME_Exception); + /*! Check group names for duplications. + * Consider maximum group name length stored in MED file. + */ + CORBA::Boolean HasDuplicatedGroupNamesMED(); + void ExportToMED( const char* file, CORBA::Boolean auto_groups, SMESH::MED_VERSION theVersion ) throw (SALOME::SALOME_Exception); void ExportMED( const char* file, CORBA::Boolean auto_groups )