Message d'erreur en l'absence de fichier

This commit is contained in:
Gérald NICOLAS 2021-02-09 17:05:33 +01:00
parent 52a01fdffe
commit 4c3cd911ff
2 changed files with 39 additions and 11 deletions

View File

@ -30,6 +30,9 @@
#include "MEDFileField.hxx" #include "MEDFileField.hxx"
#include "MEDCouplingFieldDouble.hxx" #include "MEDCouplingFieldDouble.hxx"
#include <SALOME_NamingService.hxx>
#include <Utils_SALOME_Exception.hxx>
#include <utilities.h> #include <utilities.h>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
@ -218,11 +221,27 @@ MgAdaptHypothesisData* MgAdapt::getData() const
return data; return data;
} }
void MgAdapt::setMedFileIn(std::string fileName) void MgAdapt::setMedFileIn(std::string fileName)
{
if ( isFileExist(fileName) )
{ {
medFileIn = fileName; medFileIn = fileName;
if (medFileOut == "") // default MED file Out if (medFileOut == "") // default MED file Out
medFileOut = remove_extension( fileName )+ ".adapt.med"; medFileOut = remove_extension( fileName )+ ".adapt.med";
} }
else
{
std::cout << "\nThe file " + fileName + " does not exist.\n" << std::endl;
// SALOME::ExceptionStruct es;
// es.type = SALOME::BAD_PARAM;
// std::string text = "\nThe file " + fileName + " does not exist.\n" ;
// std::cout << text << std::endl;
// es.text = "The mesh file does not exist.";
// es.text = CORBA::string_dup(text.c_str());
// throw SALOME::SALOME_Exception(es);
throw SALOME_Exception(("The file " + fileName + " does not exist." ).c_str() );
}
}
std::string MgAdapt::getMedFileIn() std::string MgAdapt::getMedFileIn()
{ {
@ -233,7 +252,6 @@ void MgAdapt::setMedFileOut(std::string fileOut)
{ {
medFileOut = fileOut; medFileOut = fileOut;
} }
std::string MgAdapt::getMedFileOut() std::string MgAdapt::getMedFileOut()
{ {
return medFileOut; return medFileOut;
@ -362,9 +380,17 @@ bool MgAdapt::getRemoveOnSuccess()
return removeOnSuccess; return removeOnSuccess;
} }
void MgAdapt::setSizeMapFile(std::string mapFile) void MgAdapt::setSizeMapFile(std::string mapFile)
{
if ( mapFile == "" || isFileExist(mapFile) )
{ {
sizeMapFile = mapFile; sizeMapFile = mapFile;
} }
else
{
std::cout << "\nThe file " + mapFile + " does not exist.\n" << std::endl;
throw SALOME_Exception(("The file " + mapFile + " does not exist." ).c_str() );
}
}
std::string MgAdapt::getSizeMapFile() std::string MgAdapt::getSizeMapFile()
{ {
return sizeMapFile; return sizeMapFile;
@ -428,7 +454,6 @@ bool MgAdapt::getPrintLogInFile()
return printLogInFile; return printLogInFile;
} }
bool MgAdapt::setAll() bool MgAdapt::setAll()
{ {
@ -1315,8 +1340,13 @@ med_idt MgAdapt::openMedFile(const std::string aFile)
med_idt medIdt = MEDfileOpen(aFile.c_str(),MED_ACC_RDONLY); med_idt medIdt = MEDfileOpen(aFile.c_str(),MED_ACC_RDONLY);
if (medIdt <0) if (medIdt <0)
{ {
//~addMessage( ToComment(" error: Can't open ") << aFile, /*fatal=*/true ); SALOME::ExceptionStruct es;
; es.type = SALOME::BAD_PARAM;
std::string text = "The med file " + aFile + " cannot be opened." ;
// es.text = "The mesh file does not exist.";
es.text = CORBA::string_dup(text.c_str());
throw SALOME::SALOME_Exception(es);
return 0;
} }
return medIdt; return medIdt;
} }

View File

@ -18,14 +18,12 @@
// //
#include "MG_ADAPT_i.hxx" #include "MG_ADAPT_i.hxx"
//~#include "ADAPT_Gen_i.hxx"
#include "string.h" #include "string.h"
#include "SMESH_Gen_i.hxx" #include "SMESH_Gen_i.hxx"
#include <SMESH_Gen.hxx> #include <SMESH_Gen.hxx>
#include <SALOMEconfig.h> #include <SALOMEconfig.h>
#include CORBA_CLIENT_HEADER(SALOMEDS) #include CORBA_CLIENT_HEADER(SALOMEDS)
//~#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
//~#include CORBA_CLIENT_HEADER(SMESH_Gen)
//============================================================================= //=============================================================================