1 // Copyright (C) 2020-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MG_ADAPT_i.hxx"
22 #include CORBA_SERVER_HEADER(SMESH_Homard)
24 #include "MG_ADAPT.hxx"
25 #include "SMESH_File.hxx"
26 #include "SMESH_Gen_i.hxx"
27 #include "SMESH_PythonDump.hxx"
28 #include "SMESH_TryCatch.hxx"
30 using namespace SMESH;
32 void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const
34 to->myFileInDir = from.myFileInDir;
35 to->myMeshFileIn = from.myMeshFileIn;
36 to->myMeshFileBackground = from.myMeshFileBackground;
37 to->myOutMeshName = from.myOutMeshName;
38 to->myMeshFileOut = from.myMeshFileOut;
39 to->myFileOutDir = from.myFileOutDir;
40 to->myFileSizeMapDir = from.myFileSizeMapDir;
41 to->myFieldName = from.myFieldName;
42 to->fromMedFile = from.fromMedFile;
43 to->myPublish = from.myPublish;
44 to->myMeshOutMed = from.myMeshOutMed;
45 to->myUseLocalMap = from.myUseLocalMap;
46 to->myUseBackgroundMap = from.myUseBackgroundMap;
47 to->myUseConstantValue = from.myUseConstantValue;
48 to->myConstantValue = from.myConstantValue;
49 to->myTimeStep = from.myTimeStep;
50 to->myRank = from.myRank;
51 to->myUseNoTimeStep = from.myUseNoTimeStep;
52 to->myUseLastTimeStep = from.myUseLastTimeStep;
53 to->myUseChosenTimeStep = from.myUseChosenTimeStep;
54 to->myWorkingDir = from.myWorkingDir;
55 to->myLogFile = from.myLogFile;
56 to->myPrintLogInFile = from.myPrintLogInFile;
57 to->myKeepFiles = from.myKeepFiles;
58 to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess;
59 to->myVerboseLevel = from.myVerboseLevel;
61 void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const
63 to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str());
64 to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str());
65 to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str());
66 to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str());
67 to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str());
68 to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str());
69 to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str());
70 to->myFieldName = CORBA::string_dup(from->myFieldName.c_str());
71 to->fromMedFile = from->fromMedFile;
72 to->myPublish = from->myPublish;
73 to->myMeshOutMed = from->myMeshOutMed;
74 to->myUseLocalMap = from->myUseLocalMap;
75 to->myUseBackgroundMap = from->myUseBackgroundMap;
76 to->myUseConstantValue = from->myUseConstantValue;
77 to->myConstantValue = from->myConstantValue;
78 to->myTimeStep = from->myTimeStep;
79 to->myRank = from->myRank;
80 to->myUseNoTimeStep = from->myUseNoTimeStep;
81 to->myUseLastTimeStep = from->myUseLastTimeStep;
82 to->myUseChosenTimeStep = from->myUseChosenTimeStep;
83 to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str());
84 to->myLogFile = CORBA::string_dup(from->myLogFile.c_str());
85 to->myPrintLogInFile = from->myPrintLogInFile;
86 to->myKeepFiles = from->myKeepFiles;
87 to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
88 to->myVerboseLevel = from->myVerboseLevel;
91 //=============================================================================
93 * SMESH_Gen_i::CreateMG_ADAPT
95 * Create measurement instance
97 //=============================================================================
99 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT()
101 #ifndef DISABLE_MG_ADAPT
102 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
103 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
104 return anObj._retn();
106 return SMESH::MG_ADAPT_ptr();
109 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
111 #ifndef DISABLE_MG_ADAPT
112 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
113 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
114 return anObj._retn();
116 return SMESH::MG_ADAPT_ptr();
119 //SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
120 SALOME::GenericObj_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
122 #ifndef DISABLE_MG_ADAPT
123 if (!strcmp(adaptationType, "MG_Adapt"))
125 SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i();
126 SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this();
127 return anObj._retn();
130 #ifndef DISABLE_HOMARD_ADAPT
131 if (!strcmp(adaptationType, "Uniform")) {
132 return CreateHOMARD_ADAPT();
135 return SALOME::GenericObj_ptr();
137 //=============================================================================
139 * standard constructor
141 //=============================================================================
142 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
144 myMgAdapt = new ::MG_ADAPT::MgAdapt();
147 //=============================================================================
149 * standard destructor
151 //=============================================================================
152 MG_ADAPT_i::~MG_ADAPT_i()
156 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
158 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
159 copyHypothesisDataToImpl(data, baseData);
160 myMgAdapt->setData(baseData);
163 void MG_ADAPT_i::setMedFileIn(const char* str)
165 myMgAdapt->setMedFileIn(str);
167 char* MG_ADAPT_i::getMedFileIn()
169 return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
171 void MG_ADAPT_i::setMedFileOut(const char* str)
173 myMgAdapt->setMedFileOut(str);
175 char* MG_ADAPT_i::getMedFileOut()
177 return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
179 void MG_ADAPT_i::setMeshName(const char* str)
181 myMgAdapt->setMeshName(str);
183 char* MG_ADAPT_i::getMeshName()
185 return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
187 void MG_ADAPT_i::setMeshNameOut(const char* str)
189 myMgAdapt->setMeshNameOut(str);
191 char* MG_ADAPT_i::getMeshNameOut()
193 return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
195 void MG_ADAPT_i::setMeshOutMed(bool mybool)
197 myMgAdapt->setMeshOutMed(mybool);
199 bool MG_ADAPT_i::getMeshOutMed()
201 return myMgAdapt->getMeshOutMed();
203 void MG_ADAPT_i::setPublish(bool mybool)
205 myMgAdapt->setPublish(mybool);
207 bool MG_ADAPT_i::getPublish()
209 return myMgAdapt->getPublish();
211 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
213 myMgAdapt->setFieldName(str);
215 char* MG_ADAPT_i::getSizeMapFieldName()
217 return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
219 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
221 myMgAdapt->setTimeStep(t);
223 CORBA::Long MG_ADAPT_i::getTimeStep()
225 return myMgAdapt->getTimeStep();
227 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
229 myMgAdapt->setChosenTimeStepRank();
230 myMgAdapt->setRankTimeStep(t, r);
232 CORBA::Long MG_ADAPT_i::getRank()
234 return myMgAdapt->getRank();
236 void MG_ADAPT_i::setTimeStepRankLast()
238 myMgAdapt->setTimeStepRankLast();
240 void MG_ADAPT_i::setNoTimeStep()
242 myMgAdapt->setNoTimeStep();
244 void MG_ADAPT_i::setLogFile(const char* str)
246 myMgAdapt->setLogFile(str);
248 char* MG_ADAPT_i::getLogFile()
250 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
253 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
255 myMgAdapt->setVerbosityLevel(v);
257 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
259 return myMgAdapt->getVerbosityLevel();
261 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
263 myMgAdapt->setRemoveOnSuccess(mybool);
265 bool MG_ADAPT_i::getRemoveOnSuccess()
267 return myMgAdapt->getRemoveOnSuccess();
269 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
271 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
272 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
273 copyHypothesisDataFromImpl(from, result);
276 void MG_ADAPT_i::setUseLocalMap(bool mybool)
278 myMgAdapt->setUseLocalMap(mybool);
280 bool MG_ADAPT_i::getUseLocalMap()
282 return myMgAdapt->getUseLocalMap();
284 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
286 myMgAdapt->setUseBackgroundMap(mybool);
288 bool MG_ADAPT_i::getUseBackgroundMap()
290 return myMgAdapt->getUseBackgroundMap();
292 void MG_ADAPT_i::setUseConstantValue(bool mybool)
294 myMgAdapt->setUseConstantValue(mybool);
296 bool MG_ADAPT_i::getUseConstantValue()
298 return myMgAdapt->getUseConstantValue();
300 void MG_ADAPT_i::setConstantSize(double value)
302 myMgAdapt->setConstantValue(value);
304 double MG_ADAPT_i::getConstantSize()
306 return myMgAdapt->getConstantValue();
308 void MG_ADAPT_i::setSizeMapFile(const char* str)
310 myMgAdapt->setSizeMapFile(str);
312 char* MG_ADAPT_i::getSizeMapFile()
314 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
316 void MG_ADAPT_i::setFromMedFile(bool mybool)
318 myMgAdapt->setFromMedFile(mybool);
320 bool MG_ADAPT_i::isFromMedFile()
322 return myMgAdapt->isFromMedFile();
325 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
327 myMgAdapt->setKeepWorkingFiles(mybool);
329 bool MG_ADAPT_i::getKeepWorkingFiles()
331 return myMgAdapt->getKeepWorkingFiles();
334 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
335 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
337 void MG_ADAPT_i::setSizeMapType(const char* type)
339 setUseLocalMap(false);
340 setUseBackgroundMap(false);
341 setUseConstantValue(false);
343 if (!strcmp("Local", type))
344 setUseLocalMap(true);
345 else if (!strcmp("Background", type))
346 setUseBackgroundMap(true);
348 setUseConstantValue(true);
350 void MG_ADAPT_i::setWorkingDir(const char* dir)
352 myMgAdapt->setWorkingDir(dir);
354 char* MG_ADAPT_i::getWorkingDir()
356 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
358 bool MG_ADAPT_i::setAll()
360 return myMgAdapt->setAll();
362 char* MG_ADAPT_i::getCommandToRun()
364 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
367 // macro used to initialize excStr by exception description
368 // returned by SMESH_CATCH( SMESH::returnError )
370 #define SMESH_CAUGHT excStr =
372 void MG_ADAPT_i::compute()
374 SMESH::TPythonDump noDumpSoFar;
380 myMgAdapt->compute(errStr);
382 SMESH_CATCH( SMESH::returnError );
384 SMESH_Comment errMsg;
385 if ( !excStr.empty() )
387 errMsg << "Exception thrown on MG_ADAPT_i::compute invocation with error message \""
388 << errStr << "\" with exception \"" << excStr << "\"";
390 else if ( !errStr.empty() )
392 errMsg << "MG_ADAPT_i::compute invocation returned error message \"" << errStr << "\"";
394 if ( !errMsg.empty() )
396 THROW_SALOME_CORBA_EXCEPTION( errMsg.c_str(), SALOME::INTERNAL_ERROR);
399 if(myMgAdapt->getPublish())
401 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
402 SMESH::DriverMED_ReadStatus theStatus;
403 smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
409 char* MG_ADAPT_i::getErrMsg()
411 return CORBA::string_dup(errStr.c_str());
413 char* MG_ADAPT_i::getFileName()
415 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
417 char* MG_ADAPT_i::getExeName()
419 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
421 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
423 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
424 copyHypothesisDataToImpl(data, baseData);
425 myMgAdapt->copyMgAdaptHypothesisData(baseData);
429 //~void MG_ADAPT_i::checkDirPath(char*& str)
431 //~myMgAdapt->checkDirPath(str);
434 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
436 return myMgAdapt->hasOptionDefined(optionName);
438 void MG_ADAPT_i::setOptionValue(const char* optionName,
439 const char* optionValue)
442 myMgAdapt->setOptionValue(optionName, optionValue);
443 SMESH_CATCH( SMESH::throwCorbaException );
446 char* MG_ADAPT_i::getOptionValue(const char* optionName,
450 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
451 SMESH_CATCH( SMESH::throwCorbaException );
454 SMESH::string_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
456 SMESH::string_array_var result = new SMESH::string_array();
457 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
458 result->length((CORBA::ULong) vals.size()) ;
459 for (CORBA::ULong i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
460 return result._retn();
462 SMESH::string_array* MG_ADAPT_i::getOptionValuesStrVec()
465 SMESH::string_array_var result = new SMESH::string_array();
466 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
467 result->length((CORBA::ULong) vals.size());
468 for (CORBA::ULong i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
469 return result._retn();
472 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
474 myMgAdapt->setPrintLogInFile(mybool);
476 bool MG_ADAPT_i::getPrintLogInFile()
478 return myMgAdapt->getPrintLogInFile();
480 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
481 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
483 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
487 medFileBackground="";
489 //~myMesh = CORBA::nil;
492 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
494 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
496 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
500 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
504 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
506 medFileBackground = f;
508 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
511 mg->setMedFileIn(medFileIn.c_str());
512 mg->setMedFileOut(medFileOut.c_str());
513 mg->setSizeMapFile(medFileBackground.c_str());
514 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
515 hypothesis->Register();
517 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
519 SMESH::TPythonDump noDumpSoFar;
521 if(!checkMeshFileIn()){
522 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
525 hypothesis->setPublish(publish);
526 hypothesis->compute();
530 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
532 SMESH::TPythonDump noDumpSoFar;
534 bool ret = false; // 1 ok , 0 nook
535 if ( !( ret = SMESH_File( medFileIn ).exists()))
537 if(!myMesh->_is_nil())
539 bool toOverwrite = true;
540 bool toFindOutDim = true;
541 medFileIn = (CORBA::String_var( hypothesis->getFileName() )).in();
543 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
544 hypothesis->setMedFileIn(medFileIn.c_str());