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