Salome HOME
SALOME_TESTS/Grids/smesh/bugs_09/J9
authoreap <eap@opencascade.com>
Wed, 30 Apr 2014 10:22:37 +0000 (14:22 +0400)
committereap <eap@opencascade.com>
Wed, 30 Apr 2014 10:22:37 +0000 (14:22 +0400)
 In CreateMeshFrom*(), throw an exception if the file does not exist

src/SMESHUtils/SMESH_File.cxx
src/SMESH_I/SMESH_Gen_i.cxx

index ade3256bbe7c5a3d2d52e485b22452586c99416a..b0720551629cf4757b476920df69f09241035e28 100644 (file)
@@ -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;
 }
index 6b962a028b003449a14ee77f41dc4c2aa5b7b537..c9243ad878907b1dcd06b3a4a6a135d649da8e58 100644 (file)
@@ -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