From: eap Date: Tue, 14 Jun 2011 13:51:27 +0000 (+0000) Subject: 0020743: EDF 1271 SMESH : Create a mesh from a group / export groups X-Git-Tag: V6_4_0a1~216 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=00fdc117cd916df5caf44578dff4751737f03358;p=modules%2Fsmesh.git 0020743: EDF 1271 SMESH : Create a mesh from a group / export groups void ExportMED(const char *file, const char* theMeshName = NULL, bool theAutoGroups = true, - int theVersion = 0) + int theVersion = 0, + const SMESHDS_Mesh* meshPart = 0) --- diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 60458d830..8e22cc24d 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1045,7 +1045,7 @@ bool SMESH_Mesh::HasModificationsToDiscard() const if ( ! _isModified ) return false; - // return true if there the next Compute() will be partial and + // return true if the next Compute() will be partial and // existing but changed elements may prevent successful re-compute bool hasComputed = false, hasNotComputed = false; map ::const_iterator i_sm = _mapSubMesh.begin(); @@ -1069,11 +1069,11 @@ bool SMESH_Mesh::HasModificationsToDiscard() const return false; } -//============================================================================= -/*! Export* methods. - * To store mesh contents on disk in different formats. +//================================================================================ +/*! + * \brief Check if any groups of the same type have equal names */ -//============================================================================= +//================================================================================ bool SMESH_Mesh::HasDuplicatedGroupNamesMED() { @@ -1092,17 +1092,24 @@ bool SMESH_Mesh::HasDuplicatedGroupNamesMED() return false; } -void SMESH_Mesh::ExportMED(const char *file, - const char* theMeshName, - bool theAutoGroups, - int theVersion) +//================================================================================ +/*! + * \brief Export the mesh to a med file + */ +//================================================================================ + +void SMESH_Mesh::ExportMED(const char * file, + const char* theMeshName, + bool theAutoGroups, + int theVersion, + const SMESHDS_Mesh* meshPart) throw(SALOME_Exception) { Unexpect aCatch(SalomeException); DriverMED_W_SMESHDS_Mesh myWriter; myWriter.SetFile ( file, MED::EVersion(theVersion) ); - myWriter.SetMesh ( _myMeshDS ); + myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); if ( !theMeshName ) myWriter.SetMeshId ( _idDoc ); else { @@ -1119,69 +1126,96 @@ void SMESH_Mesh::ExportMED(const char *file, // Pass groups to writer. Provide unique group names. //set aGroupNames; // Corrected for Mantis issue 0020028 - map< SMDSAbs_ElementType, 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 ) { - SMDSAbs_ElementType aType = aGroupDS->GetType(); - string aGroupName0 = aGroup->GetName(); - aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH); - string aGroupName = aGroupName0; - for (int i = 1; !aGroupNames[aType].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); + if ( !meshPart ) + { + map< SMDSAbs_ElementType, 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 ) { + SMDSAbs_ElementType aType = aGroupDS->GetType(); + string aGroupName0 = aGroup->GetName(); + aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH); + string aGroupName = aGroupName0; + for (int i = 1; !aGroupNames[aType].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 ); } - aGroupDS->SetStoreName( aGroupName.c_str() ); - myWriter.AddGroup( aGroupDS ); } } - // Perform export myWriter.Perform(); } -void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception) +//================================================================================ +/*! + * \brief Export the mesh to a DAT file + */ +//================================================================================ + +void SMESH_Mesh::ExportDAT(const char * file, + const SMESHDS_Mesh* meshPart) throw(SALOME_Exception) { Unexpect aCatch(SalomeException); DriverDAT_W_SMDS_Mesh myWriter; - myWriter.SetFile(string(file)); - myWriter.SetMesh(_myMeshDS); + myWriter.SetFile( file ); + myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); myWriter.SetMeshId(_idDoc); myWriter.Perform(); } -void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception) +//================================================================================ +/*! + * \brief Export the mesh to an UNV file + */ +//================================================================================ + +void SMESH_Mesh::ExportUNV(const char * file, + const SMESHDS_Mesh* meshPart) throw(SALOME_Exception) { Unexpect aCatch(SalomeException); DriverUNV_W_SMDS_Mesh myWriter; - myWriter.SetFile(string(file)); - myWriter.SetMesh(_myMeshDS); + myWriter.SetFile( file ); + myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS ); myWriter.SetMeshId(_idDoc); // myWriter.SetGroups(_mapGroup); - for ( map::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) { - SMESH_Group* aGroup = it->second; - SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS(); - if ( aGroupDS ) { - string aGroupName = aGroup->GetName(); - aGroupDS->SetStoreName( aGroupName.c_str() ); - myWriter.AddGroup( aGroupDS ); + if ( !meshPart ) + { + for ( map::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) { + SMESH_Group* aGroup = it->second; + SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS(); + if ( aGroupDS ) { + string aGroupName = aGroup->GetName(); + aGroupDS->SetStoreName( aGroupName.c_str() ); + myWriter.AddGroup( aGroupDS ); + } } } myWriter.Perform(); } -void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception) +//================================================================================ +/*! + * \brief Export the mesh to an STL file + */ +//================================================================================ + +void SMESH_Mesh::ExportSTL(const char * file, + const bool isascii, + const SMESHDS_Mesh* meshPart) throw(SALOME_Exception) { Unexpect aCatch(SalomeException); DriverSTL_W_SMDS_Mesh myWriter; - myWriter.SetFile(string(file)); + myWriter.SetFile( file ); myWriter.SetIsAscii( isascii ); - myWriter.SetMesh(_myMeshDS); + myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS); myWriter.SetMeshId(_idDoc); myWriter.Perform(); } diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index a77498ed5..f1406685b 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -219,12 +219,17 @@ public: void ExportMED(const char *file, const char* theMeshName = NULL, bool theAutoGroups = true, - int theVersion = 0) + int theVersion = 0, + const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception); - void ExportDAT(const char *file) throw(SALOME_Exception); - void ExportUNV(const char *file) throw(SALOME_Exception); - void ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception); + void ExportDAT(const char * file, + const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception); + void ExportUNV(const char * file, + const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception); + void ExportSTL(const char * file, + const bool isascii, + const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception); int NbNodes() const throw(SALOME_Exception);