1 // Copyright (C) 2011-2020 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"
21 //~#include "ADAPT_Gen_i.hxx"
23 #include "SMESH_Gen_i.hxx"
24 #include <SMESH_Gen.hxx>
25 #include <SALOMEconfig.h>
26 #include CORBA_CLIENT_HEADER(SALOMEDS)
27 //~#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
28 //~#include CORBA_CLIENT_HEADER(SMESH_Gen)
31 //=============================================================================
33 * SMESH_Gen_i::CreateMG_ADAPT
35 * Create measurement instance
37 //=============================================================================
40 using namespace SMESH;
41 void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const
43 to->myFileInDir = from.myFileInDir;
44 to->myMeshFileIn = from.myMeshFileIn;
45 to->myMeshFileBackground = from.myMeshFileBackground;
46 to->myOutMeshName = from.myOutMeshName;
47 to->myMeshFileOut = from.myMeshFileOut;
48 to->myFileOutDir = from.myFileOutDir;
49 to->myFileSizeMapDir = from.myFileSizeMapDir;
50 to->myFieldName = from.myFieldName;
51 to->fromMedFile = from.fromMedFile;
52 to->myPublish = from.myPublish;
53 to->myMeshOutMed = from.myMeshOutMed;
54 to->myUseLocalMap = from.myUseLocalMap;
55 to->myUseBackgroundMap = from.myUseBackgroundMap;
56 to->myUseConstantValue = from.myUseConstantValue;
57 to->myConstantValue = from.myConstantValue;
58 to->myTimeStep = from.myTimeStep;
59 to->myRank = from.myRank;
60 to->myUseNoTimeStep = from.myUseNoTimeStep;
61 to->myUseLastTimeStep = from.myUseLastTimeStep;
62 to->myUseChosenTimeStep = from.myUseChosenTimeStep;
63 to->myWorkingDir = from.myWorkingDir;
64 to->myLogFile = from.myLogFile;
65 to->myPrintLogInFile = from.myPrintLogInFile;
66 to->myKeepFiles = from.myKeepFiles;
67 to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess;
68 to->myVerboseLevel = from.myVerboseLevel;
70 void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const
72 to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str());
73 to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str());
74 to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str());
75 to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str());
76 to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str());
77 to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str());
78 to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str());
79 to->myFieldName = CORBA::string_dup(from->myFieldName.c_str());
80 to->fromMedFile = from->fromMedFile;
81 to->myPublish = from->myPublish;
82 to->myMeshOutMed = from->myMeshOutMed;
83 to->myUseLocalMap = from->myUseLocalMap;
84 to->myUseBackgroundMap = from->myUseBackgroundMap;
85 to->myUseConstantValue = from->myUseConstantValue;
86 to->myConstantValue = from->myConstantValue;
87 to->myTimeStep = from->myTimeStep;
88 to->myRank = from->myRank;
89 to->myUseNoTimeStep = from->myUseNoTimeStep;
90 to->myUseLastTimeStep = from->myUseLastTimeStep;
91 to->myUseChosenTimeStep = from->myUseChosenTimeStep;
92 to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str());
93 to->myLogFile = CORBA::string_dup(from->myLogFile.c_str());
94 to->myPrintLogInFile = from->myPrintLogInFile;
95 to->myKeepFiles = from->myKeepFiles;
96 to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
97 to->myVerboseLevel = from->myVerboseLevel;
99 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT()
101 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
102 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
103 return anObj._retn();
105 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
107 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
108 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
109 return anObj._retn();
111 SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
114 if (!strcmp(adaptationType, "MG_Adapt"))
116 SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i();
117 SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this();
118 return anObj._retn();
122 //~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT()
125 //~SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
126 //~SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i(smeshGen_i->GetPOA());
127 //~SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
128 //~return anObj._retn();
130 //=============================================================================
132 * standard constructor
134 //=============================================================================
135 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
137 myMgAdapt = new ::MG_ADAPT::MgAdapt();
139 //~MG_ADAPT_i::MG_ADAPT_i(PortableServer::POA_var myPoa): SALOME::GenericObj_i( myPoa )
141 //~myMgAdapt = new ::MG_ADAPT::MgAdapt();
144 //=============================================================================
146 * standard constructor
148 //=============================================================================
149 //~MG_ADAPT_i::MG_ADAPT_i( CORBA::ORB_ptr orb,
150 //~ADAPT::ADAPT_Gen_var engine )
155 //~myMgAdapt = new MgAdapt();
158 //=============================================================================
160 * standard destructor
162 //=============================================================================
163 MG_ADAPT_i::~MG_ADAPT_i()
166 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
168 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
169 copyHypothesisDataToImpl(data, baseData);
170 myMgAdapt->setData(baseData);
173 void MG_ADAPT_i::setMedFileIn(const char* str)
175 myMgAdapt->setMedFileIn(str);
177 char* MG_ADAPT_i::getMedFileIn()
179 return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
181 void MG_ADAPT_i::setMedFileOut(const char* str)
183 myMgAdapt->setMedFileOut(str);
185 char* MG_ADAPT_i::getMedFileOut()
187 return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
189 void MG_ADAPT_i::setMeshName(const char* str)
191 myMgAdapt->setMeshName(str);
193 char* MG_ADAPT_i::getMeshName()
195 return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
197 void MG_ADAPT_i::setMeshNameOut(const char* str)
199 myMgAdapt->setMeshNameOut(str);
201 char* MG_ADAPT_i::getMeshNameOut()
203 return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
205 void MG_ADAPT_i::setMeshOutMed(bool mybool)
207 myMgAdapt->setMeshOutMed(mybool);
209 bool MG_ADAPT_i::getMeshOutMed()
211 return myMgAdapt->getMeshOutMed();
213 void MG_ADAPT_i::setPublish(bool mybool)
215 myMgAdapt->setPublish(mybool);
217 bool MG_ADAPT_i::getPublish()
219 return myMgAdapt->getPublish();
221 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
223 myMgAdapt->setFieldName(str);
225 char* MG_ADAPT_i::getSizeMapFieldName()
227 return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
229 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
231 myMgAdapt->setTimeStep(t);
233 CORBA::Long MG_ADAPT_i::getTimeStep()
235 return myMgAdapt->getTimeStep();
237 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
239 myMgAdapt->setChosenTimeStepRank();
240 myMgAdapt->setRankTimeStep(t, r);
242 CORBA::Long MG_ADAPT_i::getRank()
244 return myMgAdapt->getRank();
246 void MG_ADAPT_i::setTimeStepRankLast()
248 myMgAdapt->setTimeStepRankLast();
250 void MG_ADAPT_i::setNoTimeStep()
252 myMgAdapt->setNoTimeStep();
254 void MG_ADAPT_i::setLogFile(const char* str)
256 myMgAdapt->setLogFile(str);
258 char* MG_ADAPT_i::getLogFile()
260 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
263 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
265 myMgAdapt->setVerbosityLevel(v);
267 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
269 return myMgAdapt->getVerbosityLevel();
271 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
273 myMgAdapt->setRemoveOnSuccess(mybool);
275 bool MG_ADAPT_i::getRemoveOnSuccess()
277 myMgAdapt->getRemoveOnSuccess();
279 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
281 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
282 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
283 copyHypothesisDataFromImpl(from, result);
286 void MG_ADAPT_i::setUseLocalMap(bool mybool)
288 myMgAdapt->setUseLocalMap(mybool);
290 bool MG_ADAPT_i::getUseLocalMap()
292 return myMgAdapt->getUseLocalMap();
294 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
296 myMgAdapt->setUseBackgroundMap(mybool);
298 bool MG_ADAPT_i::getUseBackgroundMap()
300 return myMgAdapt->getUseBackgroundMap();
302 void MG_ADAPT_i::setUseConstantValue(bool mybool)
304 myMgAdapt->setUseConstantValue(mybool);
306 bool MG_ADAPT_i::getUseConstantValue()
308 return myMgAdapt->getUseConstantValue();
310 void MG_ADAPT_i::setConstantSize(double value)
312 myMgAdapt->setConstantValue(value);
314 double MG_ADAPT_i::getConstantSize()
316 return myMgAdapt->getConstantValue();
318 void MG_ADAPT_i::setSizeMapFile(const char* str)
320 myMgAdapt->setSizeMapFile(str);
322 char* MG_ADAPT_i::getSizeMapFile()
324 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
326 void MG_ADAPT_i::setFromMedFile(bool mybool)
328 myMgAdapt->setFromMedFile(mybool);
330 bool MG_ADAPT_i::isFromMedFile()
332 return myMgAdapt->isFromMedFile();
335 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
337 myMgAdapt->setKeepWorkingFiles(mybool);
339 bool MG_ADAPT_i::getKeepWorkingFiles()
341 return myMgAdapt->getKeepWorkingFiles();
344 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
345 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
347 void MG_ADAPT_i::setSizeMapType(const char* type)
349 setUseLocalMap(false);
350 setUseBackgroundMap(false);
351 setUseConstantValue(false);
353 if (!strcmp("Local", type))
354 setUseLocalMap(true);
355 else if (!strcmp("Background", type))
356 setUseBackgroundMap(true);
358 setUseConstantValue(true);
360 void MG_ADAPT_i::setWorkingDir(const char* dir)
362 myMgAdapt->setWorkingDir(dir);
364 char* MG_ADAPT_i::getWorkingDir()
366 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
368 bool MG_ADAPT_i::setAll()
370 return myMgAdapt->setAll();
372 char* MG_ADAPT_i::getCommandToRun()
374 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
377 //~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr)
379 //~std::string err("");
380 //~CORBA::Long ret = myMgAdapt->compute(err);
381 //~errStr = err.c_str();
384 CORBA::Long MG_ADAPT_i::compute()
390 ret = myMgAdapt->compute(errStr);
392 catch (const std::exception& e)
397 if(ret!=-1 && 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);
403 //~errStr = err.c_str();
406 char* MG_ADAPT_i::getErrMsg()
408 return CORBA::string_dup(errStr.c_str());
410 char* MG_ADAPT_i::getFileName()
412 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
414 char* MG_ADAPT_i::getExeName()
416 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
418 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
420 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
421 copyHypothesisDataToImpl(data, baseData);
422 myMgAdapt->copyMgAdaptHypothesisData(baseData);
426 //~void MG_ADAPT_i::checkDirPath(char*& str)
428 //~myMgAdapt->checkDirPath(str);
431 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
433 return myMgAdapt->hasOptionDefined(optionName);
435 void MG_ADAPT_i::setOptionValue(const char* optionName,
436 const char* optionValue) throw (std::invalid_argument)
438 myMgAdapt->setOptionValue(optionName, optionValue);
441 char* MG_ADAPT_i::getOptionValue(const char* optionName,
442 bool& isDefault) throw (std::invalid_argument)
444 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
446 str_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
448 SMESH::str_array_var result = new SMESH::str_array();
449 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
450 result->length(vals.size());
451 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
452 return result._retn();
454 str_array* MG_ADAPT_i::getOptionValuesStrVec()
457 SMESH::str_array_var result = new SMESH::str_array();
458 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
459 result->length(vals.size());
460 for (int 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);
508 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
510 if(!checkMeshFileIn()){
511 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
514 hypothesis->setPublish(publish);
515 return hypothesis->compute();
518 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
520 bool ret = false; // 1 ok , 0 nook
521 if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
523 if(!myMesh->_is_nil())
525 bool toOverwrite = true;
526 bool toFindOutDim = true;
527 medFileIn = hypothesis->getFileName();
529 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
530 hypothesis->setMedFileIn(medFileIn.c_str());