X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FMG_ADAPT_i.cxx;h=7950f58dde37ecc727629123f52f97a964bae23e;hp=188a3523659271c089883d98bd624d1a446f84dd;hb=e23a7cb81923e27e3b96ab97a90c325a703fef68;hpb=ded5e634c9bc8912e88db3c72f60c471ee017594 diff --git a/src/SMESH_I/MG_ADAPT_i.cxx b/src/SMESH_I/MG_ADAPT_i.cxx index 188a35236..7950f58dd 100644 --- a/src/SMESH_I/MG_ADAPT_i.cxx +++ b/src/SMESH_I/MG_ADAPT_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2011-2020 CEA/DEN, EDF R&D +// Copyright (C) 2020-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -19,23 +19,16 @@ #include "MG_ADAPT_i.hxx" -#include "string.h" -#include "SMESH_Gen_i.hxx" -#include -#include -#include CORBA_CLIENT_HEADER(SALOMEDS) - - -//============================================================================= -/*! - * SMESH_Gen_i::CreateMG_ADAPT - * - * Create measurement instance - */ -//============================================================================= +#include CORBA_SERVER_HEADER(SMESH_Homard) +#include "MG_ADAPT.hxx" +#include "SMESH_File.hxx" +#include "SMESH_Gen_i.hxx" +#include "SMESH_PythonDump.hxx" +#include "SMESH_TryCatch.hxx" using namespace SMESH; + void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const { to->myFileInDir = from.myFileInDir; @@ -94,37 +87,51 @@ void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisD to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess; to->myVerboseLevel = from->myVerboseLevel; } + +//============================================================================= +/*! + * SMESH_Gen_i::CreateMG_ADAPT + * + * Create measurement instance + */ +//============================================================================= + SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT() { +#ifndef DISABLE_MG_ADAPT SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i(); SMESH::MG_ADAPT_var anObj = aMGadapt->_this(); return anObj._retn(); +#else + return SMESH::MG_ADAPT_ptr(); +#endif } SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis() { +#ifndef DISABLE_MG_ADAPT SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i(); SMESH::MG_ADAPT_var anObj = aMGadapt->_this(); return anObj._retn(); +#else + return SMESH::MG_ADAPT_ptr(); +#endif } -SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType) +//SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType) +SALOME::GenericObj_ptr SMESH_Gen_i::Adaptation( const char* adaptationType) { - +#ifndef DISABLE_MG_ADAPT if (!strcmp(adaptationType, "MG_Adapt")) { SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i(); SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this(); return anObj._retn(); } - +#endif + if (!strcmp(adaptationType, "Uniform")) { + return CreateHOMARD_ADAPT(); + } + return SMESH::MG_ADAPT_OBJECT_ptr(); } -//~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT() -//~{ - - //~SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); - //~SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i(smeshGen_i->GetPOA()); - //~SMESH::MG_ADAPT_var anObj = aMGadapt->_this(); - //~return anObj._retn(); -//~} //============================================================================= /*! * standard constructor @@ -134,24 +141,6 @@ MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() ) { myMgAdapt = new ::MG_ADAPT::MgAdapt(); } -//~MG_ADAPT_i::MG_ADAPT_i(PortableServer::POA_var myPoa): SALOME::GenericObj_i( myPoa ) -//~{ - //~myMgAdapt = new ::MG_ADAPT::MgAdapt(); -//~} - -//============================================================================= -/*! - * standard constructor - */ -//============================================================================= -//~MG_ADAPT_i::MG_ADAPT_i( CORBA::ORB_ptr orb, - //~ADAPT::ADAPT_Gen_var engine ) -//~{ - - //~_gen_i = engine; - //~_orb = orb; - //~myMgAdapt = new MgAdapt(); -//~} //============================================================================= /*! @@ -160,6 +149,7 @@ MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() ) //============================================================================= MG_ADAPT_i::~MG_ADAPT_i() { + delete myMgAdapt; } void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data) { @@ -272,7 +262,7 @@ void MG_ADAPT_i::setRemoveOnSuccess(bool mybool) } bool MG_ADAPT_i::getRemoveOnSuccess() { - myMgAdapt->getRemoveOnSuccess(); + return myMgAdapt->getRemoveOnSuccess(); } SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData() { @@ -372,19 +362,38 @@ char* MG_ADAPT_i::getCommandToRun() return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str()); } +// macro used to initialize excStr by exception description +// returned by SMESH_CATCH( SMESH::returnError ) +#undef SMESH_CAUGHT +#define SMESH_CAUGHT excStr = + void MG_ADAPT_i::compute() { + SMESH::TPythonDump noDumpSoFar; + errStr = ""; - try + std::string excStr; + SMESH_TRY; + + myMgAdapt->compute(errStr); + + SMESH_CATCH( SMESH::returnError ); + + SMESH_Comment errMsg; + if ( !excStr.empty() ) + { + errMsg << "Exception thrown on MG_ADAPT_i::compute invocation with error message \"" + << errStr << "\" with exception \"" << excStr << "\""; + } + else if ( !errStr.empty() ) { - myMgAdapt->compute(errStr); + errMsg << "MG_ADAPT_i::compute invocation returned error message \"" << errStr << "\""; } - catch (const std::exception& e) + if ( !errMsg.empty() ) { - 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); + THROW_SALOME_CORBA_EXCEPTION( errMsg.c_str(), SALOME::INTERNAL_ERROR); } + if(myMgAdapt->getPublish()) { SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen(); @@ -392,6 +401,9 @@ void MG_ADAPT_i::compute() smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus); } } +#undef SMESH_CAUGHT +#define SMESH_CAUGHT + char* MG_ADAPT_i::getErrMsg() { return CORBA::string_dup(errStr.c_str()); @@ -422,31 +434,36 @@ bool MG_ADAPT_i::hasOptionDefined( const char* optionName ) return myMgAdapt->hasOptionDefined(optionName); } void MG_ADAPT_i::setOptionValue(const char* optionName, - const char* optionValue) throw (std::invalid_argument) + const char* optionValue) { + SMESH_TRY; myMgAdapt->setOptionValue(optionName, optionValue); + SMESH_CATCH( SMESH::throwCorbaException ); } char* MG_ADAPT_i::getOptionValue(const char* optionName, - bool& isDefault) throw (std::invalid_argument) + bool& isDefault) { + SMESH_TRY; return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str()); + SMESH_CATCH( SMESH::throwCorbaException ); + return 0; } -str_array* MG_ADAPT_i::getCustomOptionValuesStrVec() +SMESH::string_array* MG_ADAPT_i::getCustomOptionValuesStrVec() { - SMESH::str_array_var result = new SMESH::str_array(); + SMESH::string_array_var result = new SMESH::string_array(); std::vector vals = myMgAdapt->getCustomOptionValuesStrVec(); - result->length(vals.size()); - for (int i = 0; ilength((CORBA::ULong) vals.size()) ; + for (CORBA::ULong i = 0; i vals = myMgAdapt->getOptionValuesStrVec(); - result->length(vals.size()); - for (int i = 0; ilength((CORBA::ULong) vals.size()); + for (CORBA::ULong i = 0; isetMedFileOut(medFileOut.c_str()); mg->setSizeMapFile(medFileBackground.c_str()); hypothesis = SMESH::MG_ADAPT::_duplicate(mg); + hypothesis->Register(); } CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish) { + SMESH::TPythonDump noDumpSoFar; + if(!checkMeshFileIn()){ std::cerr<< "\n Error : Please check the MED file input or mesh input. \n"; return -1; @@ -507,22 +527,22 @@ CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish) bool MG_ADAPT_OBJECT_i::checkMeshFileIn() { + SMESH::TPythonDump noDumpSoFar; + bool ret = false; // 1 ok , 0 nook - if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn)) + if ( !( ret = SMESH_File( medFileIn ).exists())) { if(!myMesh->_is_nil()) { bool toOverwrite = true; bool toFindOutDim = true; - medFileIn = hypothesis->getFileName(); + medFileIn = (CORBA::String_var( hypothesis->getFileName() )).in(); medFileIn+= ".med"; myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim); hypothesis->setMedFileIn(medFileIn.c_str()); ret = true; } } - else - ret = true; return ret; }