Salome HOME
Forward medcoupling exception thrown in case of problem of conversion
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 17 Feb 2021 21:22:22 +0000 (22:22 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 17 Feb 2021 21:22:22 +0000 (22:22 +0100)
idl/MG_ADAPT.idl
src/SMESH/MG_ADAPT.cxx
src/SMESHGUI/SMESHGUI_MG_ADAPTDRIVER.cxx
src/SMESH_I/MG_ADAPT_i.cxx
src/SMESH_I/MG_ADAPT_i.hxx

index 6a4c7c98328b0dad7d85e224ca79dfb487b8aed9..7608ab67ace39abad6458263884c3f0a78c79e6d 100644 (file)
@@ -122,8 +122,7 @@ module SMESH{
     void setSizeMapType(in string f);
     boolean setAll();
     string getCommandToRun() ;
     void setSizeMapType(in string f);
     boolean setAll();
     string getCommandToRun() ;
-    //long compute(out string errStr);
-    long compute();
+    void compute() raises(SALOME::SALOME_Exception);
     string getErrMsg();
     string getFileName() ;
     string getExeName();
     string getErrMsg();
     string getFileName() ;
     string getExeName();
index c3e95da76d5e71a0bb34b567a885b36bca4329fa..f0accd50d3023fe943cc881c82d36ead378ae13f 100644 (file)
@@ -1244,9 +1244,7 @@ void MgAdapt::checkTimeStepRank(std::string fileIn)
 {
   bool ret = false ;
   MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileIn);
 {
   bool ret = false ;
   MEDCoupling::MCAuto<MEDCoupling::MEDFileData> mfd = MEDCoupling::MEDFileData::New(fileIn);
-  MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>( mfd->getFields()->getFieldWithName(fieldName) );
-//   std::cout << "--- timeStep " << timeStep << std::endl;
-//   std::cout << "--- rank " << rank << std::endl;
+  MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts( mfd->getFields()->getFieldWithName(fieldName) );
   std::vector<double> timevalue;
   std::vector< std::pair<int,int> > timesteprank = fts->getTimeSteps(timevalue);
   std::size_t jaux(timesteprank.size());
   std::vector<double> timevalue;
   std::vector< std::pair<int,int> > timesteprank = fts->getTimeSteps(timevalue);
   std::size_t jaux(timesteprank.size());
@@ -1299,7 +1297,7 @@ void MgAdapt::convertMedFile(std::string& meshFormatMeshFileName, std::string& s
   {
     checkFieldName(medFileIn) ;
     checkTimeStepRank(medFileIn) ;
   {
     checkFieldName(medFileIn) ;
     checkTimeStepRank(medFileIn) ;
-    MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>( mfd->getFields()->getFieldWithName(fieldName) );
+    MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts( mfd->getFields()->getFieldWithName(fieldName) );
     MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts->getTimeStep(timeStep, rank);
     MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
     tmFts->pushBackTimeStep(f);
     MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts->getTimeStep(timeStep, rank);
     MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
     tmFts->pushBackTimeStep(f);
@@ -1438,8 +1436,8 @@ void MgAdapt::buildBackGroundMeshAndSolFiles(const std::vector<std::string>& fie
 {
   MEDCoupling::MCAuto<MEDCoupling::MEDFileData> tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile);
   MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields();
 {
   MEDCoupling::MCAuto<MEDCoupling::MEDFileData> tmpMfd = MEDCoupling::MEDFileData::New(sizeMapFile);
   MEDCoupling::MEDFileFields* tmpFields = tmpMfd->getFields();
-  MEDCoupling::MEDFileAnyTypeFieldMultiTS* fts = tmpFields->getFieldWithName(fieldName);
-  MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS>  fts1 = dynamic_cast<MEDCoupling::MEDFileFieldMultiTS *>(fts);
+  MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeFieldMultiTS> fts( tmpFields->getFieldWithName(fieldName) );
+  MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS>  fts1 = MEDCoupling::DynamicCastSafe<MEDCoupling::MEDFileAnyTypeFieldMultiTS,MEDCoupling::MEDFileFieldMultiTS>(fts);
   MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts1->getTimeStep(timeStep, rank);
   MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
   tmFts->pushBackTimeStep(f);
   MEDCoupling::MCAuto<MEDCoupling::MEDFileAnyTypeField1TS> f = fts1->getTimeStep(timeStep, rank);
   MEDCoupling::MCAuto<MEDCoupling::MEDFileFieldMultiTS> tmFts = MEDCoupling::MEDFileFieldMultiTS::New();
   tmFts->pushBackTimeStep(f);
index fc1496380c1b6462edd792630a65e42ce29ac4e4..d3bed87fdecc983aef5a4ada9b116ddb36f32db2 100644 (file)
@@ -385,12 +385,12 @@ bool SMESHGUI_MG_ADAPTDRIVER::PushOnApply()
 
 bool SMESHGUI_MG_ADAPTDRIVER::execute()
 {
 
 bool SMESHGUI_MG_ADAPTDRIVER::execute()
 {
-  int err;
-  //~std::string errStr;
+  int err = 1;
   char* errStr;
   try
   {
   char* errStr;
   try
   {
-    err = getModel()->compute();
+    getModel()->compute();
+    err = 0;
     errStr = getModel()->getErrMsg();
     std::string msg = err == 0 ? " ok" : std::string("Not ok \n")+CORBA::string_dup(errStr) ;
   }
     errStr = getModel()->getErrMsg();
     std::string msg = err == 0 ? " ok" : std::string("Not ok \n")+CORBA::string_dup(errStr) ;
   }
@@ -398,7 +398,7 @@ bool SMESHGUI_MG_ADAPTDRIVER::execute()
   {
     std::cerr<<e.what();
   }
   {
     std::cerr<<e.what();
   }
-  return err == 0? true: false;
+  return err == 0;
 }
 
 //=================================================================================
 }
 
 //=================================================================================
index fbe27fd473246ce4eb130d3273bf7855a30d9be6..188a3523659271c089883d98bd624d1a446f84dd 100644 (file)
@@ -372,34 +372,25 @@ char* MG_ADAPT_i::getCommandToRun()
   return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
 }
 
   return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
 }
 
-//~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr)
-//~{
-  //~std::string err("");
-  //~CORBA::Long ret = myMgAdapt->compute(err);
-  //~errStr =  err.c_str();
-  //~return ret;
-//~}
-CORBA::Long MG_ADAPT_i::compute()
+void MG_ADAPT_i::compute()
 {
   errStr = "";
 {
   errStr = "";
-  CORBA::Long ret;
   try
   {
   try
   {
-    ret = myMgAdapt->compute(errStr);
+    myMgAdapt->compute(errStr);
   }
   catch (const std::exception& e)
   {
   }
   catch (const std::exception& e)
   {
-    std::cerr<<e.what();
-    ret = -1;
+    std::ostringstream oss; oss << "Exception thrown on MG_ADAPT_i::compute invocation with error message \"" << errStr
+                << "\" with exception message \"" << e.what() << "\"";
+               THROW_SALOME_CORBA_EXCEPTION(oss.str().c_str(),SALOME::INTERNAL_ERROR);
   }
   }
-  if(ret!=-1 && myMgAdapt->getPublish())
+  if(myMgAdapt->getPublish())
   {
     SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
     SMESH::DriverMED_ReadStatus theStatus;
     smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
   }
   {
     SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
     SMESH::DriverMED_ReadStatus theStatus;
     smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
   }
-  //~errStr =  err.c_str();
-  return ret;
 }
 char* MG_ADAPT_i::getErrMsg()
 {
 }
 char* MG_ADAPT_i::getErrMsg()
 {
@@ -510,7 +501,8 @@ CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
     return -1;
   }
   hypothesis->setPublish(publish);
     return -1;
   }
   hypothesis->setPublish(publish);
-  return hypothesis->compute();
+  hypothesis->compute();
+  return 0;
 }
 
 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
 }
 
 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
index b259531754582e992e8b64311c3c1c3bc28650cb..edc398d0792d39566f02264e02a212117905b41d 100644 (file)
@@ -109,8 +109,7 @@ public:
 
   bool setAll();
   char* getCommandToRun() ;
 
   bool setAll();
   char* getCommandToRun() ;
-  //~CORBA::Long compute(::CORBA::String_out errStr);
-  CORBA::Long compute();
+  void compute();
   char* getFileName();
   char* getExeName();
   void copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data ) ;
   char* getFileName();
   char* getExeName();
   void copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data ) ;