From: eap Date: Wed, 30 Apr 2014 10:22:37 +0000 (+0400) Subject: SALOME_TESTS/Grids/smesh/bugs_09/J9 X-Git-Tag: V7_4_0rc1~15 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=commitdiff_plain;h=2107fb0fba6fb5276625455541e4ee59a6c5b305 SALOME_TESTS/Grids/smesh/bugs_09/J9 In CreateMeshFrom*(), throw an exception if the file does not exist --- diff --git a/src/SMESHUtils/SMESH_File.cxx b/src/SMESHUtils/SMESH_File.cxx index ade3256bb..b07205516 100644 --- a/src/SMESHUtils/SMESH_File.cxx +++ b/src/SMESHUtils/SMESH_File.cxx @@ -105,6 +105,10 @@ bool SMESH_File::open() #endif } } + else if ( _error.empty() ) + { + _error = "Can't open for reading an existing file " + _name; + } } return _pos; } diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 6b962a028..c9243ad87 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -953,6 +953,29 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh() return mesh._retn(); } +namespace +{ + //================================================================================ + /*! + * \brief Throws an exception in case if the file can't be read + */ + //================================================================================ + + void checkFileReadable( const char* theFileName ) throw ( SALOME::SALOME_Exception ) + { + SMESH_File f ( theFileName ); + if ( !f ) + { + if ( !f.error().empty() ) + THROW_SALOME_CORBA_EXCEPTION( f.error().c_str(), SALOME::BAD_PARAM); + + THROW_SALOME_CORBA_EXCEPTION + (( SMESH_Comment("Can't open for reading the file ") << theFileName ).c_str(), + SALOME::BAD_PARAM ); + } + } +} + //============================================================================= /*! * SMESH_Gen_i::CreateMeshFromUNV @@ -965,7 +988,8 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" ); + + checkFileReadable( theFileName ); SMESH::SMESH_Mesh_var aMesh = createMesh(); string aFileName; @@ -1082,10 +1106,11 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, SMESH::DriverMED_ReadStatus& theStatus) - throw ( SALOME::SALOME_Exception ) + throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" ); + checkFileReadable( theFileName ); + SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(theFileName, theStatus, "CreateMeshesFromMED", theFileName); return result; } @@ -1103,7 +1128,8 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName, throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromSAUV" ); + checkFileReadable( theFileName ); + std::string sauvfilename(theFileName); std::string medfilename(theFileName); medfilename += ".med"; @@ -1142,7 +1168,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" ); + checkFileReadable( theFileName ); SMESH::SMESH_Mesh_var aMesh = createMesh(); //string aFileName; @@ -1184,6 +1210,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName, throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); + checkFileReadable( theFileName ); SMESH::mesh_array_var aResult = new SMESH::mesh_array(); @@ -1271,6 +1298,7 @@ SMESH_Gen_i::CreateMeshesFromGMF( const char* theFileName, throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); + checkFileReadable( theFileName ); SMESH::SMESH_Mesh_var aMesh = createMesh(); #ifdef WIN32