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 "MG_ADAPT.hxx"
23 #include "SMESH_File.hxx"
24 #include "SMESH_Gen_i.hxx"
25 #include "SMESH_PythonDump.hxx"
26 #include "SMESH_TryCatch.hxx"
28 using namespace SMESH;
30 void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const
32 to->myFileInDir = from.myFileInDir;
33 to->myMeshFileIn = from.myMeshFileIn;
34 to->myMeshFileBackground = from.myMeshFileBackground;
35 to->myOutMeshName = from.myOutMeshName;
36 to->myMeshFileOut = from.myMeshFileOut;
37 to->myFileOutDir = from.myFileOutDir;
38 to->myFileSizeMapDir = from.myFileSizeMapDir;
39 to->myFieldName = from.myFieldName;
40 to->fromMedFile = from.fromMedFile;
41 to->myPublish = from.myPublish;
42 to->myMeshOutMed = from.myMeshOutMed;
43 to->myUseLocalMap = from.myUseLocalMap;
44 to->myUseBackgroundMap = from.myUseBackgroundMap;
45 to->myUseConstantValue = from.myUseConstantValue;
46 to->myConstantValue = from.myConstantValue;
47 to->myTimeStep = from.myTimeStep;
48 to->myRank = from.myRank;
49 to->myUseNoTimeStep = from.myUseNoTimeStep;
50 to->myUseLastTimeStep = from.myUseLastTimeStep;
51 to->myUseChosenTimeStep = from.myUseChosenTimeStep;
52 to->myWorkingDir = from.myWorkingDir;
53 to->myLogFile = from.myLogFile;
54 to->myPrintLogInFile = from.myPrintLogInFile;
55 to->myKeepFiles = from.myKeepFiles;
56 to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess;
57 to->myVerboseLevel = from.myVerboseLevel;
59 void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const
61 to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str());
62 to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str());
63 to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str());
64 to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str());
65 to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str());
66 to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str());
67 to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str());
68 to->myFieldName = CORBA::string_dup(from->myFieldName.c_str());
69 to->fromMedFile = from->fromMedFile;
70 to->myPublish = from->myPublish;
71 to->myMeshOutMed = from->myMeshOutMed;
72 to->myUseLocalMap = from->myUseLocalMap;
73 to->myUseBackgroundMap = from->myUseBackgroundMap;
74 to->myUseConstantValue = from->myUseConstantValue;
75 to->myConstantValue = from->myConstantValue;
76 to->myTimeStep = from->myTimeStep;
77 to->myRank = from->myRank;
78 to->myUseNoTimeStep = from->myUseNoTimeStep;
79 to->myUseLastTimeStep = from->myUseLastTimeStep;
80 to->myUseChosenTimeStep = from->myUseChosenTimeStep;
81 to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str());
82 to->myLogFile = CORBA::string_dup(from->myLogFile.c_str());
83 to->myPrintLogInFile = from->myPrintLogInFile;
84 to->myKeepFiles = from->myKeepFiles;
85 to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
86 to->myVerboseLevel = from->myVerboseLevel;
89 //=============================================================================
91 * SMESH_Gen_i::CreateMG_ADAPT
93 * Create measurement instance
95 //=============================================================================
97 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT()
99 #ifndef DISABLE_MG_ADAPT
100 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
101 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
102 return anObj._retn();
104 return SMESH::MG_ADAPT_ptr();
107 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
109 #ifndef DISABLE_MG_ADAPT
110 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
111 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
112 return anObj._retn();
114 return SMESH::MG_ADAPT_ptr();
117 SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
119 #ifndef DISABLE_MG_ADAPT
120 if (!strcmp(adaptationType, "MG_Adapt"))
122 SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i();
123 SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this();
124 return anObj._retn();
127 return SMESH::MG_ADAPT_OBJECT_ptr();
129 //=============================================================================
131 * standard constructor
133 //=============================================================================
134 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
136 myMgAdapt = new ::MG_ADAPT::MgAdapt();
139 //=============================================================================
141 * standard destructor
143 //=============================================================================
144 MG_ADAPT_i::~MG_ADAPT_i()
148 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
150 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
151 copyHypothesisDataToImpl(data, baseData);
152 myMgAdapt->setData(baseData);
155 void MG_ADAPT_i::setMedFileIn(const char* str)
157 myMgAdapt->setMedFileIn(str);
159 char* MG_ADAPT_i::getMedFileIn()
161 return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
163 void MG_ADAPT_i::setMedFileOut(const char* str)
165 myMgAdapt->setMedFileOut(str);
167 char* MG_ADAPT_i::getMedFileOut()
169 return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
171 void MG_ADAPT_i::setMeshName(const char* str)
173 myMgAdapt->setMeshName(str);
175 char* MG_ADAPT_i::getMeshName()
177 return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
179 void MG_ADAPT_i::setMeshNameOut(const char* str)
181 myMgAdapt->setMeshNameOut(str);
183 char* MG_ADAPT_i::getMeshNameOut()
185 return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
187 void MG_ADAPT_i::setMeshOutMed(bool mybool)
189 myMgAdapt->setMeshOutMed(mybool);
191 bool MG_ADAPT_i::getMeshOutMed()
193 return myMgAdapt->getMeshOutMed();
195 void MG_ADAPT_i::setPublish(bool mybool)
197 myMgAdapt->setPublish(mybool);
199 bool MG_ADAPT_i::getPublish()
201 return myMgAdapt->getPublish();
203 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
205 myMgAdapt->setFieldName(str);
207 char* MG_ADAPT_i::getSizeMapFieldName()
209 return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
211 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
213 myMgAdapt->setTimeStep(t);
215 CORBA::Long MG_ADAPT_i::getTimeStep()
217 return myMgAdapt->getTimeStep();
219 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
221 myMgAdapt->setChosenTimeStepRank();
222 myMgAdapt->setRankTimeStep(t, r);
224 CORBA::Long MG_ADAPT_i::getRank()
226 return myMgAdapt->getRank();
228 void MG_ADAPT_i::setTimeStepRankLast()
230 myMgAdapt->setTimeStepRankLast();
232 void MG_ADAPT_i::setNoTimeStep()
234 myMgAdapt->setNoTimeStep();
236 void MG_ADAPT_i::setLogFile(const char* str)
238 myMgAdapt->setLogFile(str);
240 char* MG_ADAPT_i::getLogFile()
242 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
245 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
247 myMgAdapt->setVerbosityLevel(v);
249 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
251 return myMgAdapt->getVerbosityLevel();
253 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
255 myMgAdapt->setRemoveOnSuccess(mybool);
257 bool MG_ADAPT_i::getRemoveOnSuccess()
259 return myMgAdapt->getRemoveOnSuccess();
261 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
263 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
264 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
265 copyHypothesisDataFromImpl(from, result);
268 void MG_ADAPT_i::setUseLocalMap(bool mybool)
270 myMgAdapt->setUseLocalMap(mybool);
272 bool MG_ADAPT_i::getUseLocalMap()
274 return myMgAdapt->getUseLocalMap();
276 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
278 myMgAdapt->setUseBackgroundMap(mybool);
280 bool MG_ADAPT_i::getUseBackgroundMap()
282 return myMgAdapt->getUseBackgroundMap();
284 void MG_ADAPT_i::setUseConstantValue(bool mybool)
286 myMgAdapt->setUseConstantValue(mybool);
288 bool MG_ADAPT_i::getUseConstantValue()
290 return myMgAdapt->getUseConstantValue();
292 void MG_ADAPT_i::setConstantSize(double value)
294 myMgAdapt->setConstantValue(value);
296 double MG_ADAPT_i::getConstantSize()
298 return myMgAdapt->getConstantValue();
300 void MG_ADAPT_i::setSizeMapFile(const char* str)
302 myMgAdapt->setSizeMapFile(str);
304 char* MG_ADAPT_i::getSizeMapFile()
306 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
308 void MG_ADAPT_i::setFromMedFile(bool mybool)
310 myMgAdapt->setFromMedFile(mybool);
312 bool MG_ADAPT_i::isFromMedFile()
314 return myMgAdapt->isFromMedFile();
317 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
319 myMgAdapt->setKeepWorkingFiles(mybool);
321 bool MG_ADAPT_i::getKeepWorkingFiles()
323 return myMgAdapt->getKeepWorkingFiles();
326 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
327 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
329 void MG_ADAPT_i::setSizeMapType(const char* type)
331 setUseLocalMap(false);
332 setUseBackgroundMap(false);
333 setUseConstantValue(false);
335 if (!strcmp("Local", type))
336 setUseLocalMap(true);
337 else if (!strcmp("Background", type))
338 setUseBackgroundMap(true);
340 setUseConstantValue(true);
342 void MG_ADAPT_i::setWorkingDir(const char* dir)
344 myMgAdapt->setWorkingDir(dir);
346 char* MG_ADAPT_i::getWorkingDir()
348 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
350 bool MG_ADAPT_i::setAll()
352 return myMgAdapt->setAll();
354 char* MG_ADAPT_i::getCommandToRun()
356 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
359 // macro used to initialize excStr by exception description
360 // returned by SMESH_CATCH( SMESH::returnError )
362 #define SMESH_CAUGHT excStr =
364 void MG_ADAPT_i::compute()
366 SMESH::TPythonDump noDumpSoFar;
372 myMgAdapt->compute(errStr);
374 SMESH_CATCH( SMESH::returnError );
376 SMESH_Comment errMsg;
377 if ( !excStr.empty() )
379 errMsg << "Exception thrown on MG_ADAPT_i::compute invocation with error message \""
380 << errStr << "\" with exception \"" << excStr << "\"";
382 else if ( !errStr.empty() )
384 errMsg << "MG_ADAPT_i::compute invocation returned error message \"" << errStr << "\"";
386 if ( !errMsg.empty() )
388 THROW_SALOME_CORBA_EXCEPTION( errMsg.c_str(), SALOME::INTERNAL_ERROR);
391 if(myMgAdapt->getPublish())
393 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
394 SMESH::DriverMED_ReadStatus theStatus;
395 smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
401 char* MG_ADAPT_i::getErrMsg()
403 return CORBA::string_dup(errStr.c_str());
405 char* MG_ADAPT_i::getFileName()
407 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
409 char* MG_ADAPT_i::getExeName()
411 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
413 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
415 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
416 copyHypothesisDataToImpl(data, baseData);
417 myMgAdapt->copyMgAdaptHypothesisData(baseData);
421 //~void MG_ADAPT_i::checkDirPath(char*& str)
423 //~myMgAdapt->checkDirPath(str);
426 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
428 return myMgAdapt->hasOptionDefined(optionName);
430 void MG_ADAPT_i::setOptionValue(const char* optionName,
431 const char* optionValue)
434 myMgAdapt->setOptionValue(optionName, optionValue);
435 SMESH_CATCH( SMESH::throwCorbaException );
438 char* MG_ADAPT_i::getOptionValue(const char* optionName,
442 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
443 SMESH_CATCH( SMESH::throwCorbaException );
446 SMESH::string_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
448 SMESH::string_array_var result = new SMESH::string_array();
449 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
450 result->length((CORBA::ULong) vals.size()) ;
451 for (CORBA::ULong i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
452 return result._retn();
454 SMESH::string_array* MG_ADAPT_i::getOptionValuesStrVec()
457 SMESH::string_array_var result = new SMESH::string_array();
458 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
459 result->length((CORBA::ULong) vals.size());
460 for (CORBA::ULong i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
461 return result._retn();
464 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
466 myMgAdapt->setPrintLogInFile(mybool);
468 bool MG_ADAPT_i::getPrintLogInFile()
470 return myMgAdapt->getPrintLogInFile();
472 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
473 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
475 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
479 medFileBackground="";
481 //~myMesh = CORBA::nil;
484 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
486 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
488 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
492 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
496 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
498 medFileBackground = f;
500 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
503 mg->setMedFileIn(medFileIn.c_str());
504 mg->setMedFileOut(medFileOut.c_str());
505 mg->setSizeMapFile(medFileBackground.c_str());
506 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
507 hypothesis->Register();
509 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
511 SMESH::TPythonDump noDumpSoFar;
513 if(!checkMeshFileIn()){
514 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
517 hypothesis->setPublish(publish);
518 hypothesis->compute();
522 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
524 SMESH::TPythonDump noDumpSoFar;
526 bool ret = false; // 1 ok , 0 nook
527 if ( !( ret = SMESH_File( medFileIn ).exists()))
529 if(!myMesh->_is_nil())
531 bool toOverwrite = true;
532 bool toFindOutDim = true;
533 medFileIn = (CORBA::String_var( hypothesis->getFileName() )).in();
535 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
536 hypothesis->setMedFileIn(medFileIn.c_str());