From 87b989815b84e50bbf1af3236d1a1c2e1dac0fd0 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 24 Sep 2012 11:31:39 +0000 Subject: [PATCH] 021382: EDF 1985 SMESH: Read/write of .mesh files (GMF format) + void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart, + const char* file) throw (SALOME::SALOME_Exception); + SMESH::ComputeError* ImportGMFFile( const char* theFileName ) --- src/SMESH_I/SMESH_Mesh_i.cxx | 94 ++++++++++++++++++++++++++++++++++-- src/SMESH_I/SMESH_Mesh_i.hxx | 6 +++ 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 73d801492..2f9c47727 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -63,15 +63,16 @@ #include #include #include +#include #include #include #include #include #include #include -#include -#include #include +#include +#include // STL Includes #include @@ -305,7 +306,7 @@ void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID) //============================================================================= /*! - * + * Convert enum Driver_Mesh::Status to SMESH::DriverMED_ReadStatus */ //============================================================================= @@ -329,6 +330,30 @@ static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus) return res; } +//============================================================================= +/*! + * Convert ::SMESH_ComputeError to SMESH::ComputeError + */ +//============================================================================= + +static SMESH::ComputeError* ConvertComputeError( SMESH_ComputeErrorPtr errorPtr ) +{ + SMESH::ComputeError_var errVar = new SMESH::ComputeError(); + errVar->subShapeID = -1; + errVar->hasBadMesh = false; + + if ( !errorPtr || errorPtr->IsOK() ) + { + errVar->code = SMESH::COMPERR_OK; + } + else + { + errVar->code = ConvertDriverMEDReadStatus( errorPtr->myName ); + errVar->comment = errorPtr->myComment.c_str(); + } + return errVar._retn(); +} + //============================================================================= /*! * ImportMEDFile @@ -452,6 +477,45 @@ int SMESH_Mesh_i::ImportSTLFile( const char* theFileName ) return 1; } +//================================================================================ +/*! + * \brief Imports data from a GMF file and returns an error description + */ +//================================================================================ + +SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName ) + throw (SALOME::SALOME_Exception) +{ + SMESH_ComputeErrorPtr error; + try { + error = _impl->GMFToMesh( theFileName ); + } + catch ( std::bad_alloc& exc ) { + error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "std::bad_alloc raised" ); + } + catch ( Standard_OutOfMemory& exc ) { + error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "Standard_OutOfMemory raised" ); + } + catch (Standard_Failure& ex) { + error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, ex.DynamicType()->Name() ); + if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) + error->myComment += string(": ") + ex.GetMessageString(); + } + catch ( SALOME_Exception& S_ex ) { + error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, S_ex.what() ); + } + catch ( std::exception& exc ) { + error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, exc.what() ); + } + catch (...) { + error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "Unknown exception" ); + } + + CreateGroupServants(); + + return ConvertComputeError( error ); +} + //============================================================================= /*! * @@ -2968,6 +3032,28 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart, #endif } +//================================================================================ +/*! + * \brief Export a part of mesh to a GMF file + */ +//================================================================================ + +void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart, + const char* file) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + if ( _preMeshInfo ) + _preMeshInfo->FullLoadFromFile(); + + PrepareForWriting(file,/*overwrite=*/true); + + SMESH_MeshPartDS partDS( meshPart ); + _impl->ExportGMF(file, &partDS); + + TPythonDump() << _this() << ".ExportGMF( " << meshPart<< ", r'" << file << "')"; +} + //============================================================================= /*! * Return implementation of SALOME_MED::MESH interfaces @@ -4053,7 +4139,7 @@ SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id) */ //============================================================================= -void SMESH_Mesh_i::CreateGroupServants() +void SMESH_Mesh_i::CreateGroupServants() { SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy(); diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 8963687d2..0c2a3ca97 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -29,6 +29,7 @@ #include "SMESH.hxx" #include +#include CORBA_SERVER_HEADER(SMESH_Gen) #include CORBA_SERVER_HEADER(SMESH_Mesh) #include CORBA_SERVER_HEADER(SMESH_Group) #include CORBA_SERVER_HEADER(SMESH_Hypothesis) @@ -197,6 +198,9 @@ public: int ImportSTLFile( const char* theFileName ) throw (SALOME::SALOME_Exception); + SMESH::ComputeError* ImportGMFFile( const char* theFileName ) + throw (SALOME::SALOME_Exception); + /*! * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value */ @@ -244,6 +248,8 @@ public: void ExportCGNS(SMESH::SMESH_IDSource_ptr meshPart, const char* file, CORBA::Boolean overwrite) throw (SALOME::SALOME_Exception); + void ExportGMF(SMESH::SMESH_IDSource_ptr meshPart, + const char* file) throw (SALOME::SALOME_Exception); void ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, const char* file, -- 2.39.2