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