Salome HOME
Merge branch 'master' into gni/evolution
[modules/homard.git] / src / HOMARD_I / HOMARD_Gen_i.cxx
1 // Copyright (C) 2011-2020  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
31 #include "HOMARD.hxx"
32
33 #include "FrontTrack.hxx"
34
35 #include "HOMARD_version.h"
36
37 #include "utilities.h"
38 #include "Basics_Utils.hxx"
39 #include "Basics_DirUtils.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "Utils_CorbaException.hxx"
42 #include "SALOMEDS_Tool.hxx"
43 #include "SALOME_LifeCycleCORBA.hxx"
44 #include "SALOMEconfig.h"
45 #include <SMESH_Gen_i.hxx>
46 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
47 #include CORBA_CLIENT_HEADER(SMESH_Gen)
48
49 #include <cmath>
50 #include <stdlib.h>
51 #include <sys/stat.h>
52 #ifndef WIN32
53 #include <dirent.h>
54 #endif
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 #ifdef WIN32
65 #include <direct.h>
66 #endif
67
68 using  namespace std;
69
70 //=============================================================================
71 //functions
72 //=============================================================================
73 std::string RemoveTabulation( std::string theScript )
74 {
75   std::string::size_type aPos = 0;
76   while( aPos < theScript.length() )
77   {
78     aPos = theScript.find( "\n\t", aPos );
79     if( aPos == std::string::npos )
80       break;
81     theScript.replace( aPos, 2, "\n" );
82     aPos++;
83   }
84   return theScript;
85 }
86 //=============================================================================
87 /*!
88  *  standard constructor
89  */
90 //=============================================================================
91 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
92                             PortableServer::POA_ptr poa,
93                             PortableServer::ObjectId * contId,
94                             const char *instanceName,
95                             const char *interfaceName) :
96 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
97 {
98   INFOS("constructor de HOMARD_Gen_i");
99   MESSAGE("constructor");
100   _thisObj = this;
101   _id = _poa->activate_object(_thisObj);
102
103   myHomard = new ::HOMARD_Gen();
104   _NS = SINGLETON_<SALOME_NamingService>::Instance();
105   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
106   _NS->init_orb(_orb);
107
108   myStudy = SALOMEDS::Study::_duplicate( SMESH_Gen_i::getStudyServant() );
109
110   _tag_gene = 0 ;
111   _tag_boun = 0 ;
112   _tag_hypo = 0 ;
113   _tag_yacs = 0 ;
114   _tag_zone = 0 ;
115
116   SetPreferences( ) ;
117 }
118 //=================================
119 /*!
120  *  standard destructor
121  */
122 //================================
123 HOMARD_Gen_i::~HOMARD_Gen_i()
124 {
125 }
126 //=============================================================================
127 //=============================================================================
128 // Utilitaires pour l'étude
129 //=============================================================================
130 //=============================================================================
131 void HOMARD_Gen_i::UpdateStudy()
132 {
133   ASSERT(!CORBA::is_nil(myStudy));
134   SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
135
136   // Create SComponent labelled 'homard' if it doesn't already exit
137   SALOMEDS::SComponent_var homardFather = myStudy->FindComponent(ComponentDataType());
138   if (CORBA::is_nil(homardFather))
139   {
140     myBuilder->NewCommand();
141     MESSAGE("Add Component HOMARD");
142
143     bool aLocked = myStudy->GetProperties()->IsLocked();
144     if (aLocked) myStudy->GetProperties()->SetLocked(false);
145
146     homardFather = myBuilder->NewComponent(ComponentDataType());
147     SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
148     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
149     CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
150     SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
151                 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
152     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
153     if (!Comp->_is_nil())
154     {
155       aName->SetValue(ComponentDataType());
156     }
157
158     anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
159     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
160     aPixmap->SetPixMap("HOMARD_2.png");
161     myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
162
163     if (aLocked) myStudy->GetProperties()->SetLocked(true);
164     myBuilder->CommitCommand();
165   }
166 }
167
168 //=============================================================================
169 //=============================================================================
170 // Utilitaires pour l'iteration
171 //=============================================================================
172 //=============================================================================
173 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Long Etat)
174 //=====================================================================================
175 {
176   MESSAGE( "SetEtatIter : affectation de l'etat " << Etat << " a l'iteration " << nomIter );
177   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
178   if (CORBA::is_nil(myIteration))
179   {
180       SALOME::ExceptionStruct es;
181       es.type = SALOME::BAD_PARAM;
182       es.text = "Invalid iteration";
183       throw SALOME::SALOME_Exception(es);
184       return ;
185   };
186
187   myIteration->SetState(Etat);
188
189   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
190   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
191
192   std::string icone ;
193   if ( Etat <= 0 )
194     icone = "iter0.png" ;
195   else if ( Etat == 2 )
196     icone = "iter_calculee.png" ;
197   else
198     icone = "iter_non_calculee.png" ;
199   PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone.c_str(), NULL) ;
200
201   aStudyBuilder->CommitCommand();
202
203 }
204 //=============================================================================
205 //=============================================================================
206 //
207 //=============================================================================
208 //=============================================================================
209 // Destruction des structures identifiees par leurs noms
210 //=============================================================================
211 //=============================================================================
212 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
213 {
214   MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
215   HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
216   if (CORBA::is_nil(myBoundary))
217   {
218     SALOME::ExceptionStruct es;
219     es.type = SALOME::BAD_PARAM;
220     es.text = "Invalid boundary";
221     throw SALOME::SALOME_Exception(es);
222     return 1 ;
223   };
224
225 // On verifie que la frontiere n'est plus utilisee
226   HOMARD::listeCases* maListe = GetAllCasesName();
227   int numberOfCases = maListe->length();
228   MESSAGE ( ".. Nombre de cas = " << numberOfCases );
229   std::string CaseName ;
230   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
231   int numberOfitems ;
232   HOMARD::HOMARD_Cas_var myCase ;
233   for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
234   {
235     CaseName = std::string((*maListe)[NumeCas]);
236     MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
237     myCase = myStudyContext._mesCas[CaseName];
238     ASSERT(!CORBA::is_nil(myCase));
239     ListBoundaryGroupType = myCase->GetBoundaryGroup();
240     numberOfitems = ListBoundaryGroupType->length();
241     MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
242     for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
243     {
244       if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
245       {
246         SALOME::ExceptionStruct es;
247         es.type = SALOME::BAD_PARAM;
248         es.text = "This boundary is used in a case and cannot be deleted.";
249         throw SALOME::SALOME_Exception(es);
250         return 2 ;
251       };
252     };
253   }
254
255   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
256   myStudyContext._mesBoundarys.erase(BoundaryName);
257   SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(BoundaryName, ComponentDataType());
258   SALOMEDS::SObject_var aSO =listSO[0];
259   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
260   myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
261
262   return 0 ;
263 }
264 //=============================================================================
265 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas, CORBA::Long Option)
266 {
267   // Pour detruire un cas
268   MESSAGE ( "DeleteCase : nomCas = " << nomCas << ", avec option = " << Option );
269   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
270   if (CORBA::is_nil(myCase))
271   {
272     SALOME::ExceptionStruct es;
273     es.type = SALOME::BAD_PARAM;
274     es.text = "Invalid case context";
275     throw SALOME::SALOME_Exception(es);
276     return 1;
277   };
278   // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
279   CORBA::String_var nomIter = myCase->GetIter0Name();
280   CORBA::Long Option1 = 0 ;
281   if ( DeleteIterationOption(nomIter, Option1, Option) != 0 )
282   {
283     return 2;
284   };
285
286   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
287   myStudyContext._mesCas.erase(nomCas);
288   SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomCas, ComponentDataType());
289   SALOMEDS::SObject_var aSO =listSO[0];
290   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
291   myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
292
293   return 0 ;
294 }
295 //=============================================================================
296 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
297 {
298   MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
299   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
300   if (CORBA::is_nil(myHypo))
301   {
302     SALOME::ExceptionStruct es;
303     es.type = SALOME::BAD_PARAM;
304     es.text = "Invalid hypothesis";
305     throw SALOME::SALOME_Exception(es);
306     return 1 ;
307   };
308
309 // On verifie que l'hypothese n'est plus utilisee
310   HOMARD::listeIters* maListeIter = myHypo->GetIterations();
311   int numberOfIter = maListeIter->length();
312   if ( numberOfIter > 0 )
313   {
314     SALOME::ExceptionStruct es;
315     es.type = SALOME::BAD_PARAM;
316     es.text = "This hypothesis is used in an iteration and cannot be deleted.";
317     throw SALOME::SALOME_Exception(es);
318     return 2 ;
319   };
320
321   // suppression du lien avec les zones eventuelles
322   HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
323   int numberOfZones = maListe->length();
324   MESSAGE ( ".. Nombre de zones = " << numberOfZones );
325   for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
326   {
327     std::string ZoneName = std::string((*maListe)[NumeZone]);
328     MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
329     DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
330     NumeZone += 1 ;
331   }
332
333   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
334   myStudyContext._mesHypotheses.erase(nomHypo);
335   SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomHypo, ComponentDataType());
336   SALOMEDS::SObject_var aSO =listSO[0];
337   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
338   myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
339
340   return 0 ;
341 }
342 //=============================================================================
343 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter, CORBA::Long Option)
344 {
345   //  Option = 0 : On ne supprime pas le fichier du maillage associe
346   //  Option = 1 : On supprime le fichier du maillage associe
347   // Pour detruire une iteration courante
348   MESSAGE ( "DeleteIteration : nomIter = " << nomIter << ", avec option = " << Option );
349   CORBA::Long Option1 = 1 ;
350   return DeleteIterationOption(nomIter, Option1, Option);
351 }
352 //=============================================================================
353 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option1, CORBA::Long Option2)
354 {
355   //  Option1 = 0 : On autorise la destruction de l'iteration 0
356   //  Option1 = 1 : On interdit la destruction de l'iteration 0
357
358   //  Option2 = 0 : On ne supprime pas le fichier du maillage associe
359   //  Option2 = 1 : On supprime le fichier du maillage associe
360   MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec options = " << Option1<< ", " << Option2 );
361   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
362   if (CORBA::is_nil(myIteration))
363   {
364     SALOME::ExceptionStruct es;
365     es.type = SALOME::BAD_PARAM;
366     es.text = "Invalid iteration";
367     throw SALOME::SALOME_Exception(es);
368     return 1 ;
369   };
370
371   int numero = myIteration->GetNumber();
372   MESSAGE ( "DeleteIterationOption : numero = " << numero );
373   if ( numero == 0 && Option1 == 1 )
374   {
375     SALOME::ExceptionStruct es;
376     es.type = SALOME::BAD_PARAM;
377     es.text = "This iteration cannot be deleted.";
378     throw SALOME::SALOME_Exception(es);
379     return 2 ;
380   };
381
382   // On detruit recursivement toutes les filles
383   HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
384   int numberOfIter = maListe->length();
385   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
386   {
387     std::string nomIterFille = std::string((*maListe)[NumeIter]);
388     MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
389     DeleteIterationOption(nomIterFille.c_str(), Option1, Option2);
390   }
391
392   // On arrive ici pour une iteration sans fille
393   MESSAGE ( "Destruction effective de " << nomIter );
394   // On commence par invalider l'iteration pour faire le menage des dependances
395   // et eventuellement du maillage associe
396   int option ;
397   if ( numero == 0 ) { option = 0 ; }
398   else               { option = Option2 ; }
399   InvalideIterOption(nomIter, option) ;
400
401   // Retrait dans la descendance de l'iteration parent
402   if ( numero > 0 )
403   {
404     std::string nomIterationParent = myIteration->GetIterParentName();
405     MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
406     HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
407     if (CORBA::is_nil(myIterationParent))
408     {
409       SALOME::ExceptionStruct es;
410       es.type = SALOME::BAD_PARAM;
411       es.text = "Invalid iteration";
412       throw SALOME::SALOME_Exception(es);
413       return 3 ;
414     };
415     myIterationParent->UnLinkNextIteration(nomIter);
416   }
417
418   // suppression du lien avec l'hypothese
419   if ( numero > 0 )
420   {
421     std::string nomHypo = myIteration->GetHypoName();
422     HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
423     ASSERT(!CORBA::is_nil(myHypo));
424     myHypo->UnLinkIteration(nomIter);
425   }
426
427   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
428   myStudyContext._mesIterations.erase(nomIter);
429   SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomIter, ComponentDataType());
430   SALOMEDS::SObject_var aSO =listSO[0];
431   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
432   myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
433   // on peut aussi faire RemoveObject
434 //   MESSAGE ( "Au final" );
435 //   HOMARD::listeIterations* Liste = GetAllIterationsName() ;
436 //   numberOfIter = Liste->length();
437 //   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
438 //   {
439 //       std::string nomIterFille = std::string((*Liste)[NumeIter]);
440 //       MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
441 //   }
442
443   return 0 ;
444 }
445 //=============================================================================
446 CORBA::Long HOMARD_Gen_i::DeleteYACS(const char* nomYACS, CORBA::Long Option)
447 {
448   //  Option = 0 : On ne supprime pas le fichier du schema associe
449   //  Option = 1 : On supprime le fichier du schema associe
450   MESSAGE ( "DeleteYACS : nomYACS = " << nomYACS << ", avec option = " << Option );
451   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
452   if (CORBA::is_nil(myYACS))
453   {
454     SALOME::ExceptionStruct es;
455     es.type = SALOME::BAD_PARAM;
456     es.text = "Invalid schema YACS";
457     throw SALOME::SALOME_Exception(es);
458     return 1 ;
459   };
460   // Suppression eventuelle du fichier XML
461   if ( Option == 1 )
462   {
463     std::string nomFichier = myYACS->GetXMLFile();
464     std::string commande = "rm -rf " + nomFichier ;
465     MESSAGE ( "commande = " << commande );
466     if ((system(commande.c_str())) != 0)
467     {
468       SALOME::ExceptionStruct es;
469       es.type = SALOME::BAD_PARAM;
470       es.text = "The xml file for the schema YACS cannot be removed." ;
471       throw SALOME::SALOME_Exception(es);
472       return 2 ;
473     }
474   }
475   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
476   myStudyContext._mesYACSs.erase(nomYACS);
477   SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomYACS, ComponentDataType());
478   SALOMEDS::SObject_var aSO =listSO[0];
479   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
480   myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
481
482   return 0 ;
483 }
484 //=============================================================================
485 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
486 {
487   MESSAGE ( "DeleteZone : nomZone = " << nomZone );
488   HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[nomZone];
489   if (CORBA::is_nil(myZone))
490   {
491     SALOME::ExceptionStruct es;
492     es.type = SALOME::BAD_PARAM;
493     es.text = "Invalid zone";
494     throw SALOME::SALOME_Exception(es);
495     return 1 ;
496   };
497
498 // On verifie que la zone n'est plus utilisee
499   HOMARD::listeHypo* maListe = myZone->GetHypo();
500   int numberOfHypo = maListe->length();
501   MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
502   if ( numberOfHypo > 0 )
503   {
504     SALOME::ExceptionStruct es;
505     es.type = SALOME::BAD_PARAM;
506     es.text = "This zone is used in a hypothesis and cannot be deleted.";
507     throw SALOME::SALOME_Exception(es);
508     return 2 ;
509   };
510 //
511   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
512   myStudyContext._mesZones.erase(nomZone);
513   SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(nomZone, ComponentDataType());
514   SALOMEDS::SObject_var aSO =listSO[0];
515   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
516   myStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
517
518   return 0 ;
519 }
520 //=============================================================================
521 //=============================================================================
522 //
523 //=============================================================================
524 //=============================================================================
525 // Invalidation des structures identifiees par leurs noms
526 //=============================================================================
527 //=============================================================================
528 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
529 {
530   MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName  );
531   HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
532   if (CORBA::is_nil(myBoundary))
533   {
534     SALOME::ExceptionStruct es;
535     es.type = SALOME::BAD_PARAM;
536     es.text = "Invalid boundary";
537     throw SALOME::SALOME_Exception(es);
538     return ;
539   }
540   else
541   {
542     SALOME::ExceptionStruct es;
543     es.type = SALOME::BAD_PARAM;
544     es.text = "No change is allowed in a boundary. Ask for evolution.";
545     throw SALOME::SALOME_Exception(es);
546     return ;
547   };
548 }
549 //=============================================================================
550 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
551 {
552   MESSAGE( "InvalideHypo : nomHypo    = " << nomHypo  );
553   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
554   if (CORBA::is_nil(myHypo))
555   {
556       SALOME::ExceptionStruct es;
557       es.type = SALOME::BAD_PARAM;
558       es.text = "Invalid hypothesis";
559       throw SALOME::SALOME_Exception(es);
560       return ;
561   };
562
563   HOMARD::listeIters* maListe = myHypo->GetIterations();
564   int numberOfIter = maListe->length();
565   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
566   {
567       std::string nomIter = std::string((*maListe)[NumeIter]);
568       MESSAGE( ".. nomIter = " << nomIter );
569       InvalideIter(nomIter.c_str());
570   }
571 }
572 //=============================================================================
573 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
574 {
575   MESSAGE("InvalideIter : nomIter = " << nomIter);
576   // Pour invalider totalement une iteration courante
577   CORBA::Long Option = 1 ;
578   return InvalideIterOption(nomIter, Option);
579 }
580 //=============================================================================
581 void HOMARD_Gen_i::InvalideIterOption(const char* nomIter, CORBA::Long Option)
582 {
583   //  Option = 0 : On ne supprime pas le fichier du maillage associe
584   //  Option = 1 : On supprime le fichier du maillage associe
585   MESSAGE ( "InvalideIterOption : nomIter = " << nomIter << ", avec option = " << Option );
586   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
587   if (CORBA::is_nil(myIteration))
588   {
589       SALOME::ExceptionStruct es;
590       es.type = SALOME::BAD_PARAM;
591       es.text = "Invalid iteration";
592       throw SALOME::SALOME_Exception(es);
593       return ;
594   };
595
596   HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
597   int numberOfIter = maListe->length();
598   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
599   {
600       std::string nomIterFille = std::string((*maListe)[NumeIter]);
601       MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
602       InvalideIter(nomIterFille.c_str());
603   }
604
605   // On arrive ici pour une iteration sans fille
606   MESSAGE ( "Invalidation effective de " << nomIter );
607   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
608   SALOMEDS::ChildIterator_var  aIter = myStudy->NewChildIterator(aIterSO);
609   for (; aIter->More(); aIter->Next())
610   {
611       SALOMEDS::SObject_var so = aIter->Value();
612       SALOMEDS::GenericAttribute_var anAttr;
613       if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
614       SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
615       std::string value (aCommentAttr->Value());
616       if(value == std::string("IterationHomard")) continue;
617       if(value == std::string("HypoHomard")) continue;
618       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
619       aStudyBuilder->RemoveObject(so);
620   }
621
622   int etat = myIteration->GetState();
623   if ( etat > 0 )
624   {
625     SetEtatIter(nomIter,1);
626     const char * nomCas = myIteration->GetCaseName();
627     HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
628     if (CORBA::is_nil(myCase))
629     {
630         SALOME::ExceptionStruct es;
631         es.type = SALOME::BAD_PARAM;
632         es.text = "Invalid case context";
633         throw SALOME::SALOME_Exception(es);
634         return ;
635     };
636     std::string nomDir     = myIteration->GetDirName();
637     std::string nomFichier = myIteration->GetMeshFile();
638     std::string commande = "rm -rf " + std::string(nomDir);
639     if ( Option == 1 ) { commande = commande + ";rm -rf " + std::string(nomFichier) ; }
640     MESSAGE ( "commande = " << commande );
641     if ((system(commande.c_str())) != 0)
642     {
643       SALOME::ExceptionStruct es;
644       es.type = SALOME::BAD_PARAM;
645       es.text = "The directory for the calculation cannot be cleared." ;
646       throw SALOME::SALOME_Exception(es);
647       return ;
648     }
649   // Suppression du maillage publie dans SMESH
650     std::string MeshName = myIteration->GetMeshName() ;
651     DeleteResultInSmesh(nomFichier, MeshName) ;
652   };
653
654 }
655 //=============================================================================
656 void HOMARD_Gen_i::InvalideIterInfo(const char* nomIter)
657 {
658   MESSAGE("InvalideIterInfo : nomIter = " << nomIter);
659   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
660   if (CORBA::is_nil(myIteration))
661   {
662       SALOME::ExceptionStruct es;
663       es.type = SALOME::BAD_PARAM;
664       es.text = "Invalid iteration";
665       throw SALOME::SALOME_Exception(es);
666       return ;
667   };
668
669   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
670   SALOMEDS::ChildIterator_var  aIter = myStudy->NewChildIterator(aIterSO);
671   for (; aIter->More(); aIter->Next())
672   {
673       SALOMEDS::SObject_var so = aIter->Value();
674       SALOMEDS::GenericAttribute_var anAttr;
675       if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
676       SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
677       std::string value (aCommentAttr->Value());
678 /*      MESSAGE("... value = " << value);*/
679       if( (value == std::string("logInfo")) || ( value == std::string("SummaryInfo")) )
680       {
681         SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
682         aStudyBuilder->RemoveObject(so);
683       }
684   }
685
686   const char * nomCas = myIteration->GetCaseName();
687   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
688   if (CORBA::is_nil(myCase))
689   {
690       SALOME::ExceptionStruct es;
691       es.type = SALOME::BAD_PARAM;
692       es.text = "Invalid case context";
693       throw SALOME::SALOME_Exception(es);
694       return ;
695   };
696   const char* nomDir   = myIteration->GetDirName();
697   std::string commande = "rm -f " + std::string(nomDir) + "/info* " ;
698   commande += std::string(nomDir) + "/Liste.*info" ;
699 /*  MESSAGE ( "commande = " << commande );*/
700   if ((system(commande.c_str())) != 0)
701   {
702     SALOME::ExceptionStruct es;
703     es.type = SALOME::BAD_PARAM;
704     es.text = "The directory for the calculation cannot be cleared." ;
705     throw SALOME::SALOME_Exception(es);
706     return ;
707   }
708 }
709 //=============================================================================
710 void HOMARD_Gen_i::InvalideYACS(const char* YACSName)
711 {
712   MESSAGE( "InvalideYACS : YACSName    = " << YACSName );
713   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[YACSName];
714   if (CORBA::is_nil(myYACS))
715   {
716       SALOME::ExceptionStruct es;
717       es.type = SALOME::BAD_PARAM;
718       es.text = "Invalid schema YACS";
719       throw SALOME::SALOME_Exception(es);
720       return ;
721   };
722   //
723   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
724   SALOMEDS::ChildIterator_var  aYACS = myStudy->NewChildIterator(aYACSSO);
725   for (; aYACS->More(); aYACS->Next())
726   {
727     SALOMEDS::SObject_var so = aYACS->Value();
728     SALOMEDS::GenericAttribute_var anAttr;
729     if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
730     SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
731     std::string value (aCommentAttr->Value());
732     if( value == std::string("xml") )
733     {
734       SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
735       aStudyBuilder->RemoveObject(so);
736     }
737   }
738   std::string nomFichier = myYACS->GetXMLFile();
739   std::string commande = "rm -rf " + std::string(nomFichier) ;
740   MESSAGE ( "commande = " << commande );
741   if ((system(commande.c_str())) != 0)
742   {
743     SALOME::ExceptionStruct es;
744     es.type = SALOME::BAD_PARAM;
745     es.text = "The XML file for the schema YACS cannot be removed." ;
746     throw SALOME::SALOME_Exception(es);
747     return ;
748   }
749 }
750 //=============================================================================
751 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
752 {
753   MESSAGE( "InvalideZone : ZoneName    = " << ZoneName );
754   HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
755   if (CORBA::is_nil(myZone))
756   {
757       SALOME::ExceptionStruct es;
758       es.type = SALOME::BAD_PARAM;
759       es.text = "Invalid zone";
760       throw SALOME::SALOME_Exception(es);
761       return ;
762   };
763   HOMARD::listeHypo* maListe = myZone->GetHypo();
764   int numberOfHypo = maListe->length();
765   MESSAGE( ".. numberOfHypo = " << numberOfHypo );
766   for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
767   {
768       std::string nomHypo = std::string((*maListe)[NumeHypo]);
769       MESSAGE( ".. nomHypo = " << nomHypo );
770       InvalideHypo(nomHypo.c_str());
771   }
772 }
773 //=============================================================================
774 //=============================================================================
775 //
776 //=============================================================================
777 //=============================================================================
778 // Association de lien entre des structures identifiees par leurs noms
779 //=============================================================================
780 //=============================================================================
781 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
782 {
783   MESSAGE( "AssociateCaseIter : " << nomCas << ", " << nomIter << ", "  << labelIter );
784
785   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
786   if (CORBA::is_nil(myCase))
787   {
788     SALOME::ExceptionStruct es;
789     es.type = SALOME::BAD_PARAM;
790     es.text = "Invalid case";
791     throw SALOME::SALOME_Exception(es);
792     return ;
793   };
794
795   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
796   if (CORBA::is_nil(myIteration))
797   {
798     SALOME::ExceptionStruct es;
799     es.type = SALOME::BAD_PARAM;
800     es.text = "Invalid iteration";
801     throw SALOME::SALOME_Exception(es);
802     return ;
803   };
804
805   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
806   SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
807   if (CORBA::is_nil(aCasSO))
808   {
809     SALOME::ExceptionStruct es;
810     es.type = SALOME::BAD_PARAM;
811     es.text = "Invalid case";
812     throw SALOME::SALOME_Exception(es);
813     return ;
814   };
815
816   aStudyBuilder->NewCommand();
817   SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
818   PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
819                      "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
820   aStudyBuilder->CommitCommand();
821
822   myCase->AddIteration(nomIter);
823   myIteration->SetCaseName(nomCas);
824 }
825 //=====================================================================================
826 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
827 {
828   MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
829
830   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
831   ASSERT(!CORBA::is_nil(myHypo));
832   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
833   ASSERT(!CORBA::is_nil(aHypoSO));
834
835   HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
836   ASSERT(!CORBA::is_nil(myZone));
837   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
838   ASSERT(!CORBA::is_nil(aZoneSO));
839
840   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
841
842   aStudyBuilder->NewCommand();
843
844   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
845   aStudyBuilder->Addreference(aSubSO, aZoneSO);
846
847   aStudyBuilder->CommitCommand();
848
849   myZone->AddHypo(nomHypothesis);
850   myHypo->AddZone0(ZoneName, TypeUse);
851 };
852 //=============================================================================
853 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
854 {
855   MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
856
857   // Verification de l'existence de l'hypothese
858   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
859   ASSERT(!CORBA::is_nil(myHypo));
860   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
861   ASSERT(!CORBA::is_nil(aHypoSO));
862
863   // Verification de l'existence de l'iteration
864   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[nomIter];
865   ASSERT(!CORBA::is_nil(myIteration));
866   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
867   ASSERT(!CORBA::is_nil(aIterSO));
868
869   // Gestion de l'arbre d'etudes
870   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
871   aStudyBuilder->NewCommand();
872   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
873   aStudyBuilder->Addreference(aSubSO, aHypoSO);
874   aStudyBuilder->CommitCommand();
875
876   // Liens reciproques
877   myIteration->SetHypoName(nomHypo);
878   myHypo->LinkIteration(nomIter);
879
880   // On stocke les noms des champ a interpoler pour le futur controle de la donnée des pas de temps
881   myIteration->SupprFieldInterps() ;
882   HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
883   int numberOfFieldsx2 = ListField->length();
884   for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
885   {
886     std::string FieldName = std::string((*ListField)[iaux]) ;
887     myIteration->SetFieldInterp(FieldName.c_str()) ;
888     iaux++ ;
889   }
890 };
891 //=============================================================================
892 //=============================================================================
893 //
894 //=============================================================================
895 //=============================================================================
896 // Dissociation de lien entre des structures identifiees par leurs noms
897 //=============================================================================
898 //=============================================================================
899 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
900 {
901   MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
902
903   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypothesis];
904   ASSERT(!CORBA::is_nil(myHypo));
905   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
906   ASSERT(!CORBA::is_nil(aHypoSO));
907
908   HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
909   ASSERT(!CORBA::is_nil(myZone));
910   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myZone)));
911   ASSERT(!CORBA::is_nil(aZoneSO));
912
913   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
914
915   SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(aHypoSO);
916   for (; it->More(); it->Next())
917   {
918     SALOMEDS::SObject_var aHypObj = it->Value();
919     SALOMEDS::SObject_var ptrObj;
920     if (aHypObj->ReferencedObject(ptrObj))
921     {
922       if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
923       {
924         aStudyBuilder->NewCommand();
925         aStudyBuilder->RemoveObject(aHypObj);
926         aStudyBuilder->CommitCommand();
927         break;
928       }
929     }
930   }
931
932   myZone->SupprHypo(nomHypothesis);
933   myHypo->SupprZone(ZoneName);
934 };
935 //=============================================================================
936 //=============================================================================
937 //
938
939 //=============================================================================
940 //=============================================================================
941 // Recuperation des listes
942 //=============================================================================
943 //=============================================================================
944 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
945 {
946   MESSAGE("GetAllBoundarysName");
947   IsValidStudy () ;
948
949   HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
950   ret->length(myStudyContext._mesBoundarys.size());
951   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
952   int i = 0;
953   for (it = myStudyContext._mesBoundarys.begin();
954   it != myStudyContext._mesBoundarys.end(); it++)
955   {
956     ret[i++] = CORBA::string_dup((*it).first.c_str());
957   }
958
959   return ret._retn();
960 }
961 //=============================================================================
962 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
963 {
964   MESSAGE("GetAllCasesName");
965   IsValidStudy () ;
966
967   HOMARD::listeCases_var ret = new HOMARD::listeCases;
968   ret->length(myStudyContext._mesCas.size());
969   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
970   int i = 0;
971   for (it = myStudyContext._mesCas.begin();
972   it != myStudyContext._mesCas.end(); it++)
973   {
974     ret[i++] = CORBA::string_dup((*it).first.c_str());
975   }
976
977   return ret._retn();
978 }
979 //=============================================================================
980 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
981 {
982   MESSAGE("GetAllHypothesesName");
983   IsValidStudy () ;
984
985   HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
986   ret->length(myStudyContext._mesHypotheses.size());
987   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
988   int i = 0;
989   for (it = myStudyContext._mesHypotheses.begin();
990   it != myStudyContext._mesHypotheses.end(); it++)
991   {
992     ret[i++] = CORBA::string_dup((*it).first.c_str());
993   }
994
995   return ret._retn();
996 }
997 //=============================================================================
998 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
999 {
1000   MESSAGE("GetAllIterationsName");
1001   IsValidStudy () ;
1002
1003   HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1004   ret->length(myStudyContext._mesIterations.size());
1005   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1006   int i = 0;
1007   for (it = myStudyContext._mesIterations.begin();
1008   it != myStudyContext._mesIterations.end(); it++)
1009   {
1010     ret[i++] = CORBA::string_dup((*it).first.c_str());
1011   }
1012
1013   return ret._retn();
1014 }
1015 //=============================================================================
1016 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
1017 {
1018   MESSAGE("GetAllYACSsName");
1019   IsValidStudy () ;
1020
1021   HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
1022   ret->length(myStudyContext._mesYACSs.size());
1023   std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1024   int i = 0;
1025   for (it = myStudyContext._mesYACSs.begin();
1026   it != myStudyContext._mesYACSs.end(); it++)
1027   {
1028     ret[i++] = CORBA::string_dup((*it).first.c_str());
1029   }
1030
1031   return ret._retn();
1032 }
1033 //=============================================================================
1034 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1035 {
1036   MESSAGE("GetAllZonesName");
1037   IsValidStudy () ;
1038
1039   HOMARD::listeZones_var ret = new HOMARD::listeZones;
1040   ret->length(myStudyContext._mesZones.size());
1041   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1042   int i = 0;
1043   for (it = myStudyContext._mesZones.begin();
1044   it != myStudyContext._mesZones.end(); it++)
1045   {
1046     ret[i++] = CORBA::string_dup((*it).first.c_str());
1047   }
1048
1049   return ret._retn();
1050 }
1051 //=============================================================================
1052 //=============================================================================
1053
1054 //=============================================================================
1055 //=============================================================================
1056 // Recuperation des structures identifiees par leurs noms
1057 //=============================================================================
1058 //=============================================================================
1059 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1060 {
1061   HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[nomBoundary];
1062   ASSERT(!CORBA::is_nil(myBoundary));
1063   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1064 }
1065 //=============================================================================
1066 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1067 {
1068   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1069   ASSERT(!CORBA::is_nil(myCase));
1070   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1071 }
1072 //=============================================================================
1073 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1074 {
1075   HOMARD::HOMARD_Hypothesis_var myHypothesis = myStudyContext._mesHypotheses[nomHypothesis];
1076   ASSERT(!CORBA::is_nil(myHypothesis));
1077   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1078 }
1079 //=============================================================================
1080 HOMARD::HOMARD_Iteration_ptr  HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1081 {
1082   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIterationation];
1083   ASSERT(!CORBA::is_nil(myIteration));
1084   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1085 }
1086 //=============================================================================
1087 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1088 {
1089   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
1090   ASSERT(!CORBA::is_nil(myYACS));
1091   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1092 }
1093 //=============================================================================
1094 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1095 {
1096   HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
1097   ASSERT(!CORBA::is_nil(myZone));
1098   return HOMARD::HOMARD_Zone::_duplicate(myZone);
1099 }
1100 //=============================================================================
1101 //=============================================================================
1102
1103 //=============================================================================
1104 //=============================================================================
1105 // Informations
1106 //=============================================================================
1107 //=============================================================================
1108 void HOMARD_Gen_i::MeshInfo(const char* nomCas, const char* MeshName, const char* MeshFile, const char* DirName, CORBA::Long Qual, CORBA::Long Diam, CORBA::Long Conn, CORBA::Long Tail, CORBA::Long Inte)
1109 {
1110   INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile  );
1111   INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte  );
1112   IsValidStudy () ;
1113
1114 // Creation du cas
1115   int option = 1 ;
1116   if ( _PublisMeshIN != 0 ) option = 2 ;
1117   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, option) ;
1118   myCase->SetDirName(DirName) ;
1119 // Analyse
1120   myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1121
1122   return ;
1123 }
1124 //=============================================================================
1125 //=============================================================================
1126
1127 //=============================================================================
1128 //=============================================================================
1129 // Recuperation des structures par le contexte
1130 //=============================================================================
1131 //=============================================================================
1132 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1133 {
1134   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1135   ASSERT(!CORBA::is_nil(myCase));
1136 //
1137   HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1138   ASSERT(!CORBA::is_nil(myIteration));
1139 //
1140   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1141 }
1142 //=============================================================================
1143 //=============================================================================
1144
1145 //=============================================================================
1146 //=============================================================================
1147 // Nouvelles structures
1148 //=============================================================================
1149 //=============================================================================
1150 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1151 {
1152   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1153   HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1154   HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1155   return aCase._retn();
1156 }
1157 //=============================================================================
1158 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1159 {
1160   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1161   HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1162   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1163   return aHypo._retn();
1164 }
1165 //=============================================================================
1166 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1167 {
1168   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1169   HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1170   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1171   return aIter._retn();
1172 }
1173 //=============================================================================
1174 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1175 {
1176   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1177   HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1178   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1179   return aBoundary._retn();
1180 }
1181 //=============================================================================
1182 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1183 {
1184   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1185   HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1186   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1187   return aZone._retn();
1188 }
1189 //=============================================================================
1190 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1191 {
1192   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1193   HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1194   HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1195   return aYACS._retn();
1196 }
1197 //=============================================================================
1198 //=============================================================================
1199
1200 //=============================================================================
1201 //=============================================================================
1202 // Creation des structures identifiees par leurs noms
1203 //=============================================================================
1204 //=============================================================================
1205 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1206 //
1207 // Creation d'un cas initial
1208 // nomCas : nom du cas a creer
1209 // MeshName, MeshFile : nom et fichier du maillage correspondant
1210 //
1211 {
1212   INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1213
1214   int option = 1 ;
1215   if ( _PublisMeshIN != 0 ) option = 2 ;
1216   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, option) ;
1217
1218 // Valeurs par defaut des filtrages
1219   myCase->SetPyram(0);
1220
1221   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1222 }
1223 //=============================================================================
1224 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1225 //
1226 // nomCas : nom du cas a creer
1227 // DirNameStart : nom du répertoire contenant l'iteration de reprise
1228 //
1229 {
1230   INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1231   std::string nomDirWork = getenv("PWD") ;
1232   int codret ;
1233
1234   // A. Decodage du point de reprise
1235   // A.1. Controle du répertoire de depart de l'iteration
1236   codret = CHDIR(DirNameStart) ;
1237   if ( codret != 0 )
1238   {
1239     SALOME::ExceptionStruct es;
1240     es.type = SALOME::BAD_PARAM;
1241     es.text = "The directory of the iteration does not exist.";
1242     throw SALOME::SALOME_Exception(es);
1243     return 0;
1244   };
1245   // A.2. Reperage des fichiers du répertoire de reprise
1246   std::string file_configuration = "" ;
1247   std::string file_maillage_homard = "" ;
1248   int bilan ;
1249 #ifndef WIN32
1250   DIR *dp;
1251   struct dirent *dirp;
1252   dp  = opendir(DirNameStart);
1253   while ( (dirp = readdir(dp)) != NULL )
1254   {
1255     std::string file_name(dirp->d_name);
1256 //     MESSAGE ( file_name );
1257     bilan = file_name.find("HOMARD.Configuration.") ;
1258     if ( bilan != string::npos ) { file_configuration = file_name ; }
1259     bilan = file_name.find("maill.") ;
1260     if ( bilan != string::npos )
1261     {
1262       bilan = file_name.find(".hom.med") ;
1263       if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1264     }
1265   }
1266   closedir(dp);
1267 #else
1268   HANDLE hFind = INVALID_HANDLE_VALUE;
1269   WIN32_FIND_DATA ffd;
1270   hFind = FindFirstFile(DirNameStart, &ffd);
1271   if (INVALID_HANDLE_VALUE != hFind) {
1272     while (FindNextFile(hFind, &ffd) != 0) {
1273       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1274       std::string file_name(ffd.cFileName);
1275       bilan = file_name.find("HOMARD.Configuration.") ;
1276       if ( bilan != string::npos ) { file_configuration = file_name ; }
1277       bilan = file_name.find("maill.") ;
1278       if ( bilan != string::npos )
1279       {
1280         bilan = file_name.find(".hom.med") ;
1281         if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1282       }
1283     }
1284     FindClose(hFind);
1285   }
1286 #endif
1287   MESSAGE ( "==> file_configuration   : " << file_configuration ) ;
1288   MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1289   // A.3. Controle
1290   if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1291   {
1292     SALOME::ExceptionStruct es;
1293     es.type = SALOME::BAD_PARAM;
1294     std::string text ;
1295     if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1296     else                            { text = "The HOMARD mesh file cannot be found." ; }
1297     es.text = CORBA::string_dup(text.c_str());
1298     throw SALOME::SALOME_Exception(es);
1299   }
1300
1301   // B. Lecture du fichier de configuration
1302   // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1303   int NumeIter ;
1304   int TypeExt = 0 ;
1305   int TypeConf = 0 ;
1306   int Pyram = 0 ;
1307   char* MeshName ;
1308   char* MeshFile ;
1309   // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1310   std::ifstream fichier( file_configuration.c_str() );
1311   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1312   {
1313     std::string ligne; // variable contenant chaque ligne lue
1314     std::string mot_cle;
1315     std::string argument;
1316     int decalage;
1317     // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1318     while ( std::getline( fichier, ligne ) )
1319     {
1320       // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1321       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1322       ligne_bis >> mot_cle ;
1323       // B.2. Des valeurs entieres : le second bloc de la ligne
1324       if ( mot_cle == "NumeIter" )
1325       {
1326         ligne_bis >> NumeIter ;
1327         NumeIter += 1 ;
1328       }
1329       // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1330       else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1331       {
1332         ligne_bis >> argument ;
1333
1334         if ( mot_cle == "TypeConf" )
1335         {
1336           if      ( argument == "conforme" )                { TypeConf = 1 ; }
1337           else if ( argument == "non_conforme_1_noeud" )    { TypeConf = 2 ; }
1338           else if ( argument == "non_conforme_1_arete" )    { TypeConf = 3 ; }
1339           else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1340         }
1341         else if ( mot_cle == "TypeElem" )
1342         {
1343           if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1344           else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1345         }
1346       }
1347       // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1348       //                               il faut les supprimer
1349       else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1350       {
1351         ligne_bis >> argument ;
1352         if ( argument[0] == '"' ) { decalage = 1 ; }
1353         else                      { decalage = 0 ; }
1354         size_t size = argument.size() + 1 - 2*decalage ;
1355
1356         if ( mot_cle == "CCNoMNP1" )
1357         {
1358           MeshName = new char[ size ];
1359           strncpy( MeshName, argument.c_str()+decalage, size );
1360           MeshName[size-1] = '\0' ;
1361         }
1362         else if ( mot_cle == "CCMaiNP1" )
1363         {
1364           MeshFile = new char[ size ];
1365           strncpy( MeshFile, argument.c_str()+decalage, size );
1366           MeshFile[size-1] = '\0' ;
1367         }
1368       }
1369     }
1370     MESSAGE ( "==> TypeConf   : " << TypeConf ) ;
1371     MESSAGE ( "==> MeshName   : " << MeshName ) ;
1372     MESSAGE ( "==> MeshFile   : " << MeshFile ) ;
1373     MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1374     MESSAGE ( "==> Pyram      : " << Pyram ) ;
1375   }
1376   else
1377   {
1378     SALOME::ExceptionStruct es;
1379     es.type = SALOME::BAD_PARAM;
1380     std::string text = "The configuration file cannot be read." ;
1381     es.text = CORBA::string_dup(text.c_str());
1382     throw SALOME::SALOME_Exception(es);
1383   }
1384
1385   // C. Creation effective du cas
1386
1387   int option = 1 ;
1388   if ( _PublisMeshIN != 0 ) option = 2 ;
1389   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1390
1391   // D. Parametrages lus dans le fichier de configuration
1392
1393   myCase->SetConfType (TypeConf) ;
1394   myCase->SetExtType (TypeExt) ;
1395   myCase->SetPyram (Pyram) ;
1396
1397   // E. Copie du fichier de maillage homard
1398   // E.1. Répertoire associe au cas
1399   char* nomDirCase = myCase->GetDirName() ;
1400   // E.2. Répertoire associe a l'iteration de ce cas
1401   char* IterName ;
1402   IterName = myCase->GetIter0Name() ;
1403   HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1404   char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1405   Iter->SetDirNameLoc(nomDirIter);
1406   std::string nomDirIterTotal ;
1407   nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1408 #ifndef WIN32
1409   if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1410 #else
1411   if (_mkdir(nomDirIterTotal.c_str()) != 0)
1412 #endif
1413   {
1414     MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1415     SALOME::ExceptionStruct es;
1416     es.type = SALOME::BAD_PARAM;
1417     std::string text = "The directory for the computation cannot be created." ;
1418     es.text = CORBA::string_dup(text.c_str());
1419     throw SALOME::SALOME_Exception(es);
1420   }
1421   // E.3. Copie du maillage HOMARD au format MED
1422   codret = CHDIR(DirNameStart) ;
1423   std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1424   MESSAGE ( "commande : " << commande ) ;
1425   codret = system(commande.c_str()) ;
1426   MESSAGE ( "codret : " << codret ) ;
1427   if ( codret != 0 )
1428   {
1429     SALOME::ExceptionStruct es;
1430     es.type = SALOME::BAD_PARAM;
1431     es.text = "The starting point for the case cannot be copied into the working directory.";
1432     throw SALOME::SALOME_Exception(es);
1433     return 0;
1434   };
1435
1436   // F. Menage
1437
1438   delete[] MeshName ;
1439   delete[] MeshFile ;
1440
1441   CHDIR(nomDirWork.c_str());
1442   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1443 }
1444 //=============================================================================
1445 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1446 //
1447 // nomCas : nom du cas a creer
1448 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1449 //
1450 {
1451   INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1452
1453   std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1454
1455   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1456   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1457
1458   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1459 }
1460 //=============================================================================
1461 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1462 //
1463 // nomCas : nom du cas a creer
1464 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1465 // Number : numero de l'iteration de depart
1466 //
1467 {
1468   INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1469   if ( Number < 0 )
1470   {
1471     SALOME::ExceptionStruct es;
1472     es.type = SALOME::BAD_PARAM;
1473     es.text = "The number of iteration must be positive.";
1474     throw SALOME::SALOME_Exception(es);
1475     return 0;
1476   };
1477
1478   std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1479
1480   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1481   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1482
1483   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1484 }
1485 //=============================================================================
1486 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1487 //
1488 // Retourne le nom du répertoire ou se trouve l'iteration voulue.
1489 // DirNameStart : nom du répertoire du cas contenant l'iteration de reprise
1490 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1491 //
1492 {
1493   MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1494   std::string nomDirWork = getenv("PWD") ;
1495   std::string DirNameStartIter ;
1496   int codret ;
1497   int NumeIterMax = -1 ;
1498
1499   // A.1. Controle du répertoire de depart du cas
1500   codret = CHDIR(DirNameStart) ;
1501   if ( codret != 0 )
1502   {
1503     SALOME::ExceptionStruct es;
1504     es.type = SALOME::BAD_PARAM;
1505     es.text = "The directory of the case for the pursuit does not exist.";
1506     throw SALOME::SALOME_Exception(es);
1507     return 0;
1508   };
1509   // A.2. Reperage des sous-répertoire du répertoire de reprise
1510   bool existe = false ;
1511 #ifndef WIN32
1512   DIR *dp;
1513   struct dirent *dirp;
1514   dp  = opendir(DirNameStart);
1515   while ( (dirp = readdir(dp)) != NULL ) {
1516     std::string DirName_1(dirp->d_name);
1517 #else
1518   HANDLE hFind = INVALID_HANDLE_VALUE;
1519   WIN32_FIND_DATA ffd;
1520   hFind = FindFirstFile(DirNameStart, &ffd);
1521   if (INVALID_HANDLE_VALUE != hFind) {
1522     while (FindNextFile(hFind, &ffd) != 0) {
1523       std::string DirName_1 = "";
1524       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1525         DirName_1 = std::string(ffd.cFileName);
1526       }
1527 #endif
1528     if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1529     {
1530       if ( CHDIR(DirName_1.c_str()) == 0 )
1531       {
1532 //      On cherche le fichier de configuration dans ce sous-répertoire
1533         codret = CHDIR(DirNameStart);
1534 #ifndef WIN32
1535         DIR *dp_1;
1536         struct dirent *dirp_1;
1537         dp_1  = opendir(DirName_1.c_str()) ;
1538         while ( (dirp_1 = readdir(dp_1)) != NULL )
1539         {
1540           std::string file_name_1(dirp_1->d_name);
1541 #else
1542         HANDLE hFind1 = INVALID_HANDLE_VALUE;
1543         WIN32_FIND_DATA ffd1;
1544         hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1545         while (FindNextFile(hFind1, &ffd1) != 0)
1546         {
1547           if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1548           std::string file_name_1(ffd1.cFileName);
1549 #endif
1550           int bilan = file_name_1.find("HOMARD.Configuration.") ;
1551           if ( bilan != string::npos )
1552           {
1553   // Decodage du fichier pour trouver le numero d'iteration
1554             CHDIR(DirName_1.c_str()) ;
1555
1556             std::ifstream fichier( file_name_1.c_str() );
1557             if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1558             {
1559               int NumeIter ;
1560               std::string ligne; // variable contenant chaque ligne lue
1561               std::string mot_cle;
1562               // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1563               while ( std::getline( fichier, ligne ) )
1564               {
1565                 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1566                 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1567                 ligne_bis >> mot_cle ;
1568                 if ( mot_cle == "NumeIter" )
1569                 {
1570                   ligne_bis >> NumeIter ;
1571                   NumeIter += 1 ;
1572 //                   MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1573                   if ( Number == - 1 )
1574                   {
1575                     if ( NumeIter >= NumeIterMax )
1576                     {
1577                       NumeIterMax = NumeIter ;
1578                       DirNameStartIter = DirName_1 ;
1579                     }
1580                   }
1581                   else
1582                   {
1583                     if ( NumeIter == Number )
1584                     {
1585                       DirNameStartIter = DirName_1 ;
1586                       existe = true ;
1587                       break ;
1588                     }
1589                   }
1590                 }
1591               }
1592             }
1593             else
1594             {
1595               SALOME::ExceptionStruct es;
1596               es.type = SALOME::BAD_PARAM;
1597               std::string text = "The configuration file cannot be read." ;
1598               es.text = CORBA::string_dup(text.c_str());
1599               throw SALOME::SALOME_Exception(es);
1600             }
1601             CHDIR(DirNameStart) ;
1602           }
1603           if ( existe ) { break ; }
1604         }
1605 #ifndef WIN32
1606         closedir(dp_1);
1607 #else
1608         FindClose(hFind1);
1609 #endif
1610         if ( existe ) { break ; }
1611      }
1612     }
1613   }
1614 #ifndef WIN32
1615   closedir(dp);
1616 #else
1617   FindClose(hFind);
1618 #endif
1619   CHDIR(nomDirWork.c_str());
1620
1621   if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1622   {
1623     SALOME::ExceptionStruct es;
1624     es.type = SALOME::BAD_PARAM;
1625     es.text = "The directory of the iteration does not exist.";
1626     throw SALOME::SALOME_Exception(es);
1627     return 0;
1628   };
1629
1630   return DirNameStartIter ;
1631 }
1632 //=============================================================================
1633 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase0(const char* nomCas, const char* MeshName, const char* MeshFile, CORBA::Long MeshOption, CORBA::Long NumeIter, CORBA::Long Option)
1634 //
1635 // nomCas : nom du cas a creer
1636 // MeshName, MeshFile : nom et fichier du maillage correspondant
1637 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1638 //              1 : le maillage fourni peut ne pas exister ==> on continue si absent
1639 //             -1 : le maillage n'est pas fourni
1640 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1641 // Option : multiple de nombres premiers
1642 //         1 : aucune option
1643 //        x2 : publication du maillage dans SMESH
1644 {
1645   MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1646   MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1647   MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1648 //
1649   // A. Controles
1650   // A.1. L'etude
1651   IsValidStudy () ;
1652
1653   // A.2. Controle du nom :
1654   if ((myStudyContext._mesCas).find(nomCas)!=(myStudyContext._mesCas).end())
1655   {
1656     SALOME::ExceptionStruct es;
1657     es.type = SALOME::BAD_PARAM;
1658     es.text = "This case has already been defined.";
1659     throw SALOME::SALOME_Exception(es);
1660     return 0;
1661   };
1662
1663   // A.3. Controle du fichier du maillage
1664   int existeMeshFile ;
1665   if ( MeshOption >= 0 )
1666   {
1667     existeMeshFile = MEDFileExist ( MeshFile ) ;
1668     MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1669     if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1670     {
1671       SALOME::ExceptionStruct es;
1672       es.type = SALOME::BAD_PARAM;
1673       es.text = "The mesh file does not exist.";
1674       throw SALOME::SALOME_Exception(es);
1675       return 0;
1676     }
1677   }
1678   else { existeMeshFile = 0 ; }
1679
1680   // B. Creation de l'objet cas et publication
1681 //   MESSAGE ( "CreateCase0 : Creation de l'objet" );
1682   HOMARD::HOMARD_Cas_var myCase = newCase();
1683   myCase->SetName(nomCas);
1684   SALOMEDS::SObject_var aSO;
1685   SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myCase, nomCas);
1686   myStudyContext._mesCas[nomCas] = myCase;
1687
1688   // C. Caracteristiques du maillage
1689   if ( existeMeshFile != 0 )
1690   {
1691   // Les valeurs extremes des coordonnées
1692 //     MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnées" );
1693     std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1694     HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1695     if (LesExtremes.size()!=10) { return 0; }
1696     aSeq->length(10) ;
1697     for (int i =0 ; i< LesExtremes.size() ; i++)
1698         aSeq[i]=LesExtremes[i] ;
1699     myCase->SetBoundingBox(aSeq) ;
1700   // Les groupes
1701 //     MESSAGE ( "CreateCase0 : Les groupes" );
1702     std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile) ;
1703     HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1704     aSeqGroupe->length(LesGroupes.size());
1705     std::set<std::string>::const_iterator it ;
1706     int i = 0 ;
1707     for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1708       aSeqGroupe[i++]=(*it).c_str() ;
1709     myCase->SetGroups(aSeqGroupe) ;
1710   }
1711
1712   // D. L'iteration initiale du cas
1713   MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1714   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1715   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1716   int monNum = 0;
1717   std::string NomIteration = std::string(MeshName) ;
1718   while ( (myStudyContext._mesIterations).find(NomIteration) != (myStudyContext._mesIterations.end()) )
1719   {
1720     std::ostringstream nom;
1721     nom << MeshName << monNum;
1722     NomIteration = nom.str();
1723     monNum += 1;
1724   }
1725   MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1726
1727   // D.2. Creation de l'iteration
1728   HOMARD::HOMARD_Iteration_var anIter = newIteration();
1729   myStudyContext._mesIterations[NomIteration] = anIter;
1730   anIter->SetName(NomIteration.c_str());
1731   AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1732
1733   // D.4. Maillage correspondant
1734   if ( existeMeshFile != 0 )
1735   {
1736     anIter->SetMeshFile(MeshFile);
1737     if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1738   }
1739   anIter->SetMeshName(MeshName);
1740
1741   // D.5. Numero d'iteration
1742   anIter->SetNumber(NumeIter);
1743
1744   // D.6. Etat
1745   SetEtatIter(NomIteration.c_str(), -NumeIter);
1746 //
1747
1748   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1749 }
1750 //=============================================================================
1751 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1752 {
1753   INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1754   IsValidStudy () ;
1755
1756   // A. Controle du nom :
1757   if ((myStudyContext._mesHypotheses).find(nomHypothesis) != (myStudyContext._mesHypotheses).end())
1758   {
1759     SALOME::ExceptionStruct es;
1760     es.type = SALOME::BAD_PARAM;
1761     es.text = "This hypothesis has already been defined.";
1762     throw SALOME::SALOME_Exception(es);
1763     return 0;
1764   }
1765
1766   // B. Creation de l'objet
1767   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1768   if (CORBA::is_nil(myHypothesis))
1769   {
1770     SALOME::ExceptionStruct es;
1771     es.type = SALOME::BAD_PARAM;
1772     es.text = "Unable to create the hypothesis";
1773     throw SALOME::SALOME_Exception(es);
1774     return 0;
1775   };
1776   myHypothesis->SetName(nomHypothesis);
1777
1778   // C. Enregistrement
1779   myStudyContext._mesHypotheses[nomHypothesis] = myHypothesis;
1780
1781   SALOMEDS::SObject_var aSO;
1782   SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myHypothesis, nomHypothesis);
1783
1784   // D. Valeurs par defaut des options avancees
1785   myHypothesis->SetNivMax(-1);
1786   myHypothesis->SetDiamMin(-1.0);
1787   myHypothesis->SetAdapInit(0);
1788   myHypothesis->SetExtraOutput(1);
1789
1790   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1791 }
1792
1793 //=============================================================================
1794 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1795 //=============================================================================
1796 {
1797   INFOS ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
1798   IsValidStudy () ;
1799
1800   HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterParent];
1801   if (CORBA::is_nil(myIterationParent))
1802   {
1803     SALOME::ExceptionStruct es;
1804     es.type = SALOME::BAD_PARAM;
1805     es.text = "The parent iteration is not defined.";
1806     throw SALOME::SALOME_Exception(es);
1807     return 0;
1808   };
1809
1810   const char* nomCas = myIterationParent->GetCaseName();
1811   MESSAGE ("CreateIteration : nomCas = " << nomCas);
1812   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
1813   if (CORBA::is_nil(myCase))
1814   {
1815     SALOME::ExceptionStruct es;
1816     es.type = SALOME::BAD_PARAM;
1817     es.text = "Invalid case context";
1818     throw SALOME::SALOME_Exception(es);
1819     return 0;
1820   };
1821   const char* nomDirCase = myCase->GetDirName();
1822
1823   // Controle du nom :
1824   if ((myStudyContext._mesIterations).find(NomIteration)!=(myStudyContext._mesIterations).end())
1825   {
1826     SALOME::ExceptionStruct es;
1827     es.type = SALOME::BAD_PARAM;
1828     es.text = "This iteration has already been defined.";
1829     throw SALOME::SALOME_Exception(es);
1830     return 0;
1831   };
1832
1833    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1834    if (CORBA::is_nil(myIteration))
1835   {
1836     SALOME::ExceptionStruct es;
1837     es.type = SALOME::BAD_PARAM;
1838     es.text = "Unable to create the iteration";
1839     throw SALOME::SALOME_Exception(es);
1840     return 0;
1841   };
1842   myStudyContext._mesIterations[std::string(NomIteration)] = myIteration;
1843 // Nom de l'iteration et du maillage
1844   myIteration->SetName(NomIteration);
1845   myIteration->SetMeshName(NomIteration);
1846   myIteration->SetState(1);
1847
1848   int numero = myIterationParent->GetNumber() + 1;
1849   myIteration->SetNumber(numero);
1850
1851 // Nombre d'iterations deja connues pour le cas, permettant
1852 // la creation d'un sous-répertoire unique
1853   int nbitercase = myCase->GetNumberofIter();
1854   char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1855   myIteration->SetDirNameLoc(nomDirIter);
1856
1857 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1858 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1859 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1860 // situation la plus frequente.
1861 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1862 // le nombre d'iterations du cas permet d'eviter les collisions.
1863   int jaux ;
1864   if      ( nbitercase <    100 ) { jaux = 2 ; }
1865   else if ( nbitercase <   1000 ) { jaux = 3 ; }
1866   else if ( nbitercase <  10000 ) { jaux = 4 ; }
1867   else if ( nbitercase < 100000 ) { jaux = 5 ; }
1868   else                            { jaux = 9 ; }
1869   std::ostringstream iaux ;
1870   iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1871   std::stringstream MeshFile;
1872   MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1873   myIteration->SetMeshFile(MeshFile.str().c_str());
1874
1875 // Association avec le cas
1876   std::string label = "IterationHomard_" + std::string(nomIterParent);
1877   AssociateCaseIter(nomCas, NomIteration, label.c_str());
1878 // Lien avec l'iteration precedente
1879   myIterationParent->LinkNextIteration(NomIteration);
1880   myIteration->SetIterParentName(nomIterParent);
1881   // Gestion de l'arbre d'etudes
1882   SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1883   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1884   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
1885   aStudyBuilder->NewCommand();
1886   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1887   aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1888   aStudyBuilder->CommitCommand();
1889
1890   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1891 }
1892 //=============================================================================
1893 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1894 {
1895   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1896   IsValidStudy () ;
1897
1898   // Controle du nom :
1899   if ((myStudyContext._mesBoundarys).find(BoundaryName)!=(myStudyContext._mesBoundarys).end())
1900   {
1901     MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1902     SALOME::ExceptionStruct es;
1903     es.type = SALOME::BAD_PARAM;
1904     es.text = "This boundary has already been defined";
1905     throw SALOME::SALOME_Exception(es);
1906     return 0;
1907   };
1908
1909   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1910   myBoundary->SetName(BoundaryName);
1911   myBoundary->SetType(BoundaryType);
1912
1913   myStudyContext._mesBoundarys[BoundaryName] = myBoundary;
1914
1915   SALOMEDS::SObject_var aSO;
1916   SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myBoundary, BoundaryName);
1917
1918   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1919 }
1920 //=============================================================================
1921 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCAO(const char* BoundaryName, const char* CAOFile)
1922 {
1923   INFOS ("CreateBoundaryCAO : BoundaryName  = " << BoundaryName << ", CAOFile = " << CAOFile );
1924   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, -1);
1925   myBoundary->SetDataFile( CAOFile ) ;
1926
1927   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1928 }
1929 //=============================================================================
1930 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1931 {
1932   INFOS ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1933   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1934   myBoundary->SetDataFile( MeshFile ) ;
1935   myBoundary->SetMeshName( MeshName ) ;
1936
1937   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1938 }
1939 //=============================================================================
1940 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1941                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1942                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1943                                       CORBA::Double Rayon)
1944 {
1945   INFOS ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
1946 //
1947   SALOME::ExceptionStruct es;
1948   int error = 0 ;
1949   if ( Rayon <= 0.0 )
1950   { es.text = "The radius must be positive." ;
1951     error = 1 ; }
1952   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1953   if ( daux < 0.0000001 )
1954   { es.text = "The axis must be a non 0 vector." ;
1955     error = 2 ; }
1956   if ( error != 0 )
1957   {
1958     es.type = SALOME::BAD_PARAM;
1959     throw SALOME::SALOME_Exception(es);
1960     return 0;
1961   };
1962 //
1963   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1964   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1965
1966   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1967 }
1968 //=============================================================================
1969 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1970                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1971                                       CORBA::Double Rayon)
1972 {
1973   INFOS ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
1974 //
1975   SALOME::ExceptionStruct es;
1976   int error = 0 ;
1977   if ( Rayon <= 0.0 )
1978   { es.text = "The radius must be positive." ;
1979     error = 1 ; }
1980   if ( error != 0 )
1981   {
1982     es.type = SALOME::BAD_PARAM;
1983     throw SALOME::SALOME_Exception(es);
1984     return 0;
1985   };
1986 //
1987   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1988   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1989
1990   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1991 }
1992 //=============================================================================
1993 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1994                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1995                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1996 {
1997   INFOS ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
1998 //
1999   SALOME::ExceptionStruct es;
2000   int error = 0 ;
2001   if ( Angle <= 0.0 || Angle >= 90.0 )
2002   { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2003     error = 1 ; }
2004   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2005   if ( daux < 0.0000001 )
2006   { es.text = "The axis must be a non 0 vector." ;
2007     error = 2 ; }
2008   if ( error != 0 )
2009   {
2010     es.type = SALOME::BAD_PARAM;
2011     throw SALOME::SALOME_Exception(es);
2012     return 0;
2013   };
2014 //
2015   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2016   myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2017
2018   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2019 }
2020 //=============================================================================
2021 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2022                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2023                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2024 {
2025   INFOS ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
2026 //
2027   SALOME::ExceptionStruct es;
2028   int error = 0 ;
2029   if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2030   { es.text = "The radius must be positive." ;
2031     error = 1 ; }
2032   double daux = fabs(Rayon2-Rayon1) ;
2033   if ( daux < 0.0000001 )
2034   { es.text = "The radius must be different." ;
2035     error = 2 ; }
2036   daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2037   if ( daux < 0.0000001 )
2038   { es.text = "The centers must be different." ;
2039     error = 3 ; }
2040   if ( error != 0 )
2041   {
2042     es.type = SALOME::BAD_PARAM;
2043     throw SALOME::SALOME_Exception(es);
2044     return 0;
2045   };
2046 //
2047   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2048   myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2049
2050   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2051 }
2052 //=============================================================================
2053 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2054                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2055                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2056                                       CORBA::Double RayonRev, CORBA::Double RayonPri)
2057 {
2058   INFOS ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName ) ;
2059 //
2060   SALOME::ExceptionStruct es;
2061   int error = 0 ;
2062   if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2063   { es.text = "The radius must be positive." ;
2064     error = 1 ; }
2065   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2066   if ( daux < 0.0000001 )
2067   { es.text = "The axis must be a non 0 vector." ;
2068     error = 2 ; }
2069   if ( error != 0 )
2070   {
2071     es.type = SALOME::BAD_PARAM;
2072     throw SALOME::SALOME_Exception(es);
2073     return 0;
2074   };
2075 //
2076   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2077   myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2078
2079   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2080 }
2081 //=============================================================================
2082 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2083 {
2084   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
2085   IsValidStudy () ;
2086
2087   // Controle du nom :
2088   if ((myStudyContext._mesZones).find(ZoneName)!=(myStudyContext._mesZones).end())
2089   {
2090     SALOME::ExceptionStruct es;
2091     es.type = SALOME::BAD_PARAM;
2092     es.text = "This zone has already been defined";
2093     throw SALOME::SALOME_Exception(es);
2094     return 0;
2095   };
2096
2097   HOMARD::HOMARD_Zone_var myZone = newZone();
2098   myZone->SetName(ZoneName);
2099   myZone->SetType(ZoneType);
2100
2101   myStudyContext._mesZones[ZoneName] = myZone;
2102
2103   SALOMEDS::SObject_var aSO;
2104   SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myZone, ZoneName);
2105
2106   return HOMARD::HOMARD_Zone::_duplicate(myZone);
2107 }
2108 //=============================================================================
2109 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2110                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
2111                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
2112                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
2113 {
2114   INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
2115 //
2116   SALOME::ExceptionStruct es;
2117   int error = 0 ;
2118   if ( Xmini > Xmaxi )
2119   { es.text = "The X coordinates are not coherent." ;
2120     error = 1 ; }
2121   if ( Ymini > Ymaxi )
2122   { es.text = "The Y coordinates are not coherent." ;
2123     error = 2 ; }
2124   if ( Zmini > Zmaxi )
2125   { es.text = "The Z coordinates are not coherent." ;
2126     error = 3 ; }
2127   if ( error != 0 )
2128   {
2129     es.type = SALOME::BAD_PARAM;
2130     throw SALOME::SALOME_Exception(es);
2131     return 0;
2132   };
2133 //
2134   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2135   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2136
2137   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2138 }
2139 //=============================================================================
2140 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2141                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2142 {
2143   INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
2144 //
2145   SALOME::ExceptionStruct es;
2146   int error = 0 ;
2147   if ( Rayon <= 0.0 )
2148   { es.text = "The radius must be positive." ;
2149     error = 1 ; }
2150   if ( error != 0 )
2151   {
2152     es.type = SALOME::BAD_PARAM;
2153     throw SALOME::SALOME_Exception(es);
2154     return 0;
2155   };
2156 //
2157   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2158   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2159
2160   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2161 }
2162 //=============================================================================
2163 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2164                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2165                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2166                                       CORBA::Double Rayon, CORBA::Double Haut)
2167 {
2168   INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
2169 //
2170   SALOME::ExceptionStruct es;
2171   int error = 0 ;
2172   if ( Rayon <= 0.0 )
2173   { es.text = "The radius must be positive." ;
2174     error = 1 ; }
2175   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2176   if ( daux < 0.0000001 )
2177   { es.text = "The axis must be a non 0 vector." ;
2178     error = 2 ; }
2179   if ( Haut <= 0.0 )
2180   { es.text = "The height must be positive." ;
2181     error = 3 ; }
2182   if ( error != 0 )
2183   {
2184     es.type = SALOME::BAD_PARAM;
2185     throw SALOME::SALOME_Exception(es);
2186     return 0;
2187   };
2188 //
2189   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2190   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2191
2192   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2193 }
2194 //=============================================================================
2195 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2196                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2197                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2198                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2199 {
2200   INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
2201 //
2202   SALOME::ExceptionStruct es;
2203   int error = 0 ;
2204   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2205   { es.text = "The radius must be positive." ;
2206     error = 1 ; }
2207   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2208   if ( daux < 0.0000001 )
2209   { es.text = "The axis must be a non 0 vector." ;
2210     error = 2 ; }
2211   if ( Haut <= 0.0 )
2212   { es.text = "The height must be positive." ;
2213     error = 3 ; }
2214   if ( Rayon <= Rayonint )
2215   { es.text = "The external radius must be higher than the internal radius." ;
2216     error = 4 ; }
2217   if ( error != 0 )
2218   {
2219     es.type = SALOME::BAD_PARAM;
2220     throw SALOME::SALOME_Exception(es);
2221     return 0;
2222   };
2223 //
2224   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2225   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2226
2227   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2228 }
2229 //=============================================================================
2230 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2231                                       CORBA::Double Umini, CORBA::Double Umaxi,
2232                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
2233                                       CORBA::Long Orient)
2234 {
2235   INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
2236 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2237 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2238 //   MESSAGE ("Orient = " << Orient ) ;
2239 //
2240   SALOME::ExceptionStruct es;
2241   int error = 0 ;
2242   if ( Umini > Umaxi )
2243   { es.text = "The first coordinates are not coherent." ;
2244     error = 1 ; }
2245   if ( Vmini > Vmaxi )
2246   { es.text = "The second coordinates are not coherent." ;
2247     error = 2 ; }
2248   if ( Orient < 1 || Orient > 3 )
2249   { es.text = "The orientation must be 1, 2 or 3." ;
2250     error = 3 ; }
2251   if ( error != 0 )
2252   {
2253     es.type = SALOME::BAD_PARAM;
2254     throw SALOME::SALOME_Exception(es);
2255     return 0;
2256   };
2257 //
2258   double Xmini, Xmaxi ;
2259   double Ymini, Ymaxi ;
2260   double Zmini, Zmaxi ;
2261   if ( Orient == 1 )
2262   { Xmini = Umini ;
2263     Xmaxi = Umaxi ;
2264     Ymini = Vmini ;
2265     Ymaxi = Vmaxi ;
2266     Zmini = 0. ;
2267     Zmaxi = 0. ; }
2268   else if ( Orient == 2 )
2269   { Xmini = 0. ;
2270     Xmaxi = 0. ;
2271     Ymini = Umini ;
2272     Ymaxi = Umaxi ;
2273     Zmini = Vmini ;
2274     Zmaxi = Vmaxi ; }
2275   else if ( Orient == 3 )
2276   { Xmini = Vmini ;
2277     Xmaxi = Vmaxi ;
2278     Ymini = 0. ;
2279     Ymaxi = 0. ;
2280     Zmini = Umini ;
2281     Zmaxi = Umaxi ; }
2282   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2283
2284   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2285   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2286
2287   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2288 }
2289 //=============================================================================
2290 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2291                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2292                                       CORBA::Double Rayon,
2293                                       CORBA::Long Orient)
2294 {
2295   INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
2296 //
2297   SALOME::ExceptionStruct es;
2298   int error = 0 ;
2299   if ( Rayon <= 0.0 )
2300   { es.text = "The radius must be positive." ;
2301     error = 1 ; }
2302   if ( Orient < 1 || Orient > 3 )
2303   { es.text = "The orientation must be 1, 2 or 3." ;
2304     error = 3 ; }
2305   if ( error != 0 )
2306   {
2307     es.type = SALOME::BAD_PARAM;
2308     throw SALOME::SALOME_Exception(es);
2309     return 0;
2310   };
2311 //
2312   double Xcentre ;
2313   double Ycentre ;
2314   double Zcentre ;
2315   if ( Orient == 1 )
2316   { Xcentre = Ucentre ;
2317     Ycentre = Vcentre ;
2318     Zcentre = 0. ; }
2319   else if ( Orient == 2 )
2320   { Xcentre = 0. ;
2321     Ycentre = Ucentre ;
2322     Zcentre = Vcentre ; }
2323   else if ( Orient == 3 )
2324   { Xcentre = Vcentre ;
2325     Ycentre = 0. ;
2326     Zcentre = Ucentre ; }
2327   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2328
2329   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2330   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2331
2332   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2333 }
2334 //=============================================================================
2335 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2336                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2337                                       CORBA::Double Rayon, CORBA::Double Rayonint,
2338                                       CORBA::Long Orient)
2339 {
2340   INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
2341 //
2342   SALOME::ExceptionStruct es;
2343   int error = 0 ;
2344   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2345   { es.text = "The radius must be positive." ;
2346     error = 1 ; }
2347   if ( Orient < 1 || Orient > 3 )
2348   { es.text = "The orientation must be 1, 2 or 3." ;
2349     error = 3 ; }
2350   if ( Rayon <= Rayonint )
2351   { es.text = "The external radius must be higher than the internal radius." ;
2352     error = 4 ; }
2353   if ( error != 0 )
2354   {
2355     es.type = SALOME::BAD_PARAM;
2356     throw SALOME::SALOME_Exception(es);
2357     return 0;
2358   };
2359 //
2360   double Xcentre ;
2361   double Ycentre ;
2362   double Zcentre ;
2363   if ( Orient == 1 )
2364   { Xcentre = Ucentre ;
2365     Ycentre = Vcentre ;
2366     Zcentre = 0. ; }
2367   else if ( Orient == 2 )
2368   { Xcentre = 0. ;
2369     Ycentre = Ucentre ;
2370     Zcentre = Vcentre ; }
2371   else if ( Orient == 3 )
2372   { Xcentre = Vcentre ;
2373     Ycentre = 0. ;
2374     Zcentre = Ucentre ; }
2375   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2376
2377   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2378   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2379
2380   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2381 }
2382 //=============================================================================
2383 //=============================================================================
2384
2385
2386
2387
2388 //=============================================================================
2389 //=============================================================================
2390 // Traitement d'une iteration
2391 // etatMenage = 1 : destruction du répertoire d'execution
2392 // modeHOMARD  = 1 : adaptation
2393 //            != 1 : information avec les options modeHOMARD
2394 // Option1 >0 : appel depuis python
2395 //         <0 : appel depuis GUI
2396 // Option2 : multiple de nombres premiers
2397 //         1 : aucune option
2398 //        x2 : publication du maillage dans SMESH
2399 //=============================================================================
2400 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2401 {
2402   INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2403
2404   // A. Prealable
2405   int codret = 0;
2406
2407   // A.1. L'objet iteration
2408   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIteration];
2409   ASSERT(!CORBA::is_nil(myIteration));
2410
2411   // A.2. Controle de la possibilite d'agir
2412   // A.2.1. Etat de l'iteration
2413   int etat = myIteration->GetState();
2414   MESSAGE ( "etat = "<<etat );
2415   // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2416   if ( modeHOMARD == 1 )
2417   {
2418     if ( etat <= 0 )
2419     {
2420       SALOME::ExceptionStruct es;
2421       es.type = SALOME::BAD_PARAM;
2422       es.text = "This iteration is the first of the case and cannot be computed.";
2423       throw SALOME::SALOME_Exception(es);
2424       return 1 ;
2425     }
2426     else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2427     {
2428       SALOME::ExceptionStruct es;
2429       es.type = SALOME::BAD_PARAM;
2430       es.text = "This iteration is already computed.";
2431       throw SALOME::SALOME_Exception(es);
2432       return 1 ;
2433     }
2434   }
2435   // A.2.3. On n'analyse pas une iteration non calculee
2436   else
2437   {
2438     if ( etat == 1 )
2439     {
2440       SALOME::ExceptionStruct es;
2441       es.type = SALOME::BAD_PARAM;
2442       es.text = "This iteration is not computed.";
2443       throw SALOME::SALOME_Exception(es);
2444       return 1 ;
2445     }
2446   }
2447
2448   // A.3. Numero de l'iteration
2449   //     siterp1 : numero de l'iteration a traiter
2450   //     Si adaptation :
2451   //        siter   : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2452   //     Ou si information :
2453   //        siter = siterp1
2454   int NumeIter = myIteration->GetNumber();
2455   std::string siterp1 ;
2456   std::stringstream saux1 ;
2457   saux1 << NumeIter ;
2458   siterp1 = saux1.str() ;
2459   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2460
2461   std::string siter ;
2462   if ( modeHOMARD==1 )
2463   {
2464     std::stringstream saux0 ;
2465     int iaux = max(0, NumeIter-1) ;
2466     saux0 << iaux ;
2467     siter = saux0.str() ;
2468     if (NumeIter < 11) { siter = "0" + siter ; }
2469   }
2470   else
2471   { siter = siterp1 ; }
2472
2473   // A.4. Le cas
2474   const char* nomCas = myIteration->GetCaseName();
2475   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
2476   ASSERT(!CORBA::is_nil(myCase));
2477
2478   // B. Les répertoires
2479   // B.1. Le répertoire courant
2480   std::string nomDirWork = getenv("PWD") ;
2481   // B.2. Le sous-répertoire de l'iteration a traiter
2482   char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2483   MESSAGE( ". DirCompute = " << DirCompute );
2484
2485   // C. Le fichier des messages
2486   // C.1. Le deroulement de l'execution de HOMARD
2487   std::string LogFile = DirCompute ;
2488   LogFile += "/Liste" ;
2489   if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2490   LogFile += ".log" ;
2491   MESSAGE (". LogFile = " << LogFile);
2492   if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2493   // C.2. Le bilan de l'analyse du maillage
2494   std::string FileInfo = DirCompute ;
2495   FileInfo += "/" ;
2496   if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2497   else
2498   { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2499     else                 { FileInfo += "info_ap" ; }
2500   }
2501   FileInfo += "." + siterp1 + ".bilan" ;
2502   myIteration->SetFileInfo(FileInfo.c_str());
2503
2504    // D. On passe dans le répertoire de l'iteration a calculer
2505   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2506   CHDIR(DirCompute);
2507
2508   // E. Les données de l'exécution HOMARD
2509   // E.1. L'objet du texte du fichier de configuration
2510   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2511   myDriver->TexteInit(DirCompute, LogFile, _Langue);
2512
2513   // E.2. Le maillage associe a l'iteration
2514   const char* NomMesh = myIteration->GetMeshName();
2515   MESSAGE ( ". NomMesh = " << NomMesh );
2516   const char* MeshFile = myIteration->GetMeshFile();
2517   MESSAGE ( ". MeshFile = " << MeshFile );
2518
2519   // E.3. Les données du traitement HOMARD
2520   int iaux ;
2521   if ( modeHOMARD == 1 )
2522   {
2523     iaux = 1 ;
2524     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2525     myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2526     codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2527   }
2528   else
2529   {
2530     InvalideIterInfo(NomIteration);
2531     myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2532     iaux = 0 ;
2533     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2534     myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2535     myDriver->CreeFichierDonn();
2536   }
2537
2538   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2539   int BoundaryOption = DriverTexteBoundary(myCase, myDriver) ;
2540
2541   // E.5. Ecriture du texte dans le fichier
2542   MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2543   if (codret == 0)
2544   { myDriver->CreeFichier(); }
2545
2546 // G. Execution
2547 //
2548   int codretexec = 1789 ;
2549   if (codret == 0)
2550   {
2551     codretexec = myDriver->ExecuteHomard(Option1);
2552 //
2553     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2554     // En mode adaptation, on ajuste l'etat de l'iteration
2555     if ( modeHOMARD == 1 )
2556     {
2557       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2558       else                 { SetEtatIter(NomIteration,1); }
2559       // GERALD -- QMESSAGE BOX
2560     }
2561   }
2562
2563   // H. Gestion des resultats
2564   if (codret == 0)
2565   {
2566     std::string Commentaire ;
2567     // H.1. Le fichier des messages, dans tous les cas
2568     Commentaire = "log" ;
2569     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2570     else                   { Commentaire += "Info" ; }
2571     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2572
2573     // H.2. Si tout s'est bien passe :
2574     if (codretexec == 0)
2575     {
2576     // H.2.1. Le fichier de bilan
2577       Commentaire = "Summary" ;
2578       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2579       else                   { Commentaire += "Info" ; }
2580       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2581     // H.2.2. Le fichier de  maillage obtenu
2582       if ( modeHOMARD == 1 )
2583       {
2584         std::stringstream saux0 ;
2585         Commentaire = "Mesh" ;
2586         Commentaire += " " + siterp1 ;
2587         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2588         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2589       }
2590     }
2591   // H.3 Message d'erreur
2592     if (codretexec != 0)
2593     {
2594       std::string text = "" ;
2595       // Message d'erreur en cas de probleme en adaptation
2596       if ( modeHOMARD == 1 )
2597       {
2598         text = "Error during the adaptation.\n" ;
2599         bool stopvu = false ;
2600         std::ifstream fichier( LogFile.c_str() );
2601         if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2602         {
2603           std::string ligne; // variable contenant chaque ligne lue
2604           while ( std::getline( fichier, ligne ) )
2605           {
2606 //             INFOS(ligne);
2607             if ( stopvu )
2608             { text += ligne+ "\n"; }
2609             else
2610             {
2611               int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2612               if ( position > 0 ) { stopvu = true ; }
2613             }
2614           }
2615         }
2616       }
2617       text += "\n\nSee the file " + LogFile + "\n" ;
2618       INFOS ( text ) ;
2619       SALOME::ExceptionStruct es;
2620       es.type = SALOME::BAD_PARAM;
2621       es.text = CORBA::string_dup(text.c_str());
2622       throw SALOME::SALOME_Exception(es);
2623 //
2624       // En mode information, on force le succes pour pouvoir consulter le fichier log
2625       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2626     }
2627   }
2628
2629   // I. Menage et retour dans le répertoire du cas
2630   if (codret == 0)
2631   {
2632     delete myDriver;
2633     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2634
2635     CHDIR(nomDirWork.c_str());
2636   }
2637
2638   // J. Suivi de la frontière CAO
2639 //   std::cout << "- codret : " << codret << std::endl;
2640 //   std::cout << "- modeHOMARD : " << modeHOMARD << std::endl;
2641 //   std::cout << "- BoundaryOption : " << BoundaryOption << std::endl;
2642 //   std::cout << "- codretexec : " << codretexec << std::endl;
2643   if (codret == 0)
2644   {
2645     if ( ( modeHOMARD == 1 ) && ( BoundaryOption % 5 == 0 ) && (codretexec == 0) )
2646     {
2647       INFOS ( "Suivi de frontière CAO" );
2648       codret = ComputeCAO(myCase, myIteration, Option1, Option2) ;
2649     }
2650   }
2651
2652   return codretexec ;
2653 }
2654 //=============================================================================
2655 // Calcul d'une iteration : partie spécifique à l'adaptation
2656 //=============================================================================
2657 CORBA::Long HOMARD_Gen_i::ComputeAdap(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage, HomardDriver* myDriver, CORBA::Long Option1, CORBA::Long Option2)
2658 {
2659   MESSAGE ( "ComputeAdap avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2660
2661   // A. Prealable
2662   // A.1. Bases
2663   int codret = 0;
2664   // Numero de l'iteration
2665   int NumeIter = myIteration->GetNumber();
2666   std::stringstream saux0 ;
2667   saux0 << NumeIter-1 ;
2668   std::string siter = saux0.str() ;
2669   if (NumeIter < 11) { siter = "0" + siter ; }
2670
2671   // A.2. On verifie qu il y a une hypothese (erreur improbable);
2672   const char* nomHypo = myIteration->GetHypoName();
2673   if (std::string(nomHypo) == std::string(""))
2674   {
2675       SALOME::ExceptionStruct es;
2676       es.type = SALOME::BAD_PARAM;
2677       es.text = "This iteration does not have any associated hypothesis.";
2678       throw SALOME::SALOME_Exception(es);
2679       return 2;
2680   };
2681   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
2682   ASSERT(!CORBA::is_nil(myHypo));
2683
2684   // B. L'iteration parent
2685   const char* nomIterationParent = myIteration->GetIterParentName();
2686   HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
2687   ASSERT(!CORBA::is_nil(myIterationParent));
2688   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2689   if ( myIterationParent->GetState() == 1 )
2690   {
2691     int iaux = 1 ;
2692     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2693     if (codret != 0)
2694     {
2695       // GERALD -- QMESSAGE BOX
2696       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2697     }
2698   };
2699
2700   // C. Le sous-répertoire de l'iteration precedente
2701   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2702   MESSAGE( ". DirComputePa = " << DirComputePa );
2703
2704   // D. Les données de l'adaptation HOMARD
2705   // D.1. Le type de conformite
2706   int ConfType = myCase->GetConfType();
2707   MESSAGE ( ". ConfType = " << ConfType );
2708
2709   // D.1. Le type externe
2710   int ExtType = myCase->GetExtType();
2711   MESSAGE ( ". ExtType = " << ExtType );
2712
2713   // D.3. Le maillage de depart
2714   const char* NomMeshParent = myIterationParent->GetMeshName();
2715   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2716   const char* MeshFileParent = myIterationParent->GetMeshFile();
2717   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2718
2719   // D.4. Le maillage associe a l'iteration
2720   const char* MeshFile = myIteration->GetMeshFile();
2721   MESSAGE ( ". MeshFile = " << MeshFile );
2722   FILE *file = fopen(MeshFile,"r");
2723   if (file != NULL)
2724   {
2725     fclose(file);
2726     if (etatMenage == 0)
2727     {
2728       SALOME::ExceptionStruct es;
2729       es.type = SALOME::BAD_PARAM;
2730       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2731       es.text = CORBA::string_dup(text.c_str());
2732       throw SALOME::SALOME_Exception(es);
2733       return 4;
2734     }
2735     else
2736     {
2737       std::string commande = "rm -f " + std::string(MeshFile);
2738       codret = system(commande.c_str());
2739       if (codret != 0)
2740       {
2741         SALOME::ExceptionStruct es;
2742         es.type = SALOME::BAD_PARAM;
2743         es.text = "The mesh file cannot be deleted.";
2744         throw SALOME::SALOME_Exception(es);
2745         return 5;
2746       }
2747     }
2748   }
2749
2750   // D.5. Les types de raffinement et de deraffinement
2751   // Les appels corba sont lourds, il vaut mieux les grouper
2752   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2753   ASSERT(ListTypes->length() == 3);
2754   int TypeAdap = (*ListTypes)[0];
2755   int TypeRaff = (*ListTypes)[1];
2756   int TypeDera = (*ListTypes)[2];
2757 //   MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera  );
2758
2759   // E. Texte du fichier de configuration
2760   // E.1. Incontournables du texte
2761   myDriver->TexteAdap(ExtType);
2762   int iaux = 0 ;
2763   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2764   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2765   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2766
2767   // E.2. Ajout des informations liees aux zones eventuelles
2768   if ( TypeAdap == 0 )
2769   { DriverTexteZone(myHypo, myDriver) ; }
2770
2771   // E.3. Ajout des informations liees aux champs eventuels
2772   if ( TypeAdap == 1 )
2773   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2774
2775   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2776   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2777   int numberOfGroups = listeGroupes->length();
2778   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2779   if (numberOfGroups > 0)
2780   {
2781     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2782     {
2783       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2784       MESSAGE( "... GroupName = " << GroupName );
2785       myDriver->TexteGroup(GroupName);
2786     }
2787   }
2788
2789   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2790   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2791
2792   // E.6. Ajout des options avancees
2793   int Pyram = myCase->GetPyram();
2794   MESSAGE ( ". Pyram = " << Pyram );
2795   int NivMax = myHypo->GetNivMax();
2796   MESSAGE ( ". NivMax = " << NivMax );
2797   double DiamMin = myHypo->GetDiamMin() ;
2798   MESSAGE ( ". DiamMin = " << DiamMin );
2799   int AdapInit = myHypo->GetAdapInit();
2800   MESSAGE ( ". AdapInit = " << AdapInit );
2801   int ExtraOutput = myHypo->GetExtraOutput();
2802   MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2803   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2804
2805   // E.7. Ajout des informations sur le deroulement de l'execution
2806   int MessInfo = myIteration->GetInfoCompute();
2807   MESSAGE ( ". MessInfo = " << MessInfo );
2808   myDriver->TexteInfoCompute(MessInfo);
2809
2810   return codret ;
2811 }
2812 //=============================================================================
2813 // Calcul d'une iteration : partie spécifique au suivi de frontière CAO
2814 //=============================================================================
2815 CORBA::Long HOMARD_Gen_i::ComputeCAO(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2816 {
2817   MESSAGE ( "ComputeCAO avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2818
2819   // A. Prealable
2820   // A.1. Bases
2821   int codret = 0;
2822   // A.2. Le sous-répertoire de l'iteration en cours de traitement
2823   char* DirCompute = myIteration->GetDirName();
2824   // A.3. Le maillage résultat de l'iteration en cours de traitement
2825   char* MeshFile = myIteration->GetMeshFile();
2826
2827   // B. Les données pour FrontTrack
2828   // B.1. Le maillage à modifier
2829   const std::string theInputMedFile = MeshFile;
2830   MESSAGE ( ". theInputMedFile  = " << theInputMedFile );
2831
2832   // B.2. Le maillage après modification : fichier identique
2833   const std::string theOutputMedFile = MeshFile ;
2834   MESSAGE ( ". theOutputMedFile = " << theInputMedFile );
2835
2836   // B.3. La liste des fichiers contenant les numéros des noeuds à bouger
2837   std::vector< std::string > theInputNodeFiles ;
2838   MESSAGE ( ". DirCompute = " << DirCompute );
2839   int bilan ;
2840   int icpt = 0 ;
2841 #ifndef WIN32
2842   DIR *dp;
2843   struct dirent *dirp;
2844   dp  = opendir(DirCompute);
2845   while ( (dirp = readdir(dp)) != NULL )
2846   {
2847     std::string file_name(dirp->d_name);
2848     bilan = file_name.find("fr") ;
2849     if ( bilan != string::npos )
2850     {
2851       std::stringstream filename_total ;
2852       filename_total << DirCompute << "/" << file_name ;
2853       theInputNodeFiles.push_back(filename_total.str()) ;
2854       icpt += 1 ;
2855     }
2856   }
2857 #else
2858   HANDLE hFind = INVALID_HANDLE_VALUE;
2859   WIN32_FIND_DATA ffd;
2860   hFind = FindFirstFile(DirNameStart, &ffd);
2861   if (INVALID_HANDLE_VALUE != hFind) {
2862     while (FindNextFile(hFind, &ffd) != 0) {
2863       std::string file_name(ffd.cFileName);
2864       bilan = file_name.find("fr") ;
2865       if ( bilan != string::npos )
2866       {
2867         std::stringstream filename_total ;
2868         filename_total << DirCompute << "/" << file_name ;
2869         theInputNodeFiles.push_back(filename_total.str()) ;
2870         icpt += 1 ;
2871       }
2872     }
2873     FindClose(hFind);
2874   }
2875 #endif
2876   for ( int i = 0; i < icpt; i++ )
2877   { MESSAGE ( ". theInputNodeFiles["<< i << "] = " << theInputNodeFiles[i] ); }
2878
2879   // B.4. Le fichier de la CAO
2880   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2881   std::string BoundaryName = std::string((*ListBoundaryGroupType)[0]);
2882   MESSAGE ( ". BoundaryName = " << BoundaryName );
2883   HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
2884   const std::string theXaoFileName = myBoundary->GetDataFile();
2885   MESSAGE ( ". theXaoFileName = " << theXaoFileName );
2886
2887   // B.5. Parallélisme
2888   bool theIsParallel = false;
2889
2890   // C. Lancement des projections
2891   MESSAGE ( ". Lancement des projections" );
2892   FrontTrack* myFrontTrack = new FrontTrack();
2893   myFrontTrack->track(theInputMedFile, theOutputMedFile, theInputNodeFiles, theXaoFileName, theIsParallel);
2894
2895   // D. Transfert des coordonnées modifiées dans le fichier historique de HOMARD
2896   //    On lance une exécution spéciale de HOMARD en attendant de savoir le faire avec MEDCoupling
2897   MESSAGE ( ". Transfert des coordonnées" );
2898   codret = ComputeCAObis(myIteration, Option1, Option2) ;
2899
2900   return codret ;
2901 }
2902 //=============================================================================
2903 //=============================================================================
2904 // Transfert des coordonnées en suivi de frontière CAO
2905 // Option1 >0 : appel depuis python
2906 //         <0 : appel depuis GUI
2907 // Option2 : multiple de nombres premiers
2908 //         1 : aucune option
2909 //        x2 : publication du maillage dans SMESH
2910 //=============================================================================
2911 CORBA::Long HOMARD_Gen_i::ComputeCAObis(HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long Option1, CORBA::Long Option2)
2912 {
2913   MESSAGE ( "ComputeCAObis, avec Option1 = " << Option1 << ", Option2 = " << Option2 );
2914
2915   // A. Prealable
2916   int codret = 0;
2917
2918   // A.1. Controle de la possibilite d'agir
2919   // A.1.1. Etat de l'iteration
2920   int etat = myIteration->GetState();
2921   MESSAGE ( "etat = "<<etat );
2922   // A.1.2. L'iteration doit être calculee
2923   if ( etat == 1 )
2924   {
2925     SALOME::ExceptionStruct es;
2926     es.type = SALOME::BAD_PARAM;
2927     es.text = "This iteration is not computed.";
2928     throw SALOME::SALOME_Exception(es);
2929     return 1 ;
2930   }
2931   // A.2. Numero de l'iteration
2932   //     siterp1 : numero de l'iteration a traiter
2933   int NumeIter = myIteration->GetNumber();
2934   std::string siterp1 ;
2935   std::stringstream saux1 ;
2936   saux1 << NumeIter ;
2937   siterp1 = saux1.str() ;
2938   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2939   MESSAGE ( "siterp1 = "<<siterp1 );
2940
2941   // A.3. Le cas
2942   const char* CaseName = myIteration->GetCaseName();
2943   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
2944   ASSERT(!CORBA::is_nil(myCase));
2945
2946   // A.4. Le sous-répertoire de l'iteration a traiter
2947   char* DirCompute = myIteration->GetDirName();
2948   MESSAGE( ". DirCompute = " << DirCompute );
2949
2950   // C. Le fichier des messages
2951   std::string LogFile = DirCompute ;
2952   LogFile += "/Liste." + siterp1 + ".maj_coords.log" ;
2953   MESSAGE (". LogFile = " << LogFile);
2954   myIteration->SetFileInfo(LogFile.c_str());
2955
2956    // D. On passe dans le répertoire de l'iteration a calculer
2957   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2958   CHDIR(DirCompute);
2959
2960   // E. Les données de l'exécution HOMARD
2961   // E.1. L'objet du texte du fichier de configuration
2962   HomardDriver* myDriver = new HomardDriver("", siterp1);
2963   myDriver->TexteInit(DirCompute, LogFile, _Langue);
2964
2965   // E.2. Le maillage associe a l'iteration
2966   const char* NomMesh = myIteration->GetMeshName();
2967   MESSAGE ( ". NomMesh = " << NomMesh );
2968   const char* MeshFile = myIteration->GetMeshFile();
2969   MESSAGE ( ". MeshFile = " << MeshFile );
2970
2971   // E.3. Les données du traitement HOMARD
2972   int iaux ;
2973   myDriver->TexteMajCoords( NumeIter ) ;
2974   iaux = 0 ;
2975   myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2976   myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2977 //
2978   // E.4. Ecriture du texte dans le fichier
2979   MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2980   if (codret == 0)
2981   { myDriver->CreeFichier(); }
2982
2983 // F. Execution
2984 //
2985   int codretexec = 1789 ;
2986   if (codret == 0)
2987   {
2988     codretexec = myDriver->ExecuteHomard(Option1);
2989     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2990   }
2991
2992   // G. Gestion des resultats
2993   if (codret == 0)
2994   {
2995     // G.1. Le fichier des messages, dans tous les cas
2996     const char* NomIteration = myIteration->GetName();
2997     std::string Commentaire = "logmaj_coords" ;
2998     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2999     // G.2 Message d'erreur
3000     if (codretexec != 0)
3001     {
3002       std::string text = "\n\nSee the file " + LogFile + "\n" ;
3003       INFOS ( text ) ;
3004       SALOME::ExceptionStruct es;
3005       es.type = SALOME::BAD_PARAM;
3006       es.text = CORBA::string_dup(text.c_str());
3007       throw SALOME::SALOME_Exception(es);
3008
3009       // On force le succes pour pouvoir consulter le fichier log
3010       codretexec = 0 ;
3011     }
3012   }
3013
3014   // H. Menage et retour dans le répertoire du cas
3015   if (codret == 0) { delete myDriver; }
3016
3017   return codret ;
3018 }
3019 //=============================================================================
3020 // Creation d'un nom de sous-répertoire pour l'iteration au sein d'un répertoire parent
3021 //  nomrep : nom du répertoire parent
3022 //  num : le nom du sous-répertoire est sous la forme 'In', n est >= num
3023 //=============================================================================
3024 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
3025 {
3026   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
3027   // On verifie que le répertoire parent existe
3028   int codret = CHDIR(nomrep) ;
3029   if ( codret != 0 )
3030   {
3031     SALOME::ExceptionStruct es;
3032     es.type = SALOME::BAD_PARAM;
3033     es.text = "The directory of the case does not exist.";
3034     throw SALOME::SALOME_Exception(es);
3035     return 0;
3036   };
3037   std::string nomDirActuel = getenv("PWD") ;
3038   std::string DirName ;
3039   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un répertoire inconnu
3040   bool a_chercher = true ;
3041   while ( a_chercher )
3042   {
3043     // On passe dans le répertoire parent
3044
3045     CHDIR(nomrep);
3046     // On recherche un nom sous la forme Iabc, avec abc representant le numero
3047     int jaux ;
3048     if      ( num <    100 ) { jaux = 2 ; }
3049     else if ( num <   1000 ) { jaux = 3 ; }
3050     else if ( num <  10000 ) { jaux = 4 ; }
3051     else if ( num < 100000 ) { jaux = 5 ; }
3052     else                     { jaux = 9 ; }
3053     std::ostringstream iaux ;
3054     iaux << std::setw(jaux) << std::setfill('0') << num ;
3055     std::ostringstream DirNameA ;
3056     DirNameA << "I" << iaux.str();
3057     // Si on ne pas peut entrer dans le répertoire, on doit verifier
3058     // que c'est bien un probleme d'absence
3059     if ( CHDIR(DirNameA.str().c_str()) != 0 )
3060     {
3061       bool existe = false ;
3062 #ifndef WIN32
3063       DIR *dp;
3064       struct dirent *dirp;
3065       dp  = opendir(nomrep);
3066       while ( (dirp = readdir(dp)) != NULL )
3067       {
3068         std::string file_name(dirp->d_name);
3069 #else
3070       HANDLE hFind = INVALID_HANDLE_VALUE;
3071       WIN32_FIND_DATA ffd;
3072       hFind = FindFirstFile(nomrep, &ffd);
3073       if (INVALID_HANDLE_VALUE != hFind) {
3074         while (FindNextFile(hFind, &ffd) != 0) {
3075          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3076          std::string file_name(ffd.cFileName);
3077 #endif
3078         if ( file_name == DirNameA.str() ) { existe = true ; }
3079       }
3080 #ifndef WIN32
3081       closedir(dp);
3082 #else
3083       FindClose(hFind);
3084 #endif
3085       if ( !existe )
3086       {
3087         DirName = DirNameA.str() ;
3088         a_chercher = false ;
3089         break ;
3090       }
3091     }
3092     num += 1;
3093   }
3094
3095   MESSAGE ( "==> DirName = " << DirName);
3096   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
3097   CHDIR(nomDirActuel.c_str());
3098   return CORBA::string_dup( DirName.c_str() );
3099 }
3100 //=============================================================================
3101 // Calcul d'une iteration : gestion du répertoire de calcul
3102 //        Si le sous-répertoire existe :
3103 //         etatMenage =  0 : on sort en erreur si le répertoire n'est pas vide
3104 //         etatMenage =  1 : on fait le menage du répertoire
3105 //         etatMenage = -1 : on ne fait rien
3106 //=============================================================================
3107 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
3108 {
3109   MESSAGE ( "ComputeDirManagement : répertoires pour le calcul" );
3110   // B.2. Le répertoire du cas
3111   const char* nomDirCase = myCase->GetDirName();
3112   MESSAGE ( ". nomDirCase = " << nomDirCase );
3113
3114   // B.3. Le sous-répertoire de l'iteration a calculer, puis le répertoire complet a creer
3115   // B.3.1. Le nom du sous-répertoire
3116   const char* nomDirIt = myIteration->GetDirNameLoc();
3117
3118   // B.3.2. Le nom complet du sous-répertoire
3119   std::stringstream DirCompute ;
3120   DirCompute << nomDirCase << "/" << nomDirIt;
3121   MESSAGE (". DirCompute = " << DirCompute.str() );
3122
3123   // B.3.3. Si le sous-répertoire n'existe pas, on le cree
3124   if (CHDIR(DirCompute.str().c_str()) != 0)
3125   {
3126 #ifndef WIN32
3127     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
3128 #else
3129     if (_mkdir(DirCompute.str().c_str()) != 0)
3130 #endif
3131     {
3132        // GERALD -- QMESSAGE BOX
3133        std::cerr << "Pb Creation du répertoire DirCompute = " << DirCompute.str() << std::endl;
3134        VERIFICATION("Pb a la creation du répertoire" == 0);
3135     }
3136   }
3137   else
3138   {
3139 //  Le répertoire existe
3140 //  On demande de faire le menage de son contenu :
3141     if (etatMenage == 1)
3142     {
3143       MESSAGE (". Menage du répertoire DirCompute = " << DirCompute.str());
3144       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
3145       int codret = system(commande.c_str());
3146       if (codret != 0)
3147       {
3148         // GERALD -- QMESSAGE BOX
3149         std::cerr << ". Menage du répertoire de calcul" << DirCompute.str() << std::endl;
3150         VERIFICATION("Pb au menage du répertoire de calcul" == 0);
3151       }
3152     }
3153 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
3154     else
3155     {
3156       if (etatMenage == 0)
3157       {
3158 #ifndef WIN32
3159         DIR *dp;
3160         struct dirent *dirp;
3161         dp  = opendir(DirCompute.str().c_str());
3162         bool result = true;
3163         while ((dirp = readdir(dp)) != NULL && result )
3164         {
3165           std::string file_name(dirp->d_name);
3166           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3167         }
3168         closedir(dp);
3169 #else
3170        HANDLE hFind = INVALID_HANDLE_VALUE;
3171        WIN32_FIND_DATA ffd;
3172        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3173        bool result = true;
3174        if (INVALID_HANDLE_VALUE != hFind) {
3175          while (FindNextFile(hFind, &ffd) != 0) {
3176           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3177           std::string file_name(ffd.cFileName);
3178           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3179          }
3180        }
3181        FindClose(hFind);
3182 #endif
3183         if ( result == false)
3184         {
3185           SALOME::ExceptionStruct es;
3186           es.type = SALOME::BAD_PARAM;
3187           std::string text = "Directory : " + DirCompute.str() + " is not empty";
3188           es.text = CORBA::string_dup(text.c_str());
3189           throw SALOME::SALOME_Exception(es);
3190           VERIFICATION("Directory is not empty" == 0);
3191         }
3192       }
3193     }
3194   }
3195
3196   return CORBA::string_dup( DirCompute.str().c_str() );
3197 }
3198 //=============================================================================
3199 // Calcul d'une iteration : gestion du répertoire de calcul de l'iteration parent
3200 //=============================================================================
3201 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3202 {
3203   MESSAGE ( "ComputeDirPaManagement : répertoires pour le calcul" );
3204   // Le répertoire du cas
3205   const char* nomDirCase = myCase->GetDirName();
3206   MESSAGE ( ". nomDirCase = " << nomDirCase );
3207
3208   // Le sous-répertoire de l'iteration precedente
3209
3210   const char* nomIterationParent = myIteration->GetIterParentName();
3211   HOMARD::HOMARD_Iteration_var myIterationParent = myStudyContext._mesIterations[nomIterationParent];
3212   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3213   std::stringstream DirComputePa ;
3214   DirComputePa << nomDirCase << "/" << nomDirItPa;
3215   MESSAGE( ". nomDirItPa = " << nomDirItPa);
3216   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3217
3218   return CORBA::string_dup( DirComputePa.str().c_str() );
3219 }
3220 //=============================================================================
3221 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3222 //=============================================================================
3223 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3224 {
3225   MESSAGE ( "... DriverTexteZone" );
3226   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3227   int numberOfZonesx2 = ListZone->length();
3228   int NumZone ;
3229
3230   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3231   {
3232     std::string ZoneName = std::string((*ListZone)[iaux]);
3233     MESSAGE ( "... ZoneName = " << ZoneName);
3234     HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
3235     ASSERT(!CORBA::is_nil(myZone));
3236
3237     int ZoneType = myZone->GetType();
3238     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3239     int TypeUse = atoi( TypeUsestr.c_str() );
3240     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3241     NumZone = iaux/2 + 1 ;
3242     HOMARD::double_array* zone = myZone->GetCoords();
3243     if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3244     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3245     else if ( ZoneType == 4 ) // Cas d une sphere
3246     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3247     else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3248     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3249     else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3250     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3251     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3252     iaux += 1 ;
3253   }
3254   return ;
3255 }
3256 //=============================================================================
3257 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3258 //=============================================================================
3259 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3260 {
3261   MESSAGE ( "... DriverTexteField" );
3262 //  Le fichier du champ
3263   char* FieldFile = myIteration->GetFieldFile();
3264   MESSAGE ( ". FieldFile = " << FieldFile );
3265   if (strlen(FieldFile) == 0)
3266   {
3267     // GERALD -- QMESSAGE BOX
3268     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3269     VERIFICATION("The file for the field is not given." == 0);
3270   }
3271 //  Les caracteristiques d'instants du champ de pilotage
3272   int TimeStep = myIteration->GetTimeStep();
3273   MESSAGE( ". TimeStep = " << TimeStep );
3274   int Rank = myIteration->GetRank();
3275   MESSAGE( ". Rank = " << Rank );
3276 //  Les informations sur les champs
3277   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3278 //  Le nom
3279   const char* FieldName = aInfosHypo->FieldName;
3280 //  Les seuils
3281   int TypeThR = aInfosHypo->TypeThR;
3282   double ThreshR = aInfosHypo->ThreshR;
3283   int TypeThC = aInfosHypo->TypeThC;
3284   double ThreshC = aInfosHypo->ThreshC;
3285 //  Saut entre mailles ou non ?
3286   int UsField = aInfosHypo->UsField;
3287   MESSAGE( ". UsField = " << UsField );
3288 //  L'usage des composantes
3289   int UsCmpI = aInfosHypo->UsCmpI;
3290   MESSAGE( ". UsCmpI = " << UsCmpI );
3291 //
3292   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3293 //
3294 //  Les composantes
3295   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3296   int numberOfCompos = mescompo->length();
3297   MESSAGE( ". numberOfCompos = " << numberOfCompos );
3298   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3299   {
3300     std::string nomCompo = std::string((*mescompo)[NumeComp]);
3301     MESSAGE( "... nomCompo = " << nomCompo );
3302     myDriver->TexteCompo(NumeComp, nomCompo);
3303   }
3304   return ;
3305 }
3306 //=============================================================================
3307 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3308 // On ecrit dans l'ordre :
3309 //    1. la definition des frontieres
3310 //    2. les liens avec les groupes
3311 //    3. un entier resumant le type de comportement pour les frontieres
3312 //=============================================================================
3313 int HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3314 {
3315   MESSAGE ( "... DriverTexteBoundary" );
3316   // 1. Recuperation des frontieres
3317   std::list<std::string>  ListeBoundaryTraitees ;
3318   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3319   int numberOfitems = ListBoundaryGroupType->length();
3320   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3321   int BoundaryOption = 1 ;
3322   // 2. Parcours des frontieres pour ecrire leur description
3323   int NumBoundaryAnalytical = 0 ;
3324   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3325   {
3326     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3327     MESSAGE ( "... BoundaryName = " << BoundaryName);
3328     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3329     //      Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3330     int A_faire = 1 ;
3331     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3332     while (it != ListeBoundaryTraitees.end())
3333     {
3334       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3335       if ( BoundaryName == *it ) { A_faire = 0 ; }
3336       it++;
3337     }
3338     // 2.2. Ecriture de la frontiere
3339     if ( A_faire == 1 )
3340     {
3341       // 2.2.1. Caracteristiques de la frontiere
3342       HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3343       ASSERT(!CORBA::is_nil(myBoundary));
3344       int BoundaryType = myBoundary->GetType();
3345       MESSAGE ( "... BoundaryType = " << BoundaryType );
3346       // 2.2.2. Ecriture selon le type
3347       // 2.2.2.1. Cas d une frontiere CAO
3348       if (BoundaryType == -1)
3349       {
3350 //         const char* CAOFile = myBoundary->GetDataFile() ;
3351 //         MESSAGE ( ". CAOFile = " << CAOFile );
3352         if ( BoundaryOption % 5 != 0 ) { BoundaryOption = BoundaryOption*5 ; }
3353       }
3354       // 2.2.2.2. Cas d une frontiere discrete
3355       else if (BoundaryType == 0)
3356       {
3357         const char* MeshName = myBoundary->GetMeshName() ;
3358         MESSAGE ( ". MeshName = " << MeshName );
3359         const char* MeshFile = myBoundary->GetDataFile() ;
3360         MESSAGE ( ". MeshFile = " << MeshFile );
3361         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3362         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3363       }
3364       // 2.2.2.3. Cas d une frontiere analytique
3365       else
3366       {
3367         NumBoundaryAnalytical++ ;
3368         HOMARD::double_array* coor = myBoundary->GetCoords();
3369         if (BoundaryType == 1) // Cas d un cylindre
3370         {
3371           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3372           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3373         }
3374         else if (BoundaryType == 2) // Cas d une sphere
3375         {
3376           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3377           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3378         }
3379         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3380         {
3381           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3382           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3383         }
3384         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3385         {
3386           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3387           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3388         }
3389         else if (BoundaryType == 5) // Cas d un tore
3390         {
3391           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3392           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3393         }
3394       }
3395       // 2.2.3. Memorisation du traitement
3396       ListeBoundaryTraitees.push_back( BoundaryName );
3397     }
3398   }
3399   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3400   NumBoundaryAnalytical = 0 ;
3401   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3402   {
3403     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3404     MESSAGE ( "... BoundaryName = " << BoundaryName);
3405     HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3406     ASSERT(!CORBA::is_nil(myBoundary));
3407     int BoundaryType = myBoundary->GetType();
3408     MESSAGE ( "... BoundaryType = " << BoundaryType );
3409     // 3.1. Recuperation du nom du groupe
3410     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3411     MESSAGE ( "... GroupName = " << GroupName);
3412     // 3.2. Cas d une frontiere CAO
3413     if ( BoundaryType == -1 )
3414     {
3415       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryCAOGr ( GroupName ) ; }
3416     }
3417     // 3.3. Cas d une frontiere discrete
3418     else if ( BoundaryType == 0 )
3419     {
3420       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3421     }
3422     // 3.4. Cas d une frontiere analytique
3423     else
3424     {
3425       NumBoundaryAnalytical++ ;
3426       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3427     }
3428   }
3429   // 4. Ecriture de l'option finale
3430   myDriver->TexteBoundaryOption(BoundaryOption);
3431 //
3432   return BoundaryOption ;
3433 }
3434 //=============================================================================
3435 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3436 //=============================================================================
3437 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3438 {
3439   MESSAGE ( "... DriverTexteFieldInterp" );
3440   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3441   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3442   if (TypeFieldInterp != 0)
3443   {
3444 //  Le fichier des champs
3445     char* FieldFile = myIteration->GetFieldFile();
3446     MESSAGE ( ". FieldFile = " << FieldFile );
3447     if (strlen(FieldFile) == 0)
3448     {
3449       // GERALD -- QMESSAGE BOX
3450       VERIFICATION("The file for the field is not given." == 0);
3451     }
3452   //
3453     const char* MeshFile = myIteration->GetMeshFile();
3454     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3455
3456   // Les champs
3457   // Interpolation de tous les champs
3458     if ( TypeFieldInterp == 1 )
3459     {
3460       myDriver->TexteFieldInterpAll();
3461     }
3462   // Interpolation de certains champs
3463     else if (TypeFieldInterp == 2)
3464     {
3465       // Les champs et leurs instants pour l'iteration
3466       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3467       int numberOfFieldsx3 = ListFieldTSR->length();
3468       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3469       // Les champs pour l'hypothese
3470       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3471       int numberOfFieldsx2 = ListField->length();
3472       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3473       // On parcourt tous les champs de  l'hypothese
3474       int NumField = 0 ;
3475       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3476       {
3477         // Le nom du champ
3478         std::string FieldName = std::string((*ListField)[iaux]) ;
3479         // Le type d'interpolation
3480         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3481         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3482         // On cherche ?? savoir si des instants ont ??t?? pr??cis??s pour cette it??ration
3483         int tsrvu = 0;
3484         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3485         {
3486         // Le nom du champ
3487           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3488           MESSAGE( "..... FieldName2 = " << FieldName2 );
3489         // Quand c'est le bon champ, on ecrit le pas de temps
3490           if ( FieldName == FieldName2 )
3491           {
3492             tsrvu = 1 ;
3493             // Le pas de temps
3494             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3495             // Le numero d'ordre
3496             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3497             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3498             NumField += 1 ;
3499             int TimeStep = atoi( TimeStepstr.c_str() );
3500             int Rank = atoi( Rankstr.c_str() );
3501             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3502           }
3503           jaux += 2 ;
3504         }
3505         // Si aucun instant n'a été défini
3506         if ( tsrvu == 0 )
3507         {
3508           NumField += 1 ;
3509           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3510         }
3511         iaux++ ;
3512       }
3513     }
3514   }
3515   return ;
3516 }
3517 //===========================================================================
3518 //===========================================================================
3519
3520
3521 //===========================================================================
3522 //===========================================================================
3523 // Publications
3524 //===========================================================================
3525 //===========================================================================
3526 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::SObject_ptr theSObject,
3527                                                    CORBA::Object_ptr theObject,
3528                                                    const char* theName)
3529 {
3530   MESSAGE("PublishInStudy pour " << theName);
3531   SALOMEDS::SObject_var aResultSO;
3532   if (CORBA::is_nil(myStudy))
3533   {
3534     SALOME::ExceptionStruct es;
3535     es.type = SALOME::BAD_PARAM;
3536     es.text = "Invalid study context";
3537     throw SALOME::SALOME_Exception(es);
3538     return 0;
3539   };
3540
3541 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3542 // Rq : Iteration est publiee ailleurs
3543   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3544   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3545   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3546   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3547   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3548
3549   UpdateStudy();
3550
3551 // Controle de la non publication d'un objet de meme nom
3552    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3553   {
3554     SALOMEDS::Study::ListOfSObject_var listSO = myStudy->FindObjectByName(theName, ComponentDataType());
3555     if (listSO->length() >= 1)
3556     {
3557       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3558       aResultSO = listSO[0];
3559       return aResultSO._retn();
3560     }
3561   }
3562
3563   // Caracteristiques de l'etude
3564   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3565   aStudyBuilder->NewCommand();
3566   if(!aBoundary->_is_nil())
3567     aResultSO = PublishBoundaryInStudy(aStudyBuilder, aBoundary, theName);
3568   else if(!aCase->_is_nil())
3569     aResultSO = PublishCaseInStudy(aStudyBuilder, aCase, theName);
3570   else if(!aHypo->_is_nil())
3571     aResultSO = PublishHypotheseInStudy(aStudyBuilder, aHypo, theName);
3572   else if(!aYACS->_is_nil())
3573     aResultSO = PublishYACSInStudy(aStudyBuilder, aYACS, theName);
3574   else if(!aZone->_is_nil())
3575     aResultSO = PublishZoneInStudy(aStudyBuilder, aZone, theName);
3576
3577   aStudyBuilder->CommitCommand();
3578
3579   return aResultSO._retn();
3580 };
3581 //=============================================================================
3582 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy( SALOMEDS::StudyBuilder_var aStudyBuilder,
3583                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3584 {
3585   MESSAGE("PublishBoundaryStudy pour "<<theName);
3586   SALOMEDS::SObject_var aResultSO;
3587
3588   // Caracteristique de la Boundary
3589   HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[theName];
3590
3591   // On recupere le module pere dans l etude
3592   SALOMEDS::SComponent_var       theFatherHomard = myStudy->FindComponent(ComponentDataType());
3593   if (theFatherHomard->_is_nil())
3594   {
3595     MESSAGE("theFatherHomard->_is_nil()");
3596     return aResultSO._retn();
3597   }
3598
3599   // On ajoute la categorie des boundarys dans l etude si necessaire
3600   if ( _tag_boun == 0 )
3601   {
3602     _tag_gene += 1 ;
3603     _tag_boun = _tag_gene ;
3604   }
3605   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3606   SALOMEDS::SObject_var aSObject;
3607   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3608   {
3609     MESSAGE("Ajout de la categorie des boundarys");
3610     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3611     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3612   }
3613   else { MESSAGE("La categorie des boundarys existe deja."); }
3614
3615   CORBA::Long BoundaryType = myBoundary->GetType();
3616 //   MESSAGE("BoundaryType : "<<BoundaryType);
3617   std::string icone ;
3618   std::string value ;
3619   switch (BoundaryType)
3620   {
3621     case -1 :
3622     { value = "BoundaryCAOHomard" ;
3623       icone = "geometry.png" ;
3624       break;
3625     }
3626     case 0 :
3627     { value = "BoundaryDiHomard" ;
3628       icone = "mesh_tree_mesh.png" ;
3629       break;
3630     }
3631     case 1 :
3632     { value = "BoundaryAnHomard" ;
3633       icone = "cylinderpointvector_2.png" ;
3634       break;
3635     }
3636     case 2 :
3637     { value = "BoundaryAnHomard" ;
3638       icone = "spherepoint_2.png" ;
3639       break;
3640     }
3641     case 3 :
3642     { value = "BoundaryAnHomard" ;
3643       icone = "conepointvector.png" ;
3644       break;
3645     }
3646     case 4 :
3647     { value = "BoundaryAnHomard" ;
3648       icone = "conedxyz.png" ;
3649       break;
3650     }
3651     case 5 :
3652     { value = "BoundaryAnHomard" ;
3653       icone = "toruspointvector.png" ;
3654       break;
3655     }
3656   }
3657   aResultSO = aStudyBuilder->NewObject(aSObject);
3658   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3659   return aResultSO._retn();
3660 }
3661 //=============================================================================
3662 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3663                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3664 {
3665   MESSAGE("PublishCaseInStudy pour "<<theName);
3666   SALOMEDS::SObject_var aResultSO;
3667
3668   if (CORBA::is_nil(theObject)) {
3669     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3670     return aResultSO._retn();
3671   }
3672   if (myStudy->_is_nil()) {
3673     MESSAGE("HOMARD_Gen_i::myStudy->_is_nil()");
3674     return aResultSO._retn();
3675   }
3676
3677   // On recupere le module pere dans l etude
3678   SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3679   if (theFatherHomard->_is_nil())
3680   {
3681     MESSAGE("theFatherHomard->_is_nil()");
3682     return aResultSO._retn();
3683   }
3684
3685   _tag_gene += 1 ;
3686   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3687   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3688   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3689                      _orb->object_to_string(theObject) ) ;
3690
3691   return aResultSO._retn();
3692 }
3693 //=============================================================================
3694 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3695                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3696 {
3697   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3698   SALOMEDS::SObject_var aResultSO;
3699
3700   // On recupere le module pere dans l etude
3701   // On ajoute la categorie des hypotheses dans l etude si necessaire
3702   SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3703   if (theFatherHomard->_is_nil())
3704   {
3705     MESSAGE("theFatherHomard->_is_nil()");
3706     return aResultSO._retn();
3707   }
3708
3709   // On ajoute la categorie des hypotheses dans l etude si necessaire
3710   SALOMEDS::SObject_var aSObject;
3711   if ( _tag_hypo == 0 )
3712   {
3713     _tag_gene += 1 ;
3714     _tag_hypo = _tag_gene ;
3715   }
3716   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3717   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3718   {
3719     MESSAGE("Ajout de la categorie des hypotheses");
3720     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3721     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3722   }
3723   else { MESSAGE("La categorie des hypotheses existe deja."); }
3724
3725 // Creation du resultat dans l'etude
3726   aResultSO = aStudyBuilder->NewObject(aSObject);
3727   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3728
3729   return aResultSO._retn();
3730 }
3731 //=============================================================================
3732 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3733                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3734 {
3735   MESSAGE("PublishYACSInStudy pour "<<theName);
3736   SALOMEDS::SObject_var aResultSO;
3737
3738   // On recupere le module pere dans l etude
3739   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3740   SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3741   if (theFatherHomard->_is_nil())
3742   {
3743     MESSAGE("theFatherHomard->_is_nil()");
3744     return aResultSO._retn();
3745   }
3746   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3747   if ( _tag_yacs == 0 )
3748   {
3749     _tag_gene += 1 ;
3750     _tag_yacs = _tag_gene ;
3751   }
3752   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3753   SALOMEDS::SObject_var aSObject;
3754   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3755   {
3756     MESSAGE("Ajout de la categorie des schemas YACS");
3757     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3758     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3759   }
3760   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3761
3762 // Creation du resultat dans l'etude
3763   aResultSO = aStudyBuilder->NewObject(aSObject);
3764   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3765
3766   return aResultSO._retn();
3767 }
3768
3769 //=============================================================================
3770 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::StudyBuilder_var aStudyBuilder,
3771                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3772 {
3773   MESSAGE("PublishZoneStudy pour "<<theName);
3774   SALOMEDS::SObject_var aResultSO;
3775   if (CORBA::is_nil(theObject))
3776   {
3777     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3778     return aResultSO._retn();
3779   }
3780   if (myStudy->_is_nil())
3781   {
3782     MESSAGE("PublishZoneInStudy : myStudy->_is_nil()");
3783     return aResultSO._retn();
3784   }
3785   SALOMEDS::SComponent_var theFatherHomard = myStudy->FindComponent(ComponentDataType());
3786   if (theFatherHomard->_is_nil())
3787   {
3788     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3789     return aResultSO._retn();
3790   }
3791
3792   // Caracteristique de la zone
3793   HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[theName];
3794   CORBA::Long ZoneType = myZone->GetType();
3795
3796   // On ajoute la categorie des zones dans l etude si necessaire
3797   if ( _tag_zone == 0 )
3798   {
3799     _tag_gene += 1 ;
3800     _tag_zone = _tag_gene ;
3801   }
3802   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3803   SALOMEDS::SObject_var aSObject;
3804   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3805   {
3806     MESSAGE("Ajout de la categorie des zones");
3807     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3808     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3809   }
3810   else { MESSAGE("La categorie des zones existe deja."); }
3811
3812   aResultSO = aStudyBuilder->NewObject(aSObject);
3813   std::string icone ;
3814   switch (ZoneType)
3815   {
3816     case 11 :
3817     { }
3818     case 12 :
3819     { }
3820     case 13 :
3821     { icone = "boxdxy_2.png" ;
3822       break ;
3823     }
3824     case 2 :
3825     { icone = "boxdxyz_2.png" ;
3826       break ;
3827     }
3828     case 31 :
3829     { }
3830     case 32 :
3831     { }
3832     case 33 :
3833     { icone = "disk_2.png" ;
3834       break ;
3835      }
3836     case 4 :
3837     { icone = "spherepoint_2.png" ;
3838       break ;
3839     }
3840     case 5 :
3841     { icone = "cylinderpointvector_2.png" ;
3842       break ;
3843     }
3844     case 61 :
3845     { }
3846     case 62 :
3847     { }
3848     case 63 :
3849     { icone = "diskwithhole_2.png" ;
3850       break ;
3851      }
3852     case 7 :
3853     { icone = "pipe_2.png" ;
3854       break ;
3855     }
3856   }
3857   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3858
3859   return aResultSO._retn();
3860 }
3861 //===========================================================================
3862 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3863                                       SALOMEDS::SObject_var aResultSO,
3864                                       const char* name, const char* comment, const char* icone, const char* ior)
3865 {
3866   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3867 //   MESSAGE("icone = "<<icone);
3868 //   MESSAGE("ior   = "<<ior);
3869   SALOMEDS::GenericAttribute_var anAttr ;
3870 //  Ajout du nom
3871   if ( name != NULL )
3872   {
3873     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3874     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3875     aNameAttrib->SetValue(name);
3876   }
3877
3878 //  Ajout du commentaire
3879   if ( comment != NULL )
3880   {
3881     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3882     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3883     aCommentAttrib->SetValue(comment);
3884   }
3885
3886 //  Ajout de l'icone
3887   if ( icone != NULL  )
3888   {
3889     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3890     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3891     aPixmap->SetPixMap(icone);
3892   }
3893
3894 //  Ajout de l ior
3895   if ( ior != NULL  )
3896   {
3897     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3898     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3899     anIOR->SetValue(ior);
3900   }
3901 };
3902
3903 //=====================================================================================
3904 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3905 {
3906   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3907
3908   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3909   ASSERT(!CORBA::is_nil(myCase));
3910   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3911   ASSERT(!CORBA::is_nil(aCaseSO));
3912
3913   HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
3914   ASSERT(!CORBA::is_nil(myBoundary));
3915   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3916   ASSERT(!CORBA::is_nil(aBoundarySO));
3917
3918   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3919
3920   aStudyBuilder->NewCommand();
3921
3922   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3923   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3924 //   aStudyBuilder->RemoveReference(aSubSO);
3925
3926   aStudyBuilder->CommitCommand();
3927
3928 };
3929 //=====================================================================================
3930 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3931 {
3932   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3933
3934   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
3935   ASSERT(!CORBA::is_nil(myYACS));
3936   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3937   ASSERT(!CORBA::is_nil(aYACSSO));
3938
3939   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[CaseName];
3940   ASSERT(!CORBA::is_nil(myCase));
3941   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3942   ASSERT(!CORBA::is_nil(aCaseSO));
3943
3944   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
3945
3946   aStudyBuilder->NewCommand();
3947
3948   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3949   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3950
3951   aStudyBuilder->CommitCommand();
3952
3953 };
3954 //=============================================================================
3955 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3956 //  Option = 0 : fichier issu d'une importation
3957 //  Option = 1 : fichier issu d'une execution HOMARD
3958 {
3959   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3960   if (CORBA::is_nil(myStudy))
3961   {
3962     SALOME::ExceptionStruct es;
3963     es.type = SALOME::BAD_PARAM;
3964     es.text = "Invalid study context";
3965     throw SALOME::SALOME_Exception(es);
3966     return ;
3967   };
3968
3969 // Le module SMESH est-il actif ?
3970   SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
3971 //
3972   if (!CORBA::is_nil(aSmeshSO))
3973   {
3974 // On verifie que le fichier n est pas deja publie
3975     SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
3976     for (; aIter->More(); aIter->Next())
3977     {
3978       SALOMEDS::SObject_var  aSO = aIter->Value();
3979       SALOMEDS::GenericAttribute_var aGAttr;
3980       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3981       {
3982         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3983         CORBA::String_var value=anAttr->Value();
3984         if (strcmp((const char*)value,NomFich) == 0)
3985         {
3986           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3987           // Pour un fichier importe, on ne republie pas
3988           if ( Option == 0 ) { return; }
3989           // Pour un fichier calcule, on commence par faire la depublication
3990           else
3991           {
3992             MESSAGE ( "PublishResultInSmesh : depublication" );
3993             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3994             CORBA::String_var value2=anAttr2->Value();
3995             std::string MeshName = string(value2) ;
3996             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3997             DeleteResultInSmesh(NomFich, MeshName) ;
3998           }
3999         }
4000       }
4001     }
4002   }
4003
4004 // On enregistre le fichier
4005   MESSAGE( "Enregistrement du fichier");
4006   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
4007   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
4008   ASSERT(!CORBA::is_nil(aSmeshEngine));
4009   aSmeshEngine->UpdateStudy();
4010   SMESH::DriverMED_ReadStatus theStatus;
4011   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4012
4013 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
4014   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
4015   for (int i = 0; i < mesMaillages->length();  i++)
4016   {
4017     MESSAGE( ". Mise a jour des attributs du maillage");
4018     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
4019     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
4020     SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4021     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
4022     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4023     anAttr->SetValue(NomFich);
4024     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
4025     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
4026     const char* icone ;
4027     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
4028     else               { icone = "mesh_tree_mesh.png" ; }
4029     anAttr2->SetPixMap( icone );
4030   }
4031
4032 }
4033 //=============================================================================
4034 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
4035 {
4036   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
4037   if (CORBA::is_nil(myStudy))
4038   {
4039       SALOME::ExceptionStruct es;
4040       es.type = SALOME::BAD_PARAM;
4041       es.text = "Invalid study context";
4042       throw SALOME::SALOME_Exception(es);
4043       return ;
4044   };
4045
4046 // Le module SMESH est-il actif ?
4047   SALOMEDS::SObject_var aSmeshSO = myStudy->FindComponent("SMESH");
4048 //
4049   if (CORBA::is_nil(aSmeshSO))
4050   {
4051       return ;
4052   };
4053 // On verifie que le fichier est deja publie
4054   SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
4055   SALOMEDS::ChildIterator_var aIter = myStudy->NewChildIterator(aSmeshSO);
4056   for (; aIter->More(); aIter->Next())
4057   {
4058      SALOMEDS::SObject_var  aSO = aIter->Value();
4059      SALOMEDS::GenericAttribute_var aGAttr;
4060      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
4061      {
4062        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
4063        CORBA::String_var value=anAttr->Value();
4064        if (strcmp((const char*)value,NomFich.c_str()) == 0)
4065        {
4066          if (aSO->FindAttribute(aGAttr,"AttributeName"))
4067          {
4068            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
4069            CORBA::String_var value2=anAttr2->Value();
4070            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
4071            {
4072              myBuilder->RemoveObjectWithChildren( aSO ) ;
4073            }
4074          }
4075        }
4076      }
4077   }
4078   return ;
4079 }
4080 //=============================================================================
4081 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
4082 {
4083   MESSAGE( "PublishMeshIterInSmesh " << NomIter);
4084   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4085
4086   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4087   if (CORBA::is_nil(myIteration))
4088   {
4089       SALOME::ExceptionStruct es;
4090       es.type = SALOME::BAD_PARAM;
4091       es.text = "Invalid iterationStudy Object";
4092       throw SALOME::SALOME_Exception(es);
4093       return ;
4094   };
4095   const char* MeshFile = myIteration->GetMeshFile() ;
4096   const char* MeshName = myIteration->GetMeshName() ;
4097   CORBA::Long Option = -1 ;
4098   int etat = myIteration->GetState();
4099 // Iteration initiale
4100   if ( etat <= 0 )      { Option = 0 ; }
4101 // ou iteration calculee
4102   else if ( etat == 2 ) { Option = 1 ; }
4103 // Publication effective apres menage eventuel
4104   if ( Option >= 0 )
4105   {
4106     DeleteResultInSmesh(MeshFile, MeshName) ;
4107     PublishResultInSmesh(MeshFile, Option) ;
4108   }
4109
4110 }
4111 //=============================================================================
4112 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
4113 {
4114 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4115   HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[NomIter];
4116
4117   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
4118   if (CORBA::is_nil(myIteration))
4119   {
4120       SALOME::ExceptionStruct es;
4121       es.type = SALOME::BAD_PARAM;
4122       es.text = "Invalid iterationStudy Object";
4123       throw SALOME::SALOME_Exception(es);
4124       return ;
4125   };
4126
4127   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4128
4129   aStudyBuilder->NewCommand();
4130
4131   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
4132 // Pour les fichiers med, on affiche une icone de maillage
4133 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
4134 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
4135   std::string icone ;
4136   std::string ior = " " ;
4137   if ( Commentaire[0] == 'M' )
4138   { icone = "med.png" ; }
4139   else
4140   { icone = "texte_2.png" ; }
4141   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4142
4143   aStudyBuilder->CommitCommand();
4144 }
4145 //
4146 //=============================================================================
4147 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
4148 {
4149 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
4150   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4151
4152   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
4153   if (CORBA::is_nil(myYACS))
4154   {
4155       SALOME::ExceptionStruct es;
4156       es.type = SALOME::BAD_PARAM;
4157       es.text = "Invalid YACSStudy Object";
4158       throw SALOME::SALOME_Exception(es);
4159       return ;
4160   };
4161
4162   SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4163
4164   aStudyBuilder->NewCommand();
4165
4166   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
4167   std::string icone = "texte_2.png" ;
4168   std::string ior = " " ;
4169   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
4170
4171   aStudyBuilder->CommitCommand();
4172 }
4173 //
4174 //=============================================================================
4175 //=============================================================================
4176 // YACS
4177 //=============================================================================
4178 //=============================================================================
4179 //=============================================================================
4180 // Creation d'un schema YACS
4181 // nomCas : nom du cas a traiter
4182 // FileName : nom du fichier contenant le script de lancement du calcul
4183 // DirName : le répertoire de lancement des calculs du schéma
4184 //=============================================================================
4185 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4186 {
4187   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4188   INFOS ( ". nomCas     : " << nomCas);
4189   INFOS ( ". ScriptFile : " << ScriptFile);
4190   INFOS ( ". DirName    : " << DirName);
4191   INFOS ( ". MeshFile   : " << MeshFile);
4192
4193   // A. Controle du nom :
4194   if ((myStudyContext._mesYACSs).find(nomYACS) != (myStudyContext._mesYACSs).end())
4195   {
4196     SALOME::ExceptionStruct es;
4197     es.type = SALOME::BAD_PARAM;
4198     es.text = "This schema YACS has already been defined.";
4199     throw SALOME::SALOME_Exception(es);
4200     return 0;
4201   }
4202
4203   // B. Creation de l'objet
4204   HOMARD::HOMARD_YACS_var myYACS = newYACS();
4205   if (CORBA::is_nil(myYACS))
4206   {
4207     SALOME::ExceptionStruct es;
4208     es.type = SALOME::BAD_PARAM;
4209     es.text = "Unable to create the schema YACS";
4210     throw SALOME::SALOME_Exception(es);
4211     return 0;
4212   };
4213   myYACS->SetName( nomYACS ) ;
4214
4215   // C. Enregistrement
4216   myStudyContext._mesYACSs[nomYACS] = myYACS;
4217
4218   SALOMEDS::SObject_var aSO;
4219   SALOMEDS::SObject_var aResultSO=PublishInStudy(aSO, myYACS, nomYACS);
4220
4221   PublishCaseUnderYACS(nomYACS, nomCas);
4222
4223   // D. Caracterisation
4224   // D.1. Options
4225   myYACS->SetDirName( DirName ) ;
4226   myYACS->SetMeshFile( MeshFile ) ;
4227   myYACS->SetScriptFile( ScriptFile ) ;
4228   myYACS->SetCaseName( nomCas ) ;
4229   // D.2. Defaut
4230   int defaut_i ;
4231   // D.2.1. Type constant
4232   myYACS->SetType( 1 ) ;
4233   // D.2.2. Convergence
4234   defaut_i = GetYACSMaxIter() ;
4235   myYACS->SetMaxIter( defaut_i ) ;
4236   defaut_i = GetYACSMaxNode() ;
4237   myYACS->SetMaxNode( defaut_i ) ;
4238   defaut_i = GetYACSMaxElem() ;
4239   myYACS->SetMaxElem( defaut_i ) ;
4240   // D.3. Fichier de sauvegarde dans le répertoire du cas
4241   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4242   std::string dirnamecase = caseyacs->GetDirName() ;
4243   std::string XMLFile ;
4244   XMLFile = dirnamecase + "/schema.xml" ;
4245   myYACS->SetXMLFile( XMLFile.c_str() ) ;
4246
4247   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4248 }
4249 //=============================================================================
4250 // Ecriture d'un schema YACS
4251 //=============================================================================
4252 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4253 {
4254   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4255 // Le répertoire du cas
4256   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4257   ASSERT(!CORBA::is_nil(myYACS));
4258 // Le nom du fichier du schema
4259   std::string XMLFile ;
4260   XMLFile = myYACS->GetXMLFile() ;
4261
4262   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4263
4264   return codret ;
4265 }
4266 //=============================================================================
4267 // Ecriture d'un schema YACS sur un fichier donne
4268 //=============================================================================
4269 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4270 {
4271   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4272
4273   // A. Prealable
4274   int codret = 0;
4275
4276   // B. L'objet YACS
4277   // B.1. L'objet
4278   HOMARD::HOMARD_YACS_var myYACS = myStudyContext._mesYACSs[nomYACS];
4279   ASSERT(!CORBA::is_nil(myYACS));
4280   // B.2. Les caracteristiques
4281   std::string DirName = myYACS->GetDirName() ;
4282   std::string MeshFile = myYACS->GetMeshFile() ;
4283   std::string ScriptFile = myYACS->GetScriptFile() ;
4284   // B.3. Les caracteristiques de convergence
4285   int MaxIter = myYACS->GetMaxIter() ;
4286   int MaxNode = myYACS->GetMaxNode() ;
4287   int MaxElem = myYACS->GetMaxElem() ;
4288
4289   // C. Le cas
4290   // C.1. L'objet cas
4291   const char* nomCas = myYACS->GetCaseName();
4292   HOMARD::HOMARD_Cas_var myCase = myStudyContext._mesCas[nomCas];
4293   ASSERT(!CORBA::is_nil(myCase));
4294   // C.2. Les instructions python associees au cas
4295   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4296   std::string pythonCas = dumpCorbaCase.in();
4297   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4298
4299   // D. Les iterations
4300   // D.1. L'iteration initiale
4301   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4302   std::string Iter0Name = myCase->GetIter0Name() ;
4303   MESSAGE (". Iter0Name = " << Iter0Name);
4304   std::string MeshName = Iter0->GetMeshName();
4305   MESSAGE (". MeshName = " << MeshName);
4306   // D.2. L'iteration numero 1
4307   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4308   int numberOfIter = maListe->length();
4309   if ( numberOfIter > 1 )
4310   {
4311     MESSAGE (". numberOfIter = " << numberOfIter);
4312     SALOME::ExceptionStruct es ;
4313     es.type = SALOME::BAD_PARAM;
4314     std::string text = "Une seule iteration est permise." ;
4315     es.text = CORBA::string_dup(text.c_str());
4316     throw SALOME::SALOME_Exception(es);
4317     return 0;
4318   }
4319   std::string Iter1Name = std::string((*maListe)[0]);
4320   MESSAGE ("... Iter1Name = " << Iter1Name);
4321   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4322   // D.3. Les instructions python associees a l'iteration
4323   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4324   std::string pythonIter = dumpCorbaIter.in();
4325   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4326
4327   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4328   // E.1. La structure
4329   std::string nomHypo = Iter1->GetHypoName();
4330   MESSAGE (". nomHypo = " << nomHypo);
4331   HOMARD::HOMARD_Hypothesis_var myHypo = myStudyContext._mesHypotheses[nomHypo];
4332   ASSERT(!CORBA::is_nil(myHypo));
4333   // E.2. Les caracteristiques de l'adaptation
4334   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4335   ASSERT(ListTypes->length() == 3);
4336   int TypeAdap = (*ListTypes)[0];
4337 //   int TypeRaff = (*ListTypes)[1];
4338 //   int TypeDera = (*ListTypes)[2];
4339   // E.3. Les instructions python associees a l'hypothese
4340   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4341   std::string pythonHypo = dumpCorbaHypo.in();
4342   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4343
4344   // F. Le fichier du schema de reference
4345   // HOMARD_ROOT_DIR : répertoire ou se trouve le module HOMARD
4346   std::string XMLFile_base ;
4347   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4348   else
4349   {
4350     SALOME::ExceptionStruct es ;
4351     es.type = SALOME::BAD_PARAM;
4352     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4353     es.text = CORBA::string_dup(text.c_str());
4354     throw SALOME::SALOME_Exception(es);
4355     return 0;
4356   }
4357   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4358 //   if ( _Langue ==
4359   MESSAGE("XMLFile_base ="<<XMLFile_base);
4360
4361   // G. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4362   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName, _LangueShort);
4363   std::ifstream fichier( XMLFile_base.c_str() );
4364   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4365   {
4366     // G.1. Lecture du schema de reference et insertion des données propres au fil de la rencontre des mots-cles
4367     std::string ligne; // variable contenant chaque ligne lue
4368     std::string mot_cle;
4369     while ( std::getline( fichier, ligne ) )
4370     {
4371       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4372       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4373       ligne_bis >> mot_cle ;
4374       // G.1.2. Le maillage initial
4375       if ( mot_cle == "DataInit_MeshFile" )
4376       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4377       // G.1.3. Le script de lancement
4378       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4379       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4380       // G.1.4. Les options du cas
4381       else if ( mot_cle == "Iter_1_Case_Options" )
4382       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4383       // G.1.5. Execution de HOMARD : le répertoire du cas
4384       else if ( mot_cle == "HOMARD_Exec_DirName" )
4385       { myDriver->Texte_HOMARD_Exec_DirName(); }
4386       // G.1.6. Execution de HOMARD : le nom du maillage
4387       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4388       {
4389         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4390         std::string node ;
4391         if ( _LangueShort == "fr" ) { node = "Boucle_de_convergence.Alternance_Calcul_HOMARD" ; }
4392         else                        { node = "Convergence_Loop.Alternation_Computation_HOMARD" ; }
4393         node += ".Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4394         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4395       }
4396       // G.1.7. Execution de HOMARD : les options de l'hypothese
4397       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4398       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4399       // G.1.8. Execution de HOMARD : les options de l'iteration
4400       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4401       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4402       // G.1.9. a. Creation eventuelles des zones et frontieres
4403       //        b. Enchainement
4404       else if ( mot_cle == "Iter_1" )
4405       {
4406         std::string texte_control = "" ;
4407         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4408         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4409         texte_control += myDriver->Texte_Iter_1_control() ;
4410         myDriver->TexteAdd(texte_control);
4411       }
4412       // G.1.10. Les tests de convergence
4413       else if ( mot_cle == "Analyse_Test_Convergence" )
4414       { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4415       // G.1.11. Les parametres
4416       else if ( mot_cle == "PARAMETRES" )
4417       { myDriver->TexteAddParametres(); }
4418       // G.1.n. La ligne est recopiee telle quelle
4419       else { myDriver->TexteAdd(ligne);  }
4420     }
4421     // G.2. Ecriture du texte dans le fichier
4422     if ( codret == 0 )
4423     { myDriver->CreeFichier(); }
4424   }
4425   else
4426   {
4427     SALOME::ExceptionStruct es;
4428     es.type = SALOME::BAD_PARAM;
4429     std::string text = "The reference file for the YACS schema cannot be read." ;
4430     es.text = CORBA::string_dup(text.c_str());
4431     throw SALOME::SALOME_Exception(es);
4432   }
4433
4434   delete myDriver;
4435
4436   // H. Publication du fichier dans l'arbre
4437
4438     std::string Commentaire = "xml" ;
4439     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4440
4441   return codret ;
4442 }
4443 //=============================================================================
4444 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4445 //=============================================================================
4446 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4447 {
4448   MESSAGE ( "YACSDriverTexteZone" );
4449   // A. Les zones associees a cette hypothese
4450   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4451   int numberOfZonesx2 = ListZone->length();
4452
4453   // B. Parcours des zones
4454   std::string texte_control ;
4455   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4456   {
4457     // 1. Reperage de la zone
4458     std::string ZoneName = std::string((*ListZone)[iaux]);
4459     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4460     HOMARD::HOMARD_Zone_var myZone = myStudyContext._mesZones[ZoneName];
4461     ASSERT(!CORBA::is_nil(myZone));
4462     // 2. Les instructions python associees a la zone
4463     //    La premiere ligne est un commentaire a eliminer
4464     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4465     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4466     std::string pythonStructure_0 = dumpCorbaZone.in();
4467     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4468     std::istringstream tout (pythonStructure_0) ;
4469     std::string ligne ;
4470     std::string pythonStructure ;
4471     while ( std::getline( tout, ligne ) )
4472     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4473     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4474     // 3. Decodage du nom du service
4475     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4476     MESSAGE ( "... methode = " << methode);
4477     // 4. Mise en place des instructions
4478     int ZoneType = myZone->GetType();
4479     MESSAGE ( "... ZoneType = " << ZoneType);
4480     std::string texte_control_0 ;
4481     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4482     texte_control += texte_control_0 ;
4483     // 5. Decalage
4484     iaux ++ ;
4485   }
4486
4487   return texte_control ;
4488 }
4489 //=============================================================================
4490 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4491 //=============================================================================
4492 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4493 {
4494   MESSAGE ( "YACSDriverTexteBoundary" );
4495   // A. Les frontieres associees au cas
4496   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4497   int numberOfitems = ListBoundaryGroupType->length();
4498
4499   // B. Parcours des frontieres
4500   std::string texte_control ;
4501   std::list<std::string>  ListeBoundaryTraitees ;
4502   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4503   {
4504     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4505     MESSAGE ( "... BoundaryName = " << BoundaryName);
4506     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4507     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4508     int A_faire = 1 ;
4509     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4510     while (it != ListeBoundaryTraitees.end())
4511     {
4512       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4513       if ( BoundaryName == *it ) { A_faire = 0 ; }
4514       it++;
4515     }
4516     if ( A_faire == 1 )
4517     {
4518     // 1. Caracteristiques de la frontiere
4519       HOMARD::HOMARD_Boundary_var myBoundary = myStudyContext._mesBoundarys[BoundaryName];
4520       ASSERT(!CORBA::is_nil(myBoundary));
4521       // 2. Les instructions python associees a la frontiere
4522       //    La premiere ligne est un commentaire a eliminer
4523       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4524       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4525       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4526       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4527       std::istringstream tout (pythonStructure_0) ;
4528       std::string ligne ;
4529       std::string pythonStructure ;
4530       while ( std::getline( tout, ligne ) )
4531       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4532       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4533       // 3. Decodage du nom du service
4534       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4535       MESSAGE ( "... methode = " << methode);
4536       // 4. Mise en place des instructions
4537       int BoundaryType = myBoundary->GetType();
4538       MESSAGE ( "... BoundaryType = " << BoundaryType);
4539       const char* MeshName ;
4540       const char* DataFile ;
4541       if (BoundaryType == -1)
4542       {
4543         DataFile = myBoundary->GetDataFile() ;
4544         MESSAGE ( ". CAOFile = " << DataFile );
4545       }
4546       else if (BoundaryType == 0)
4547       {
4548         MeshName = myBoundary->GetMeshName() ;
4549         MESSAGE ( ". MeshName = " << MeshName );
4550         DataFile = myBoundary->GetDataFile() ;
4551         MESSAGE ( ". MeshFile = " << DataFile );
4552       }
4553       std::string texte_control_0 ;
4554       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, DataFile );
4555       texte_control += texte_control_0 ;
4556       // 5. Memorisation du traitement
4557       ListeBoundaryTraitees.push_back( BoundaryName );
4558     }
4559   }
4560
4561   return texte_control ;
4562 }
4563 //
4564 //=============================================================================
4565 //=============================================================================
4566 // Next functions are inherited from SALOMEDS::Driver interface
4567 //=============================================================================
4568 //=============================================================================
4569 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4570                                       const char* theURL,
4571                                       CORBA::Boolean isMultiFile)
4572 {
4573   MESSAGE ("Save for theURL = "<< theURL);
4574   SALOMEDS::TMPFile_var aStreamFile;
4575
4576   // get temporary directory name
4577   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4578
4579   StudyContext& context = myStudyContext;
4580
4581   // HOMARD data file name
4582   std::string aFileName = "";
4583   if (isMultiFile)
4584     aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4585   aFileName += "_HOMARD.dat";
4586
4587   // initialize sequence of file names
4588   SALOMEDS_Tool::ListOfFiles aFileSeq;
4589   aFileSeq.reserve(1);
4590   aFileSeq.push_back(CORBA::string_dup(aFileName.c_str())) ;
4591
4592   // get full path to the data file
4593   aFileName = tmpDir + aFileName;
4594
4595   // save data
4596   // -> create file
4597   std::ofstream f(aFileName.c_str());
4598
4599   // clear temporary id map
4600   context._idmap.clear();
4601
4602   int id = 1;
4603
4604   // -> save cases
4605   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4606   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4607     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4608     PortableServer::ServantBase_var aServant = GetServant(aCas);
4609     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4610     if (aCasServant) {
4611       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4612       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4613     }
4614   }
4615   // -> save zones
4616   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4617   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4618     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4619     PortableServer::ServantBase_var aServant = GetServant(aZone);
4620     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4621     if (aZoneServant) {
4622       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4623       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4624     }
4625   }
4626   // -> save hypotheses
4627   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4628   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4629     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4630     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4631     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4632     if (aHypoServant) {
4633       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4634       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4635     }
4636   }
4637   // -> save iterations
4638   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4639   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4640     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4641     PortableServer::ServantBase_var aServant = GetServant(aIter);
4642     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4643     if (aIterServant) {
4644       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4645       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4646     }
4647   }
4648   // -> save boundaries
4649   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4650   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4651     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4652     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4653     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4654     if (aBoundaryServant) {
4655       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4656       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4657     }
4658   }
4659   // -> close file
4660   MESSAGE ("close file");
4661   f.close();
4662
4663   // put temporary files to the stream
4664   MESSAGE ("put temporary files to the stream");
4665   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq, isMultiFile);
4666
4667   // remove temporary files
4668   MESSAGE ("remove temporary files");
4669   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4670
4671   // return data stream
4672   MESSAGE ("return data stream");
4673   return aStreamFile._retn();
4674 };
4675
4676 //===========================================================================
4677 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4678                                            const char* theURL,
4679                                            CORBA::Boolean isMultiFile)
4680 {
4681   // No specific ASCII persistence
4682   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4683   return aStreamFile._retn();
4684 };
4685
4686 //===========================================================================
4687 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4688                                    const SALOMEDS::TMPFile& theStream,
4689                                    const char* theURL,
4690                                    CORBA::Boolean isMultiFile)
4691 {
4692   MESSAGE ("Load pour theURL = "<< theURL);
4693
4694   // set current study
4695   if (myStudy->_is_nil())
4696     UpdateStudy();
4697
4698   // get temporary directory name
4699   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4700
4701   // Convert the stream into sequence of files to process
4702   SALOMEDS_Tool::ListOfFiles aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4703                                                                         tmpDir.c_str(),
4704                                                                         isMultiFile);
4705   // HOMARD data file name
4706   std::string aFileName = "";
4707   if (isMultiFile)
4708     aFileName = SALOMEDS_Tool::GetNameFromPath(Kernel_Utils::encode(SMESH_Gen_i::getStudyServant()->URL()));
4709   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4710
4711   StudyContext& context = myStudyContext;
4712
4713   // save data
4714   // -> create file
4715   std::ifstream f(aFileName.c_str());
4716
4717   // clear context
4718   context._mesCas.clear();
4719   context._mesHypotheses.clear();
4720   context._mesIterations.clear();
4721   context._mesZones.clear();
4722   context._mesBoundarys.clear();
4723   context._idmap.clear();
4724
4725   int id = 1;
4726   std::string line;
4727
4728   while (f) {
4729     std::getline(f, line);
4730     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4731     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4732     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4733     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4734     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4735     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4736     if (line.substr(0, bounSignature.size()) == bounSignature) {
4737       // re-create boundary
4738       MESSAGE ("Recreation de la frontiere" );
4739       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4740       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4741       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4742       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4743         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4744         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4745       }
4746     }
4747     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4748       // re-create case
4749       MESSAGE ("Recreation du cas" );
4750       HOMARD::HOMARD_Cas_var aCase = newCase();
4751       PortableServer::ServantBase_var aServant = GetServant(aCase);
4752       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4753       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4754         context._mesCas[aCase->GetName()] = aCase;
4755         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4756       }
4757     }
4758     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4759       // re-create hypothesis
4760       MESSAGE ("Recreation de l hypothese" );
4761       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4762       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4763       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4764       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4765         context._mesHypotheses[aHypo->GetName()] = aHypo;
4766         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4767       }
4768     }
4769     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4770       // re-create iteration
4771       MESSAGE ("Recreation de l'iteration" );
4772       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4773       PortableServer::ServantBase_var aServant = GetServant(aIter);
4774       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4775       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4776         context._mesIterations[aIter->GetName()] = aIter;
4777         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4778       }
4779     }
4780     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4781       MESSAGE ("Recreation de la zone" );
4782       // re-create zone
4783       HOMARD::HOMARD_Zone_var aZone = newZone();
4784       PortableServer::ServantBase_var aServant = GetServant(aZone);
4785       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4786       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4787         context._mesZones[aZone->GetName()] = aZone;
4788         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4789       }
4790     }
4791     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4792       MESSAGE ("Recreation du schema YACS" );
4793       // re-create YACS
4794       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4795       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4796       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4797       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4798         context._mesYACSs[aYACS->GetName()] = aYACS;
4799         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4800       }
4801     }
4802     id++;
4803   }
4804
4805   // -> close file
4806   f.close();
4807
4808   // Remove temporary files created from the stream
4809   if (!isMultiFile)
4810     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq, true);
4811
4812   return true;
4813 };
4814
4815 //===========================================================================
4816 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4817                                         const SALOMEDS::TMPFile& theStream,
4818                                         const char* theURL,
4819                                         CORBA::Boolean isMultiFile)
4820 {
4821   // No specific ASCII persistence
4822   return Load(theComponent, theStream, theURL, isMultiFile);
4823 };
4824
4825 //===========================================================================
4826 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4827 {
4828 };
4829
4830 //===========================================================================
4831 char* HOMARD_Gen_i::ComponentDataType()
4832 {
4833   return CORBA::string_dup("HOMARD");
4834 };
4835
4836 //===========================================================================
4837 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4838                                             const char* IORString,
4839                                             CORBA::Boolean isMultiFile,
4840                                             CORBA::Boolean isASCII)
4841 {
4842   CORBA::String_var aString("");
4843   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4844     StudyContext context = myStudyContext;
4845     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4846     if (!CORBA::is_nil(anObj)) {
4847       PortableServer::ServantBase_var aServant = GetServant(anObj);
4848       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4849       if (aStorable) {
4850         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4851         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4852           if (it->second == aStorable) {
4853             std::stringstream os;
4854             os << it->first;
4855             aString = CORBA::string_dup(os.str().c_str());
4856           }
4857         }
4858       }
4859     }
4860   }
4861   return aString._retn();
4862 };
4863
4864 //===========================================================================
4865 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4866                                             const char* aLocalPersistentID,
4867                                             CORBA::Boolean isMultiFile,
4868                                             CORBA::Boolean isASCII)
4869 {
4870   CORBA::String_var aString("");
4871   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4872     StudyContext context = myStudyContext;
4873     int id = atoi(aLocalPersistentID);
4874     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4875       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4876       if (!CORBA::is_nil(object)) {
4877         aString = _orb->object_to_string(object);
4878       }
4879     }
4880   }
4881   return aString._retn();
4882 };
4883
4884 //===========================================================================
4885 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4886 {
4887   if(CORBA::is_nil(myStudy))
4888     return false;
4889
4890   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4891   if(!aCas->_is_nil())
4892     return true;
4893
4894   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4895   if(!aHypo->_is_nil())
4896     return true;
4897
4898   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4899   if(!aZone->_is_nil())
4900     return true;
4901
4902   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4903   if(!aBoundary->_is_nil())
4904     return true;
4905
4906   /* Iteration is not published directly
4907   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4908   if(!aIter->_is_nil())
4909     return true;
4910   */
4911   return false;
4912 };
4913
4914 //===========================================================================
4915 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4916 {
4917   // No Copy/Paste support
4918   return false;
4919 };
4920
4921 //===========================================================================
4922 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4923                                            CORBA::Long& theObjectID)
4924 {
4925   // No Copy/Paste support
4926   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4927   return aStreamFile._retn();
4928 };
4929
4930 //===========================================================================
4931 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4932                                         CORBA::Long theObjectID)
4933 {
4934   // No Copy/Paste support
4935   return false;
4936 };
4937
4938 //===========================================================================
4939 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4940                                                CORBA::Long theObjectID,
4941                                                SALOMEDS::SObject_ptr theSObject)
4942 {
4943   // No Copy/Paste support
4944   SALOMEDS::SObject_var aResultSO;
4945   return aResultSO._retn();
4946 };
4947
4948 //===========================================================================
4949 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4950 {
4951   PortableServer::Servant aServant = 0;
4952   if (!CORBA::is_nil(theObject)) {
4953     try {
4954       aServant = _poa->reference_to_servant(theObject);
4955     }
4956     catch (...) {
4957     }
4958   }
4959   return aServant;
4960 }
4961
4962 //==========================================================================
4963 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Boolean isPublished,
4964                                            CORBA::Boolean isMultiFile,
4965                                            CORBA::Boolean& isValidScript)
4966 {
4967    MESSAGE ("Entree dans DumpPython");
4968    isValidScript=1;
4969
4970    SALOMEDS::SObject_var aSO = SMESH_Gen_i::getStudyServant()->FindComponent("HOMARD");
4971    if(CORBA::is_nil(aSO))
4972       return new Engines::TMPFile(0);
4973
4974    std::string aScript = "\"\"\"\n";
4975    aScript += "Python script for HOMARD\n";
4976    aScript += "Copyright 1996, 2011, 2015 EDF\n";
4977    aScript += "\"\"\"\n";
4978    aScript += "__revision__ = \"V1.2\"\n";
4979    aScript += "import HOMARD\n";
4980    if( isMultiFile )
4981       aScript += "import salome\n";
4982    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4983    aScript += "\thomard.UpdateStudy()\n";
4984    MESSAGE (". Au depart \n"<<aScript);
4985
4986
4987    if (myStudyContext._mesBoundarys.size() > 0)
4988    {
4989     MESSAGE (". Ecritures des frontieres");
4990     aScript += "#\n# Creation of the boundaries";
4991     aScript +=  "\n# ==========================";
4992    }
4993    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4994    for (it_boundary  = myStudyContext._mesBoundarys.begin();
4995         it_boundary != myStudyContext._mesBoundarys.end(); ++it_boundary)
4996    {
4997     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4998     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4999     std::string dumpBoundary = dumpCorbaBoundary.in();
5000     MESSAGE (dumpBoundary<<"\n");
5001     aScript += dumpBoundary;
5002    }
5003
5004
5005    if (myStudyContext._mesZones.size() > 0)
5006    {
5007     MESSAGE (". Ecritures des zones");
5008     aScript += "#\n# Creation of the zones";
5009     aScript +=  "\n# =====================";
5010    }
5011    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
5012    for ( it_zone  = myStudyContext._mesZones.begin();
5013          it_zone != myStudyContext._mesZones.end(); ++it_zone)
5014    {
5015     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
5016     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
5017     std::string dumpZone = dumpCorbaZone.in();
5018     MESSAGE (dumpZone<<"\n");
5019     aScript += dumpZone;
5020    }
5021
5022
5023    if (myStudyContext._mesHypotheses.size() > 0)
5024    {
5025     MESSAGE (". Ecritures des hypotheses");
5026     aScript += "#\n# Creation of the hypotheses";
5027     aScript +=  "\n# ==========================";
5028    }
5029    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
5030    for ( it_hypo  = myStudyContext._mesHypotheses.begin();
5031          it_hypo != myStudyContext._mesHypotheses.end(); it_hypo++)
5032    {
5033     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
5034     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
5035     std::string dumpHypo = dumpCorbaHypo.in();
5036     MESSAGE (dumpHypo<<"\n");
5037     aScript += dumpHypo;
5038    }
5039
5040
5041    if (myStudyContext._mesCas.size() > 0)
5042    {
5043     MESSAGE (". Ecritures des cas");
5044     aScript += "#\n# Creation of the cases";
5045     aScript += "\n# =====================";
5046    }
5047    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
5048    for (it_cas  = myStudyContext._mesCas.begin();
5049         it_cas != myStudyContext._mesCas.end(); it_cas++)
5050         {
5051            std::string nomCas = (*it_cas).first;
5052            std::string dumpCas = std::string("\n# Creation of the case ") ;
5053            dumpCas +=  nomCas + std::string("\n");
5054            dumpCas += std::string("\t") + nomCas;
5055            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
5056
5057            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
5058            CORBA::String_var cIter0= myCase->GetIter0Name();
5059            std::string iter0 = cIter0.in();
5060
5061            HOMARD::HOMARD_Iteration_var myIteration = myStudyContext._mesIterations[iter0];
5062            CORBA::String_var cMesh0= myIteration->GetMeshFile();
5063            std::string mesh0 = cMesh0.in();
5064            CORBA::String_var cMeshName0= myIteration->GetMeshName();
5065            std::string meshName0 = cMeshName0.in();
5066            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
5067            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
5068            std::string dumpCas2= dumpCorbaCase.in();
5069
5070            MESSAGE (dumpCas<<dumpCas2<<"\n");
5071            aScript += dumpCas + dumpCas2;
5072         };
5073
5074
5075    if (myStudyContext._mesIterations.size() > 0)
5076    {
5077     MESSAGE (". Ecritures des iterations");
5078     aScript += "#\n# Creation of the iterations" ;
5079     aScript += "\n# ==========================";
5080    }
5081    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
5082    for (it_iter  = myStudyContext._mesIterations.begin();
5083         it_iter != myStudyContext._mesIterations.end(); ++it_iter)
5084    {
5085     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
5086     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
5087     std::string dumpIter = dumpCorbaIter.in();
5088     MESSAGE (dumpIter<<"\n");
5089     aScript += dumpIter;
5090    }
5091
5092
5093    if (myStudyContext._mesYACSs.size() > 0)
5094    {
5095     MESSAGE (". Ecritures des schemas YACS");
5096     aScript += "#\n# Creation of the schemas YACS";
5097     aScript +=  "\n# ============================";
5098    }
5099    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
5100    for ( it_yacs  = myStudyContext._mesYACSs.begin();
5101          it_yacs != myStudyContext._mesYACSs.end(); ++it_yacs)
5102    {
5103     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
5104     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
5105     std::string dumpYACS = dumpCorbaYACS.in();
5106     MESSAGE (dumpYACS<<"\n");
5107     aScript += dumpYACS;
5108    }
5109
5110   MESSAGE (". Ecritures finales");
5111   if( isMultiFile )
5112     aScript += "\n\tpass";
5113   aScript += "\n";
5114
5115   if( !isMultiFile ) // remove unnecessary tabulation
5116     aScript = RemoveTabulation( aScript );
5117
5118 //   MESSAGE ("A ecrire \n"<<aScript);
5119   const size_t aLen = strlen(aScript.c_str());
5120   char* aBuffer = new char[aLen+1];
5121   strcpy(aBuffer, aScript.c_str());
5122
5123   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
5124   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
5125
5126   MESSAGE ("Sortie de DumpPython");
5127   return aStreamFile._retn();
5128 }
5129
5130
5131 //=============================================================================
5132 //=============================================================================
5133 // Utilitaires
5134 //=============================================================================
5135 //=============================================================================
5136 void HOMARD_Gen_i::IsValidStudy( )
5137 {
5138 //   MESSAGE( "IsValidStudy" );
5139   if (CORBA::is_nil(SMESH_Gen_i::getStudyServant()))
5140   {
5141     SALOME::ExceptionStruct es;
5142     es.type = SALOME::BAD_PARAM;
5143     es.text = "Invalid study context";
5144     throw SALOME::SALOME_Exception(es);
5145   };
5146   return ;
5147 }
5148
5149 //=============================================================================
5150 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
5151 {
5152   std::string casename = std::string("") ;
5153   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
5154   for (it = myStudyContext._mesCas.begin();
5155   it != myStudyContext._mesCas.end(); it++)
5156   {
5157    if (std::string(nomDir) == std::string(it->second->GetDirName()))
5158    {
5159      casename = std::string(it->second->GetName()) ;
5160      break ;
5161    }
5162   }
5163   return CORBA::string_dup( casename.c_str() );
5164 }
5165 /*//=============================================================================
5166 void SALOMEException( std::string message )
5167 {
5168   SALOME::ExceptionStruct es;
5169   es.type = SALOME::BAD_PARAM;
5170   es.text = message;
5171   throw SALOME::SALOME_Exception(es);
5172   return ;
5173 }*/
5174 //=============================================================================
5175 char* HOMARD_Gen_i::getVersion()
5176 {
5177 #if HOMARD_DEVELOPMENT
5178   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5179 #else
5180   return CORBA::string_dup(HOMARD_VERSION_STR);
5181 #endif
5182 }
5183 //===============================================================================
5184 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5185 // ligne : la ligne a manipuler
5186 // caractere : le caractere a reperer
5187 // option : 0 : la chaine avant la premiere apparition du caractere
5188 //          1 : la chaine apres la premiere apparition du caractere
5189 //          2 : la chaine avant la derniere apparition du caractere
5190 //          3 : la chaine apres la derniere apparition du caractere
5191 // Si le caractere est absent, on retourne la chaine totale
5192 //===============================================================================
5193 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5194 {
5195 //   MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5196 //
5197   std::string chaine = ligne ;
5198   int position ;
5199   if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5200   else              { position = ligne.find_last_of( caractere ) ; }
5201 //   MESSAGE("position = "<<position);
5202 //   MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5203 //   MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5204 //
5205   if ( position != std::string::npos )
5206   {
5207     if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5208     else                                      { chaine = ligne.substr( position+1 ) ; }
5209   }
5210   return chaine ;
5211 //
5212 }
5213 //=============================================================================
5214 //=============================================================================
5215 // Gestion des preferences
5216 //=============================================================================
5217 //=============================================================================
5218 // Decodage du fichier d'arcihvage des preferences
5219 //
5220 void HOMARD_Gen_i::SetPreferences( )
5221 {
5222   MESSAGE ( "SetPreferences" );
5223
5224   std::string ligne, mot_cle, salome_version ;
5225   bool ok = true ;
5226
5227   // A. Les valeurs par defaut ; elles doivent etre coherentes
5228   std::string LanguageShort = "en" ;
5229   int PublisMeshIN = 0 ;
5230   int PublisMeshOUT = 0 ;
5231   int YACSMaxIter = 0 ;
5232   int YACSMaxNode = 0 ;
5233   int YACSMaxElem = 0 ;
5234   std::string YACSTypeTestchaine = "None" ;
5235
5236   // B. La version de salome
5237   // Cela se presente sous la forme :
5238   // [SALOME KERNEL] : 7.3.0
5239   std::string File ;
5240   File  = getenv("KERNEL_ROOT_DIR") ;
5241   File += "/bin/salome/VERSION" ;
5242   MESSAGE ( "File = "<<File ) ;
5243   std::ifstream fichier0( File.c_str() ) ;
5244   if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5245   {
5246     std::string ligne; // variable contenant chaque ligne lue
5247     while ( std::getline( fichier0, ligne ) )
5248     {
5249       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5250       ligne_bis >> mot_cle ;
5251       if ( mot_cle == "[SALOME" )
5252       {
5253         salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5254 //         MESSAGE ( "salome_version = "<<salome_version<<"|||");
5255         break ;
5256       }
5257     }
5258   }
5259   else { ok = false ; }
5260
5261   // B. Decodage du fichier de preferences
5262   if ( ok )
5263   {
5264     std::string PrefFile ;
5265     PrefFile  = Kernel_Utils::HomePath() ;
5266     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5267     MESSAGE ( "PrefFile = "<<PrefFile ) ;
5268
5269     std::ifstream fichier( PrefFile.c_str() );
5270     if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5271     {
5272       bool section_langue = false ;
5273       bool section_homard = false ;
5274       while ( std::getline( fichier, ligne ) )
5275       {
5276         std::string chaine ;
5277         // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5278         std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5279         ligne_bis >> mot_cle ;
5280
5281         // 2. Les sections
5282         // 2.1. Debut d'une section
5283   //       MESSAGE(mot_cle);
5284         if ( mot_cle == "<section" )
5285         { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5286           ligne_bis >> mot_cle ;
5287           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5288           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5289           if ( chaine == "language" ) { section_langue = true ; }
5290           if ( chaine == "HOMARD" )   { section_homard = true ; }
5291   //         MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5292         }
5293         // 2.2. Fin d'une section
5294         else if ( mot_cle == "</section>" )
5295         { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5296           section_langue = false ;
5297           section_homard = false ; }
5298
5299         // 3. Parametres
5300         // 3.1. La langue
5301         else if ( section_langue || section_homard )
5302         { MESSAGE ( "a decoder : "<< ligne);
5303 //        La valeur : entre les deux premieres quotes
5304           chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5305 //           MESSAGE("chaine 1 = |"<<chaine<<"|");
5306           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5307 //           MESSAGE("chaine = |"<<chaine<<"|");
5308 //        Le mot_cle : entre les deux dernieres quotes
5309           std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5310 //           MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5311           chaine2 = GetStringInTexte ( chaine2,  "\"", 3 ) ;
5312 //           MESSAGE("chaine2 = |"<<chaine2<<"|");
5313           // 3.1. La langue
5314           if ( section_langue )
5315           { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5316           // 3.2. HOMARD
5317           if ( section_homard )
5318           {
5319             std::istringstream chainebis( chaine ) ;
5320             // 3.2.1. Les publications
5321             if ( chaine2 == "publish_mesh_in" )  { chainebis >> PublisMeshIN ; }
5322             if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5323             // 3.2.2. Les maximum pour YACS
5324             if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5325             if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5326             if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5327             if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5328           }
5329         }
5330       }
5331     }
5332   }
5333
5334   // C. Enregistrements
5335   MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5336   SetLanguageShort( LanguageShort.c_str() ) ;
5337
5338   MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5339   SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5340
5341   MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5342   SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5343
5344   MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5345   int YACSTypeTest ;
5346   if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest &gt; VRef" ) )      { YACSTypeTest = 1 ; }
5347   else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest &lt; VRef" ) ) { YACSTypeTest = 2 ; }
5348   else                                                                                                { YACSTypeTest = 0 ; }
5349   MESSAGE ("==> TypeTest = " << YACSTypeTest );
5350   SetYACSConvergenceType( YACSTypeTest ) ;
5351
5352   return ;
5353 }
5354 //===============================================================================
5355 // Langue de SALOME
5356 //===============================================================================
5357 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5358 {
5359 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5360   _LangueShort = LanguageShort ;
5361   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5362   else                        { _Langue = "English" ; }
5363   return ;
5364 }
5365 char* HOMARD_Gen_i::GetLanguageShort()
5366 {
5367 //   MESSAGE ("GetLanguageShort");
5368   return CORBA::string_dup( _LangueShort.c_str() );
5369 }
5370 //===============================================================================
5371 // Options de publications
5372 //===============================================================================
5373 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5374 {
5375   _PublisMeshIN  = PublisMeshIN  ;
5376   _PublisMeshOUT = PublisMeshOUT ;
5377   return ;
5378 }
5379 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5380 {
5381   return _PublisMeshIN ;
5382 }
5383 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5384 {
5385   return _PublisMeshOUT ;
5386 }
5387 //===============================================================================
5388 // YACS - test de convergence
5389 //===============================================================================
5390 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5391 {
5392   _YACSMaxIter = YACSMaxIter ;
5393   _YACSMaxNode = YACSMaxNode ;
5394   _YACSMaxElem = YACSMaxElem ;
5395   return ;
5396 }
5397 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5398 {
5399   return _YACSMaxIter ;
5400 }
5401 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5402 {
5403   return _YACSMaxNode ;
5404 }
5405 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5406 {
5407   return _YACSMaxElem ;
5408 }
5409 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5410 {
5411   _YACSTypeTest = YACSTypeTest ;
5412   return ;
5413 }
5414 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5415 {
5416   return _YACSTypeTest ;
5417 }
5418
5419 //=============================================================================
5420 extern "C"
5421 {
5422   HOMARDENGINE_EXPORT
5423   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5424                                                   PortableServer::POA_ptr poa,
5425                                                   PortableServer::ObjectId* contId,
5426                                                   const char* instanceName,
5427                                                   const char* interfaceName)
5428   {
5429     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5430     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5431     return myHOMARD_Gen->getId();
5432   }
5433 }