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=fcbc77eda9dfe7ac6d6e4a26d5c79c1abe877be4;hp=ec2c9d30d53489664f7ce1a2d83246c777feaa8e;hb=499f29d24922cec66e41b41a0039a954993bc6df;hpb=ed49807f170bded5dffd1f25be7b8c5799cdab6b diff --git a/src/SMESH_I/MG_ADAPT_i.cxx b/src/SMESH_I/MG_ADAPT_i.cxx index ec2c9d30d..fcbc77eda 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-2022 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 @@ -18,26 +18,17 @@ // #include "MG_ADAPT_i.hxx" -//~#include "ADAPT_Gen_i.hxx" -#include "string.h" -#include "SMESH_Gen_i.hxx" -#include -#include -#include CORBA_CLIENT_HEADER(SALOMEDS) -//~#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) -//~#include CORBA_CLIENT_HEADER(SMESH_Gen) +#include CORBA_SERVER_HEADER(SMESH_Homard) -//============================================================================= -/*! - * SMESH_Gen_i::CreateMG_ADAPT - * - * Create measurement instance - */ -//============================================================================= - +#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; @@ -96,37 +87,53 @@ 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 +#ifndef DISABLE_HOMARD_ADAPT + if (!strcmp(adaptationType, "Uniform")) { + return CreateHOMARD_ADAPT(); + } +#endif + return SALOME::GenericObj_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 @@ -136,24 +143,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(); -//~} //============================================================================= /*! @@ -162,6 +151,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) { @@ -274,7 +264,7 @@ void MG_ADAPT_i::setRemoveOnSuccess(bool mybool) } bool MG_ADAPT_i::getRemoveOnSuccess() { - myMgAdapt->getRemoveOnSuccess(); + return myMgAdapt->getRemoveOnSuccess(); } SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData() { @@ -374,35 +364,48 @@ char* MG_ADAPT_i::getCommandToRun() 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() +// 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 = ""; - CORBA::Long ret; - try + std::string excStr; + SMESH_TRY; + + myMgAdapt->compute(errStr); + + SMESH_CATCH( SMESH::returnError ); + + SMESH_Comment errMsg; + if ( !excStr.empty() ) { - ret = myMgAdapt->compute(errStr); + errMsg << "Exception thrown on MG_ADAPT_i::compute invocation with error message \"" + << errStr << "\" with exception \"" << excStr << "\""; } - catch (const std::exception& e) + else if ( !errStr.empty() ) { - std::cerr<getPublish()) + if ( !errMsg.empty() ) + { + THROW_SALOME_CORBA_EXCEPTION( errMsg.c_str(), SALOME::INTERNAL_ERROR); + } + + if(myMgAdapt->getPublish()) { 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; } +#undef SMESH_CAUGHT +#define SMESH_CAUGHT + char* MG_ADAPT_i::getErrMsg() { return CORBA::string_dup(errStr.c_str()); @@ -433,31 +436,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; } hypothesis->setPublish(publish); - return hypothesis->compute(); + hypothesis->compute(); + return 0; } 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; }