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