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->setChosenTimeStepRank();
250 myMgAdapt->setRankTimeStep(t, r);
252 CORBA::Long MG_ADAPT_i::getRank()
254 return myMgAdapt->getRank();
256 void MG_ADAPT_i::setTimeStepRankLast()
258 myMgAdapt->setTimeStepRankLast();
260 void MG_ADAPT_i::setNoTimeStep()
262 myMgAdapt->setNoTimeStep();
264 void MG_ADAPT_i::setLogFile(const char* str)
266 myMgAdapt->setLogFile(str);
268 char* MG_ADAPT_i::getLogFile()
270 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
273 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
275 myMgAdapt->setVerbosityLevel(v);
277 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
279 return myMgAdapt->getVerbosityLevel();
281 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
283 myMgAdapt->setRemoveOnSuccess(mybool);
285 bool MG_ADAPT_i::getRemoveOnSuccess()
287 myMgAdapt->getRemoveOnSuccess();
289 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
291 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
292 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
293 copyHypothesisDataFromImpl(from, result);
296 void MG_ADAPT_i::setUseLocalMap(bool mybool)
298 myMgAdapt->setUseLocalMap(mybool);
300 bool MG_ADAPT_i::getUseLocalMap()
302 return myMgAdapt->getUseLocalMap();
304 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
306 myMgAdapt->setUseBackgroundMap(mybool);
308 bool MG_ADAPT_i::getUseBackgroundMap()
310 return myMgAdapt->getUseBackgroundMap();
312 void MG_ADAPT_i::setUseConstantValue(bool mybool)
314 myMgAdapt->setUseConstantValue(mybool);
316 bool MG_ADAPT_i::getUseConstantValue()
318 return myMgAdapt->getUseConstantValue();
321 void MG_ADAPT_i::setConstantSize(double value)
323 myMgAdapt->setConstantValue(value);
325 double MG_ADAPT_i::getConstantSize()
327 return myMgAdapt->getConstantValue();
329 void MG_ADAPT_i::setSizeMapFile(const char* str)
331 myMgAdapt->setSizeMapFile(str);
333 char* MG_ADAPT_i::getSizeMapFile()
335 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
337 void MG_ADAPT_i::setFromMedFile(bool mybool)
339 myMgAdapt->setFromMedFile(mybool);
341 bool MG_ADAPT_i::isFromMedFile()
343 return myMgAdapt->isFromMedFile();
346 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
348 myMgAdapt->setKeepWorkingFiles(mybool);
350 bool MG_ADAPT_i::getKeepWorkingFiles()
352 return myMgAdapt->getKeepWorkingFiles();
355 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
356 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
358 void MG_ADAPT_i::setSizeMapType(const char* type)
360 setUseLocalMap(false);
361 setUseBackgroundMap(false);
362 setUseConstantValue(false);
364 if (!strcmp("Local", type))
365 setUseLocalMap(true);
366 else if (!strcmp("Background", type))
367 setUseBackgroundMap(true);
369 setUseConstantValue(true);
371 void MG_ADAPT_i::setWorkingDir(const char* dir)
373 myMgAdapt->setWorkingDir(dir);
375 char* MG_ADAPT_i::getWorkingDir()
377 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
379 bool MG_ADAPT_i::setAll()
381 return myMgAdapt->setAll();
383 char* MG_ADAPT_i::getCommandToRun()
385 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
388 //~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr)
390 //~std::string err("");
391 //~CORBA::Long ret = myMgAdapt->compute(err);
392 //~errStr = err.c_str();
395 CORBA::Long MG_ADAPT_i::compute()
401 ret = myMgAdapt->compute(errStr);
403 catch (const std::exception& e)
408 //~errStr = err.c_str();
411 char* MG_ADAPT_i::getErrMsg()
413 return CORBA::string_dup(errStr.c_str());
415 char* MG_ADAPT_i::getFileName()
417 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
419 char* MG_ADAPT_i::getExeName()
421 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
423 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
425 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
426 copyHypothesisDataToImpl(data, baseData);
427 myMgAdapt->copyMgAdaptHypothesisData(baseData);
431 //~void MG_ADAPT_i::checkDirPath(char*& str)
433 //~myMgAdapt->checkDirPath(str);
436 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
438 return myMgAdapt->hasOptionDefined(optionName);
440 void MG_ADAPT_i::setOptionValue(const char* optionName,
441 const char* optionValue) throw (std::invalid_argument)
443 myMgAdapt->setOptionValue(optionName, optionValue);
446 char* MG_ADAPT_i::getOptionValue(const char* optionName,
447 bool& isDefault) throw (std::invalid_argument)
449 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
451 str_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
453 SMESH::str_array_var result = new SMESH::str_array();
454 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
455 result->length(vals.size());
456 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
457 return result._retn();
459 str_array* MG_ADAPT_i::getOptionValuesStrVec()
462 SMESH::str_array_var result = new SMESH::str_array();
463 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
464 result->length(vals.size());
465 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
466 return result._retn();
469 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
471 myMgAdapt->setPrintLogInFile(mybool);
473 bool MG_ADAPT_i::getPrintLogInFile()
475 return myMgAdapt->getPrintLogInFile();
477 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
478 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
480 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
484 medFileBackground="";
486 //~myMesh = CORBA::nil;
489 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
491 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
493 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
497 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
501 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
503 medFileBackground = f;
505 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
508 mg->setMedFileIn(medFileIn.c_str());
509 mg->setMedFileOut(medFileOut.c_str());
510 mg->setSizeMapFile(medFileBackground.c_str());
511 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
513 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
515 if(!checkMeshFileIn()){
516 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
519 hypothesis->setPublish(publish);
520 return hypothesis->compute();
523 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
525 bool ret = false; // 1 ok , 0 nook
526 if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
528 if(!myMesh->_is_nil())
530 bool toOverwrite = true;
531 bool toFindOutDim = true;
532 medFileIn = hypothesis->getFileName();
534 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
535 hypothesis->setMedFileIn(medFileIn.c_str());