From: eap Date: Wed, 10 Aug 2011 10:28:52 +0000 (+0000) Subject: 0020511: EDF 1101 SMESH : Add CGNS to Mesh Format Supported X-Git-Tag: V6_4_0a1~119 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17e228432159e132d3992ab1795fc0d82a669982;p=modules%2Fsmesh.git 0020511: EDF 1101 SMESH : Add CGNS to Mesh Format Supported + SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName, + SMESH::DriverMED_ReadStatus& theStatus ) --- diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 5c2293c4c..3197d7204 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -100,6 +100,7 @@ #include "DriverMED_W_SMESHDS_Mesh.h" #include "DriverMED_R_SMESHDS_Mesh.h" +#include "DriverCGNS_Read.hxx" #include "SALOMEDS_Tool.hxx" #include "SALOME_NamingService.hxx" @@ -1023,6 +1024,84 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName return aMesh._retn(); } +//================================================================================ +/*! + * \brief Create meshes and import data from the CGSN file + */ +//================================================================================ + +SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName, + SMESH::DriverMED_ReadStatus& theStatus) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + + // Retrieve nb meshes from the file + DriverCGNS_Read myReader; + myReader.SetFile( theFileName ); + Driver_Mesh::Status aStatus; + int nbMeshes = myReader.GetNbMeshes(aStatus); + theStatus = (SMESH::DriverMED_ReadStatus)aStatus; + + SMESH::mesh_array_var aResult = new SMESH::mesh_array(); + aResult->length( nbMeshes ); + + { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups() + + // Python Dump + TPythonDump aPythonDump; + aPythonDump << "(["; + + if (theStatus == SMESH::DRS_OK) + { + SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder(); + aStudyBuilder->NewCommand(); // There is a transaction + + int i = 0; + + // Iterate through all meshes and create mesh objects + for ( ; i < nbMeshes; ++i ) + { + // Python Dump + if (i > 0) aPythonDump << ", "; + + // create mesh + SMESH::SMESH_Mesh_var mesh = createMesh(); + aResult[i] = SMESH::SMESH_Mesh::_duplicate( mesh ); + + // Read mesh data (groups are published automatically by ImportMEDFile()) + SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); + ASSERT( meshServant ); + string meshName; + SMESH::DriverMED_ReadStatus status1 = + meshServant->ImportCGNSFile( theFileName, i, meshName ); + if (status1 > theStatus) + theStatus = status1; + + meshServant->GetImpl().GetMeshDS()->Modified(); + // publish mesh in the study + SALOMEDS::SObject_var aSO; + if ( CanPublishInStudy( mesh ) ) + aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() ); + + // Python Dump + if ( !aSO->_is_nil() ) + aPythonDump << aSO; + else + aPythonDump << "mesh_" << i; + } + aStudyBuilder->CommitCommand(); + } + + aPythonDump << "], status) = " << this << ".CreateMeshesFromCGNS(r'" << theFileName << "')"; + } + // Dump creation of groups + for ( int i = 0; i < aResult->length(); ++i ) + SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups(); + + return aResult._retn(); +} + //============================================================================= /*! * SMESH_Gen_i::IsReadyToCompute @@ -2367,10 +2446,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart, if ( elem->GetType() != SMDSAbs_Node ) { int ID = toKeepIDs ? elem->GetID() : 0; - const SMDS_MeshElement * newElem = editor.AddElement( nodes, - elem->GetType(), - elem->IsPoly(), - ID); + const SMDS_MeshElement * newElem; + if ( elem->GetEntityType() == SMDSEntity_Polyhedra ) + newElem = editor.GetMeshDS()-> + AddPolyhedralVolumeWithID( nodes, + static_cast(elem)->GetQuantities(), + elem->GetID()); + else + newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID); + if ( toCopyGroups && !toKeepIDs ) e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem )); } diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 1087dc023..f1d449edd 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -234,6 +234,11 @@ public: SMESH::SMESH_Mesh_ptr CreateMeshesFromSTL( const char* theFileName ) throw ( SALOME::SALOME_Exception ); + // Create mesh(es) and import data from CGNS file + SMESH::mesh_array* CreateMeshesFromCGNS( const char* theFileName, + SMESH::DriverMED_ReadStatus& theStatus ) + throw ( SALOME::SALOME_Exception ); + // Copy a part of mesh SMESH::SMESH_Mesh_ptr CopyMesh(SMESH::SMESH_IDSource_ptr meshPart, const char* meshName,