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
21 // L'ordre de description des fonctions est le meme dans tous les fichiers
22 // HOMARD_aaaa.idl, HOMARD_aaaa.hxx, HOMARD_aaaa.cxx, HOMARD_aaaa_i.hxx, HOMARD_aaaa_i.cxx :
23 // 1. Les generalites : Name, Delete, DumpPython, Dump, Restore
24 // 2. Les caracteristiques
25 // 3. Le lien avec les autres structures
27 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
30 #include "MG_ADAPT_i.hxx"
31 //~#include "ADAPT_Gen_i.hxx"
33 #include "SMESH_Gen_i.hxx"
34 #include <SMESH_Gen.hxx>
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(SALOMEDS)
37 //~#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
38 //~#include CORBA_CLIENT_HEADER(SMESH_Gen)
41 //=============================================================================
43 * SMESH_Gen_i::CreateMG_ADAPT
45 * Create measurement instance
47 //=============================================================================
50 using namespace SMESH;
51 void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const
53 to->myFileInDir = from.myFileInDir;
54 to->myMeshFileIn = from.myMeshFileIn;
55 to->myMeshFileBackground = from.myMeshFileBackground;
56 to->myOutMeshName = from.myOutMeshName;
57 to->myMeshFileOut = from.myMeshFileOut;
58 to->myFileOutDir = from.myFileOutDir;
59 to->myFileSizeMapDir = from.myFileSizeMapDir;
60 to->myFieldName = from.myFieldName;
61 to->fromMedFile = from.fromMedFile;
62 to->myPublish = from.myPublish;
63 to->myMeshOutMed = from.myMeshOutMed;
64 to->myUseLocalMap = from.myUseLocalMap;
65 to->myUseBackgroundMap = from.myUseBackgroundMap;
66 to->myUseConstantValue = from.myUseConstantValue;
67 to->myConstantValue = from.myConstantValue;
68 to->myTimeStep = from.myTimeStep;
69 to->myRank = from.myRank;
70 to->myUseNoTimeStep = from.myUseNoTimeStep;
71 to->myUseLastTimeStep = from.myUseLastTimeStep;
72 to->myUseChosenTimeStep = from.myUseChosenTimeStep;
73 to->myWorkingDir = from.myWorkingDir;
74 to->myLogFile = from.myLogFile;
75 to->myPrintLogInFile = from.myPrintLogInFile;
76 to->myKeepFiles = from.myKeepFiles;
77 to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess;
78 to->myVerboseLevel = from.myVerboseLevel;
80 void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const
82 to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str());
83 to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str());
84 to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str());
85 to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str());
86 to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str());
87 to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str());
88 to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str());
89 to->myFieldName = CORBA::string_dup(from->myFieldName.c_str());
90 to->fromMedFile = from->fromMedFile;
91 to->myPublish = from->myPublish;
92 to->myMeshOutMed = from->myMeshOutMed;
93 to->myUseLocalMap = from->myUseLocalMap;
94 to->myUseBackgroundMap = from->myUseBackgroundMap;
95 to->myUseConstantValue = from->myUseConstantValue;
96 to->myConstantValue = from->myConstantValue;
97 to->myTimeStep = from->myTimeStep;
98 to->myRank = from->myRank;
99 to->myUseNoTimeStep = from->myUseNoTimeStep;
100 to->myUseLastTimeStep = from->myUseLastTimeStep;
101 to->myUseChosenTimeStep = from->myUseChosenTimeStep;
102 to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str());
103 to->myLogFile = CORBA::string_dup(from->myLogFile.c_str());
104 to->myPrintLogInFile = from->myPrintLogInFile;
105 to->myKeepFiles = from->myKeepFiles;
106 to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
107 to->myVerboseLevel = from->myVerboseLevel;
109 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT()
111 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
112 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
113 return anObj._retn();
115 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
117 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
118 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
119 return anObj._retn();
121 SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
124 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();
132 //~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT()
135 //~SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
136 //~SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i(smeshGen_i->GetPOA());
137 //~SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
138 //~return anObj._retn();
140 //=============================================================================
142 * standard constructor
144 //=============================================================================
145 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
147 myMgAdapt = new ::MG_ADAPT::MgAdapt();
149 //~MG_ADAPT_i::MG_ADAPT_i(PortableServer::POA_var myPoa): SALOME::GenericObj_i( myPoa )
151 //~myMgAdapt = new ::MG_ADAPT::MgAdapt();
154 //=============================================================================
156 * standard constructor
158 //=============================================================================
159 //~MG_ADAPT_i::MG_ADAPT_i( CORBA::ORB_ptr orb,
160 //~ADAPT::ADAPT_Gen_var engine )
165 //~myMgAdapt = new MgAdapt();
168 //=============================================================================
170 * standard destructor
172 //=============================================================================
173 MG_ADAPT_i::~MG_ADAPT_i()
176 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
178 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
179 copyHypothesisDataToImpl(data, baseData);
180 myMgAdapt->setData(baseData);
183 void MG_ADAPT_i::setMedFileIn(const char* str)
185 myMgAdapt->setMedFileIn(str);
187 char* MG_ADAPT_i::getMedFileIn()
189 return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
191 void MG_ADAPT_i::setMedFileOut(const char* str)
193 myMgAdapt->setMedFileOut(str);
195 char* MG_ADAPT_i::getMedFileOut()
197 return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
199 void MG_ADAPT_i::setMeshName(const char* str)
201 myMgAdapt->setMeshName(str);
203 char* MG_ADAPT_i::getMeshName()
205 return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
207 void MG_ADAPT_i::setMeshNameOut(const char* str)
209 myMgAdapt->setMeshNameOut(str);
211 char* MG_ADAPT_i::getMeshNameOut()
213 return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
215 void MG_ADAPT_i::setMeshOutMed(bool mybool)
217 myMgAdapt->setMeshOutMed(mybool);
219 bool MG_ADAPT_i::getMeshOutMed()
221 return myMgAdapt->getMeshOutMed();
223 void MG_ADAPT_i::setPublish(bool mybool)
225 myMgAdapt->setPublish(mybool);
227 bool MG_ADAPT_i::getPublish()
229 return myMgAdapt->getPublish();
231 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
233 myMgAdapt->setFieldName(str);
235 char* MG_ADAPT_i::getSizeMapFieldName()
237 return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
239 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
241 myMgAdapt->setTimeStep(t);
243 CORBA::Long MG_ADAPT_i::getTimeStep()
245 return myMgAdapt->getTimeStep();
247 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
249 myMgAdapt->setRankTimeStep(t, r);
251 CORBA::Long MG_ADAPT_i::getRank()
253 return myMgAdapt->getRank();
255 void MG_ADAPT_i::setTimeStepRankLast()
257 myMgAdapt->setTimeStepRankLast();
259 void MG_ADAPT_i::setNoTimeStep()
261 myMgAdapt->setNoTimeStep();
263 void MG_ADAPT_i::setLogFile(const char* str)
265 myMgAdapt->setLogFile(str);
267 char* MG_ADAPT_i::getLogFile()
269 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
272 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
274 myMgAdapt->setVerbosityLevel(v);
276 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
278 return myMgAdapt->getVerbosityLevel();
280 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
282 myMgAdapt->setRemoveOnSuccess(mybool);
284 bool MG_ADAPT_i::getRemoveOnSuccess()
286 myMgAdapt->getRemoveOnSuccess();
288 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
290 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
291 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
292 copyHypothesisDataFromImpl(from, result);
295 void MG_ADAPT_i::setUseLocalMap(bool mybool)
297 myMgAdapt->setUseLocalMap(mybool);
299 bool MG_ADAPT_i::getUseLocalMap()
301 return myMgAdapt->getUseLocalMap();
303 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
305 myMgAdapt->setUseBackgroundMap(mybool);
307 bool MG_ADAPT_i::getUseBackgroundMap()
309 return myMgAdapt->getUseBackgroundMap();
311 void MG_ADAPT_i::setUseConstantValue(bool mybool)
313 myMgAdapt->setUseConstantValue(mybool);
315 bool MG_ADAPT_i::getUseConstantValue()
317 return myMgAdapt->getUseConstantValue();
320 void MG_ADAPT_i::setConstantSize(double value)
322 myMgAdapt->setConstantValue(value);
324 double MG_ADAPT_i::getConstantSize()
326 return myMgAdapt->getConstantValue();
328 void MG_ADAPT_i::setSizeMapFile(const char* str)
330 myMgAdapt->setSizeMapFile(str);
332 char* MG_ADAPT_i::getSizeMapFile()
334 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
336 void MG_ADAPT_i::setFromMedFile(bool mybool)
338 myMgAdapt->setFromMedFile(mybool);
340 bool MG_ADAPT_i::isFromMedFile()
342 return myMgAdapt->isFromMedFile();
345 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
347 myMgAdapt->setKeepWorkingFiles(mybool);
349 bool MG_ADAPT_i::getKeepWorkingFiles()
351 return myMgAdapt->getKeepWorkingFiles();
354 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
355 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
357 void MG_ADAPT_i::setSizeMapType(const char* type)
359 setUseLocalMap(false);
360 setUseBackgroundMap(false);
361 setUseConstantValue(false);
363 if (!strcmp("Local", type))
364 setUseLocalMap(true);
365 else if (!strcmp("Background", type))
366 setUseBackgroundMap(true);
368 setUseConstantValue(true);
370 void MG_ADAPT_i::setWorkingDir(const char* dir)
372 myMgAdapt->setWorkingDir(dir);
374 char* MG_ADAPT_i::getWorkingDir()
376 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
378 bool MG_ADAPT_i::setAll()
380 return myMgAdapt->setAll();
382 char* MG_ADAPT_i::getCommandToRun()
384 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
387 //~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr)
389 //~std::string err("");
390 //~CORBA::Long ret = myMgAdapt->compute(err);
391 //~errStr = err.c_str();
394 CORBA::Long MG_ADAPT_i::compute()
400 ret = myMgAdapt->compute(errStr);
402 catch (const std::exception& e)
407 //~errStr = err.c_str();
410 char* MG_ADAPT_i::getErrMsg()
412 return CORBA::string_dup(errStr.c_str());
414 char* MG_ADAPT_i::getFileName()
416 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
418 char* MG_ADAPT_i::getExeName()
420 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
422 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
424 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
425 copyHypothesisDataToImpl(data, baseData);
426 myMgAdapt->copyMgAdaptHypothesisData(baseData);
430 //~void MG_ADAPT_i::checkDirPath(char*& str)
432 //~myMgAdapt->checkDirPath(str);
435 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
437 return myMgAdapt->hasOptionDefined(optionName);
439 void MG_ADAPT_i::setOptionValue(const char* optionName,
440 const char* optionValue) throw (std::invalid_argument)
442 myMgAdapt->setOptionValue(optionName, optionValue);
445 char* MG_ADAPT_i::getOptionValue(const char* optionName,
446 bool& isDefault) throw (std::invalid_argument)
448 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
450 str_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
452 SMESH::str_array_var result = new SMESH::str_array();
453 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
454 result->length(vals.size());
455 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
456 return result._retn();
458 str_array* MG_ADAPT_i::getOptionValuesStrVec()
461 SMESH::str_array_var result = new SMESH::str_array();
462 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
463 result->length(vals.size());
464 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
465 return result._retn();
468 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
470 myMgAdapt->setPrintLogInFile(mybool);
472 bool MG_ADAPT_i::getPrintLogInFile()
474 return myMgAdapt->getPrintLogInFile();
476 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
477 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
479 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
483 medFileBackground="";
485 //~myMesh = CORBA::nil;
488 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
490 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
492 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
496 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
500 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
502 medFileBackground = f;
504 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
507 mg->setMedFileIn(medFileIn.c_str());
508 mg->setMedFileOut(medFileOut.c_str());
509 mg->setSizeMapFile(medFileBackground.c_str());
510 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
512 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
514 if(!checkMeshFileIn()){
515 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
518 hypothesis->setPublish(publish);
519 return hypothesis->compute();
522 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
524 bool ret = false; // 1 ok , 0 nook
525 if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
527 if(!myMesh->_is_nil())
529 bool toOverwrite = true;
530 bool toFindOutDim = true;
531 medFileIn = hypothesis->getFileName();
533 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
534 hypothesis->setMedFileIn(medFileIn.c_str());