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")){
115 SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i();
116 SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this();
117 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();
311 void MG_ADAPT_i::setConstantSize(double value)
313 myMgAdapt->setConstantValue(value);
315 double MG_ADAPT_i::getConstantSize()
317 return myMgAdapt->getConstantValue();
319 void MG_ADAPT_i::setSizeMapFile(const char* str)
321 myMgAdapt->setSizeMapFile(str);
323 char* MG_ADAPT_i::getSizeMapFile()
325 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
327 void MG_ADAPT_i::setFromMedFile(bool mybool)
329 myMgAdapt->setFromMedFile(mybool);
331 bool MG_ADAPT_i::isFromMedFile()
333 return myMgAdapt->isFromMedFile();
336 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
338 myMgAdapt->setKeepWorkingFiles(mybool);
340 bool MG_ADAPT_i::getKeepWorkingFiles()
342 return myMgAdapt->getKeepWorkingFiles();
345 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
346 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
348 void MG_ADAPT_i::setSizeMapType(const char* type)
350 setUseLocalMap(false);
351 setUseBackgroundMap(false);
352 setUseConstantValue(false);
354 if (!strcmp("Local", type))
355 setUseLocalMap(true);
356 else if (!strcmp("Background", type))
357 setUseBackgroundMap(true);
359 setUseConstantValue(true);
361 void MG_ADAPT_i::setWorkingDir(const char* dir)
363 myMgAdapt->setWorkingDir(dir);
365 char* MG_ADAPT_i::getWorkingDir()
367 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
369 bool MG_ADAPT_i::setAll()
371 return myMgAdapt->setAll();
373 char* MG_ADAPT_i::getCommandToRun()
375 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
378 //~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr)
380 //~std::string err("");
381 //~CORBA::Long ret = myMgAdapt->compute(err);
382 //~errStr = err.c_str();
385 CORBA::Long MG_ADAPT_i::compute()
391 ret = myMgAdapt->compute(errStr);
393 catch (const std::exception& e)
398 if(ret!=-1 && myMgAdapt->getPublish())
400 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
401 SMESH::DriverMED_ReadStatus theStatus;
402 smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
404 //~errStr = err.c_str();
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) throw (std::invalid_argument)
439 myMgAdapt->setOptionValue(optionName, optionValue);
442 char* MG_ADAPT_i::getOptionValue(const char* optionName,
443 bool& isDefault) throw (std::invalid_argument)
445 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
447 str_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
449 SMESH::str_array_var result = new SMESH::str_array();
450 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
451 result->length(vals.size());
452 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
453 return result._retn();
455 str_array* MG_ADAPT_i::getOptionValuesStrVec()
458 SMESH::str_array_var result = new SMESH::str_array();
459 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
460 result->length(vals.size());
461 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
462 return result._retn();
465 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
467 myMgAdapt->setPrintLogInFile(mybool);
469 bool MG_ADAPT_i::getPrintLogInFile()
471 return myMgAdapt->getPrintLogInFile();
473 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
474 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
476 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
480 medFileBackground="";
482 //~myMesh = CORBA::nil;
485 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
487 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
489 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
493 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
497 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
499 medFileBackground = f;
501 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
504 mg->setMedFileIn(medFileIn.c_str());
505 mg->setMedFileOut(medFileOut.c_str());
506 mg->setSizeMapFile(medFileBackground.c_str());
507 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
509 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
511 if(!checkMeshFileIn()){
512 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
515 hypothesis->setPublish(publish);
516 return hypothesis->compute();
519 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
521 bool ret = false; // 1 ok , 0 nook
522 if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
524 if(!myMesh->_is_nil())
526 bool toOverwrite = true;
527 bool toFindOutDim = true;
528 medFileIn = hypothesis->getFileName();
530 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
531 hypothesis->setMedFileIn(medFileIn.c_str());