]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESH_I/SMESH_Homard_i.cxx
Salome HOME
556869c34e4bd66102e1f15cd495dae1fa13b60e
[modules/smesh.git] / src / SMESH_I / SMESH_Homard_i.cxx
1 // Copyright (C) 2011-2021  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 #include "SMESH_Homard_i.hxx"
21 #include "SMESH_Homard.hxx"
22
23 #include "SMESH_Gen_i.hxx"
24 #include "SMESH_PythonDump.hxx"
25
26 #include "SMESH_File.hxx"
27
28 // TODO?
29 //#include "FrontTrack.hxx"
30
31 #include "utilities.h"
32 #include "Basics_Utils.hxx"
33 #include "Basics_DirUtils.hxx"
34 #include "Utils_SINGLETON.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "SALOMEDS_Tool.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
38 #include "SALOMEconfig.h"
39
40 #include <vector>
41 #include <cmath>
42 #include <cstdlib>
43 #include <stdlib.h>
44 #include <sys/stat.h>
45 #include <algorithm>
46
47 #include <med.h>
48
49 #ifdef WIN32
50 #include <direct.h>
51 #else
52 #include <dirent.h>
53 #endif
54
55 #include <string>
56 #include <cstring>
57 #include <iostream>
58 #include <fstream>
59 #include <iomanip>
60 #include <set>
61 #include <vector>
62 #include <stdio.h>
63
64 using namespace std;
65
66 SMESHHOMARD::HOMARD_Gen_ptr SMESH_Gen_i::CreateHOMARD_ADAPT()
67 {
68   SMESHHOMARD_I::HOMARD_Gen_i* aHomardGen = new SMESHHOMARD_I::HOMARD_Gen_i();
69   SMESHHOMARD::HOMARD_Gen_var anObj = aHomardGen->_this();
70   return anObj._retn();
71 }
72
73 namespace SMESHHOMARD_I
74 {
75
76 //=============================================================================
77 /*!
78  *  standard constructor
79  */
80 //=============================================================================
81 HOMARD_Boundary_i::HOMARD_Boundary_i()
82   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
83 {
84   MESSAGE("Default constructor, not for use");
85   ASSERT(0);
86 }
87 //=============================================================================
88 /*!
89  *  standard constructor
90  */
91 //=============================================================================
92 HOMARD_Boundary_i::HOMARD_Boundary_i(SMESHHOMARD::HOMARD_Gen_var engine)
93   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
94 {
95   MESSAGE("HOMARD_Boundary_i");
96   _gen_i = engine;
97   myHomardBoundary = new SMESHHOMARDImpl::HOMARD_Boundary();
98   ASSERT(myHomardBoundary);
99 }
100 //=============================================================================
101 /*!
102  *  standard destructor
103  */
104 //=============================================================================
105 HOMARD_Boundary_i::~HOMARD_Boundary_i()
106 {
107 }
108 //=============================================================================
109 //=============================================================================
110 // Generalites
111 //=============================================================================
112 //=============================================================================
113 void HOMARD_Boundary_i::SetName(const char* Name)
114 {
115   ASSERT(myHomardBoundary);
116   myHomardBoundary->SetName(Name);
117 }
118 //=============================================================================
119 char* HOMARD_Boundary_i::GetName()
120 {
121   ASSERT(myHomardBoundary);
122   return CORBA::string_dup(myHomardBoundary->GetName().c_str());
123 }
124 //=============================================================================
125 char* HOMARD_Boundary_i::GetDumpPython()
126 {
127   ASSERT(myHomardBoundary);
128   return CORBA::string_dup(myHomardBoundary->GetDumpPython().c_str());
129 }
130 //=============================================================================
131 //=============================================================================
132 // Caracteristiques
133 //=============================================================================
134 //=============================================================================
135 void HOMARD_Boundary_i::SetType(CORBA::Long Type)
136 {
137   ASSERT(myHomardBoundary);
138   myHomardBoundary->SetType(Type);
139 }
140 //=============================================================================
141 CORBA::Long HOMARD_Boundary_i::GetType()
142 {
143   ASSERT(myHomardBoundary);
144   return  CORBA::Long(myHomardBoundary->GetType());
145 }
146 //=============================================================================
147 void HOMARD_Boundary_i::SetMeshName(const char* MeshName)
148 {
149   ASSERT(myHomardBoundary);
150   myHomardBoundary->SetMeshName(MeshName);
151 }
152 //=============================================================================
153 char* HOMARD_Boundary_i::GetMeshName()
154 {
155   ASSERT(myHomardBoundary);
156   return CORBA::string_dup(myHomardBoundary->GetMeshName().c_str());
157 }
158 //=============================================================================
159 void HOMARD_Boundary_i::SetDataFile(const char* DataFile)
160 {
161   ASSERT(myHomardBoundary);
162   myHomardBoundary->SetDataFile(DataFile);
163 }
164 //=============================================================================
165 char* HOMARD_Boundary_i::GetDataFile()
166 {
167   ASSERT(myHomardBoundary);
168   return CORBA::string_dup(myHomardBoundary->GetDataFile().c_str());
169 }
170 //=============================================================================
171 void HOMARD_Boundary_i::SetCylinder(double X0, double X1, double X2, double X3, double X4, double X5, double X6)
172 {
173   ASSERT(myHomardBoundary);
174   myHomardBoundary->SetCylinder(X0, X1, X2, X3, X4, X5, X6);
175 }
176 //=============================================================================
177 void HOMARD_Boundary_i::SetSphere(double Xcentre, double Ycentre, double ZCentre, double rayon)
178 {
179   ASSERT(myHomardBoundary);
180   myHomardBoundary->SetSphere(Xcentre, Ycentre, ZCentre, rayon);
181 }
182 //=============================================================================
183 void HOMARD_Boundary_i::SetConeR(double Xcentre1, double Ycentre1, double Zcentre1, double Rayon1, double Xcentre2, double Ycentre2, double Zcentre2, double Rayon2)
184 {
185   ASSERT(myHomardBoundary);
186   myHomardBoundary->SetConeR(Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2);
187 }
188 //=============================================================================
189 void HOMARD_Boundary_i::SetConeA(double Xaxe, double Yaxe, double Zaxe, double Angle, double Xcentre, double Ycentre, double Zcentre)
190 {
191   ASSERT(myHomardBoundary);
192   myHomardBoundary->SetConeA(Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre);
193 }
194 //=============================================================================
195 void HOMARD_Boundary_i::SetTorus(double X0, double X1, double X2, double X3, double X4, double X5, double X6, double X7)
196 {
197   ASSERT(myHomardBoundary);
198   myHomardBoundary->SetTorus(X0, X1, X2, X3, X4, X5, X6, X7);
199 }
200 //=============================================================================
201 SMESHHOMARD::double_array* HOMARD_Boundary_i::GetCoords()
202 {
203   ASSERT(myHomardBoundary);
204   SMESHHOMARD::double_array_var aResult = new SMESHHOMARD::double_array();
205   std::vector<double> mesCoor = myHomardBoundary->GetCoords();
206   aResult->length(mesCoor .size());
207   std::vector<double>::const_iterator it;
208   int i = 0;
209   for (it = mesCoor.begin(); it != mesCoor.end(); it++)
210     aResult[i++] = (*it);
211   return aResult._retn();
212 }
213 //=============================================================================
214 void HOMARD_Boundary_i::SetLimit(double Xincr, double Yincr, double Zincr)
215 {
216   ASSERT(myHomardBoundary);
217   myHomardBoundary->SetLimit(Xincr, Yincr, Zincr);
218 }
219 //=============================================================================
220 SMESHHOMARD::double_array* HOMARD_Boundary_i::GetLimit()
221 {
222   ASSERT(myHomardBoundary);
223   SMESHHOMARD::double_array_var aResult = new SMESHHOMARD::double_array();
224   std::vector<double> mesCoor = myHomardBoundary->GetLimit();
225   aResult->length(mesCoor .size());
226   std::vector<double>::const_iterator it;
227   int i = 0;
228   for (it = mesCoor.begin(); it != mesCoor.end(); it++)
229     aResult[i++] = (*it);
230   return aResult._retn();
231 }
232 //=============================================================================
233 void HOMARD_Boundary_i::AddGroup(const char* Group)
234 {
235   ASSERT(myHomardBoundary);
236   myHomardBoundary->AddGroup(Group);
237 }
238 //=============================================================================
239 void HOMARD_Boundary_i::SetGroups(const SMESHHOMARD::ListGroupType& ListGroup)
240 {
241   ASSERT(myHomardBoundary);
242   std::list<std::string> ListString;
243   for (unsigned int i = 0; i < ListGroup.length(); i++) {
244     ListString.push_back(std::string(ListGroup[i]));
245   }
246   myHomardBoundary->SetGroups(ListString);
247 }
248 //=============================================================================
249 SMESHHOMARD::ListGroupType*  HOMARD_Boundary_i::GetGroups()
250 {
251   ASSERT(myHomardBoundary);
252   const std::list<std::string>& ListString = myHomardBoundary->GetGroups();
253   SMESHHOMARD::ListGroupType_var aResult = new SMESHHOMARD::ListGroupType;
254   aResult->length(ListString.size());
255   std::list<std::string>::const_iterator it;
256   int i = 0;
257   for (it = ListString.begin(); it != ListString.end(); it++)
258   {
259     aResult[i++] = CORBA::string_dup((*it).c_str());
260   }
261   return aResult._retn();
262 }
263 //=============================================================================
264 //=============================================================================
265 // Liens avec les autres structures
266 //=============================================================================
267 //=============================================================================
268 void HOMARD_Boundary_i::SetCaseCreation(const char* NomCaseCreation)
269 {
270   ASSERT(myHomardBoundary);
271   myHomardBoundary->SetCaseCreation(NomCaseCreation);
272 }
273 //=============================================================================
274 char* HOMARD_Boundary_i::GetCaseCreation()
275 {
276   ASSERT(myHomardBoundary);
277   return CORBA::string_dup(myHomardBoundary->GetCaseCreation().c_str());
278 }
279
280 //=============================================================================
281 /*!
282  *  standard constructor
283  */
284 //=============================================================================
285 HOMARD_Cas_i::HOMARD_Cas_i()
286   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
287 {
288   MESSAGE("Default constructor, not for use");
289   ASSERT(0);
290 }
291
292 //=============================================================================
293 /*!
294  *  standard constructor
295  */
296 //=============================================================================
297 HOMARD_Cas_i::HOMARD_Cas_i(SMESHHOMARD::HOMARD_Gen_var engine)
298   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
299 {
300   MESSAGE("HOMARD_Cas_i");
301   _gen_i = engine;
302   myHomardCas = new SMESHHOMARDImpl::HOMARD_Cas();
303   ASSERT(myHomardCas);
304   myHomardCas->SetName("Case_1");
305 }
306
307 //=============================================================================
308 /*!
309  *  standard destructor
310  */
311 //=============================================================================
312 HOMARD_Cas_i::~HOMARD_Cas_i()
313 {
314 }
315 //=============================================================================
316 //=============================================================================
317 // Generalites
318 //=============================================================================
319 //=============================================================================
320 char* HOMARD_Cas_i::GetName()
321 {
322   ASSERT(myHomardCas);
323   return CORBA::string_dup(myHomardCas->GetName().c_str());
324 }
325 //=============================================================================
326 char* HOMARD_Cas_i::GetDumpPython()
327 {
328   ASSERT(myHomardCas);
329   return CORBA::string_dup(myHomardCas->GetDumpPython().c_str());
330 }
331 //=============================================================================
332 //=============================================================================
333 // Caracteristiques
334 //=============================================================================
335 //=============================================================================
336 void HOMARD_Cas_i::SetDirName(const char* NomDir)
337 {
338   ASSERT(myHomardCas);
339   int codret;
340   // A. recuperation du nom; on ne fait rien si c'est le meme
341   char* oldrep = GetDirName();
342   if (strcmp(oldrep,NomDir) == 0) return;
343   MESSAGE ("SetDirName : passage de oldrep = "<< oldrep << " a NomDir = "<<NomDir);
344   // C. Changement/creation du repertoire
345   codret = myHomardCas->SetDirName(NomDir);
346   if (codret != 0) {
347     SALOME::ExceptionStruct es;
348     es.type = SALOME::BAD_PARAM;
349     std::string text;
350     if (codret == 1)
351       text = "The directory for the case cannot be modified because some iterations are already defined.";
352     else
353       text = "The directory for the case cannot be reached.";
354     es.text = CORBA::string_dup(text.c_str());
355     throw SALOME::SALOME_Exception(es);
356   }
357   // D. En cas de reprise, deplacement du point de depart
358   SMESHHOMARD::HOMARD_Iteration_ptr Iter0 = _gen_i->GetIteration(0);
359   int state = Iter0->GetNumber();
360   if (state != 0) { // GetState()
361     MESSAGE ("etat : " << state);
362     // D.1. Nom local du repertoire de l'iteration de depart dans le repertoire actuel du cas
363     char* DirNameIter = Iter0->GetDirNameLoc();
364     MESSAGE ("SetDirName : nom actuel pour le repertoire de l iteration, DirNameIter = "<< DirNameIter);
365     // D.2. Recherche d'un nom local pour l'iteration de depart dans le futur repertoire du cas
366     char* nomDirIter = _gen_i->CreateDirNameIter(NomDir, 0);
367     MESSAGE ("SetDirName : nom futur pour le repertoire de l iteration, nomDirIter = "<< nomDirIter);
368     // D.3. Creation du futur repertoire local pour l'iteration de depart
369     std::string nomDirIterTotal;
370     nomDirIterTotal = std::string(NomDir) + "/" + std::string(nomDirIter);
371 #ifndef WIN32
372     if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
373 #else
374     if (_mkdir(nomDirIterTotal.c_str()) != 0)
375 #endif
376     {
377       MESSAGE ("nomDirIterTotal : " << nomDirIterTotal);
378       SALOME::ExceptionStruct es;
379       es.type = SALOME::BAD_PARAM;
380       std::string text = "The directory for the starting iteration cannot be created.";
381       es.text = CORBA::string_dup(text.c_str());
382       throw SALOME::SALOME_Exception(es);
383     }
384     // D.4. Deplacement du contenu du repertoire
385     std::string oldnomDirIterTotal;
386     oldnomDirIterTotal = std::string(oldrep) + "/" + std::string(DirNameIter);
387     std::string commande = "mv " + std::string(oldnomDirIterTotal) + "/*" + " " + std::string(nomDirIterTotal);
388     codret = system(commande.c_str());
389     if (codret != 0)
390     {
391       SALOME::ExceptionStruct es;
392       es.type = SALOME::BAD_PARAM;
393       std::string text = "The starting point for the case cannot be moved into the new directory.";
394       es.text = CORBA::string_dup(text.c_str());
395       throw SALOME::SALOME_Exception(es);
396     }
397     commande = "rm -rf " + std::string(oldnomDirIterTotal);
398     codret = system(commande.c_str());
399     if (codret != 0)
400     {
401       SALOME::ExceptionStruct es;
402       es.type = SALOME::BAD_PARAM;
403       std::string text = "The starting point for the case cannot be deleted.";
404       es.text = CORBA::string_dup(text.c_str());
405       throw SALOME::SALOME_Exception(es);
406     }
407     // D.5. Memorisation du nom du repertoire de l'iteration
408     Iter0->SetDirNameLoc(nomDirIter);
409   }
410 }
411 //=============================================================================
412 char* HOMARD_Cas_i::GetDirName()
413 {
414   ASSERT(myHomardCas);
415   return CORBA::string_dup(myHomardCas->GetDirName().c_str());
416 }
417 //=============================================================================
418 void HOMARD_Cas_i::SetConfType(CORBA::Long ConfType)
419 {
420   ASSERT(myHomardCas);
421   //VERIFICATION((ConfType>=-2) && (ConfType<=3));
422   myHomardCas->SetConfType(ConfType);
423 }
424 //=============================================================================
425 CORBA::Long HOMARD_Cas_i::GetConfType()
426 {
427   ASSERT(myHomardCas);
428   return myHomardCas->GetConfType();
429 }
430 //=============================================================================
431 void HOMARD_Cas_i::SetBoundingBox(const SMESHHOMARD::extrema& LesExtrema)
432 {
433   ASSERT(myHomardCas);
434   std::vector<double> VExtrema;
435   ASSERT(LesExtrema.length() == 10);
436   VExtrema.resize(LesExtrema.length());
437   for (int i = 0; i < (int)LesExtrema.length(); i++) {
438     VExtrema[i] = LesExtrema[i];
439   }
440   myHomardCas->SetBoundingBox(VExtrema);
441 }
442 //=============================================================================
443 SMESHHOMARD::extrema* HOMARD_Cas_i::GetBoundingBox()
444 {
445   ASSERT(myHomardCas);
446   SMESHHOMARD::extrema_var aResult = new SMESHHOMARD::extrema();
447   std::vector<double> LesExtremes = myHomardCas->GetBoundingBox();
448   ASSERT(LesExtremes.size() == 10);
449   aResult->length(10);
450   for (int i = 0; i < (int)LesExtremes.size(); i++) {
451     aResult[i] = LesExtremes[i];
452   }
453   return aResult._retn();
454 }
455
456 //=============================================================================
457 void HOMARD_Cas_i::AddGroup(const char* Group)
458 {
459   ASSERT(myHomardCas);
460   myHomardCas->AddGroup(Group);
461 }
462 //=============================================================================
463 void HOMARD_Cas_i::SetGroups(const SMESHHOMARD::ListGroupType& ListGroup)
464 {
465   ASSERT(myHomardCas);
466   std::list<std::string> ListString;
467   for (int i = 0; i < ListGroup.length(); i++)
468   {
469     ListString.push_back(std::string(ListGroup[i]));
470   }
471   myHomardCas->SetGroups(ListString);
472 }
473 //=============================================================================
474 SMESHHOMARD::ListGroupType* HOMARD_Cas_i::GetGroups()
475 {
476   ASSERT(myHomardCas);
477   const std::list<std::string>& ListString = myHomardCas->GetGroups();
478   SMESHHOMARD::ListGroupType_var aResult = new SMESHHOMARD::ListGroupType();
479   aResult->length(ListString.size());
480   std::list<std::string>::const_iterator it;
481   int i = 0;
482   for (it = ListString.begin(); it != ListString.end(); it++) {
483     aResult[i++] = CORBA::string_dup((*it).c_str());
484   }
485   return aResult._retn();
486 }
487
488 //=============================================================================
489 void HOMARD_Cas_i::AddBoundary(const char* BoundaryName)
490 {
491   MESSAGE ("HOMARD_Cas_i::AddBoundary : BoundaryName = "<< BoundaryName);
492   const char * Group = "";
493   AddBoundaryGroup(BoundaryName, Group);
494 }
495 //=============================================================================
496 void HOMARD_Cas_i::AddBoundaryGroup(const char* BoundaryName, const char* Group)
497 {
498   MESSAGE ("HOMARD_Cas_i::AddBoundaryGroup : BoundaryName = "<< BoundaryName << ", Group = " << Group);
499   ASSERT(myHomardCas);
500   // A. Préalables
501   // A.1. Caractéristiques de la frontière à ajouter
502   SMESHHOMARD::HOMARD_Boundary_ptr myBoundary = _gen_i->GetBoundary(BoundaryName);
503   ASSERT(!CORBA::is_nil(myBoundary));
504   int BoundaryType = myBoundary->GetType();
505   MESSAGE (". BoundaryType = " << BoundaryType);
506   // A.2. La liste des frontiere+groupes
507   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
508   std::list<std::string>::const_iterator it;
509   // B. Controles
510   const char * boun;
511   int erreur = 0;
512   while (erreur == 0)
513   {
514     // B.1. Si on ajoute une frontière CAO, elle doit être la seule frontière
515     if (BoundaryType == -1)
516     {
517       for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
518       {
519         boun = (*it).c_str();
520         MESSAGE ("..  Frontiere enregistrée : "<< boun);
521         if (*it != BoundaryName)
522         { erreur = 1;
523           break; }
524         // On saute le nom du groupe
525         it++;
526       }
527     }
528     if (erreur != 0) { break; }
529     // B.2. Si on ajoute une frontière non CAO, il ne doit pas y avoir de frontière CAO
530     if (BoundaryType != -1)
531     {
532       for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
533       {
534         boun = (*it).c_str();
535         MESSAGE ("..  Frontiere enregistrée : "<< boun);
536         SMESHHOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun);
537         int BoundaryType_0 = myBoundary_0->GetType();
538         MESSAGE (".. BoundaryType_0 = " << BoundaryType_0);
539         if (BoundaryType_0 == -1)
540         { erreur = 2;
541           break; }
542         // On saute le nom du groupe
543         it++;
544       }
545       if (erreur != 0) { break; }
546     }
547     // B.3. Si on ajoute une frontière discrète, il ne doit pas y avoir d'autre frontière discrète
548     if (BoundaryType == 0)
549     {
550       for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
551       {
552         boun = (*it).c_str();
553         MESSAGE ("..  Frontiere enregistrée : "<< boun);
554         if (boun != BoundaryName)
555         {
556           SMESHHOMARD::HOMARD_Boundary_ptr myBoundary_0 = _gen_i->GetBoundary(boun);
557           int BoundaryType_0 = myBoundary_0->GetType();
558           MESSAGE (".. BoundaryType_0 = " << BoundaryType_0);
559           if (BoundaryType_0 == 0)
560           { erreur = 3;
561             break; }
562         }
563         // On saute le nom du groupe
564         it++;
565       }
566       if (erreur != 0) { break; }
567     }
568     // B.4. Pour une nouvelle frontiere, publication dans l'arbre d'etudes sous le cas
569     for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++) {
570       MESSAGE ("..  Frontiere : "<< *it);
571       // On saute le nom du groupe
572       it++;
573     }
574     // B.5. Le groupe est-il deja enregistre pour une frontiere de ce cas ?
575     for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++) {
576       boun = (*it).c_str();
577       it++;
578       MESSAGE ("..  Groupe enregistré : "<< *it);
579       if (*it == Group) {
580         erreur = 5;
581         break;
582       }
583     }
584     if (erreur != 0) { break; }
585     //
586     break;
587   }
588   // F. Si aucune erreur, enregistrement du couple (frontiere,groupe) dans la reference du cas
589   //    Sinon, arrêt
590   if (erreur == 0) {
591     myHomardCas->AddBoundaryGroup(BoundaryName, Group);
592   }
593   else {
594     std::stringstream ss;
595     ss << erreur;
596     std::string str = ss.str();
597     std::string texte;
598     texte = "Erreur numéro " + str + " pour la frontière à enregistrer : " + std::string(BoundaryName);
599     if (erreur == 1) { texte += "\nIl existe déjà la frontière "; }
600     else if (erreur == 2) { texte += "\nIl existe déjà la frontière CAO "; }
601     else if (erreur == 3) { texte += "\nIl existe déjà une frontière discrète : "; }
602     else if (erreur == 5) { texte += "\nLe groupe " + std::string(Group) + " est déjà enregistré pour la frontière "; }
603     texte += std::string(boun);
604     //
605     SALOME::ExceptionStruct es;
606     es.type = SALOME::BAD_PARAM;
607 #ifdef _DEBUG_
608     texte += "\nInvalid AddBoundaryGroup";
609 #endif
610     INFOS(texte);
611     es.text = CORBA::string_dup(texte.c_str());
612     throw SALOME::SALOME_Exception(es);
613   }
614 }
615 //=============================================================================
616 SMESHHOMARD::ListBoundaryGroupType* HOMARD_Cas_i::GetBoundaryGroup()
617 {
618   MESSAGE ("GetBoundaryGroup");
619   ASSERT(myHomardCas);
620   const std::list<std::string>& ListBoundaryGroup = myHomardCas->GetBoundaryGroup();
621   SMESHHOMARD::ListBoundaryGroupType_var aResult = new SMESHHOMARD::ListBoundaryGroupType();
622   aResult->length(ListBoundaryGroup.size());
623   std::list<std::string>::const_iterator it;
624   int i = 0;
625   for (it = ListBoundaryGroup.begin(); it != ListBoundaryGroup.end(); it++)
626   {
627     aResult[i++] = CORBA::string_dup((*it).c_str());
628   }
629   return aResult._retn();
630 }
631 //=============================================================================
632 void HOMARD_Cas_i::SupprBoundaryGroup()
633 {
634   MESSAGE ("SupprBoundaryGroup");
635   ASSERT(myHomardCas);
636   myHomardCas->SupprBoundaryGroup();
637 }
638
639 void HOMARD_Cas_i::AddIteration(const char* NomIteration)
640 {
641   ASSERT(myHomardCas);
642   myHomardCas->AddIteration(NomIteration);
643 }
644
645 //=============================================================================
646 /*!
647  *  standard constructor
648  */
649 //=============================================================================
650 HOMARD_Hypothesis_i::HOMARD_Hypothesis_i()
651   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
652 {
653   MESSAGE("Default constructor, not for use");
654   ASSERT(0);
655 }
656
657 //=============================================================================
658 /*!
659  *  standard constructor
660  */
661 //=============================================================================
662 HOMARD_Hypothesis_i::HOMARD_Hypothesis_i(SMESHHOMARD::HOMARD_Gen_var engine)
663   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
664 {
665   MESSAGE("standard constructor");
666   _gen_i = engine;
667   myHomardHypothesis = new SMESHHOMARDImpl::HOMARD_Hypothesis();
668   ASSERT(myHomardHypothesis);
669
670   // SetUnifRefinUnRef(1)
671   int RefinType = 1;
672   int UnRefType = 0;
673   myHomardHypothesis->SetAdapType(-1);
674   myHomardHypothesis->SetRefinTypeDera(RefinType, UnRefType);
675
676   // Set name
677   myHomardHypothesis->SetName("Hypo_1");
678 }
679
680 //=============================================================================
681 /*!
682  *  standard destructor
683  */
684 //=============================================================================
685 HOMARD_Hypothesis_i::~HOMARD_Hypothesis_i()
686 {
687 }
688
689 //=============================================================================
690 void HOMARD_Hypothesis_i::SetExtraOutput(CORBA::Long ExtraOutput)
691 {
692   ASSERT(myHomardHypothesis);
693   myHomardHypothesis->SetExtraOutput(ExtraOutput);
694 }
695 //=============================================================================
696 CORBA::Long HOMARD_Hypothesis_i::GetExtraOutput()
697 {
698   ASSERT(myHomardHypothesis);
699   return myHomardHypothesis->GetExtraOutput();
700 }
701
702 //=============================================================================
703 //=============================================================================
704 // Liens avec les autres structures
705 //=============================================================================
706 //=============================================================================
707 void HOMARD_Hypothesis_i::LinkIteration(const char* NomIteration)
708 {
709   ASSERT(myHomardHypothesis);
710   myHomardHypothesis->LinkIteration(NomIteration);
711 }
712 //=============================================================================
713 void HOMARD_Hypothesis_i::UnLinkIteration(const char* NomIteration)
714 {
715   ASSERT(myHomardHypothesis);
716   myHomardHypothesis->UnLinkIteration(NomIteration);
717 }
718
719 //=============================================================================
720 /*!
721  *  standard constructor
722  */
723 //=============================================================================
724 HOMARD_Iteration_i::HOMARD_Iteration_i()
725   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
726 {
727   MESSAGE("Default constructor, not for use");
728   ASSERT(0);
729 }
730 //=============================================================================
731 /*!
732  *  standard constructor
733  */
734 //=============================================================================
735 HOMARD_Iteration_i::HOMARD_Iteration_i(SMESHHOMARD::HOMARD_Gen_var engine)
736   : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA())
737 {
738   MESSAGE("constructor");
739   _gen_i = engine;
740   myHomardIteration = new SMESHHOMARDImpl::HOMARD_Iteration();
741   ASSERT(myHomardIteration);
742 }
743 //=============================================================================
744 /*!
745  *  standard destructor
746  */
747 //=============================================================================
748 HOMARD_Iteration_i::~HOMARD_Iteration_i()
749 {
750 }
751 //=============================================================================
752 void HOMARD_Iteration_i::SetName(const char* Name)
753 {
754   ASSERT(myHomardIteration);
755   myHomardIteration->SetName(Name);
756 }
757 //=============================================================================
758 char* HOMARD_Iteration_i::GetName()
759 {
760   ASSERT(myHomardIteration);
761   return CORBA::string_dup(myHomardIteration->GetName().c_str());
762 }
763 //=============================================================================
764 void HOMARD_Iteration_i::SetDirNameLoc(const char* NomDir)
765 {
766   ASSERT(myHomardIteration);
767   myHomardIteration->SetDirNameLoc(NomDir);
768 }
769 //=============================================================================
770 char* HOMARD_Iteration_i::GetDirNameLoc()
771 {
772   ASSERT(myHomardIteration);
773   return CORBA::string_dup(myHomardIteration->GetDirNameLoc().c_str());
774 }
775 //=============================================================================
776 char* HOMARD_Iteration_i::GetDirName()
777 {
778   ASSERT(myHomardIteration);
779   SMESHHOMARD::HOMARD_Cas_ptr caseiter = _gen_i->GetCase();
780   std::string dirnamecase = caseiter->GetDirName();
781   std::string dirname = dirnamecase + "/" +  GetDirNameLoc();
782   return CORBA::string_dup(dirname.c_str());
783 }
784 //=============================================================================
785 void HOMARD_Iteration_i::SetNumber(CORBA::Long NumIter)
786 {
787   ASSERT(myHomardIteration);
788   myHomardIteration->SetNumber(NumIter);
789 }
790 //=============================================================================
791 CORBA::Long HOMARD_Iteration_i::GetNumber()
792 {
793   ASSERT(myHomardIteration);
794   return myHomardIteration->GetNumber();
795 }
796 //=============================================================================
797 void HOMARD_Iteration_i::SetState(CORBA::Long Etat)
798 {
799   ASSERT(myHomardIteration);
800   myHomardIteration->SetState(Etat);
801 }
802 //=============================================================================
803 CORBA::Long HOMARD_Iteration_i::GetState()
804 {
805   ASSERT(myHomardIteration);
806   return myHomardIteration->GetState();
807 }
808 //=============================================================================
809 void HOMARD_Iteration_i::SetMeshName(const char* NomMesh)
810 {
811   ASSERT(myHomardIteration);
812   myHomardIteration->SetMeshName(NomMesh);
813 }
814 //=============================================================================
815 char* HOMARD_Iteration_i::GetMeshName()
816 {
817   ASSERT(myHomardIteration);
818   return CORBA::string_dup(myHomardIteration->GetMeshName().c_str());
819 }
820 //=============================================================================
821 void HOMARD_Iteration_i::SetMeshFile(const char* MeshFile)
822 {
823   ASSERT(myHomardIteration);
824   myHomardIteration->SetMeshFile(MeshFile);
825 }
826 //=============================================================================
827 char* HOMARD_Iteration_i::GetMeshFile()
828 {
829   ASSERT(myHomardIteration);
830   return CORBA::string_dup(myHomardIteration->GetMeshFile().c_str());
831 }
832 //=============================================================================
833 void HOMARD_Iteration_i::SetLogFile(const char* LogFile)
834 {
835   ASSERT(myHomardIteration);
836   myHomardIteration->SetLogFile(LogFile);
837 }
838 //=============================================================================
839 char* HOMARD_Iteration_i::GetLogFile()
840 {
841   ASSERT(myHomardIteration);
842   return CORBA::string_dup(myHomardIteration->GetLogFile().c_str());
843 }
844 //=============================================================================
845 void HOMARD_Iteration_i::SetFileInfo(const char* FileInfo)
846 {
847   ASSERT(myHomardIteration);
848   myHomardIteration->SetFileInfo(FileInfo);
849 }
850 //=============================================================================
851 char* HOMARD_Iteration_i::GetFileInfo()
852 {
853   ASSERT(myHomardIteration);
854   return CORBA::string_dup(myHomardIteration->GetFileInfo().c_str());
855 }
856 //=============================================================================
857 //=============================================================================
858 // Liens avec les autres iterations
859 //=============================================================================
860 //=============================================================================
861 void HOMARD_Iteration_i::LinkNextIteration(const char* NomIteration)
862 {
863   ASSERT(myHomardIteration);
864   myHomardIteration->LinkNextIteration(NomIteration);
865 }
866 //=============================================================================
867 void HOMARD_Iteration_i::UnLinkNextIteration(const char* NomIteration)
868 {
869   ASSERT(myHomardIteration);
870   myHomardIteration->UnLinkNextIteration(NomIteration);
871 }
872 //=============================================================================
873 void HOMARD_Iteration_i::SetIterParentName(const char* NomIterParent)
874 {
875   ASSERT(myHomardIteration);
876   myHomardIteration->SetIterParentName(NomIterParent);
877 }
878 //=============================================================================
879 char* HOMARD_Iteration_i::GetIterParentName()
880 {
881   ASSERT(myHomardIteration);
882   return CORBA::string_dup(myHomardIteration->GetIterParentName().c_str());
883 }
884
885 //=============================================================================
886 //=============================================================================
887 // Liens avec les autres structures
888 //=============================================================================
889 //=============================================================================
890 void HOMARD_Iteration_i::SetCaseName(const char* NomCas)
891 {
892   ASSERT(myHomardIteration);
893   myHomardIteration->SetCaseName(NomCas);
894 }
895 //=============================================================================
896 char* HOMARD_Iteration_i::GetCaseName()
897 {
898   ASSERT(myHomardIteration);
899   return CORBA::string_dup(myHomardIteration->GetCaseName().c_str());
900 }
901 //=============================================================================
902 void HOMARD_Iteration_i::SetHypoName(const char* NomHypo)
903 {
904   ASSERT(myHomardIteration);
905   myHomardIteration->SetHypoName(NomHypo);
906 }
907 //=============================================================================
908 //=============================================================================
909 // Divers
910 //=============================================================================
911 //=============================================================================
912 void HOMARD_Iteration_i::SetInfoCompute(CORBA::Long MessInfo)
913 {
914   ASSERT(myHomardIteration);
915   myHomardIteration->SetInfoCompute(MessInfo);
916 }
917 //=============================================================================
918 CORBA::Long HOMARD_Iteration_i::GetInfoCompute()
919 {
920   ASSERT(myHomardIteration);
921   return myHomardIteration->GetInfoCompute();
922 }
923
924 //=============================================================================
925 /*!
926  *  standard constructor
927  */
928 //=============================================================================
929 HOMARD_Gen_i::HOMARD_Gen_i() : SALOME::GenericObj_i(SMESH_Gen_i::GetPOA()),
930                                _KeepMedOUT(true),
931                                _PublishMeshOUT(false),
932                                _KeepWorkingFiles(false),
933                                _LogInFile(false),
934                                _RemoveLogOnSuccess(false),
935                                _VerboseLevel(0),
936                                _MeshNameOUT(""),
937                                _MeshFileOUT(""),
938                                _LogFile(""),
939                                _CaseOnMedFile(true),
940                                _SmeshMesh(SMESH::SMESH_Mesh::_nil()),
941                                _TmpMeshFile("")
942 {
943   MESSAGE("constructor de HOMARD_Gen_i");
944   myHomard = new SMESHHOMARDImpl::HOMARD_Gen;
945 }
946
947 //=============================================================================
948 /*!
949  *  standard destructor
950  */
951 //=============================================================================
952 HOMARD_Gen_i::~HOMARD_Gen_i()
953 {
954   if (!myCase->_is_nil()) {
955     CleanCase();
956   }
957 }
958
959 //=============================================================================
960 //=============================================================================
961 // Destruction des structures identifiees par leurs noms
962 //=============================================================================
963 //=============================================================================
964 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
965 {
966   MESSAGE ("DeleteBoundary : BoundaryName = " << BoundaryName);
967   SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
968   if (CORBA::is_nil(myBoundary)) {
969     SALOME::ExceptionStruct es;
970     es.type = SALOME::BAD_PARAM;
971     es.text = "Invalid boundary";
972     throw SALOME::SALOME_Exception(es);
973   }
974
975   // Boundaries should be deleted only after all cases deletion!!!
976
977   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
978   _mesBoundarys.erase(BoundaryName);
979
980   return 0;
981 }
982
983 //=============================================================================
984 CORBA::Long HOMARD_Gen_i::DeleteCase()
985 {
986   MESSAGE ("DeleteCase");
987   if (!CORBA::is_nil(myCase)) {
988     // Delete Iteration0
989     if (DeleteIteration(0) != 0) return 2;
990
991     myCase = SMESHHOMARD::HOMARD_Cas::_nil();
992   }
993   return 0;
994 }
995
996 //=============================================================================
997 CORBA::Long HOMARD_Gen_i::DeleteIteration(int numIter)
998 {
999   MESSAGE ("DeleteIteration : numIter = " << numIter);
1000
1001   if (numIter == 0) {
1002     myIteration0 = SMESHHOMARD::HOMARD_Iteration::_nil();
1003   }
1004   else {
1005     if (!CORBA::is_nil(myIteration1)) {
1006       if (CORBA::is_nil(myIteration0)) {
1007         SALOME::ExceptionStruct es;
1008         es.type = SALOME::BAD_PARAM;
1009         es.text = "Invalid iteration 0";
1010         throw SALOME::SALOME_Exception(es);
1011       }
1012
1013       // Invalide Iteration
1014       if (myIteration1->GetState() > 0) {
1015         myIteration1->SetState(1);
1016         if (!_KeepWorkingFiles) {
1017           std::string nomDir = myIteration1->GetDirName();
1018           std::string commande = "rm -rf " + nomDir;
1019           if (numIter > 0 && !_KeepMedOUT) {
1020             // Remove associated mesh file
1021             std::string nomFichier = myIteration1->GetMeshFile();
1022             commande = commande + ";rm -rf " + nomFichier;
1023           }
1024           MESSAGE ("commande = " << commande);
1025           if ((system(commande.c_str())) != 0) {
1026             SALOME::ExceptionStruct es;
1027             es.type = SALOME::BAD_PARAM;
1028             es.text = "The directory for the calculation cannot be cleared.";
1029             throw SALOME::SALOME_Exception(es);
1030           }
1031         }
1032       }
1033
1034       // Unlink from the parent iteration and from the hypothesis
1035       myIteration0->UnLinkNextIteration("Iter_1");
1036       ASSERT(!CORBA::is_nil(myHypothesis));
1037       myHypothesis->UnLinkIteration("Iter_1");
1038       myIteration1 = SMESHHOMARD::HOMARD_Iteration::_nil();
1039     }
1040   }
1041
1042   return 0;
1043 }
1044
1045 //=============================================================================
1046 //=============================================================================
1047 // Invalidation des structures identifiees par leurs noms
1048 //=============================================================================
1049 //=============================================================================
1050 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
1051 {
1052   MESSAGE("InvalideBoundary : BoundaryName = " << BoundaryName);
1053   SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
1054   if (CORBA::is_nil(myBoundary)) {
1055     SALOME::ExceptionStruct es;
1056     es.type = SALOME::BAD_PARAM;
1057     es.text = "Invalid boundary";
1058     throw SALOME::SALOME_Exception(es);
1059   }
1060   else {
1061     SALOME::ExceptionStruct es;
1062     es.type = SALOME::BAD_PARAM;
1063     es.text = "No change is allowed in a boundary. Ask for evolution.";
1064     throw SALOME::SALOME_Exception(es);
1065   }
1066 }
1067
1068 //=============================================================================
1069 //=============================================================================
1070 // Association de lien entre des structures identifiees par leurs noms
1071 //=============================================================================
1072 //=============================================================================
1073 void HOMARD_Gen_i::AssociateCaseIter(int numIter, const char* labelIter)
1074 {
1075   MESSAGE("AssociateCaseIter : " << numIter << ", "  << labelIter);
1076
1077   if (CORBA::is_nil(myCase)) {
1078     SALOME::ExceptionStruct es;
1079     es.type = SALOME::BAD_PARAM;
1080     es.text = "Invalid case";
1081     throw SALOME::SALOME_Exception(es);
1082   }
1083
1084   SMESHHOMARD::HOMARD_Iteration_var myIteration;
1085   if (numIter == 0) myIteration = myIteration0;
1086   else              myIteration = myIteration1;
1087   if (CORBA::is_nil(myIteration)) {
1088     SALOME::ExceptionStruct es;
1089     es.type = SALOME::BAD_PARAM;
1090     es.text = "Invalid iteration";
1091     throw SALOME::SALOME_Exception(es);
1092   }
1093
1094   myCase->AddIteration(myIteration->GetName());
1095   myIteration->SetCaseName("Case_1");
1096 }
1097
1098 //=============================================================================
1099 //=============================================================================
1100 // Recuperation des listes
1101 //=============================================================================
1102 //=============================================================================
1103 SMESHHOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
1104 {
1105   MESSAGE("GetAllBoundarysName");
1106
1107   SMESHHOMARD::listeBoundarys_var ret = new SMESHHOMARD::listeBoundarys;
1108   ret->length(_mesBoundarys.size());
1109   std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it;
1110   int i = 0;
1111   for (it = _mesBoundarys.begin();
1112        it != _mesBoundarys.end(); it++) {
1113     ret[i++] = CORBA::string_dup((*it).first.c_str());
1114   }
1115
1116   return ret._retn();
1117 }
1118
1119 //=============================================================================
1120 //=============================================================================
1121 // Recuperation des structures identifiees par leurs noms
1122 //=============================================================================
1123 //=============================================================================
1124 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1125 {
1126   SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[nomBoundary];
1127   ASSERT(!CORBA::is_nil(myBoundary));
1128   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1129 }
1130 //=============================================================================
1131 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase()
1132 {
1133   ASSERT(!CORBA::is_nil(myCase));
1134   return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1135 }
1136 //=============================================================================
1137 SMESHHOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::GetIteration(int numIter)
1138 {
1139   if (numIter == 0) {
1140     ASSERT(!CORBA::is_nil(myIteration0));
1141     return SMESHHOMARD::HOMARD_Iteration::_duplicate(myIteration0);
1142   }
1143
1144   ASSERT(!CORBA::is_nil(myIteration1));
1145   return SMESHHOMARD::HOMARD_Iteration::_duplicate(myIteration1);
1146 }
1147
1148 //=============================================================================
1149 //=============================================================================
1150 // Nouvelles structures
1151 //=============================================================================
1152 //=============================================================================
1153 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1154 {
1155   SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1156   HOMARD_Cas_i* aServant = new HOMARD_Cas_i(engine);
1157   SMESHHOMARD::HOMARD_Cas_var aCase = SMESHHOMARD::HOMARD_Cas::_narrow(aServant->_this());
1158   return aCase._retn();
1159 }
1160 //=============================================================================
1161 SMESHHOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1162 {
1163   SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1164   HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(engine);
1165   SMESHHOMARD::HOMARD_Iteration_var aIter =
1166     SMESHHOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1167   return aIter._retn();
1168 }
1169 //=============================================================================
1170 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1171 {
1172   SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1173   HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(engine);
1174   SMESHHOMARD::HOMARD_Boundary_var aBoundary =
1175     SMESHHOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1176   return aBoundary._retn();
1177 }
1178
1179 //=============================================================================
1180 //=============================================================================
1181 // Creation des structures identifiees par leurs noms
1182 //=============================================================================
1183 //=============================================================================
1184
1185 //=============================================================================
1186 // Creation of a case
1187 // MeshName : name of the mesh
1188 // smeshMesh : correspondent mesh
1189 // theWorkingDir : path to working directory
1190 //=============================================================================
1191 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseOnMesh (const char* MeshName,
1192                                                             SMESH::SMESH_Mesh_ptr smeshMesh,
1193                                                             const char* theWorkingDir)
1194 {
1195   INFOS("CreateCaseOnMesh");
1196
1197   // A. Controles
1198   // A.1. Controle du nom :
1199   if (!myCase->_is_nil()) {
1200     CleanCase();
1201   }
1202
1203   // A.2. Controle du objet maillage
1204   if (CORBA::is_nil(smeshMesh)) {
1205     SALOME::ExceptionStruct es;
1206     es.type = SALOME::BAD_PARAM;
1207     es.text = "The mesh object is null.";
1208     throw SALOME::SALOME_Exception(es);
1209   }
1210   MESSAGE("CreateCaseOnMesh : smeshMesh is not nil");
1211
1212   // A.3. Write mesh object in a temporary file in the working directory
1213   std::string aTmpMeshFile = theWorkingDir;
1214   aTmpMeshFile = theWorkingDir;
1215   aTmpMeshFile += std::string("/") + std::string(MeshName) + "_saved_from_SMESH";
1216   _TmpMeshFile = aTmpMeshFile + ".med";
1217   SMESH_File aFile (_TmpMeshFile, false);
1218   for (int ii = 1; aFile.exists(); ii++) {
1219     _TmpMeshFile = aTmpMeshFile + std::string("_") + std::to_string(ii) + ".med";
1220     aFile = SMESH_File(_TmpMeshFile, false);
1221   }
1222   const char* MeshFile = _TmpMeshFile.c_str();
1223   bool toOverwrite = true;
1224   bool toFindOutDim = true;
1225
1226   // Prevent dump of ExportMED
1227   {
1228     SMESH::TPythonDump pDump; // do not delete this line of code
1229     smeshMesh->ExportMED(MeshFile, false, -1, toOverwrite, toFindOutDim);
1230   }
1231
1232   // A.4. Controle du fichier du maillage
1233   med_idt medIdt = MEDfileOpen(MeshFile, MED_ACC_RDONLY);
1234   bool existeMeshFile = medIdt >= 0;
1235   if (existeMeshFile) MEDfileClose(medIdt);
1236   MESSAGE("CreateCaseOnMesh : existeMeshFile = " << existeMeshFile);
1237   if (!existeMeshFile) {
1238     SALOME::ExceptionStruct es;
1239     es.type = SALOME::BAD_PARAM;
1240     es.text = "The mesh file does not exist.";
1241     throw SALOME::SALOME_Exception(es);
1242   }
1243
1244   // B. Creation de l'objet cas
1245   myCase = newCase();
1246   _CaseOnMedFile = false;
1247   _SmeshMesh = SMESH::SMESH_Mesh::_duplicate(smeshMesh);
1248
1249   // C. Caracteristiques du maillage
1250   if (existeMeshFile) {
1251     // Les valeurs extremes des coordonnées
1252     //MESSAGE ("CreateCaseOnMesh : Les valeurs extremes des coordonnées");
1253     std::vector<double> LesExtremes = GetBoundingBoxInMedFile(MeshFile);
1254     SMESHHOMARD::extrema_var aSeq = new SMESHHOMARD::extrema();
1255     if (LesExtremes.size() != 10) { return 0; }
1256     aSeq->length(10);
1257     for (int i = 0; i < LesExtremes.size(); i++)
1258       aSeq[i] = LesExtremes[i];
1259     myCase->SetBoundingBox(aSeq);
1260     // Les groupes
1261     //MESSAGE ("CreateCaseOnMesh : Les groupes");
1262     std::set<std::string> LesGroupes = GetListeGroupesInMedFile(MeshFile);
1263     SMESHHOMARD::ListGroupType_var aSeqGroupe = new SMESHHOMARD::ListGroupType;
1264     aSeqGroupe->length(LesGroupes.size());
1265     std::set<std::string>::const_iterator it;
1266     int i = 0;
1267     for (it = LesGroupes.begin(); it != LesGroupes.end(); it++)
1268       aSeqGroupe[i++] = (*it).c_str();
1269     myCase->SetGroups(aSeqGroupe);
1270   }
1271
1272   // D. L'iteration initiale du cas
1273   MESSAGE ("CreateCaseOnMesh : iteration initiale du cas");
1274   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1275   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1276   MESSAGE("CreateCaseOnMesh : ==> NomIteration = " << MeshName);
1277
1278   // D.2. Creation de l'iteration 0
1279   myIteration0 = newIteration();
1280   myIteration0->SetName(MeshName);
1281   AssociateCaseIter(0, "IterationHomard");
1282
1283   // D.4. Maillage correspondant
1284   if (existeMeshFile) {
1285     myIteration0->SetMeshFile(MeshFile);
1286   }
1287   myIteration0->SetMeshName(MeshName);
1288   myIteration0->SetNumber(0);
1289   myIteration0->SetState(0);
1290
1291   // Only after full initialization of Iteration0
1292   myCase->SetDirName(theWorkingDir);
1293
1294   return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1295 }
1296
1297 //=============================================================================
1298 // Creation of a case
1299 // MeshName : name of the mesh
1300 // MeshFile : med file
1301 // theWorkingDir : path to working directory
1302 //=============================================================================
1303 SMESHHOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* MeshName,
1304                                                      const char* MeshFile,
1305                                                      const char* theWorkingDir)
1306 {
1307   INFOS("CreateCase : MeshName = " << MeshName << ", MeshFile = " << MeshFile);
1308
1309   // A. Controles
1310   // A.1. Controle du nom :
1311   if (!myCase->_is_nil()) {
1312     CleanCase();
1313   }
1314
1315   // A.3. Controle du fichier du maillage
1316   med_idt medIdt = MEDfileOpen(MeshFile, MED_ACC_RDONLY);
1317   bool existeMeshFile = medIdt >= 0;
1318   if (existeMeshFile) MEDfileClose(medIdt);
1319   MESSAGE("CreateCase : existeMeshFile = " << existeMeshFile);
1320   if (!existeMeshFile) {
1321     SALOME::ExceptionStruct es;
1322     es.type = SALOME::BAD_PARAM;
1323     es.text = "The mesh file does not exist.";
1324     throw SALOME::SALOME_Exception(es);
1325   }
1326
1327   // B. Creation de l'objet cas
1328   myCase = newCase();
1329   _CaseOnMedFile = true;
1330
1331   // C. Caracteristiques du maillage
1332   if (existeMeshFile) {
1333     // Les valeurs extremes des coordonnées
1334     //MESSAGE ("CreateCase : Les valeurs extremes des coordonnées");
1335     std::vector<double> LesExtremes = GetBoundingBoxInMedFile(MeshFile);
1336     SMESHHOMARD::extrema_var aSeq = new SMESHHOMARD::extrema();
1337     if (LesExtremes.size() != 10) { return 0; }
1338     aSeq->length(10);
1339     for (int i = 0; i < LesExtremes.size(); i++)
1340       aSeq[i] = LesExtremes[i];
1341     myCase->SetBoundingBox(aSeq);
1342     // Les groupes
1343     //MESSAGE ("CreateCase : Les groupes");
1344     std::set<std::string> LesGroupes = GetListeGroupesInMedFile(MeshFile);
1345     SMESHHOMARD::ListGroupType_var aSeqGroupe = new SMESHHOMARD::ListGroupType;
1346     aSeqGroupe->length(LesGroupes.size());
1347     std::set<std::string>::const_iterator it;
1348     int i = 0;
1349     for (it = LesGroupes.begin(); it != LesGroupes.end(); it++)
1350       aSeqGroupe[i++] = (*it).c_str();
1351     myCase->SetGroups(aSeqGroupe);
1352   }
1353
1354   // D. L'iteration initiale du cas
1355   MESSAGE ("CreateCase : iteration initiale du cas");
1356   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1357   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1358   MESSAGE("CreateCas : ==> NomIteration = " << MeshName);
1359
1360   // D.2. Creation de l'iteration
1361   myIteration0 = newIteration();
1362   myIteration0->SetName(MeshName);
1363   AssociateCaseIter(0, "IterationHomard");
1364
1365   // D.4. Maillage correspondant
1366   if (existeMeshFile) {
1367     myIteration0->SetMeshFile(MeshFile);
1368   }
1369   myIteration0->SetMeshName(MeshName);
1370   myIteration0->SetNumber(0);
1371   myIteration0->SetState(0);
1372
1373   // Only after full initialization of Iteration0
1374   myCase->SetDirName(theWorkingDir);
1375
1376   return SMESHHOMARD::HOMARD_Cas::_duplicate(myCase);
1377 }
1378
1379 //=============================================================================
1380 // Create Iteration1
1381 //=============================================================================
1382 SMESHHOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration()
1383 {
1384   if (CORBA::is_nil(myIteration0)) {
1385     SALOME::ExceptionStruct es;
1386     es.type = SALOME::BAD_PARAM;
1387     es.text = "The parent iteration is not defined.";
1388     throw SALOME::SALOME_Exception(es);
1389   }
1390
1391   if (CORBA::is_nil(myCase)) {
1392     SALOME::ExceptionStruct es;
1393     es.type = SALOME::BAD_PARAM;
1394     es.text = "Invalid case context";
1395     throw SALOME::SALOME_Exception(es);
1396   }
1397   const char* nomDirCase = myCase->GetDirName();
1398
1399   if (!myIteration1->_is_nil()) {
1400     DeleteIteration(1);
1401   }
1402
1403   myIteration1 = newIteration();
1404   if (CORBA::is_nil(myIteration1)) {
1405     SALOME::ExceptionStruct es;
1406     es.type = SALOME::BAD_PARAM;
1407     es.text = "Unable to create the iteration 1";
1408     throw SALOME::SALOME_Exception(es);
1409   }
1410
1411   // Nom de l'iteration et du maillage
1412   myIteration1->SetName("Iter_1");
1413   myIteration1->SetMeshName("Iter_1");
1414   myIteration1->SetState(1);
1415   myIteration1->SetNumber(1);
1416
1417   int nbitercase = 1; //myCase->GetNumberofIter()
1418   char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase);
1419   myIteration1->SetDirNameLoc(nomDirIter);
1420
1421   // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1422   // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1423   // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1424   // situation la plus frequente.
1425   // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1426   // le nombre d'iterations du cas permet d'eviter les collisions.
1427   int jaux;
1428   if      (nbitercase <    100) { jaux = 2; }
1429   else if (nbitercase <   1000) { jaux = 3; }
1430   else if (nbitercase <  10000) { jaux = 4; }
1431   else if (nbitercase < 100000) { jaux = 5; }
1432   else                          { jaux = 9; }
1433   std::ostringstream iaux;
1434   iaux << std::setw(jaux) << std::setfill('0') << nbitercase;
1435   std::stringstream MeshFile;
1436   MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1437   myIteration1->SetMeshFile(MeshFile.str().c_str());
1438
1439   // Association avec le cas
1440   std::string nomIterParent = myIteration0->GetName();
1441   std::string label = "IterationHomard_" + nomIterParent;
1442   AssociateCaseIter(1, label.c_str());
1443
1444   // Lien avec l'iteration precedente
1445   myIteration0->LinkNextIteration("Iter_1");
1446   myIteration1->SetIterParentName(nomIterParent.c_str());
1447
1448   // Associate hypothesis
1449   if (CORBA::is_nil(myHypothesis)) {
1450     SMESHHOMARD::HOMARD_Gen_var engine = POA_SMESHHOMARD::HOMARD_Gen::_this();
1451     HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(engine);
1452     myHypothesis = SMESHHOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1453     if (CORBA::is_nil(myHypothesis)) {
1454       SALOME::ExceptionStruct es;
1455       es.type = SALOME::BAD_PARAM;
1456       es.text = "Unable to create the hypothesis";
1457       throw SALOME::SALOME_Exception(es);
1458     }
1459     //myHypothesis->SetNivMax(-1);
1460     //myHypothesis->SetDiamMin(-1.0);
1461     //myHypothesis->SetAdapInit(0);
1462     //myHypothesis->SetExtraOutput(1);
1463   }
1464   myIteration1->SetHypoName("Hypo_1");
1465   myHypothesis->LinkIteration("Iter_1");
1466
1467   return SMESHHOMARD::HOMARD_Iteration::_duplicate(myIteration1);
1468 }
1469 //=============================================================================
1470 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName,
1471                                                               CORBA::Long BoundaryType)
1472 {
1473   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName <<
1474            ", BoundaryType = " << BoundaryType);
1475
1476   // Controle du nom :
1477   if ((_mesBoundarys).find(BoundaryName) != (_mesBoundarys).end()) {
1478     MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1479     SALOME::ExceptionStruct es;
1480     es.type = SALOME::BAD_PARAM;
1481     es.text = "This boundary has already been defined";
1482     throw SALOME::SALOME_Exception(es);
1483   }
1484
1485   SMESHHOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1486   myBoundary->SetName(BoundaryName);
1487   myBoundary->SetType(BoundaryType);
1488
1489   _mesBoundarys[BoundaryName] = myBoundary;
1490
1491   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1492 }
1493 //=============================================================================
1494 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1495 {
1496   MESSAGE ("CreateBoundaryCAO : BoundaryName  = " << BoundaryName << ", CAOFile = " << CAOFile);
1497   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1498   myBoundary->SetDataFile(CAOFile);
1499
1500   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1501 }
1502 //=============================================================================
1503 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1504 {
1505   MESSAGE ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile);
1506   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1507   myBoundary->SetDataFile(MeshFile);
1508   myBoundary->SetMeshName(MeshName);
1509
1510   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1511 }
1512 //=============================================================================
1513 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1514                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1515                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1516                                       CORBA::Double Rayon)
1517 {
1518   MESSAGE ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName);
1519 //
1520   SALOME::ExceptionStruct es;
1521   int error = 0;
1522   if (Rayon <= 0.0)
1523   { es.text = "The radius must be positive.";
1524     error = 1; }
1525   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1526   if (daux < 0.0000001)
1527   { es.text = "The axis must be a non 0 vector.";
1528     error = 2; }
1529   if (error != 0)
1530   {
1531     es.type = SALOME::BAD_PARAM;
1532     throw SALOME::SALOME_Exception(es);
1533     return 0;
1534   };
1535 //
1536   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1);
1537   myBoundary->SetCylinder(Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon);
1538
1539   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1540 }
1541 //=============================================================================
1542 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1543                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1544                                       CORBA::Double Rayon)
1545 {
1546   MESSAGE ("CreateBoundarySphere : BoundaryName  = " << BoundaryName);
1547 //
1548   SALOME::ExceptionStruct es;
1549   int error = 0;
1550   if (Rayon <= 0.0)
1551   { es.text = "The radius must be positive.";
1552     error = 1; }
1553   if (error != 0)
1554   {
1555     es.type = SALOME::BAD_PARAM;
1556     throw SALOME::SALOME_Exception(es);
1557     return 0;
1558   };
1559 //
1560   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2);
1561   myBoundary->SetSphere(Xcentre, Ycentre, Zcentre, Rayon);
1562
1563   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1564 }
1565 //=============================================================================
1566 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1567                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1568                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1569 {
1570   MESSAGE ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName);
1571 //
1572   SALOME::ExceptionStruct es;
1573   int error = 0;
1574   if (Angle <= 0.0 || Angle >= 90.0)
1575   { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees.";
1576     error = 1; }
1577   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1578   if (daux < 0.0000001)
1579   { es.text = "The axis must be a non 0 vector.";
1580     error = 2; }
1581   if (error != 0)
1582   {
1583     es.type = SALOME::BAD_PARAM;
1584     throw SALOME::SALOME_Exception(es);
1585     return 0;
1586   };
1587 //
1588   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3);
1589   myBoundary->SetConeA(Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre);
1590
1591   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1592 }
1593 //=============================================================================
1594 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1595                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1596                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1597 {
1598   MESSAGE ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName);
1599 //
1600   SALOME::ExceptionStruct es;
1601   int error = 0;
1602   if (Rayon1 < 0.0 || Rayon2 < 0.0)
1603   { es.text = "The radius must be positive.";
1604     error = 1; }
1605   double daux = fabs(Rayon2-Rayon1);
1606   if (daux < 0.0000001)
1607   { es.text = "The radius must be different.";
1608     error = 2; }
1609   daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1);
1610   if (daux < 0.0000001)
1611   { es.text = "The centers must be different.";
1612     error = 3; }
1613   if (error != 0)
1614   {
1615     es.type = SALOME::BAD_PARAM;
1616     throw SALOME::SALOME_Exception(es);
1617     return 0;
1618   };
1619 //
1620   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4);
1621   myBoundary->SetConeR(Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2);
1622
1623   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1624 }
1625 //=============================================================================
1626 SMESHHOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
1627                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1628                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1629                                       CORBA::Double RayonRev, CORBA::Double RayonPri)
1630 {
1631   MESSAGE ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName);
1632 //
1633   SALOME::ExceptionStruct es;
1634   int error = 0;
1635   if ((RayonRev <= 0.0) || (RayonPri <= 0.0))
1636   { es.text = "The radius must be positive.";
1637     error = 1; }
1638   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe);
1639   if (daux < 0.0000001)
1640   { es.text = "The axis must be a non 0 vector.";
1641     error = 2; }
1642   if (error != 0)
1643   {
1644     es.type = SALOME::BAD_PARAM;
1645     throw SALOME::SALOME_Exception(es);
1646     return 0;
1647   };
1648 //
1649   SMESHHOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5);
1650   myBoundary->SetTorus(Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri);
1651
1652   return SMESHHOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1653 }
1654
1655 //=============================================================================
1656 //=============================================================================
1657 CORBA::Long HOMARD_Gen_i::Compute()
1658 {
1659   INFOS ("Compute");
1660   // A. Prealable
1661   int codret = 0;
1662
1663   // A.0. Create Iteration 1
1664   myIteration1 = CreateIteration();
1665   myIteration1->SetInfoCompute(_VerboseLevel);
1666   myIteration1->SetMeshName(_MeshNameOUT.c_str());
1667   myIteration1->SetMeshFile(_MeshFileOUT.c_str());
1668   if (_LogInFile) myIteration1->SetLogFile(_LogFile.c_str());
1669
1670   // A.1. L'objet iteration
1671   ASSERT(!CORBA::is_nil(myIteration1));
1672
1673   // A.2. Controle de la possibilite d'agir
1674   // A.2.1. Etat de l'iteration
1675   int etat = myIteration1->GetState();
1676   MESSAGE ("etat = " << etat);
1677   // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
1678   if (etat == 2) {
1679     SALOME::ExceptionStruct es;
1680     es.type = SALOME::BAD_PARAM;
1681     es.text = "This iteration is already computed.";
1682     throw SALOME::SALOME_Exception(es);
1683   }
1684
1685   // A.3. Numero de l'iteration
1686   //     siterp1 : numero de l'iteration a traiter
1687   //     Si adaptation :
1688   //        siter: numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
1689   //     Ou si information :
1690   //        siter = siterp1
1691   int NumeIter = myIteration1->GetNumber();
1692   std::string siterp1;
1693   std::stringstream saux1;
1694   saux1 << NumeIter;
1695   siterp1 = saux1.str();
1696   if (NumeIter < 10) { siterp1 = "0" + siterp1; }
1697
1698   std::string siter;
1699   std::stringstream saux0;
1700   int iaux = max(0, NumeIter-1);
1701   saux0 << iaux;
1702   siter = saux0.str();
1703   if (NumeIter < 11) { siter = "0" + siter; }
1704
1705   // A.4. Le cas
1706   ASSERT(!CORBA::is_nil(myCase));
1707
1708   // B. Les répertoires
1709   // B.1. Le répertoire courant
1710   std::string nomDirWork = getenv("PWD");
1711   // B.2. Le sous-répertoire de l'iteration a traiter
1712   char* DirCompute = ComputeDirManagement(myCase, myIteration1);
1713   MESSAGE(". DirCompute = " << DirCompute);
1714
1715   // C. Le fichier des messages
1716   // C.1. Le deroulement de l'execution de HOMARD
1717   std::string LogFile = myIteration1->GetLogFile();
1718   if (LogFile.empty()) {
1719     LogFile = DirCompute;
1720     LogFile += "/Liste." + siter + ".vers." + siterp1 + ".log";
1721     myIteration1->SetLogFile(LogFile.c_str());
1722   }
1723   MESSAGE (". LogFile = " << LogFile);
1724   // C.2. Le bilan de l'analyse du maillage
1725   std::string FileInfo = DirCompute;
1726   FileInfo += "/apad." + siterp1 + ".bilan";
1727   myIteration1->SetFileInfo(FileInfo.c_str());
1728
1729    // D. On passe dans le répertoire de l'iteration a calculer
1730   MESSAGE (". On passe dans DirCompute = " << DirCompute);
1731   CHDIR(DirCompute);
1732
1733   // E. Les données de l'exécution HOMARD
1734   // E.1. L'objet du texte du fichier de configuration
1735   SMESHHOMARDImpl::HomardDriver* myDriver = new SMESHHOMARDImpl::HomardDriver(siter, siterp1);
1736   myDriver->TexteInit(DirCompute, LogFile, "English");
1737
1738   // E.2. Le maillage associe a l'iteration
1739   const char* NomMesh = myIteration1->GetMeshName();
1740   MESSAGE (". NomMesh = " << NomMesh);
1741   const char* MeshFile = myIteration1->GetMeshFile();
1742   MESSAGE (". MeshFile = " << MeshFile);
1743
1744   // E.3. Les données du traitement HOMARD
1745   iaux = 1;
1746   myDriver->TexteMaillageHOMARD(DirCompute, siterp1, iaux);
1747   myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1748   codret = ComputeAdap(myCase, myIteration1, myDriver);
1749
1750   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
1751   int BoundaryOption = DriverTexteBoundary(myCase, myDriver);
1752
1753   // E.5. Ecriture du texte dans le fichier
1754   MESSAGE (". Ecriture du texte dans le fichier de configuration; codret = "<<codret);
1755   if (codret == 0)
1756   { myDriver->CreeFichier(); }
1757
1758   // G. Execution
1759   //
1760   int codretexec = 1789;
1761   if (codret == 0) {
1762     codretexec = myDriver->ExecuteHomard();
1763     //
1764     MESSAGE ("Erreur en executant HOMARD : " << codretexec);
1765     // En mode adaptation, on ajuste l'etat de l'iteration
1766     if (codretexec == 0) { myIteration1->SetState(2); }
1767     else                 { myIteration1->SetState(1); }
1768   }
1769
1770   // H. Gestion des resultats
1771   if (codret == 0) {
1772     std::string Commentaire;
1773     // H.1. Le fichier des messages, dans tous les cas
1774     Commentaire = "log";
1775     Commentaire += " " + siterp1;
1776
1777     // H.2. Si tout s'est bien passe :
1778     if (codretexec == 0) {
1779       // H.2.1. Le fichier de bilan
1780       Commentaire = "Summary";
1781       Commentaire += " " + siterp1;
1782       // H.2.2. Le fichier de  maillage obtenu
1783       std::stringstream saux0;
1784       Commentaire = "Mesh";
1785       Commentaire += " " + siterp1;
1786       if (_PublishMeshOUT) PublishResultInSmesh(MeshFile, 1);
1787     }
1788     // H.3 Message d'erreur
1789     if (codretexec != 0) {
1790       std::string text = "";
1791       // Message d'erreur en cas de probleme en adaptation
1792       text = "Error during the adaptation.\n";
1793       bool stopvu = false;
1794       std::ifstream fichier(LogFile.c_str());
1795       if (fichier) { // ce test échoue si le fichier n'est pas ouvert
1796         std::string ligne; // variable contenant chaque ligne lue
1797         while (std::getline(fichier, ligne)) {
1798           //INFOS(ligne);
1799           if (stopvu) { text += ligne+ "\n"; }
1800           else {
1801             int position = ligne.find("===== HOMARD ===== STOP =====");
1802             if (position > 0) { stopvu = true; }
1803           }
1804         }
1805       }
1806       text += "\n\nSee the file " + LogFile + "\n";
1807       INFOS (text);
1808       SALOME::ExceptionStruct es;
1809       es.type = SALOME::BAD_PARAM;
1810       es.text = CORBA::string_dup(text.c_str());
1811       throw SALOME::SALOME_Exception(es);
1812     }
1813   }
1814
1815   // I. Menage et retour dans le répertoire du cas
1816   if (codret == 0) {
1817     delete myDriver;
1818     MESSAGE (". On retourne dans nomDirWork = " << nomDirWork);
1819     CHDIR(nomDirWork.c_str());
1820   }
1821
1822   // J. Suivi de la frontière CAO
1823   if (codret == 0) {
1824     if ((BoundaryOption % 5 == 0) && (codretexec == 0)) {
1825       MESSAGE ("Suivi de frontière CAO");
1826       codret = ComputeCAO(myCase, myIteration1);
1827     }
1828   }
1829
1830   if (codretexec == 0) {
1831     // Python Dump
1832     PythonDump();
1833
1834     // Clean all data
1835     CleanCase();
1836   }
1837
1838   return codretexec;
1839 }
1840
1841 void HOMARD_Gen_i::CleanCase()
1842 {
1843   // Delete log file, if required
1844   MESSAGE("myIteration1->GetLogFile() = " << myIteration1->GetLogFile());
1845   if (_LogInFile && _RemoveLogOnSuccess) {
1846     // Remove log file on success
1847     SMESH_File(myIteration1->GetLogFile(), false).remove();
1848   }
1849
1850   // Delete all boundaries
1851   std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
1852   for (it_boundary  = _mesBoundarys.begin();
1853        it_boundary != _mesBoundarys.end(); ++it_boundary) {
1854     DeleteBoundary((*it_boundary).first.c_str());
1855   }
1856
1857   // Delete iteration
1858   DeleteIteration(1);
1859
1860   // Delete hypothesis
1861   // Hypothesis should be deleted only after iteration deletion
1862   myHypothesis = SMESHHOMARD::HOMARD_Hypothesis::_nil();
1863
1864   // Delete case
1865   DeleteCase();
1866
1867   // Delete tmp mesh file
1868   if (!_CaseOnMedFile && !_TmpMeshFile.empty()) {
1869     SMESH_File aFile (_TmpMeshFile, false);
1870     if (aFile.exists()) aFile.remove();
1871   }
1872   _SmeshMesh = SMESH::SMESH_Mesh::_nil();
1873 }
1874
1875 //=============================================================================
1876 // Calcul d'une iteration : partie spécifique à l'adaptation
1877 //=============================================================================
1878 CORBA::Long HOMARD_Gen_i::ComputeAdap(SMESHHOMARD::HOMARD_Cas_var myCase,
1879                                       SMESHHOMARD::HOMARD_Iteration_var myIteration,
1880                                       SMESHHOMARDImpl::HomardDriver* myDriver)
1881 {
1882   MESSAGE ("ComputeAdap");
1883
1884   // A. Prealable
1885   // A.1. Bases
1886   int codret = 0;
1887   // Numero de l'iteration
1888   int NumeIter = myIteration->GetNumber();
1889   std::stringstream saux0;
1890   saux0 << NumeIter-1;
1891   std::string siter = saux0.str();
1892   if (NumeIter < 11) { siter = "0" + siter; }
1893
1894   // A.2. On verifie qu il y a une hypothese (erreur improbable);
1895   ASSERT(!CORBA::is_nil(myHypothesis));
1896
1897   // B. L'iteration parent
1898   //const char* nomIterationParent = myIteration->GetIterParentName();
1899   SMESHHOMARD::HOMARD_Iteration_var myIterationParent = myIteration0;
1900   ASSERT(!CORBA::is_nil(myIterationParent));
1901   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
1902   //if (myIterationParent->GetState() == 1) {
1903   //  int codret = Compute(nomIterationParent);
1904   //  if (codret != 0) VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
1905   //}
1906
1907   // C. Le sous-répertoire de l'iteration precedente
1908   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
1909   MESSAGE(". DirComputePa = " << DirComputePa);
1910
1911   // D. Les données de l'adaptation HOMARD
1912   // D.1. Le type de conformite
1913   int ConfType = myCase->GetConfType();
1914   MESSAGE (". ConfType = " << ConfType);
1915
1916   // D.3. Le maillage de depart
1917   const char* NomMeshParent = myIterationParent->GetMeshName();
1918   MESSAGE (". NomMeshParent = " << NomMeshParent);
1919   const char* MeshFileParent = myIterationParent->GetMeshFile();
1920   MESSAGE (". MeshFileParent = " << MeshFileParent);
1921
1922   // D.4. Le maillage associe a l'iteration
1923   const char* MeshFile = myIteration->GetMeshFile();
1924   MESSAGE (". MeshFile = " << MeshFile);
1925   FILE *file = fopen(MeshFile,"r");
1926   if (file != NULL) {
1927     fclose(file);
1928     // CleanOption = 0 : report an error if output mesh file exists
1929     // CleanOption = 1 : destruction du répertoire d'execution
1930     int CleanOption = 1;
1931     if (CleanOption == 0) {
1932       SALOME::ExceptionStruct es;
1933       es.type = SALOME::BAD_PARAM;
1934       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1935       es.text = CORBA::string_dup(text.c_str());
1936       throw SALOME::SALOME_Exception(es);
1937     }
1938     else {
1939       std::string commande = "rm -f " + std::string(MeshFile);
1940       codret = system(commande.c_str());
1941       if (codret != 0) {
1942         SALOME::ExceptionStruct es;
1943         es.type = SALOME::BAD_PARAM;
1944         es.text = "The mesh file cannot be deleted.";
1945         throw SALOME::SALOME_Exception(es);
1946       }
1947     }
1948   }
1949
1950   // D.5. Les types de raffinement et de deraffinement
1951   // Les appels corba sont lourds, il vaut mieux les grouper
1952   //SMESHHOMARD::listeTypes* ListTypes = myHypothesis->GetAdapRefinUnRef();
1953   //ASSERT(ListTypes->length() == 3);
1954   int TypeAdap = -1; // HomardHypothesis->GetAdapType()
1955   int TypeRaff = 1; // HomardHypothesis->GetRefinType()
1956   int TypeDera = 0; // HomardHypothesis->GetUnRefType()
1957
1958   // E. Texte du fichier de configuration
1959   // E.1. Incontournables du texte
1960   myDriver->TexteAdap();
1961   int iaux = 0;
1962   myDriver->TexteMaillageHOMARD(DirComputePa, siter, iaux);
1963   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1964   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1965
1966   // E.6. Ajout des options avancees
1967   //int NivMax = myHypo->GetNivMax();
1968   //MESSAGE (". NivMax = " << NivMax);
1969   //double DiamMin = myHypo->GetDiamMin();
1970   //MESSAGE (". DiamMin = " << DiamMin);
1971   //int AdapInit = myHypo->GetAdapInit();
1972   //MESSAGE (". AdapInit = " << AdapInit);
1973   //int ExtraOutput = myHypo->GetExtraOutput();
1974   //MESSAGE (". ExtraOutput = " << ExtraOutput);
1975   //myDriver->TexteAdvanced(NivMax, DiamMin, AdapInit, ExtraOutput);
1976   myDriver->TexteAdvanced(-1, -1.0, 0, 1);
1977
1978   // E.7. Ajout des informations sur le deroulement de l'execution
1979   int MessInfo = myIteration->GetInfoCompute();
1980   MESSAGE (". MessInfo = " << MessInfo);
1981   myDriver->TexteInfoCompute(MessInfo);
1982
1983   return codret;
1984 }
1985 //=============================================================================
1986 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
1987 //=============================================================================
1988 CORBA::Long HOMARD_Gen_i::ComputeCAO(SMESHHOMARD::HOMARD_Cas_var myCase,
1989                                      SMESHHOMARD::HOMARD_Iteration_var myIteration)
1990 {
1991   MESSAGE ("ComputeCAO");
1992
1993   // A. Prealable
1994   // A.1. Bases
1995   int codret = 0;
1996   // A.2. Le sous-répertoire de l'iteration en cours de traitement
1997   char* DirCompute = myIteration->GetDirName();
1998   // A.3. Le maillage résultat de l'iteration en cours de traitement
1999   char* MeshFile = myIteration->GetMeshFile();
2000
2001   // B. Les données pour FrontTrack
2002   // B.1. Le maillage à modifier
2003   const std::string theInputMedFile = MeshFile;
2004   MESSAGE (". theInputMedFile  = " << theInputMedFile);
2005
2006   // B.2. Le maillage après modification : fichier identique
2007   const std::string theOutputMedFile = MeshFile;
2008   MESSAGE (". theOutputMedFile = " << theInputMedFile);
2009
2010   // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2011   std::vector< std::string > theInputNodeFiles;
2012   MESSAGE (". DirCompute = " << DirCompute);
2013   std::basic_string<char>::size_type bilan;
2014   int icpt = 0;
2015 #ifndef WIN32
2016   DIR *dp;
2017   struct dirent *dirp;
2018   dp  = opendir(DirCompute);
2019   while ((dirp = readdir(dp)) != NULL)
2020   {
2021     std::string file_name(dirp->d_name);
2022     bilan = file_name.find("fr");
2023     if (bilan != string::npos)
2024     {
2025       std::stringstream filename_total;
2026       filename_total << DirCompute << "/" << file_name;
2027       theInputNodeFiles.push_back(filename_total.str());
2028       icpt += 1;
2029     }
2030   }
2031 #else
2032   HANDLE hFind = INVALID_HANDLE_VALUE;
2033   WIN32_FIND_DATA ffd;
2034   hFind = FindFirstFile(DirNameStart, &ffd);
2035   if (INVALID_HANDLE_VALUE != hFind) {
2036     while (FindNextFile(hFind, &ffd) != 0) {
2037       std::string file_name(ffd.cFileName);
2038       bilan = file_name.find("fr");
2039       if (bilan != string::npos)
2040       {
2041         std::stringstream filename_total;
2042         filename_total << DirCompute << "/" << file_name;
2043         theInputNodeFiles.push_back(filename_total.str());
2044         icpt += 1;
2045       }
2046     }
2047     FindClose(hFind);
2048   }
2049 #endif
2050   for (int i = 0; i < icpt; i++)
2051   { MESSAGE (". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i]); }
2052
2053   // B.4. Le fichier de la CAO
2054   SMESHHOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2055   std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2056   MESSAGE (". BoundaryName = " << BoundaryName);
2057   SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2058   const std::string theXaoFileName = myBoundary->GetDataFile();
2059   MESSAGE (". theXaoFileName = " << theXaoFileName);
2060
2061   // B.5. Parallélisme
2062   //bool theIsParallel = false;
2063
2064   // C. Lancement des projections
2065   MESSAGE (". Lancement des projections");
2066   // TODO?
2067   //FrontTrack* myFrontTrack = new FrontTrack();
2068   //myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2069
2070   // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2071   //    On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2072   MESSAGE (". Transfert des coordonnées");
2073   codret = ComputeCAObis(myIteration);
2074
2075   return codret;
2076 }
2077 //=============================================================================
2078 //=============================================================================
2079 // Transfert des coordonnées en suivi de frontière CAO
2080 //=============================================================================
2081 CORBA::Long HOMARD_Gen_i::ComputeCAObis(SMESHHOMARD::HOMARD_Iteration_var myIteration)
2082 {
2083   MESSAGE ("ComputeCAObis");
2084
2085   // A. Prealable
2086   int codret = 0;
2087
2088   // A.1. Controle de la possibilite d'agir
2089   // A.1.1. Etat de l'iteration
2090   int etat = myIteration->GetState();
2091   MESSAGE ("etat = " << etat);
2092   // A.1.2. L'iteration doit être calculee
2093   if (etat == 1) {
2094     SALOME::ExceptionStruct es;
2095     es.type = SALOME::BAD_PARAM;
2096     es.text = "This iteration is not computed.";
2097     throw SALOME::SALOME_Exception(es);
2098     return 1;
2099   }
2100   // A.2. Numero de l'iteration
2101   //     siterp1 : numero de l'iteration a traiter
2102   int NumeIter = myIteration->GetNumber();
2103   std::string siterp1;
2104   std::stringstream saux1;
2105   saux1 << NumeIter;
2106   siterp1 = saux1.str();
2107   if (NumeIter < 10) { siterp1 = "0" + siterp1; }
2108   MESSAGE ("siterp1 = "<<siterp1);
2109
2110   // A.3. Le cas
2111   ASSERT(!CORBA::is_nil(myCase));
2112
2113   // A.4. Le sous-répertoire de l'iteration a traiter
2114   char* DirCompute = myIteration->GetDirName();
2115   MESSAGE(". DirCompute = " << DirCompute);
2116
2117   // C. Le fichier des messages
2118   std::string LogFile = DirCompute;
2119   LogFile += "/Liste." + siterp1 + ".maj_coords.log";
2120   MESSAGE (". LogFile = " << LogFile);
2121   myIteration->SetFileInfo(LogFile.c_str());
2122
2123   // D. On passe dans le répertoire de l'iteration a calculer
2124   MESSAGE (". On passe dans DirCompute = " << DirCompute);
2125   CHDIR(DirCompute);
2126
2127   // E. Les données de l'exécution HOMARD
2128   // E.1. L'objet du texte du fichier de configuration
2129   SMESHHOMARDImpl::HomardDriver* myDriver = new SMESHHOMARDImpl::HomardDriver("", siterp1);
2130   myDriver->TexteInit(DirCompute, LogFile, "English");
2131
2132   // E.2. Le maillage associe a l'iteration
2133   const char* NomMesh = myIteration->GetMeshName();
2134   MESSAGE (". NomMesh = " << NomMesh);
2135   const char* MeshFile = myIteration->GetMeshFile();
2136   MESSAGE (". MeshFile = " << MeshFile);
2137
2138   // E.3. Les données du traitement HOMARD
2139   myDriver->TexteMajCoords(NumeIter);
2140   int iaux = 0;
2141   myDriver->TexteMaillageHOMARD(DirCompute, siterp1, iaux);
2142   myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2143   //
2144   // E.4. Ecriture du texte dans le fichier
2145   MESSAGE (". Ecriture du texte dans le fichier de configuration; codret = "<<codret);
2146   if (codret == 0) myDriver->CreeFichier();
2147
2148   // F. Execution
2149   //
2150   int codretexec = 1789;
2151   if (codret == 0) {
2152     codretexec = myDriver->ExecuteHomard();
2153     MESSAGE ("Erreur en executant HOMARD : " << codretexec);
2154   }
2155
2156   // G. Gestion des resultats
2157   if (codret == 0) {
2158     // G.1. Le fichier des messages, dans tous les cas
2159     std::string Commentaire = "logmaj_coords";
2160     // G.2 Message d'erreur
2161     if (codretexec != 0) {
2162       std::string text = "\n\nSee the file " + LogFile + "\n";
2163       INFOS (text);
2164       SALOME::ExceptionStruct es;
2165       es.type = SALOME::BAD_PARAM;
2166       es.text = CORBA::string_dup(text.c_str());
2167       throw SALOME::SALOME_Exception(es);
2168
2169       // On force le succes pour pouvoir consulter le fichier log
2170       codretexec = 0;
2171     }
2172   }
2173
2174   // H. Menage et retour dans le répertoire du cas
2175   if (codret == 0) { delete myDriver; }
2176
2177   return codret;
2178 }
2179 //=============================================================================
2180 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
2181 //  nomrep : nom du répertoire parent
2182 //  num : le nom du sous-répertoire est sous la forme 'In', n est >= num
2183 //=============================================================================
2184 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num)
2185 {
2186   MESSAGE ("CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2187   // On verifie que le répertoire parent existe
2188   int codret = CHDIR(nomrep);
2189   if (codret != 0) {
2190     SALOME::ExceptionStruct es;
2191     es.type = SALOME::BAD_PARAM;
2192     es.text = "The directory of the case does not exist.";
2193     throw SALOME::SALOME_Exception(es);
2194   }
2195   std::string nomDirActuel = getenv("PWD");
2196   std::string DirName;
2197   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
2198   bool a_chercher = true;
2199   while (a_chercher) {
2200     // On passe dans le répertoire parent
2201
2202     CHDIR(nomrep);
2203     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2204     int jaux;
2205     if      (num <    100) { jaux = 2; }
2206     else if (num <   1000) { jaux = 3; }
2207     else if (num <  10000) { jaux = 4; }
2208     else if (num < 100000) { jaux = 5; }
2209     else                     { jaux = 9; }
2210     std::ostringstream iaux;
2211     iaux << std::setw(jaux) << std::setfill('0') << num;
2212     std::ostringstream DirNameA;
2213     DirNameA << "I" << iaux.str();
2214     // Si on ne pas peut entrer dans le répertoire, on doit verifier
2215     // que c'est bien un probleme d'absence
2216     if (CHDIR(DirNameA.str().c_str()) != 0)
2217     {
2218       bool existe = false;
2219 #ifndef WIN32
2220       DIR *dp;
2221       struct dirent *dirp;
2222       dp  = opendir(nomrep);
2223       while ((dirp = readdir(dp)) != NULL)
2224       {
2225         std::string file_name(dirp->d_name);
2226 #else
2227       HANDLE hFind = INVALID_HANDLE_VALUE;
2228       WIN32_FIND_DATA ffd;
2229       hFind = FindFirstFile(nomrep, &ffd);
2230       if (INVALID_HANDLE_VALUE != hFind) {
2231         while (FindNextFile(hFind, &ffd) != 0) {
2232          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2233          std::string file_name(ffd.cFileName);
2234 #endif
2235         if (file_name == DirNameA.str()) { existe = true; }
2236       }
2237 #ifndef WIN32
2238       closedir(dp);
2239 #else
2240       FindClose(hFind);
2241 #endif
2242       if (!existe)
2243       {
2244         DirName = DirNameA.str();
2245         a_chercher = false;
2246         break;
2247       }
2248     }
2249     num += 1;
2250   }
2251
2252   MESSAGE ("==> DirName = " << DirName);
2253   MESSAGE (". On retourne dans nomDirActuel = " << nomDirActuel);
2254   CHDIR(nomDirActuel.c_str());
2255   return CORBA::string_dup(DirName.c_str());
2256 }
2257 //=============================================================================
2258 // Calcul d'une iteration : gestion du répertoire de calcul
2259 //=============================================================================
2260 char* HOMARD_Gen_i::ComputeDirManagement(SMESHHOMARD::HOMARD_Cas_var myCase,
2261                                          SMESHHOMARD::HOMARD_Iteration_var myIteration)
2262 {
2263   MESSAGE ("ComputeDirManagement : répertoires pour le calcul");
2264
2265   //Si le sous-répertoire existe :
2266   //  CleanOption =  0 : on sort en erreur si le répertoire n'est pas vide
2267   //  CleanOption =  1 : on fait le menage du répertoire
2268   //  CleanOption = -1 : on ne fait rien
2269   int CleanOption = 0;
2270
2271   // B.2. Le répertoire du cas
2272   const char* nomDirCase = myCase->GetDirName();
2273   MESSAGE (". nomDirCase = " << nomDirCase);
2274
2275   // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
2276   // B.3.1. Le nom du sous-répertoire
2277   const char* nomDirIt = myIteration->GetDirNameLoc();
2278
2279   // B.3.2. Le nom complet du sous-répertoire
2280   std::stringstream DirCompute;
2281   DirCompute << nomDirCase << "/" << nomDirIt;
2282   MESSAGE (". DirCompute = " << DirCompute.str());
2283
2284   // B.3.3. Si le sous-répertoire n'existe pas, on le cree
2285   if (CHDIR(DirCompute.str().c_str()) != 0)
2286   {
2287 #ifndef WIN32
2288     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2289 #else
2290     if (_mkdir(DirCompute.str().c_str()) != 0)
2291 #endif
2292     {
2293        // GERALD -- QMESSAGE BOX
2294        std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
2295        VERIFICATION("Pb a la creation du répertoire" == 0);
2296     }
2297   }
2298   else
2299   {
2300     //  Le répertoire existe
2301     //  On demande de faire le menage de son contenu :
2302     if (CleanOption == 1) {
2303       MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
2304       std::string commande = "rm -rf " + DirCompute.str()+"/*";
2305       int codret = system(commande.c_str());
2306       if (codret != 0)
2307       {
2308         // GERALD -- QMESSAGE BOX
2309         std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
2310         VERIFICATION("Pb au menage du répertoire de calcul" == 0);
2311       }
2312     }
2313     //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2314     else {
2315       if (CleanOption == 0) {
2316 #ifndef WIN32
2317         DIR *dp;
2318         struct dirent *dirp;
2319         dp  = opendir(DirCompute.str().c_str());
2320         bool result = true;
2321         while ((dirp = readdir(dp)) != NULL && result)
2322         {
2323           std::string file_name(dirp->d_name);
2324           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2325         }
2326         closedir(dp);
2327 #else
2328        HANDLE hFind = INVALID_HANDLE_VALUE;
2329        WIN32_FIND_DATA ffd;
2330        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2331        bool result = true;
2332        if (INVALID_HANDLE_VALUE != hFind) {
2333          while (FindNextFile(hFind, &ffd) != 0) {
2334           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2335           std::string file_name(ffd.cFileName);
2336           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2337          }
2338        }
2339        FindClose(hFind);
2340 #endif
2341         if (result == false)
2342         {
2343           SALOME::ExceptionStruct es;
2344           es.type = SALOME::BAD_PARAM;
2345           std::string text = "Directory : " + DirCompute.str() + " is not empty";
2346           es.text = CORBA::string_dup(text.c_str());
2347           throw SALOME::SALOME_Exception(es);
2348           VERIFICATION("Directory is not empty" == 0);
2349         }
2350       }
2351     }
2352   }
2353
2354   return CORBA::string_dup(DirCompute.str().c_str());
2355 }
2356 //=============================================================================
2357 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
2358 //=============================================================================
2359 char* HOMARD_Gen_i::ComputeDirPaManagement(SMESHHOMARD::HOMARD_Cas_var myCase, SMESHHOMARD::HOMARD_Iteration_var myIteration)
2360 {
2361   MESSAGE ("ComputeDirPaManagement : répertoires pour le calcul");
2362   // Le répertoire du cas
2363   const char* nomDirCase = myCase->GetDirName();
2364   MESSAGE (". nomDirCase = " << nomDirCase);
2365
2366   // Le sous-répertoire de l'iteration precedente
2367
2368   SMESHHOMARD::HOMARD_Iteration_var myIterationParent = myIteration0;
2369   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2370   std::stringstream DirComputePa;
2371   DirComputePa << nomDirCase << "/" << nomDirItPa;
2372   MESSAGE(". nomDirItPa = " << nomDirItPa);
2373   MESSAGE(". DirComputePa = " << DirComputePa.str());
2374
2375   return CORBA::string_dup(DirComputePa.str().c_str());
2376 }
2377
2378 //=============================================================================
2379 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2380 // On ecrit dans l'ordre :
2381 //    1. la definition des frontieres
2382 //    2. les liens avec les groupes
2383 //    3. un entier resumant le type de comportement pour les frontieres
2384 //=============================================================================
2385 int HOMARD_Gen_i::DriverTexteBoundary(SMESHHOMARD::HOMARD_Cas_var myCase, SMESHHOMARDImpl::HomardDriver* myDriver)
2386 {
2387   MESSAGE ("... DriverTexteBoundary");
2388   // 1. Recuperation des frontieres
2389   std::list<std::string>  ListeBoundaryTraitees;
2390   SMESHHOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2391   int numberOfitems = ListBoundaryGroupType->length();
2392   MESSAGE ("... number of string for Boundary+Group = " << numberOfitems);
2393   int BoundaryOption = 1;
2394   // 2. Parcours des frontieres pour ecrire leur description
2395   int NumBoundaryAnalytical = 0;
2396   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2397   {
2398     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2399     MESSAGE ("... BoundaryName = " << BoundaryName);
2400     // 2.1. La frontiere a-t-elle deja ete ecrite ?
2401     //      Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
2402     int A_faire = 1;
2403     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2404     while (it != ListeBoundaryTraitees.end())
2405     {
2406       MESSAGE ("..... BoundaryNameTraitee = " << *it);
2407       if (BoundaryName == *it) { A_faire = 0; }
2408       it++;
2409     }
2410     // 2.2. Ecriture de la frontiere
2411     if (A_faire == 1)
2412     {
2413       // 2.2.1. Caracteristiques de la frontiere
2414       SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2415       ASSERT(!CORBA::is_nil(myBoundary));
2416       int BoundaryType = myBoundary->GetType();
2417       MESSAGE ("... BoundaryType = " << BoundaryType);
2418       // 2.2.2. Ecriture selon le type
2419       // 2.2.2.1. Cas d une frontiere CAO
2420       if (BoundaryType == -1)
2421       {
2422 //         const char* CAOFile = myBoundary->GetDataFile();
2423 //         MESSAGE (". CAOFile = " << CAOFile);
2424         if (BoundaryOption % 5 != 0) { BoundaryOption = BoundaryOption*5; }
2425       }
2426       // 2.2.2.2. Cas d une frontiere discrete
2427       else if (BoundaryType == 0)
2428       {
2429         const char* MeshName = myBoundary->GetMeshName();
2430         MESSAGE (". MeshName = " << MeshName);
2431         const char* MeshFile = myBoundary->GetDataFile();
2432         MESSAGE (". MeshFile = " << MeshFile);
2433         myDriver->TexteBoundaryDi(MeshName, MeshFile);
2434         if (BoundaryOption % 2 != 0) { BoundaryOption = BoundaryOption*2; }
2435       }
2436       // 2.2.2.3. Cas d une frontiere analytique
2437       else
2438       {
2439         NumBoundaryAnalytical++;
2440         SMESHHOMARD::double_array* coor = myBoundary->GetCoords();
2441         if (BoundaryType == 1) // Cas d un cylindre
2442         {
2443           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2444           if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2445         }
2446         else if (BoundaryType == 2) // Cas d une sphere
2447         {
2448           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2449           if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2450         }
2451         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2452         {
2453           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2454           if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2455         }
2456         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2457         {
2458           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2459           if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2460         }
2461         else if (BoundaryType == 5) // Cas d un tore
2462         {
2463           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2464           if (BoundaryOption % 3 != 0) { BoundaryOption = BoundaryOption*3; }
2465         }
2466       }
2467       // 2.2.3. Memorisation du traitement
2468       ListeBoundaryTraitees.push_back(BoundaryName);
2469     }
2470   }
2471   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
2472   NumBoundaryAnalytical = 0;
2473   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2474   {
2475     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2476     MESSAGE ("... BoundaryName = " << BoundaryName);
2477     SMESHHOMARD::HOMARD_Boundary_var myBoundary = _mesBoundarys[BoundaryName];
2478     ASSERT(!CORBA::is_nil(myBoundary));
2479     int BoundaryType = myBoundary->GetType();
2480     MESSAGE ("... BoundaryType = " << BoundaryType);
2481     // 3.1. Recuperation du nom du groupe
2482     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2483     MESSAGE ("... GroupName = " << GroupName);
2484     // 3.2. Cas d une frontiere CAO
2485     if (BoundaryType == -1)
2486     {
2487       if (GroupName.size() > 0) { myDriver->TexteBoundaryCAOGr (GroupName); }
2488     }
2489     // 3.3. Cas d une frontiere discrete
2490     else if (BoundaryType == 0)
2491     {
2492       if (GroupName.size() > 0) { myDriver->TexteBoundaryDiGr (GroupName); }
2493     }
2494     // 3.4. Cas d une frontiere analytique
2495     else
2496     {
2497       NumBoundaryAnalytical++;
2498       myDriver->TexteBoundaryAnGr (BoundaryName, NumBoundaryAnalytical, GroupName);
2499     }
2500   }
2501   // 4. Ecriture de l'option finale
2502   myDriver->TexteBoundaryOption(BoundaryOption);
2503 //
2504   return BoundaryOption;
2505 }
2506 //===========================================================================
2507 //===========================================================================
2508
2509 //===========================================================================
2510 // Publications
2511 // Option = 0 : fichier issu d'une importation
2512 // Option = 1 : fichier issu d'une execution HOMARD
2513 //===========================================================================
2514 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
2515 {
2516   // Prevent dump of CreateMeshesFromMED
2517   SMESH::TPythonDump pDump; // do not delete this line of code
2518
2519   MESSAGE("PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
2520   if (CORBA::is_nil(SMESH_Gen_i::GetSMESHGen()->getStudyServant())) {
2521     SALOME::ExceptionStruct es;
2522     es.type = SALOME::BAD_PARAM;
2523     es.text = "Invalid study context";
2524     throw SALOME::SALOME_Exception(es);
2525   }
2526
2527   // Le module SMESH est-il actif ?
2528   SALOMEDS::SObject_var aSmeshSO =
2529     SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2530   //
2531   // TODO?
2532   // Temporary suppressed depublication of mesh with the same name of file
2533   /*
2534   if (!CORBA::is_nil(aSmeshSO)) {
2535     // On verifie que le fichier n est pas deja publie
2536     SALOMEDS::ChildIterator_var aIter =
2537       SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewChildIterator(aSmeshSO);
2538     for (; aIter->More(); aIter->Next()) {
2539       SALOMEDS::SObject_var aSO = aIter->Value();
2540       SALOMEDS::GenericAttribute_var aGAttr;
2541       if (aSO->FindAttribute(aGAttr, "AttributeExternalFileDef")) {
2542         SALOMEDS::AttributeExternalFileDef_var anAttr =
2543           SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2544         CORBA::String_var value = anAttr->Value();
2545         if (strcmp((const char*)value, NomFich) == 0) {
2546           MESSAGE ("PublishResultInSmesh : le fichier " << NomFich << " est deja publie.");
2547           // Pour un fichier importe, on ne republie pas
2548           if (Option == 0) { return; }
2549           // Pour un fichier calcule, on commence par faire la depublication
2550           else {
2551             MESSAGE("PublishResultInSmesh : depublication");
2552             if (aSO->FindAttribute(aGAttr, "AttributeName")) {
2553               SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2554               CORBA::String_var value2 = anAttr2->Value();
2555               std::string MeshName = string(value2);
2556               MESSAGE("PublishResultInSmesh : depublication de " << MeshName);
2557               DeleteResultInSmesh(NomFich, MeshName);
2558             }
2559           }
2560         }
2561       }
2562     }
2563   }
2564   */
2565
2566   // On enregistre le fichier
2567   MESSAGE("Enregistrement du fichier");
2568   //
2569   //SMESH::SMESH_Gen_var aSmeshEngine = this->retrieveSMESHInst();
2570   SMESH_Gen_i* aSmeshEngine = SMESH_Gen_i::GetSMESHGen();
2571   //
2572   //ASSERT(!CORBA::is_nil(aSmeshEngine));
2573   aSmeshEngine->UpdateStudy();
2574   SMESH::DriverMED_ReadStatus theStatus;
2575
2576   // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2577   SMESH::mesh_array* mesMaillages = aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2578   if (CORBA::is_nil(aSmeshSO)) {
2579     aSmeshSO = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2580     if (CORBA::is_nil(aSmeshSO)) return;
2581   }
2582
2583   for (int i = 0; i < (int)mesMaillages->length(); i++) {
2584     MESSAGE(". Mise a jour des attributs du maillage");
2585     SMESH::SMESH_Mesh_var monMaillage = (*mesMaillages)[i];
2586     SALOMEDS::SObject_var aSO = SALOMEDS::SObject::_narrow
2587       (SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectIOR
2588        (SMESH_Gen_i::GetORB()->object_to_string(monMaillage)));
2589     SALOMEDS::StudyBuilder_var aStudyBuilder =
2590       SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
2591     SALOMEDS::GenericAttribute_var aGAttr =
2592       aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2593     SALOMEDS::AttributeExternalFileDef_var anAttr =
2594       SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2595     anAttr->SetValue(NomFich);
2596     SALOMEDS::GenericAttribute_var aPixMap =
2597       aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap");
2598     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2599     const char* icone;
2600     if (Option == 0) { icone = "mesh_tree_importedmesh.png"; }
2601     else               { icone = "mesh_tree_mesh.png"; }
2602     anAttr2->SetPixMap(icone);
2603   }
2604 }
2605
2606 //=============================================================================
2607 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
2608 {
2609   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich);
2610   if (CORBA::is_nil(SMESH_Gen_i::GetSMESHGen()->getStudyServant())) {
2611     SALOME::ExceptionStruct es;
2612     es.type = SALOME::BAD_PARAM;
2613     es.text = "Invalid study context";
2614     throw SALOME::SALOME_Exception(es);
2615   }
2616
2617   // Le module SMESH est-il actif ?
2618   SALOMEDS::SObject_var aSmeshSO =
2619     SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindComponent("SMESH");
2620   //
2621   if (CORBA::is_nil(aSmeshSO)) return;
2622   // On verifie que le fichier est deja publie
2623   SALOMEDS::StudyBuilder_var myBuilder =
2624     SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewBuilder();
2625   SALOMEDS::ChildIterator_var aIter =
2626     SMESH_Gen_i::GetSMESHGen()->getStudyServant()->NewChildIterator(aSmeshSO);
2627   for (; aIter->More(); aIter->Next()) {
2628     SALOMEDS::SObject_var  aSO = aIter->Value();
2629     SALOMEDS::GenericAttribute_var aGAttr;
2630     if (aSO->FindAttribute(aGAttr, "AttributeExternalFileDef")) {
2631       SALOMEDS::AttributeExternalFileDef_var anAttr =
2632         SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2633       CORBA::String_var value = anAttr->Value();
2634       if (strcmp((const char*)value, NomFich.c_str()) == 0) {
2635         if (aSO->FindAttribute(aGAttr, "AttributeName")) {
2636           SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2637           CORBA::String_var value2 = anAttr2->Value();
2638           if (strcmp((const char*)value2, MeshName.c_str()) == 0) {
2639             myBuilder->RemoveObjectWithChildren(aSO);
2640           }
2641         }
2642       }
2643     }
2644   }
2645 }
2646
2647 void HOMARD_Gen_i::PythonDump()
2648 {
2649   MESSAGE ("Begin PythonDump");
2650   SMESH::TPythonDump pd;
2651
2652   // SMESH_Homard
2653   pd << "import SMESHHOMARD\n";
2654   //pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".CreateHOMARD_ADAPT()\n";
2655   pd << "smeshhomard = " << SMESH_Gen_i::GetSMESHGen() << ".Adaptation(\"Uniform\")\n";
2656
2657   // Boundaries
2658   if (_mesBoundarys.size() > 0) MESSAGE(". Creation of the boundaries");
2659   std::map<std::string, SMESHHOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2660   for (it_boundary  = _mesBoundarys.begin();
2661        it_boundary != _mesBoundarys.end(); ++it_boundary) {
2662     SMESHHOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2663     pd << maBoundary->GetDumpPython();
2664   }
2665
2666   // Case
2667   ASSERT(!myCase->_is_nil());
2668   MESSAGE (". Creation of the case");
2669
2670   if (_CaseOnMedFile) {
2671     pd << "Case_1 = smeshhomard.CreateCase(\"" << myIteration0->GetMeshName();
2672     pd << "\", \"" << myIteration0->GetMeshFile();
2673     pd << "\", \"" << myCase->GetDirName() << "\")\n";
2674   }
2675   else {
2676     pd << "Case_1 = smeshhomard.CreateCaseOnMesh(\"" << myIteration0->GetMeshName();
2677     pd << "\", " << _SmeshMesh;
2678     pd << ".GetMesh(), \"" << myCase->GetDirName() << "\")\n";
2679   }
2680
2681   pd << myCase->GetDumpPython();
2682
2683   // Preferences
2684   pd << "smeshhomard.SetKeepMedOUT(" << (_KeepMedOUT ? "True" : "False") << ")\n";
2685   pd << "smeshhomard.SetPublishMeshOUT(" << (_PublishMeshOUT ? "True" : "False") << ")\n";
2686   pd << "smeshhomard.SetMeshNameOUT(\"" << _MeshNameOUT << "\")\n";
2687   pd << "smeshhomard.SetMeshFileOUT(\"" << _MeshFileOUT << "\")\n";
2688
2689   pd << "smeshhomard.SetKeepWorkingFiles(" << (_KeepWorkingFiles ? "True" : "False") << ")\n";
2690   pd << "smeshhomard.SetLogInFile(" << (_LogInFile ? "True" : "False") << ")\n";
2691   if (_LogInFile) pd << "smeshhomard.SetLogFile(\"" << _LogFile << "\")\n";
2692   pd << "smeshhomard.SetRemoveLogOnSuccess(" << (_RemoveLogOnSuccess ? "True" : "False") << ")\n";
2693   pd << "smeshhomard.SetVerboseLevel(" << _VerboseLevel << ")\n";
2694
2695   // Compute
2696   pd << "smeshhomard.Compute()\n";
2697   MESSAGE ("End PythonDump");
2698 }
2699
2700 //===============================================================================
2701 // Preferences
2702 //===============================================================================
2703 void HOMARD_Gen_i::SetKeepMedOUT(bool theKeepMedOUT)
2704 {
2705   _KeepMedOUT = theKeepMedOUT;
2706 }
2707 void HOMARD_Gen_i::SetPublishMeshOUT(bool thePublishMeshOUT)
2708 {
2709   _PublishMeshOUT = thePublishMeshOUT;
2710 }
2711 void HOMARD_Gen_i::SetKeepWorkingFiles(bool theKeepWorkingFiles)
2712 {
2713   _KeepWorkingFiles = theKeepWorkingFiles;
2714 }
2715 void HOMARD_Gen_i::SetLogInFile(bool theLogInFile)
2716 {
2717   _LogInFile = theLogInFile;
2718 }
2719 void HOMARD_Gen_i::SetRemoveLogOnSuccess(bool theRemoveLogOnSuccess)
2720 {
2721   _RemoveLogOnSuccess = theRemoveLogOnSuccess;
2722 }
2723 void HOMARD_Gen_i::SetVerboseLevel(CORBA::Long theVerboseLevel)
2724 {
2725   _VerboseLevel = theVerboseLevel;
2726 }
2727 void HOMARD_Gen_i::SetMeshNameOUT(const char* theMeshNameOUT)
2728 {
2729   _MeshNameOUT = theMeshNameOUT;
2730 }
2731 void HOMARD_Gen_i::SetMeshFileOUT(const char* theMeshFileOUT)
2732 {
2733   _MeshFileOUT = theMeshFileOUT;
2734 }
2735 void HOMARD_Gen_i::SetLogFile(const char* theLogFile)
2736 {
2737   _LogFile = theLogFile;
2738 }
2739
2740 // =======================================================================
2741 std::set<std::string> GetListeGroupesInMedFile(const char * aFile)
2742 {
2743   std::set<std::string> ListeGroupes;
2744   med_err erreur = 0;
2745   med_idt medIdt;
2746   while (erreur == 0) {
2747     //  Ouverture du fichier
2748     medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
2749     if (medIdt < 0) {
2750       erreur = 1;
2751       break;
2752     }
2753     // Caracteristiques du maillage
2754     char meshname[MED_NAME_SIZE+1];
2755     med_int spacedim,meshdim;
2756     med_mesh_type meshtype;
2757     char descriptionription[MED_COMMENT_SIZE+1];
2758     char dtunit[MED_SNAME_SIZE+1];
2759     med_sorting_type sortingtype;
2760     med_int nstep;
2761     med_axis_type axistype;
2762     int naxis = MEDmeshnAxis(medIdt,1);
2763     char *axisname=new char[naxis*MED_SNAME_SIZE+1];
2764     char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
2765     erreur = MEDmeshInfo(medIdt,
2766                             1,
2767                             meshname,
2768                             &spacedim,
2769                             &meshdim,
2770                             &meshtype,
2771                             descriptionription,
2772                             dtunit,
2773                             &sortingtype,
2774                             &nstep,
2775                             &axistype,
2776                             axisname,
2777                             axisunit);
2778     delete[] axisname;
2779     delete[] axisunit;
2780     if (erreur < 0) { break; }
2781     // Nombre de familles
2782     med_int nfam;
2783     nfam = MEDnFamily(medIdt,meshname);
2784     if (nfam < 0) {
2785       erreur = 2;
2786       break;
2787     }
2788     // Lecture des caracteristiques des familles
2789     for (int i=0;i<nfam;i++) {
2790       // Lecture du nombre de groupes
2791       med_int ngro = MEDnFamilyGroup(medIdt,meshname,i+1);
2792       if (ngro < 0) {
2793         erreur = 3;
2794         break;
2795       }
2796       // Lecture de la famille
2797       else if (ngro > 0) {
2798         char familyname[MED_NAME_SIZE+1];
2799         med_int numfam;
2800         char* gro = (char*) malloc(MED_LNAME_SIZE*ngro+1);
2801         erreur = MEDfamilyInfo(medIdt,
2802                                meshname,
2803                                i+1,
2804                                familyname,
2805                                &numfam,
2806                                gro);
2807         if (erreur < 0) {
2808           free(gro);
2809           break;
2810         }
2811         // Lecture des groupes pour une famille de mailles
2812         if (numfam < 0) {
2813           for (int j=0;j<ngro;j++) {
2814             char str2[MED_LNAME_SIZE+1];
2815             strncpy(str2,gro+j*MED_LNAME_SIZE,MED_LNAME_SIZE);
2816             str2[MED_LNAME_SIZE] = '\0';
2817             ListeGroupes.insert(std::string(str2));
2818           }
2819         }
2820         free(gro);
2821       }
2822     }
2823     break;
2824   }
2825   // Fermeture du fichier
2826   if (medIdt > 0) MEDfileClose(medIdt);
2827
2828   return ListeGroupes;
2829 }
2830
2831 // =======================================================================
2832 // Le vecteur en retour contiendra les informations suivantes :
2833 // en position 0 et 1 Xmin, Xmax et en position 2 Dx si < 0  2D
2834 // en position 3 et 4 Ymin, Ymax et en position 5 Dy si < 0  2D
2835 // en position 6 et 7 Zmin, Zmax et en position 8 Dz si < 0  2D
2836 //  9 distance max dans le maillage
2837 // =======================================================================
2838 std::vector<double> GetBoundingBoxInMedFile(const char * aFile)
2839 {
2840   std::vector<double> LesExtremes;
2841   med_err erreur = 0;
2842   med_idt medIdt;
2843   while (erreur == 0) {
2844     //  Ouverture du fichier
2845     medIdt = MEDfileOpen(aFile,MED_ACC_RDONLY);
2846     if (medIdt < 0) {
2847       erreur = 1;
2848       break;
2849     }
2850     //Nombre de maillage : on ne peut en lire qu'un seul
2851     med_int numberOfMeshes = MEDnMesh(medIdt);
2852     if (numberOfMeshes != 1) {
2853       erreur = 2;
2854       break;
2855     }
2856     // Caracteristiques du maillage
2857     char meshname[MED_NAME_SIZE+1];
2858     med_int spacedim,meshdim;
2859     med_mesh_type meshtype;
2860     char descriptionription[MED_COMMENT_SIZE+1];
2861     char dtunit[MED_SNAME_SIZE+1];
2862     med_sorting_type sortingtype;
2863     med_int nstep;
2864     med_axis_type axistype;
2865     int naxis = MEDmeshnAxis(medIdt,1);
2866     char *axisname=new char[naxis*MED_SNAME_SIZE+1];
2867     char *axisunit=new char[naxis*MED_SNAME_SIZE+1];
2868     erreur = MEDmeshInfo(medIdt,
2869                             1,
2870                             meshname,
2871                             &spacedim,
2872                             &meshdim,
2873                             &meshtype,
2874                             descriptionription,
2875                             dtunit,
2876                             &sortingtype,
2877                             &nstep,
2878                             &axistype,
2879                             axisname,
2880                             axisunit);
2881     delete[] axisname;
2882     delete[] axisunit;
2883     if (erreur < 0) { break; }
2884
2885     // Nombre de noeuds
2886     med_bool chgt,trsf;
2887     med_int nnoe  = MEDmeshnEntity(medIdt,
2888                               meshname,
2889                               MED_NO_DT,
2890                               MED_NO_IT,
2891                               MED_NODE,
2892                               MED_NO_GEOTYPE,
2893                               MED_COORDINATE,
2894                               MED_NO_CMODE,
2895                               &chgt,
2896                               &trsf);
2897     if (nnoe < 0) {
2898       erreur =  4;
2899       break;
2900     }
2901
2902     // Les coordonnees
2903     med_float* coo = (med_float*) malloc(sizeof(med_float)*nnoe*spacedim);
2904
2905     erreur = MEDmeshNodeCoordinateRd(medIdt,
2906                                       meshname,
2907                                       MED_NO_DT,
2908                                       MED_NO_IT,
2909                                       MED_NO_INTERLACE,
2910                                       coo);
2911     if (erreur < 0) {
2912       free(coo);
2913       break;
2914     }
2915
2916     // Calcul des extremes
2917     med_float xmin,xmax,ymin,ymax,zmin,zmax;
2918
2919     xmin = coo[0];
2920     xmax = coo[0];
2921     for (int i = 1; i < nnoe; i++) {
2922       xmin = std::min(xmin, coo[i]);
2923       xmax = std::max(xmax, coo[i]);
2924     }
2925     //
2926     if (spacedim > 1) {
2927       ymin = coo[nnoe];
2928       ymax = coo[nnoe];
2929       for (int i = nnoe + 1; i < 2*nnoe; i++) {
2930         ymin = std::min(ymin,coo[i]);
2931         ymax = std::max(ymax,coo[i]);
2932       }
2933     }
2934     else {
2935       ymin = 0;
2936       ymax = 0;
2937       zmin = 0;
2938       zmax = 0;
2939     }
2940     //
2941     if (spacedim > 2) {
2942       zmin = coo[2*nnoe];
2943       zmax = coo[2*nnoe];
2944       for (int i = 2*nnoe + 1; i < 3*nnoe; i++) {
2945         zmin = std::min(zmin,coo[i]);
2946         zmax = std::max(zmax,coo[i]);
2947       }
2948     }
2949     else {
2950       zmin = 0;
2951       zmax = 0;
2952     }
2953
2954     MESSAGE("_______________________________________");
2955     MESSAGE("xmin : " << xmin << " xmax : " << xmax);
2956     MESSAGE("ymin : " << ymin << " ymax : " << ymax);
2957     MESSAGE("zmin : " << zmin << " zmax : " << zmax);
2958     MESSAGE("_______________________________________");
2959     double epsilon = 1.e-6;
2960     LesExtremes.push_back(xmin);
2961     LesExtremes.push_back(xmax);
2962     LesExtremes.push_back(0);
2963     LesExtremes.push_back(ymin);
2964     LesExtremes.push_back(ymax);
2965     LesExtremes.push_back(0);
2966     LesExtremes.push_back(zmin);
2967     LesExtremes.push_back(zmax);
2968     LesExtremes.push_back(0);
2969
2970     double max1 = std::max (LesExtremes[1] - LesExtremes[0], LesExtremes[4] - LesExtremes[3]);
2971     double max2 = std::max (max1 , LesExtremes[7] - LesExtremes[6]);
2972     LesExtremes.push_back(max2);
2973
2974     // LesExtremes[0] = Xmini du maillage
2975     // LesExtremes[1] = Xmaxi du maillage
2976     // LesExtremes[2] = increment de progression en X
2977     // LesExtremes[3,4,5] : idem pour Y
2978     // LesExtremes[6,7,8] : idem pour Z
2979     // LesExtremes[9] = ecart maximal entre coordonnees
2980     // On fait un traitement pour dans le cas d'une coordonnee constante
2981     // inhiber ce cas en mettant un increment negatif
2982     //
2983     double diff = LesExtremes[1] - LesExtremes[0];
2984     if (fabs(diff) > epsilon*max2) { LesExtremes[2] = diff/100.; }
2985     else                           { LesExtremes[2] = -1.; }
2986
2987     diff = LesExtremes[4] - LesExtremes[3];
2988     if (fabs(diff) > epsilon*max2) { LesExtremes[5]=diff/100.; }
2989     else                           { LesExtremes[5] = -1.; }
2990
2991     diff = LesExtremes[7] - LesExtremes[6];
2992     if (fabs(diff) > epsilon*max2) { LesExtremes[8]=diff/100.; }
2993     else                           { LesExtremes[8] = -1.;  }
2994
2995     MESSAGE ("_______________________________________");
2996     MESSAGE ("xmin : " << LesExtremes[0] << " xmax : " << LesExtremes[1] << " xincr : " << LesExtremes[2]);
2997     MESSAGE ("ymin : " << LesExtremes[3] << " ymax : " << LesExtremes[4] << " yincr : " << LesExtremes[5]);
2998     MESSAGE ("zmin : " << LesExtremes[6] << " zmax : " << LesExtremes[7] << " zincr : " << LesExtremes[8]);
2999     MESSAGE ("dmax : " << LesExtremes[9]);
3000     MESSAGE ("_______________________________________");
3001
3002     free(coo);
3003     break;
3004   }
3005   // Fermeture du fichier
3006   if (medIdt > 0) MEDfileClose(medIdt);
3007
3008   return  LesExtremes;
3009 }
3010
3011 }; // namespace SMESHHOMARD_I