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