Salome HOME
little corrections
[modules/smesh.git] / src / SMESH_I / MG_ADAPT_i.cxx
1 // Copyright (C) 2011-2020  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Remarques :
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
26 //
27 // Quand les 2 fonctions Setxxx et Getxxx sont presentes, Setxxx est decrit en premier
28 //
29
30 #include "MG_ADAPT_i.hxx"
31 //~#include "ADAPT_Gen_i.hxx"
32 #include "string.h"
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)
39
40
41 //=============================================================================
42 /*!
43  *  SMESH_Gen_i::CreateMG_ADAPT
44  *
45  *  Create measurement instance
46  */
47 //=============================================================================
48
49
50 using namespace SMESH;
51 void MG_ADAPT_i::copyHypothesisDataToImpl(const SMESH::MgAdaptHypothesisData& from, ::MG_ADAPT::MgAdaptHypothesisData* to) const
52 {
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;
79 }
80 void MG_ADAPT_i::copyHypothesisDataFromImpl(const ::MG_ADAPT::MgAdaptHypothesisData* from, SMESH::MgAdaptHypothesisData* to) const
81 {
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;
108 }
109 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateMG_ADAPT()
110 {
111   SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
112   SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
113   return anObj._retn();
114 }
115 SMESH::MG_ADAPT_ptr SMESH_Gen_i::CreateAdaptationHypothesis()
116 {
117   SMESH::MG_ADAPT_i* aMGadapt = new SMESH::MG_ADAPT_i();
118   SMESH::MG_ADAPT_var anObj = aMGadapt->_this();
119   return anObj._retn();
120 }
121 SMESH::MG_ADAPT_OBJECT_ptr SMESH_Gen_i::Adaptation( const char* adaptationType)
122 {
123
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();
128         }
129             
130
131 }
132 //~SMESH::MG_ADAPT_ptr MG_ADAPT_i::CreateMG_ADAPT()
133 //~{
134   
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();
139 //~}
140 //=============================================================================
141 /*!
142  *  standard constructor
143  */
144 //=============================================================================
145 MG_ADAPT_i::MG_ADAPT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
146 {
147   myMgAdapt = new ::MG_ADAPT::MgAdapt();
148 }
149 //~MG_ADAPT_i::MG_ADAPT_i(PortableServer::POA_var myPoa): SALOME::GenericObj_i( myPoa )
150 //~{
151   //~myMgAdapt = new ::MG_ADAPT::MgAdapt();
152 //~}
153
154 //=============================================================================
155 /*!
156  *  standard constructor
157  */
158 //=============================================================================
159 //~MG_ADAPT_i::MG_ADAPT_i( CORBA::ORB_ptr orb,
160                             //~ADAPT::ADAPT_Gen_var engine )
161 //~{
162
163   //~_gen_i = engine;
164   //~_orb = orb;
165   //~myMgAdapt = new MgAdapt();
166 //~}
167
168 //=============================================================================
169 /*!
170  *  standard destructor
171  */
172 //=============================================================================
173 MG_ADAPT_i::~MG_ADAPT_i()
174 {
175 }
176 void MG_ADAPT_i::setData( SMESH::MgAdaptHypothesisData& data)
177 {
178         ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData();
179         copyHypothesisDataToImpl(data, baseData);
180         myMgAdapt->setData(baseData);
181         delete baseData;
182 }       
183 void MG_ADAPT_i::setMedFileIn(const char* str)
184 {
185         myMgAdapt->setMedFileIn(str);
186 }
187 char* MG_ADAPT_i::getMedFileIn()
188 {
189         return CORBA::string_dup(myMgAdapt->getMedFileIn().c_str());
190 }
191 void MG_ADAPT_i::setMedFileOut(const char* str)
192 {
193         myMgAdapt->setMedFileOut(str);
194 }
195 char* MG_ADAPT_i::getMedFileOut()
196 {
197         return CORBA::string_dup(myMgAdapt->getMedFileOut().c_str());
198 }
199 void MG_ADAPT_i::setMeshName(const char* str)
200 {
201         myMgAdapt->setMeshName(str);
202 }
203 char* MG_ADAPT_i::getMeshName()
204 {
205         return CORBA::string_dup(myMgAdapt->getMeshName().c_str());
206 }
207 void MG_ADAPT_i::setMeshNameOut(const char* str)
208 {
209         myMgAdapt->setMeshNameOut(str);
210 }
211 char* MG_ADAPT_i::getMeshNameOut()
212 {
213         return CORBA::string_dup(myMgAdapt->getMeshNameOut().c_str());
214 }
215 void MG_ADAPT_i::setMeshOutMed(bool mybool)
216 {
217         myMgAdapt->setMeshOutMed(mybool);
218 }
219 bool MG_ADAPT_i::getMeshOutMed()
220 {
221         return myMgAdapt->getMeshOutMed();
222 }
223 void MG_ADAPT_i::setPublish(bool mybool)
224 {
225         myMgAdapt->setPublish(mybool);
226 }
227 bool MG_ADAPT_i::getPublish()
228 {
229         return myMgAdapt->getPublish();
230 }
231 void MG_ADAPT_i::setSizeMapFieldName(const char* str)
232 {
233         myMgAdapt->setFieldName(str);
234 }
235 char* MG_ADAPT_i::getSizeMapFieldName()
236 {
237         return CORBA::string_dup(myMgAdapt->getFieldName().c_str());
238 }
239 void MG_ADAPT_i::setTimeStep(CORBA::Long t)
240 {
241         myMgAdapt->setTimeStep(t);
242 }
243 CORBA::Long MG_ADAPT_i::getTimeStep() 
244 {
245         return myMgAdapt->getTimeStep();
246 }
247 void MG_ADAPT_i::setTimeStepRank(CORBA::Long t, CORBA::Long r)
248 {
249         myMgAdapt->setChosenTimeStepRank();
250         myMgAdapt->setRankTimeStep(t, r);
251 }
252 CORBA::Long MG_ADAPT_i::getRank()
253 {
254         return myMgAdapt->getRank();
255 }
256 void MG_ADAPT_i::setTimeStepRankLast()
257 {
258         myMgAdapt->setTimeStepRankLast();
259 }
260 void MG_ADAPT_i::setNoTimeStep()
261 {
262         myMgAdapt->setNoTimeStep();
263 }
264 void MG_ADAPT_i::setLogFile(const char* str)
265 {
266         myMgAdapt->setLogFile(str);
267 }
268 char* MG_ADAPT_i::getLogFile()
269 {
270         return CORBA::string_dup(myMgAdapt->getLogFile().c_str());
271 }
272
273 void MG_ADAPT_i::setVerbosityLevel(CORBA::Long v)
274 {
275         myMgAdapt->setVerbosityLevel(v);
276 }
277 CORBA::Long MG_ADAPT_i::getVerbosityLevel()
278 {
279         return myMgAdapt->getVerbosityLevel();
280 }
281 void MG_ADAPT_i::setRemoveOnSuccess(bool mybool)
282 {
283         myMgAdapt->setRemoveOnSuccess(mybool);
284 }
285 bool MG_ADAPT_i::getRemoveOnSuccess()
286 {
287         myMgAdapt->getRemoveOnSuccess();
288 }
289 SMESH::MgAdaptHypothesisData* MG_ADAPT_i::getData() 
290 {
291         SMESH::MgAdaptHypothesisData* result = new      SMESH::MgAdaptHypothesisData();
292         ::MG_ADAPT::MgAdaptHypothesisData* from =  myMgAdapt->getData();
293         copyHypothesisDataFromImpl(from, result);       
294         return result;
295 }
296 void MG_ADAPT_i::setUseLocalMap(bool mybool)
297 {
298         myMgAdapt->setUseLocalMap(mybool);
299 }
300 bool MG_ADAPT_i::getUseLocalMap()
301 {
302         return myMgAdapt->getUseLocalMap();
303 }
304 void MG_ADAPT_i::setUseBackgroundMap(bool mybool)
305 {
306         myMgAdapt->setUseBackgroundMap(mybool);
307 }
308 bool MG_ADAPT_i::getUseBackgroundMap()
309 {
310         return myMgAdapt->getUseBackgroundMap();
311 }
312 void MG_ADAPT_i::setUseConstantValue(bool mybool)
313 {
314         myMgAdapt->setUseConstantValue(mybool);
315 }
316 bool MG_ADAPT_i::getUseConstantValue()
317 {
318         return myMgAdapt->getUseConstantValue();
319 }
320
321 void MG_ADAPT_i::setConstantSize(double value)
322 {
323         myMgAdapt->setConstantValue(value);
324 }
325 double MG_ADAPT_i::getConstantSize() 
326 {
327         return myMgAdapt->getConstantValue();
328 }
329 void MG_ADAPT_i::setSizeMapFile(const char* str)
330 {
331         myMgAdapt->setSizeMapFile(str);
332 }
333 char* MG_ADAPT_i::getSizeMapFile()
334 {
335         return CORBA::string_dup(myMgAdapt->getSizeMapFile().c_str());
336 }
337 void MG_ADAPT_i::setFromMedFile(bool mybool)
338 {
339         myMgAdapt->setFromMedFile(mybool);
340 }
341 bool MG_ADAPT_i::isFromMedFile()
342 {
343         return myMgAdapt->isFromMedFile();
344 }
345
346 void MG_ADAPT_i::setKeepWorkingFiles(bool mybool)
347 {
348         myMgAdapt->setKeepWorkingFiles(mybool);
349 }
350 bool MG_ADAPT_i::getKeepWorkingFiles()
351 {
352         return myMgAdapt->getKeepWorkingFiles();
353 }
354
355 //~void MG_ADAPT_i::setPrCORBA::LongLogInFile(bool);
356 //~bool MG_ADAPT_i::getPrCORBA::LongLogInFile();
357
358 void MG_ADAPT_i::setSizeMapType(const char* type)
359 {
360         setUseLocalMap(false);
361         setUseBackgroundMap(false);
362         setUseConstantValue(false);
363         
364         if (!strcmp("Local", type))
365                 setUseLocalMap(true);
366         else if (!strcmp("Background", type))
367             setUseBackgroundMap(true);
368         else 
369             setUseConstantValue(true);
370 }
371 void MG_ADAPT_i::setWorkingDir(const char* dir)
372 {
373         myMgAdapt->setWorkingDir(dir);
374 }
375 char* MG_ADAPT_i::getWorkingDir() 
376 {
377         return CORBA::string_dup(myMgAdapt->getWorkingDir().c_str());
378 }
379 bool MG_ADAPT_i::setAll()
380 {
381         return myMgAdapt->setAll();
382 }
383 char* MG_ADAPT_i::getCommandToRun()
384 {
385         return CORBA::string_dup(myMgAdapt->getCommandToRun().c_str());
386 }
387
388 //~CORBA::Long MG_ADAPT_i::compute(::CORBA::String_out errStr)
389 //~{
390         //~std::string err("");
391         //~CORBA::Long ret = myMgAdapt->compute(err);
392         //~errStr =  err.c_str();
393         //~return ret;
394 //~}
395 CORBA::Long MG_ADAPT_i::compute()
396 {
397         errStr = "";
398         CORBA::Long ret;
399         try
400     {
401             ret = myMgAdapt->compute(errStr);
402     }
403     catch (const std::exception& e)
404     {
405         std::cerr<<e.what();
406         ret = -1;
407     }
408         //~errStr =  err.c_str();
409         return ret;
410 }
411 char* MG_ADAPT_i::getErrMsg()
412 {
413         return CORBA::string_dup(errStr.c_str());
414 }
415 char* MG_ADAPT_i::getFileName() 
416 {
417         return CORBA::string_dup(myMgAdapt->getFileName().c_str());
418 }
419 char* MG_ADAPT_i::getExeName()
420 {
421         return CORBA::string_dup(myMgAdapt->getExeName().c_str());
422 }
423 void MG_ADAPT_i::copyMgAdaptHypothesisData( const SMESH::MgAdaptHypothesisData& data)
424 {
425         ::MG_ADAPT::MgAdaptHypothesisData* baseData = new ::MG_ADAPT::MgAdaptHypothesisData(); 
426         copyHypothesisDataToImpl(data, baseData);
427         myMgAdapt->copyMgAdaptHypothesisData(baseData);
428         delete baseData;
429 }
430
431 //~void MG_ADAPT_i::checkDirPath(char*& str)
432 //~{
433         //~myMgAdapt->checkDirPath(str);
434 //~}
435
436 bool MG_ADAPT_i::hasOptionDefined( const char* optionName ) 
437 {
438         return myMgAdapt->hasOptionDefined(optionName);
439 }
440 void MG_ADAPT_i::setOptionValue(const char* optionName,
441                                         const char* optionValue) throw (std::invalid_argument)
442 {
443         myMgAdapt->setOptionValue(optionName, optionValue);
444 }                                       
445
446 char* MG_ADAPT_i::getOptionValue(const char* optionName,
447                                                    bool&              isDefault)  throw (std::invalid_argument)
448 {
449     return CORBA::string_dup(myMgAdapt->getOptionValue(optionName, &isDefault).c_str());
450 }
451 str_array* MG_ADAPT_i::getCustomOptionValuesStrVec() 
452 {
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();
458 }
459 str_array*  MG_ADAPT_i::getOptionValuesStrVec() 
460 {
461
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();
467 }
468
469 void MG_ADAPT_i::setPrintLogInFile(bool mybool)
470 {
471         myMgAdapt->setPrintLogInFile(mybool);
472 }
473 bool MG_ADAPT_i::getPrintLogInFile()
474 {
475         return myMgAdapt->getPrintLogInFile();
476 }
477 //~TOptionValues        MG_ADAPT_i::getOptionValues()       const;
478 //~const TOptionValues& MG_ADAPT_i::getCustomOptionValues() const ;
479
480 MG_ADAPT_OBJECT_i::MG_ADAPT_OBJECT_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
481 {
482     medFileIn="";
483     medFileOut="";
484     medFileBackground="";
485     publish = false;
486     //~myMesh = CORBA::nil;
487 }
488
489 void MG_ADAPT_OBJECT_i::setMeshIn(SMESH::SMESH_Mesh_ptr theMesh )
490 {
491         myMesh = SMESH::SMESH_Mesh::_duplicate(theMesh);
492 }
493 void MG_ADAPT_OBJECT_i::setMEDFileIn(const char* f)
494 {
495         medFileIn =  f;
496 }
497 void MG_ADAPT_OBJECT_i::setMEDFileOut(const char* f)
498 {
499         medFileOut = f;
500 }
501 void MG_ADAPT_OBJECT_i::setMEDFileBackground(const char* f)
502 {
503         medFileBackground = f;
504 }
505 void MG_ADAPT_OBJECT_i::AddHypothesis(SMESH::MG_ADAPT_ptr mg)
506 {
507         
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);
512 }
513 CORBA::Long MG_ADAPT_OBJECT_i::Compute(bool publish)
514 {
515         if(!checkMeshFileIn()){
516                 std::cerr<< "\n Error : Please check the MED file input or mesh input. \n";
517                 return -1;
518         }
519         hypothesis->setPublish(publish);
520         return hypothesis->compute();   
521 }       
522
523 bool MG_ADAPT_OBJECT_i::checkMeshFileIn()
524 {
525         bool ret = false; // 1 ok , 0 nook
526     if(!::MG_ADAPT::MgAdapt::isFileExist(medFileIn))
527     {
528         if(!myMesh->_is_nil())
529         {
530                 bool toOverwrite  = true;
531                         bool toFindOutDim = true;
532                         medFileIn = hypothesis->getFileName();
533                         medFileIn+= ".med";
534                         myMesh->ExportMED(medFileIn.c_str(), false, -1, toOverwrite, toFindOutDim);
535                         hypothesis->setMedFileIn(medFileIn.c_str());
536                         ret = true; 
537                 }
538         }
539         else
540             ret = true;
541             
542     return ret;
543 }