#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
}
//=============================================================================
-/*!
- *
+/*! Export* methods.
+ * To store mesh contents on disk in different formats.
*/
//=============================================================================
+bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
+{
+ set<string> aGroupNames;
+ for ( map<int, SMESH_Group*>::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,
throw(SALOME_Exception)
{
Unexpect aCatch(SalomeException);
+
DriverMED_W_SMESHDS_Mesh myWriter;
myWriter.SetFile ( file, MED::EVersion(theVersion) );
myWriter.SetMesh ( _myMeshDS );
myWriter.AddGroupOfVolumes();
}
+ // Pass groups to writer. Provide unique group names.
+ set<string> aGroupNames;
+ char aString [256];
+ int maxNbIter = 10000; // to guarantee cycle finish
for ( map<int, SMESH_Group*>::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();
}
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,
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);
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 )