1 // Copyright (C) 2020-2021 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 if (!strcmp(adaptationType, "Uniform")) {
131 return CreateHOMARD_ADAPT();
133 return SMESH::MG_ADAPT_OBJECT_ptr();
135 //=============================================================================
137 * standard constructor
139 //=============================================================================
140 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
142 myMgAdapt = new ::MG_ADAPT::MgAdapt();
145 //=============================================================================
147 * standard destructor
149 //=============================================================================
150 MG_ADAPT_i::~MG_ADAPT_i()
154 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
156 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
157 copyHypothesisDataToImpl(data, baseData);
158 myMgAdapt->setData(baseData);
161 void MG_ADAPT_i::setMedFileIn(const char* str)
163 myMgAdapt->setMedFileIn(str);
165 char* MG_ADAPT_i::getMedFileIn()
167 return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
169 void MG_ADAPT_i::setMedFileOut(const char* str)
171 myMgAdapt->setMedFileOut(str);
173 char* MG_ADAPT_i::getMedFileOut()
175 return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
177 void MG_ADAPT_i::setMeshName(const char* str)
179 myMgAdapt->setMeshName(str);
181 char* MG_ADAPT_i::getMeshName()
183 return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
185 void MG_ADAPT_i::setMeshNameOut(const char* str)
187 myMgAdapt->setMeshNameOut(str);
189 char* MG_ADAPT_i::getMeshNameOut()
191 return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
193 void MG_ADAPT_i::setMeshOutMed(bool mybool)
195 myMgAdapt->setMeshOutMed(mybool);
197 bool MG_ADAPT_i::getMeshOutMed()
199 return myMgAdapt->getMeshOutMed();
201 void MG_ADAPT_i::setPublish(bool mybool)
203 myMgAdapt->setPublish(mybool);
205 bool MG_ADAPT_i::getPublish()
207 return myMgAdapt->getPublish();
209 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
211 myMgAdapt->setFieldName(str);
213 char* MG_ADAPT_i::getSizeMapFieldName()
215 return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
217 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
219 myMgAdapt->setTimeStep(t);
221 CORBA::Long MG_ADAPT_i::getTimeStep()
223 return myMgAdapt->getTimeStep();
225 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
227 myMgAdapt->setChosenTimeStepRank();
228 myMgAdapt->setRankTimeStep(t, r);
230 CORBA::Long MG_ADAPT_i::getRank()
232 return myMgAdapt->getRank();
234 void MG_ADAPT_i::setTimeStepRankLast()
236 myMgAdapt->setTimeStepRankLast();
238 void MG_ADAPT_i::setNoTimeStep()
240 myMgAdapt->setNoTimeStep();
242 void MG_ADAPT_i::setLogFile(const char* str)
244 myMgAdapt->setLogFile(str);
246 char* MG_ADAPT_i::getLogFile()
248 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
251 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
253 myMgAdapt->setVerbosityLevel(v);
255 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
257 return myMgAdapt->getVerbosityLevel();
259 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
261 myMgAdapt->setRemoveOnSuccess(mybool);
263 bool MG_ADAPT_i::getRemoveOnSuccess()
265 return myMgAdapt->getRemoveOnSuccess();
267 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
269 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
270 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
271 copyHypothesisDataFromImpl(from, result);
274 void MG_ADAPT_i::setUseLocalMap(bool mybool)
276 myMgAdapt->setUseLocalMap(mybool);
278 bool MG_ADAPT_i::getUseLocalMap()
280 return myMgAdapt->getUseLocalMap();
282 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
284 myMgAdapt->setUseBackgroundMap(mybool);
286 bool MG_ADAPT_i::getUseBackgroundMap()
288 return myMgAdapt->getUseBackgroundMap();
290 void MG_ADAPT_i::setUseConstantValue(bool mybool)
292 myMgAdapt->setUseConstantValue(mybool);
294 bool MG_ADAPT_i::getUseConstantValue()
296 return myMgAdapt->getUseConstantValue();
298 void MG_ADAPT_i::setConstantSize(double value)
300 myMgAdapt->setConstantValue(value);
302 double MG_ADAPT_i::getConstantSize()
304 return myMgAdapt->getConstantValue();
306 void MG_ADAPT_i::setSizeMapFile(const char* str)
308 myMgAdapt->setSizeMapFile(str);
310 char* MG_ADAPT_i::getSizeMapFile()
312 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
314 void MG_ADAPT_i::setFromMedFile(bool mybool)
316 myMgAdapt->setFromMedFile(mybool);
318 bool MG_ADAPT_i::isFromMedFile()
320 return myMgAdapt->isFromMedFile();
323 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
325 myMgAdapt->setKeepWorkingFiles(mybool);
327 bool MG_ADAPT_i::getKeepWorkingFiles()
329 return myMgAdapt->getKeepWorkingFiles();
332 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
333 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
335 void MG_ADAPT_i::setSizeMapType(const char* type)
337 setUseLocalMap(false);
338 setUseBackgroundMap(false);
339 setUseConstantValue(false);
341 if (!strcmp("Local", type))
342 setUseLocalMap(true);
343 else if (!strcmp("Background", type))
344 setUseBackgroundMap(true);
346 setUseConstantValue(true);
348 void MG_ADAPT_i::setWorkingDir(const char* dir)
350 myMgAdapt->setWorkingDir(dir);
352 char* MG_ADAPT_i::getWorkingDir()
354 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
356 bool MG_ADAPT_i::setAll()
358 return myMgAdapt->setAll();
360 char* MG_ADAPT_i::getCommandToRun()
362 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
365 // macro used to initialize excStr by exception description
366 // returned by SMESH_CATCH( SMESH::returnError )
368 #define SMESH_CAUGHT excStr =
370 void MG_ADAPT_i::compute()
372 SMESH::TPythonDump noDumpSoFar;
378 myMgAdapt->compute(errStr);
380 SMESH_CATCH( SMESH::returnError );
382 SMESH_Comment errMsg;
383 if ( !excStr.empty() )
385 errMsg << "Exception thrown on MG_ADAPT_i::compute invocation with error message \""
386 << errStr << "\" with exception \"" << excStr << "\"";
388 else if ( !errStr.empty() )
390 errMsg << "MG_ADAPT_i::compute invocation returned error message \"" << errStr << "\"";
392 if ( !errMsg.empty() )
394 THROW_SALOME_CORBA_EXCEPTION( errMsg.c_str(), SALOME::INTERNAL_ERROR);
397 if(myMgAdapt->getPublish())
399 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
400 SMESH::DriverMED_ReadStatus theStatus;
401 smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
407 char* MG_ADAPT_i::getErrMsg()
409 return CORBA::string_dup(errStr.c_str());
411 char* MG_ADAPT_i::getFileName()
413 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
415 char* MG_ADAPT_i::getExeName()
417 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
419 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
421 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
422 copyHypothesisDataToImpl(data, baseData);
423 myMgAdapt->copyMgAdaptHypothesisData(baseData);
427 //~void MG_ADAPT_i::checkDirPath(char*& str)
429 //~myMgAdapt->checkDirPath(str);
432 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
434 return myMgAdapt->hasOptionDefined(optionName);
436 void MG_ADAPT_i::setOptionValue(const char* optionName,
437 const char* optionValue)
440 myMgAdapt->setOptionValue(optionName, optionValue);
441 SMESH_CATCH( SMESH::throwCorbaException );
444 char* MG_ADAPT_i::getOptionValue(const char* optionName,
448 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
449 SMESH_CATCH( SMESH::throwCorbaException );
452 SMESH::string_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
454 SMESH::string_array_var result = new SMESH::string_array();
455 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
456 result->length((CORBA::ULong) vals.size()) ;
457 for (CORBA::ULong i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
458 return result._retn();
460 SMESH::string_array* MG_ADAPT_i::getOptionValuesStrVec()
463 SMESH::string_array_var result = new SMESH::string_array();
464 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
465 result->length((CORBA::ULong) vals.size());
466 for (CORBA::ULong i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
467 return result._retn();
470 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
472 myMgAdapt->setPrintLogInFile(mybool);
474 bool MG_ADAPT_i::getPrintLogInFile()
476 return myMgAdapt->getPrintLogInFile();
478 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
479 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
481 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
485 medFileBackground="";
487 //~myMesh = CORBA::nil;
490 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
492 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
494 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
498 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
502 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
504 medFileBackground = f;
506 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
509 mg->setMedFileIn(medFileIn.c_str());
510 mg->setMedFileOut(medFileOut.c_str());
511 mg->setSizeMapFile(medFileBackground.c_str());
512 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
513 hypothesis->Register();
515 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
517 SMESH::TPythonDump noDumpSoFar;
519 if(!checkMeshFileIn()){
520 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
523 hypothesis->setPublish(publish);
524 hypothesis->compute();
528 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
530 SMESH::TPythonDump noDumpSoFar;
532 bool ret = false; // 1 ok , 0 nook
533 if ( !( ret = SMESH_File( medFileIn ).exists()))
535 if(!myMesh->_is_nil())
537 bool toOverwrite = true;
538 bool toFindOutDim = true;
539 medFileIn = (CORBA::String_var( hypothesis->getFileName() )).in();
541 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
542 hypothesis->setMedFileIn(medFileIn.c_str());