From 111c7a0cd2567887aae9977b0174fc617b679daf Mon Sep 17 00:00:00 2001 From: eap Date: Wed, 10 Aug 2011 10:17:29 +0000 Subject: [PATCH] 0020511: EDF 1101 SMESH : Add CGNS to Mesh Format Supported --- src/SMESH/SMESH_Mesh.cxx | 70 ++++++++++++++++++++++++++++++++++++++++ src/SMESH/SMESH_Mesh.hxx | 9 +++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index 2a9b64909..7bc5b7ceb 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -48,6 +48,8 @@ #include "DriverMED_R_SMESHDS_Mesh.h" #include "DriverUNV_R_SMDS_Mesh.h" #include "DriverSTL_R_SMDS_Mesh.h" +#include "DriverCGNS_Read.hxx" +#include "DriverCGNS_Write.hxx" #undef _Precision_HeaderFile #include @@ -441,6 +443,31 @@ int SMESH_Mesh::STLToMesh(const char* theFileName) return 1; } +//================================================================================ +/*! + * \brief Reads the given mesh from the CGNS file + * \param theFileName - name of the file + * \retval int - Driver_Mesh::Status + */ +//================================================================================ + +int SMESH_Mesh::CGNSToMesh(const char* theFileName, + const int theMeshIndex, + std::string& theMeshName) +{ + DriverCGNS_Read myReader; + myReader.SetMesh(_myMeshDS); + myReader.SetFile(theFileName); + myReader.SetMeshId(theMeshIndex); + int res = myReader.Perform(); + theMeshName = myReader.GetMeshName(); + + // create groups + SynchronizeGroups(); + + return res; +} + //============================================================================= /*! * @@ -1220,6 +1247,23 @@ void SMESH_Mesh::ExportSTL(const char * file, myWriter.Perform(); } +//================================================================================ +/*! + * \brief Export the mesh to the CGNS file + */ +//================================================================================ + +void SMESH_Mesh::ExportCGNS(const char * file, + const SMESHDS_Mesh* meshDS) +{ + DriverCGNS_Write myWriter; + myWriter.SetFile( file ); + myWriter.SetMesh( const_cast( meshDS )); + myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId()); + if ( myWriter.Perform() != Driver_Mesh::DRS_OK ) + throw SALOME_Exception("Export failed"); +} + //================================================================================ /*! * \brief Return number of nodes in the mesh @@ -1432,6 +1476,32 @@ SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType, return aGroup; } +//================================================================================ +/*! + * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups + * \retval bool - true if new SMESH_Groups have been created + * + */ +//================================================================================ + +bool SMESH_Mesh::SynchronizeGroups() +{ + int nbGroups = _mapGroup.size(); + const set& groups = _myMeshDS->GetGroups(); + set::const_iterator gIt = groups.begin(); + for ( ; gIt != groups.end(); ++gIt ) + { + SMESHDS_GroupBase* groupDS = (SMESHDS_GroupBase*) *gIt; + _groupId = groupDS->GetID(); + if ( !_mapGroup.count( _groupId )) + _mapGroup[_groupId] = new SMESH_Group( groupDS ); + } + if ( !_mapGroup.empty() ) + _groupId = _mapGroup.rbegin()->first + 1; + + return nbGroups < _mapGroup.size(); +} + //================================================================================ /*! * \brief Return iterator on all existing groups diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 79fdc3918..570dbb345 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -108,14 +108,17 @@ public: */ void ClearSubMesh(const int theShapeId); - int UNVToMesh(const char* theFileName); /*! * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value */ + int UNVToMesh(const char* theFileName); + int MEDToMesh(const char* theFileName, const char* theMeshName); int STLToMesh(const char* theFileName); + int CGNSToMesh(const char* theFileName, const int theMeshIndex, std::string& theMeshName); + SMESH_Hypothesis::Hypothesis_Status AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId) throw(SALOME_Exception); @@ -231,6 +234,8 @@ public: void ExportSTL(const char * file, const bool isascii, const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception); + void ExportCGNS(const char * file, + const SMESHDS_Mesh* mesh); int NbNodes() const throw(SALOME_Exception); @@ -286,6 +291,8 @@ public: }; void SetRemoveGroupCallUp( TRmGroupCallUp * upCaller ); + bool SynchronizeGroups(); + SMDSAbs_ElementType GetElementType( const int id, const bool iselem ); -- 2.39.2