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