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"
23 #include "SMESH_Gen_i.hxx"
24 #include <SMESH_Gen.hxx>
25 #include <SALOMEconfig.h>
26 #include CORBA_CLIENT_HEADER(SALOMEDS)
29 //=============================================================================
31 * SMESH_Gen_i::CreateMG_ADAPT
33 * Create measurement instance
35 //=============================================================================
38 using namespace SMESH;
39 void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const
41 to->myFileInDir = from.myFileInDir;
42 to->myMeshFileIn = from.myMeshFileIn;
43 to->myMeshFileBackground = from.myMeshFileBackground;
44 to->myOutMeshName = from.myOutMeshName;
45 to->myMeshFileOut = from.myMeshFileOut;
46 to->myFileOutDir = from.myFileOutDir;
47 to->myFileSizeMapDir = from.myFileSizeMapDir;
48 to->myFieldName = from.myFieldName;
49 to->fromMedFile = from.fromMedFile;
50 to->myPublish = from.myPublish;
51 to->myMeshOutMed = from.myMeshOutMed;
52 to->myUseLocalMap = from.myUseLocalMap;
53 to->myUseBackgroundMap = from.myUseBackgroundMap;
54 to->myUseConstantValue = from.myUseConstantValue;
55 to->myConstantValue = from.myConstantValue;
56 to->myTimeStep = from.myTimeStep;
57 to->myRank = from.myRank;
58 to->myUseNoTimeStep = from.myUseNoTimeStep;
59 to->myUseLastTimeStep = from.myUseLastTimeStep;
60 to->myUseChosenTimeStep = from.myUseChosenTimeStep;
61 to->myWorkingDir = from.myWorkingDir;
62 to->myLogFile = from.myLogFile;
63 to->myPrintLogInFile = from.myPrintLogInFile;
64 to->myKeepFiles = from.myKeepFiles;
65 to->myRemoveLogOnSuccess = from.myRemoveLogOnSuccess;
66 to->myVerboseLevel = from.myVerboseLevel;
68 void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const
70 to->myFileInDir = CORBA::string_dup(from->myFileInDir.c_str());
71 to->myMeshFileIn = CORBA::string_dup(from->myMeshFileIn.c_str());
72 to->myMeshFileBackground = CORBA::string_dup(from->myMeshFileBackground.c_str());
73 to->myOutMeshName = CORBA::string_dup(from->myOutMeshName.c_str());
74 to->myMeshFileOut = CORBA::string_dup(from->myMeshFileOut.c_str());
75 to->myFileOutDir = CORBA::string_dup(from->myFileOutDir.c_str());
76 to->myFileSizeMapDir = CORBA::string_dup(from->myFileSizeMapDir.c_str());
77 to->myFieldName = CORBA::string_dup(from->myFieldName.c_str());
78 to->fromMedFile = from->fromMedFile;
79 to->myPublish = from->myPublish;
80 to->myMeshOutMed = from->myMeshOutMed;
81 to->myUseLocalMap = from->myUseLocalMap;
82 to->myUseBackgroundMap = from->myUseBackgroundMap;
83 to->myUseConstantValue = from->myUseConstantValue;
84 to->myConstantValue = from->myConstantValue;
85 to->myTimeStep = from->myTimeStep;
86 to->myRank = from->myRank;
87 to->myUseNoTimeStep = from->myUseNoTimeStep;
88 to->myUseLastTimeStep = from->myUseLastTimeStep;
89 to->myUseChosenTimeStep = from->myUseChosenTimeStep;
90 to->myWorkingDir = CORBA::string_dup(from->myWorkingDir.c_str());
91 to->myLogFile = CORBA::string_dup(from->myLogFile.c_str());
92 to->myPrintLogInFile = from->myPrintLogInFile;
93 to->myKeepFiles = from->myKeepFiles;
94 to->myRemoveLogOnSuccess = from->myRemoveLogOnSuccess;
95 to->myVerboseLevel = from->myVerboseLevel;
97 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT()
99 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
100 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
101 return anObj._retn();
103 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
105 SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
106 SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
107 return anObj._retn();
109 SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
112 if (!strcmp(adaptationType, "MG_Adapt"))
114 SMESH::MG_ADAPT_OBJECT_i* mg_adapt_object = new SMESH::MG_ADAPT_OBJECT_i();
115 SMESH::MG_ADAPT_OBJECT_var anObj = mg_adapt_object->_this();
116 return anObj._retn();
120 //~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT()
123 //~SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
124 //~SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i(smeshGen_i->GetPOA());
125 //~SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
126 //~return anObj._retn();
128 //=============================================================================
130 * standard constructor
132 //=============================================================================
133 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
135 myMgAdapt = new ::MG_ADAPT::MgAdapt();
137 //~MG_ADAPT_i::MG_ADAPT_i(PortableServer::POA_var myPoa): SALOME::GenericObj_i( myPoa )
139 //~myMgAdapt = new ::MG_ADAPT::MgAdapt();
142 //=============================================================================
144 * standard constructor
146 //=============================================================================
147 //~MG_ADAPT_i::MG_ADAPT_i( CORBA::ORB_ptr orb,
148 //~ADAPT::ADAPT_Gen_var engine )
153 //~myMgAdapt = new MgAdapt();
156 //=============================================================================
158 * standard destructor
160 //=============================================================================
161 MG_ADAPT_i::~MG_ADAPT_i()
164 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
166 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
167 copyHypothesisDataToImpl(data, baseData);
168 myMgAdapt->setData(baseData);
171 void MG_ADAPT_i::setMedFileIn(const char* str)
173 myMgAdapt->setMedFileIn(str);
175 char* MG_ADAPT_i::getMedFileIn()
177 return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
179 void MG_ADAPT_i::setMedFileOut(const char* str)
181 myMgAdapt->setMedFileOut(str);
183 char* MG_ADAPT_i::getMedFileOut()
185 return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
187 void MG_ADAPT_i::setMeshName(const char* str)
189 myMgAdapt->setMeshName(str);
191 char* MG_ADAPT_i::getMeshName()
193 return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
195 void MG_ADAPT_i::setMeshNameOut(const char* str)
197 myMgAdapt->setMeshNameOut(str);
199 char* MG_ADAPT_i::getMeshNameOut()
201 return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
203 void MG_ADAPT_i::setMeshOutMed(bool mybool)
205 myMgAdapt->setMeshOutMed(mybool);
207 bool MG_ADAPT_i::getMeshOutMed()
209 return myMgAdapt->getMeshOutMed();
211 void MG_ADAPT_i::setPublish(bool mybool)
213 myMgAdapt->setPublish(mybool);
215 bool MG_ADAPT_i::getPublish()
217 return myMgAdapt->getPublish();
219 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
221 myMgAdapt->setFieldName(str);
223 char* MG_ADAPT_i::getSizeMapFieldName()
225 return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
227 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
229 myMgAdapt->setTimeStep(t);
231 CORBA::Long MG_ADAPT_i::getTimeStep()
233 return myMgAdapt->getTimeStep();
235 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
237 myMgAdapt->setChosenTimeStepRank();
238 myMgAdapt->setRankTimeStep(t, r);
240 CORBA::Long MG_ADAPT_i::getRank()
242 return myMgAdapt->getRank();
244 void MG_ADAPT_i::setTimeStepRankLast()
246 myMgAdapt->setTimeStepRankLast();
248 void MG_ADAPT_i::setNoTimeStep()
250 myMgAdapt->setNoTimeStep();
252 void MG_ADAPT_i::setLogFile(const char* str)
254 myMgAdapt->setLogFile(str);
256 char* MG_ADAPT_i::getLogFile()
258 return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
261 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
263 myMgAdapt->setVerbosityLevel(v);
265 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
267 return myMgAdapt->getVerbosityLevel();
269 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
271 myMgAdapt->setRemoveOnSuccess(mybool);
273 bool MG_ADAPT_i::getRemoveOnSuccess()
275 myMgAdapt->getRemoveOnSuccess();
277 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData()
279 SMESH::MgAdaptHypothesisData* result = new SMESH::MgAdaptHypothesisData();
280 ::MG_ADAPT::MgAdaptHypothesisData* from = myMgAdapt->getData();
281 copyHypothesisDataFromImpl(from, result);
284 void MG_ADAPT_i::setUseLocalMap(bool mybool)
286 myMgAdapt->setUseLocalMap(mybool);
288 bool MG_ADAPT_i::getUseLocalMap()
290 return myMgAdapt->getUseLocalMap();
292 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
294 myMgAdapt->setUseBackgroundMap(mybool);
296 bool MG_ADAPT_i::getUseBackgroundMap()
298 return myMgAdapt->getUseBackgroundMap();
300 void MG_ADAPT_i::setUseConstantValue(bool mybool)
302 myMgAdapt->setUseConstantValue(mybool);
304 bool MG_ADAPT_i::getUseConstantValue()
306 return myMgAdapt->getUseConstantValue();
308 void MG_ADAPT_i::setConstantSize(double value)
310 myMgAdapt->setConstantValue(value);
312 double MG_ADAPT_i::getConstantSize()
314 return myMgAdapt->getConstantValue();
316 void MG_ADAPT_i::setSizeMapFile(const char* str)
318 myMgAdapt->setSizeMapFile(str);
320 char* MG_ADAPT_i::getSizeMapFile()
322 return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
324 void MG_ADAPT_i::setFromMedFile(bool mybool)
326 myMgAdapt->setFromMedFile(mybool);
328 bool MG_ADAPT_i::isFromMedFile()
330 return myMgAdapt->isFromMedFile();
333 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
335 myMgAdapt->setKeepWorkingFiles(mybool);
337 bool MG_ADAPT_i::getKeepWorkingFiles()
339 return myMgAdapt->getKeepWorkingFiles();
342 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
343 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
345 void MG_ADAPT_i::setSizeMapType(const char* type)
347 setUseLocalMap(false);
348 setUseBackgroundMap(false);
349 setUseConstantValue(false);
351 if (!strcmp("Local", type))
352 setUseLocalMap(true);
353 else if (!strcmp("Background", type))
354 setUseBackgroundMap(true);
356 setUseConstantValue(true);
358 void MG_ADAPT_i::setWorkingDir(const char* dir)
360 myMgAdapt->setWorkingDir(dir);
362 char* MG_ADAPT_i::getWorkingDir()
364 return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
366 bool MG_ADAPT_i::setAll()
368 return myMgAdapt->setAll();
370 char* MG_ADAPT_i::getCommandToRun()
372 return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
375 void MG_ADAPT_i::compute()
380 myMgAdapt->compute(errStr);
382 catch (const std::exception& e)
384 std::ostringstream oss; oss << "Exception thrown on MG_ADAPT_i::compute invocation with error message \"" << errStr
385 << "\" with exception message \"" << e.what() << "\"";
386 THROW_SALOME_CORBA_EXCEPTION(oss.str().c_str(),SALOME::INTERNAL_ERROR);
388 if(myMgAdapt->getPublish())
390 SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
391 SMESH::DriverMED_ReadStatus theStatus;
392 smeshGen_i->CreateMeshesFromMED(myMgAdapt->getMedFileOut().c_str(), theStatus);
395 char* MG_ADAPT_i::getErrMsg()
397 return CORBA::string_dup(errStr.c_str());
399 char* MG_ADAPT_i::getFileName()
401 return CORBA::string_dup(myMgAdapt->getFileName().c_str());
403 char* MG_ADAPT_i::getExeName()
405 return CORBA::string_dup(myMgAdapt->getExeName().c_str());
407 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
409 ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
410 copyHypothesisDataToImpl(data, baseData);
411 myMgAdapt->copyMgAdaptHypothesisData(baseData);
415 //~void MG_ADAPT_i::checkDirPath(char*& str)
417 //~myMgAdapt->checkDirPath(str);
420 bool MG_ADAPT_i::hasOptionDefined( const char* optionName )
422 return myMgAdapt->hasOptionDefined(optionName);
424 void MG_ADAPT_i::setOptionValue(const char* optionName,
425 const char* optionValue) throw (std::invalid_argument)
427 myMgAdapt->setOptionValue(optionName, optionValue);
430 char* MG_ADAPT_i::getOptionValue(const char* optionName,
431 bool& isDefault) throw (std::invalid_argument)
433 return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
435 str_array* MG_ADAPT_i::getCustomOptionValuesStrVec()
437 SMESH::str_array_var result = new SMESH::str_array();
438 std::vector <std::string> vals = myMgAdapt->getCustomOptionValuesStrVec();
439 result->length(vals.size());
440 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
441 return result._retn();
443 str_array* MG_ADAPT_i::getOptionValuesStrVec()
446 SMESH::str_array_var result = new SMESH::str_array();
447 std::vector <std::string> vals = myMgAdapt->getOptionValuesStrVec();
448 result->length(vals.size());
449 for (int i = 0; i<vals.size(); i++) result[i] = CORBA::string_dup(vals[i].c_str());
450 return result._retn();
453 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
455 myMgAdapt->setPrintLogInFile(mybool);
457 bool MG_ADAPT_i::getPrintLogInFile()
459 return myMgAdapt->getPrintLogInFile();
461 //~TOptionValues MG_ADAPT_i::getOptionValues() const;
462 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
464 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
468 medFileBackground="";
470 //~myMesh = CORBA::nil;
473 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
475 myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
477 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
481 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
485 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
487 medFileBackground = f;
489 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
492 mg->setMedFileIn(medFileIn.c_str());
493 mg->setMedFileOut(medFileOut.c_str());
494 mg->setSizeMapFile(medFileBackground.c_str());
495 hypothesis = SMESH::MG_ADAPT::_duplicate(mg);
497 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
499 if(!checkMeshFileIn()){
500 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
503 hypothesis->setPublish(publish);
504 hypothesis->compute();
508 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
510 bool ret = false; // 1 ok , 0 nook
511 if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
513 if(!myMesh->_is_nil())
515 bool toOverwrite = true;
516 bool toFindOutDim = true;
517 medFileIn = hypothesis->getFileName();
519 myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
520 hypothesis->setMedFileIn(medFileIn.c_str());