Salome HOME
En cas d'erreur, affichage du nom du fichier à consulter.
[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 #ifndef WIN32
1252   codret = chdir(DirNameStart) ;
1253 #else
1254   codret = _chdir(DirNameStart) ;
1255 #endif
1256   if ( codret != 0 )
1257   {
1258     SALOME::ExceptionStruct es;
1259     es.type = SALOME::BAD_PARAM;
1260     es.text = "The directory of the iteration does not exist.";
1261     throw SALOME::SALOME_Exception(es);
1262     return 0;
1263   };
1264   // A.2. Reperage des fichiers du repertoire de reprise
1265   std::string file_configuration = "" ;
1266   std::string file_maillage_homard = "" ;
1267   int bilan ;
1268 #ifndef WIN32
1269   DIR *dp;
1270   struct dirent *dirp;
1271   dp  = opendir(DirNameStart);
1272   while ( (dirp = readdir(dp)) != NULL )
1273   {
1274     std::string file_name(dirp->d_name);
1275 //     MESSAGE ( file_name );
1276     bilan = file_name.find("HOMARD.Configuration.") ;
1277     if ( bilan != string::npos ) { file_configuration = file_name ; }
1278     bilan = file_name.find("maill.") ;
1279     if ( bilan != string::npos )
1280     {
1281       bilan = file_name.find(".hom.med") ;
1282       if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1283     }
1284   }
1285   closedir(dp);
1286 #else
1287   HANDLE hFind = INVALID_HANDLE_VALUE;
1288   WIN32_FIND_DATA ffd;
1289   hFind = FindFirstFile(DirNameStart, &ffd);
1290   if (INVALID_HANDLE_VALUE != hFind) {
1291     while (FindNextFile(hFind, &ffd) != 0) {
1292       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1293       std::string file_name(ffd.cFileName);
1294       bilan = file_name.find("HOMARD.Configuration.") ;
1295       if ( bilan != string::npos ) { file_configuration = file_name ; }
1296       bilan = file_name.find("maill.") ;
1297       if ( bilan != string::npos )
1298       {
1299         bilan = file_name.find(".hom.med") ;
1300         if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1301       }
1302     }
1303     FindClose(hFind);
1304   }
1305 #endif
1306   MESSAGE ( "==> file_configuration   : " << file_configuration ) ;
1307   MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1308   // A.3. Controle
1309   if ( ( file_configuration == "" ) || ( file_maillage_homard == "" ) )
1310   {
1311     SALOME::ExceptionStruct es;
1312     es.type = SALOME::BAD_PARAM;
1313     std::string text ;
1314     if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1315     else                            { text = "The HOMARD mesh file cannot be found." ; }
1316     es.text = CORBA::string_dup(text.c_str());
1317     throw SALOME::SALOME_Exception(es);
1318   }
1319
1320   // B. Lecture du fichier de configuration
1321   // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1322   int NumeIter ;
1323   int TypeConf = 0 ;
1324   int Pyram = 0 ;
1325   char* MeshName ;
1326   char* MeshFile ;
1327   // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1328   std::ifstream fichier( file_configuration.c_str() );
1329   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1330   {
1331     std::string ligne; // variable contenant chaque ligne lue
1332     std::string mot_cle;
1333     std::string argument;
1334     int decalage;
1335     // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1336     while ( std::getline( fichier, ligne ) )
1337     {
1338       // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1339       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1340       ligne_bis >> mot_cle ;
1341       // B.2. Des valeurs entieres : le second bloc de la ligne
1342       if ( mot_cle == "NumeIter" )
1343       {
1344         ligne_bis >> NumeIter ;
1345         NumeIter += 1 ;
1346       }
1347       // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1348       else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1349       {
1350         ligne_bis >> argument ;
1351
1352         if ( mot_cle == "TypeConf" )
1353         {
1354           if      ( argument == "conforme" )                { TypeConf = 1 ; }
1355           else if ( argument == "non_conforme_1_noeud" )    { TypeConf = 2 ; }
1356           else if ( argument == "non_conforme_1_arete" )    { TypeConf = 3 ; }
1357           else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1358         }
1359         else if ( mot_cle == "TypeElem" )
1360         {
1361           if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1362           else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1363         }
1364       }
1365       // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1366       //                               il faut les supprimer
1367       else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1368       {
1369         ligne_bis >> argument ;
1370         if ( argument[0] == '"' ) { decalage = 1 ; }
1371         else                      { decalage = 0 ; }
1372         size_t size = argument.size() + 1 - 2*decalage ;
1373
1374         if ( mot_cle == "CCNoMNP1" )
1375         {
1376           MeshName = new char[ size ];
1377           strncpy( MeshName, argument.c_str()+decalage, size );
1378           MeshName[size-1] = '\0' ;
1379         }
1380         else if ( mot_cle == "CCMaiNP1" )
1381         {
1382           MeshFile = new char[ size ];
1383           strncpy( MeshFile, argument.c_str()+decalage, size );
1384           MeshFile[size-1] = '\0' ;
1385         }
1386       }
1387     }
1388     MESSAGE ( "==> TypeConf   : " << TypeConf ) ;
1389     MESSAGE ( "==> MeshName   : " << MeshName ) ;
1390     MESSAGE ( "==> MeshFile   : " << MeshFile ) ;
1391     MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1392     MESSAGE ( "==> Pyram      : " << Pyram ) ;
1393   }
1394   else
1395   {
1396     SALOME::ExceptionStruct es;
1397     es.type = SALOME::BAD_PARAM;
1398     std::string text = "The configuration file cannot be read." ;
1399     es.text = CORBA::string_dup(text.c_str());
1400     throw SALOME::SALOME_Exception(es);
1401   }
1402
1403   // C. Creation effective du cas
1404
1405   int option = 1 ;
1406   if ( _PublisMeshIN != 0 ) option = 2 ;
1407   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1408
1409   // D. Parametrages lus dans le fichier de configuration
1410
1411   myCase->SetConfType (TypeConf) ;
1412   myCase->SetPyram (Pyram) ;
1413
1414   // E. Copie du fichier de maillage homard
1415   // E.1. Repertoire associe au cas
1416   char* nomDirCase = myCase->GetDirName() ;
1417   // E.2. Repertoire associe a l'iteration de ce cas
1418   char* IterName ;
1419   IterName = myCase->GetIter0Name() ;
1420   HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1421   char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1422   Iter->SetDirNameLoc(nomDirIter);
1423   std::string nomDirIterTotal ;
1424   nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1425 #ifndef WIN32
1426   if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1427 #else
1428   if (_mkdir(nomDirIterTotal.c_str()) != 0)
1429 #endif
1430   {
1431     MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1432     SALOME::ExceptionStruct es;
1433     es.type = SALOME::BAD_PARAM;
1434     std::string text = "The directory for the computation cannot be created." ;
1435     es.text = CORBA::string_dup(text.c_str());
1436     throw SALOME::SALOME_Exception(es);
1437   }
1438   // E.3. Copie du maillage HOMARD au format MED
1439 #ifndef WIN32
1440   codret = chdir(DirNameStart) ;
1441 #else
1442   codret = _chdir(DirNameStart) ;
1443 #endif
1444   std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1445   MESSAGE ( "commande : " << commande ) ;
1446   codret = system(commande.c_str()) ;
1447   MESSAGE ( "codret : " << codret ) ;
1448   if ( codret != 0 )
1449   {
1450     SALOME::ExceptionStruct es;
1451     es.type = SALOME::BAD_PARAM;
1452     es.text = "The starting point for the case cannot be copied into the working directory.";
1453     throw SALOME::SALOME_Exception(es);
1454     return 0;
1455   };
1456
1457   // F. Menage
1458
1459   delete[] MeshName ;
1460   delete[] MeshFile ;
1461
1462 #ifndef WIN32
1463   chdir(nomDirWork.c_str());
1464 #else
1465   _chdir(nomDirWork.c_str());
1466 #endif
1467   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1468 }
1469 //=============================================================================
1470 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1471 //
1472 // nomCas : nom du cas a creer
1473 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1474 //
1475 {
1476   INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1477
1478   std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1479
1480   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1481   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1482
1483   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1484 }
1485 //=============================================================================
1486 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1487 //
1488 // nomCas : nom du cas a creer
1489 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1490 // Number : numero de l'iteration de depart
1491 //
1492 {
1493   INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1494   if ( Number < 0 )
1495   {
1496     SALOME::ExceptionStruct es;
1497     es.type = SALOME::BAD_PARAM;
1498     es.text = "The number of iteration must be positive.";
1499     throw SALOME::SALOME_Exception(es);
1500     return 0;
1501   };
1502
1503   std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1504
1505   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1506   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1507
1508   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1509 }
1510 //=============================================================================
1511 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1512 //
1513 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1514 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1515 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1516 //
1517 {
1518   MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1519   std::string nomDirWork = getenv("PWD") ;
1520   std::string DirNameStartIter ;
1521   int codret ;
1522   int NumeIterMax = -1 ;
1523
1524   // A.1. Controle du repertoire de depart du cas
1525 #ifndef WIN32
1526   codret = chdir(DirNameStart) ;
1527 #else
1528   codret = _chdir(DirNameStart) ;
1529 #endif
1530   if ( codret != 0 )
1531   {
1532     SALOME::ExceptionStruct es;
1533     es.type = SALOME::BAD_PARAM;
1534     es.text = "The directory of the case for the pursuit does not exist.";
1535     throw SALOME::SALOME_Exception(es);
1536     return 0;
1537   };
1538   // A.2. Reperage des sous-repertoire du repertoire de reprise
1539   bool existe = false ;
1540 #ifndef WIN32
1541   DIR *dp;
1542   struct dirent *dirp;
1543   dp  = opendir(DirNameStart);
1544   while ( (dirp = readdir(dp)) != NULL ) {
1545     std::string DirName_1(dirp->d_name);
1546 #else
1547   HANDLE hFind = INVALID_HANDLE_VALUE;
1548   WIN32_FIND_DATA ffd;
1549   hFind = FindFirstFile(DirNameStart, &ffd);
1550   if (INVALID_HANDLE_VALUE != hFind) {
1551     while (FindNextFile(hFind, &ffd) != 0) {
1552       std::string DirName_1 = "";
1553       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1554         DirName_1 = std::string(ffd.cFileName);
1555       }
1556 #endif
1557     if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1558     {
1559 #ifndef WIN32
1560       if ( chdir(DirName_1.c_str()) == 0 )
1561       {
1562 //      On cherche le fichier de configuration dans ce sous-repertoire
1563         codret = chdir(DirNameStart);
1564         DIR *dp_1;
1565         struct dirent *dirp_1;
1566         dp_1  = opendir(DirName_1.c_str()) ;
1567         while ( (dirp_1 = readdir(dp_1)) != NULL )
1568         {
1569           std::string file_name_1(dirp_1->d_name);
1570 #else
1571      if ( _chdir(DirName_1.c_str()) == 0 )
1572      {
1573         codret = _chdir(DirNameStart);
1574         HANDLE hFind1 = INVALID_HANDLE_VALUE;
1575         WIN32_FIND_DATA ffd1;
1576         hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1577         while (FindNextFile(hFind1, &ffd1) != 0)
1578         {
1579           if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1580           std::string file_name_1(ffd1.cFileName);
1581 #endif
1582           int bilan = file_name_1.find("HOMARD.Configuration.") ;
1583           if ( bilan != string::npos )
1584           {
1585   // Decodage du fichier pour trouver le numero d'iteration
1586 #ifndef WIN32
1587             chdir(DirName_1.c_str()) ;
1588 #else
1589             _chdir(DirName_1.c_str()) ;
1590 #endif
1591
1592             std::ifstream fichier( file_name_1.c_str() );
1593             if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1594             {
1595               int NumeIter ;
1596               std::string ligne; // variable contenant chaque ligne lue
1597               std::string mot_cle;
1598               // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1599               while ( std::getline( fichier, ligne ) )
1600               {
1601                 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1602                 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1603                 ligne_bis >> mot_cle ;
1604                 if ( mot_cle == "NumeIter" )
1605                 {
1606                   ligne_bis >> NumeIter ;
1607                   NumeIter += 1 ;
1608 //                   MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1609                   if ( Number == - 1 )
1610                   {
1611                     if ( NumeIter >= NumeIterMax )
1612                     {
1613                       NumeIterMax = NumeIter ;
1614                       DirNameStartIter = DirName_1 ;
1615                     }
1616                   }
1617                   else
1618                   {
1619                     if ( NumeIter == Number )
1620                     {
1621                       DirNameStartIter = DirName_1 ;
1622                       existe = true ;
1623                       break ;
1624                     }
1625                   }
1626                 }
1627               }
1628             }
1629             else
1630             {
1631               SALOME::ExceptionStruct es;
1632               es.type = SALOME::BAD_PARAM;
1633               std::string text = "The configuration file cannot be read." ;
1634               es.text = CORBA::string_dup(text.c_str());
1635               throw SALOME::SALOME_Exception(es);
1636             }
1637 #ifndef WIN32
1638             chdir(DirNameStart) ;
1639 #else
1640             _chdir(DirNameStart) ;
1641 #endif
1642           }
1643           if ( existe ) { break ; }
1644         }
1645 #ifndef WIN32
1646         closedir(dp_1);
1647 #else
1648         FindClose(hFind1);
1649 #endif
1650         if ( existe ) { break ; }
1651      }
1652     }
1653   }
1654 #ifndef WIN32
1655   closedir(dp);
1656   chdir(nomDirWork.c_str());
1657 #else
1658     FindClose(hFind);
1659   }
1660   _chdir(nomDirWork.c_str());
1661 #endif
1662
1663   if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1664   {
1665     SALOME::ExceptionStruct es;
1666     es.type = SALOME::BAD_PARAM;
1667     es.text = "The directory of the iteration does not exist.";
1668     throw SALOME::SALOME_Exception(es);
1669     return 0;
1670   };
1671
1672   return DirNameStartIter ;
1673 }
1674 //=============================================================================
1675 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)
1676 //
1677 // nomCas : nom du cas a creer
1678 // MeshName, MeshFile : nom et fichier du maillage correspondant
1679 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1680 //              1 : le maillage fourni peut ne pas exister ==> on continue si absent
1681 //             -1 : le maillage n'est pas fourni
1682 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1683 // Option : multiple de nombres premiers
1684 //         1 : aucune option
1685 //        x2 : publication du maillage dans SMESH
1686 {
1687   MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1688   MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1689   MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1690 //
1691   // A. Controles
1692   // A.1. L'etude
1693   IsValidStudy () ;
1694
1695   // A.2. Controle du nom :
1696   if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1697   {
1698     SALOME::ExceptionStruct es;
1699     es.type = SALOME::BAD_PARAM;
1700     es.text = "This case has already been defined.";
1701     throw SALOME::SALOME_Exception(es);
1702     return 0;
1703   };
1704
1705   // A.3. Controle du fichier du maillage
1706   int existeMeshFile ;
1707   if ( MeshOption >= 0 )
1708   {
1709     existeMeshFile = MEDFileExist ( MeshFile ) ;
1710     MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1711     if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1712     {
1713       SALOME::ExceptionStruct es;
1714       es.type = SALOME::BAD_PARAM;
1715       es.text = "The mesh file does not exist.";
1716       throw SALOME::SALOME_Exception(es);
1717       return 0;
1718     }
1719   }
1720   else { existeMeshFile = 0 ; }
1721
1722   // B. Creation de l'objet cas et publication
1723 //   MESSAGE ( "CreateCase0 : Creation de l'objet" );
1724   HOMARD::HOMARD_Cas_var myCase = newCase();
1725   myCase->SetName(nomCas);
1726   SALOMEDS::SObject_var aSO;
1727   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1728   myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1729
1730   // C. Caracteristiques du maillage
1731   if ( existeMeshFile != 0 )
1732   {
1733   // Les valeurs extremes des coordonnees
1734 //     MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1735     std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1736     HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1737     if (LesExtremes.size()!=10) { return false; }
1738     aSeq->length(10) ;
1739     for (int i =0 ; i< LesExtremes.size() ; i++)
1740         aSeq[i]=LesExtremes[i] ;
1741     myCase->SetBoundingBox(aSeq) ;
1742   // Les groupes
1743 //     MESSAGE ( "CreateCase0 : Les groupes" );
1744     std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile) ;
1745     HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1746     aSeqGroupe->length(LesGroupes.size());
1747     std::set<std::string>::const_iterator it ;
1748     int i = 0 ;
1749     for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1750       aSeqGroupe[i++]=(*it).c_str() ;
1751     myCase->SetGroups(aSeqGroupe) ;
1752   }
1753
1754   // D. L'iteration initiale du cas
1755   MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1756   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1757   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1758   int monNum = 0;
1759   std::string NomIteration = std::string(MeshName) ;
1760   while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1761   {
1762     std::ostringstream nom;
1763     nom << MeshName << monNum;
1764     NomIteration = nom.str();
1765     monNum += 1;
1766   }
1767   MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1768
1769   // D.2. Creation de l'iteration
1770   HOMARD::HOMARD_Iteration_var anIter = newIteration();
1771   myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1772   anIter->SetName(NomIteration.c_str());
1773   AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1774
1775   // D.4. Maillage correspondant
1776   if ( existeMeshFile != 0 )
1777   {
1778     anIter->SetMeshFile(MeshFile);
1779     if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1780   }
1781   anIter->SetMeshName(MeshName);
1782
1783   // D.5. Numero d'iteration
1784   anIter->SetNumber(NumeIter);
1785
1786   // D.6. Etat
1787   SetEtatIter(NomIteration.c_str(), -NumeIter);
1788 //
1789
1790   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1791 }
1792 //=============================================================================
1793 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1794 {
1795   INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1796   IsValidStudy () ;
1797
1798   // A. Controle du nom :
1799   if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1800   {
1801     SALOME::ExceptionStruct es;
1802     es.type = SALOME::BAD_PARAM;
1803     es.text = "This hypothesis has already been defined.";
1804     throw SALOME::SALOME_Exception(es);
1805     return 0;
1806   }
1807
1808   // B. Creation de l'objet
1809   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1810   if (CORBA::is_nil(myHypothesis))
1811   {
1812     SALOME::ExceptionStruct es;
1813     es.type = SALOME::BAD_PARAM;
1814     es.text = "Unable to create the hypothesis";
1815     throw SALOME::SALOME_Exception(es);
1816     return 0;
1817   };
1818   myHypothesis->SetName(nomHypothesis);
1819
1820   // C. Enregistrement
1821   myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1822
1823   SALOMEDS::SObject_var aSO;
1824   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1825
1826   // D. Valeurs par defaut des options avancees
1827   myHypothesis->SetNivMax(-1);
1828   myHypothesis->SetDiamMin(-1.0);
1829   myHypothesis->SetAdapInit(0);
1830   myHypothesis->SetLevelOutput(0);
1831
1832   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1833 }
1834
1835 //=============================================================================
1836 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1837 //=============================================================================
1838 {
1839   INFOS ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
1840   IsValidStudy () ;
1841
1842   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1843   if (CORBA::is_nil(myIterationParent))
1844   {
1845     SALOME::ExceptionStruct es;
1846     es.type = SALOME::BAD_PARAM;
1847     es.text = "The parent iteration is not defined.";
1848     throw SALOME::SALOME_Exception(es);
1849     return 0;
1850   };
1851
1852   const char* nomCas = myIterationParent->GetCaseName();
1853   MESSAGE ("CreateIteration : nomCas = " << nomCas);
1854   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1855   if (CORBA::is_nil(myCase))
1856   {
1857     SALOME::ExceptionStruct es;
1858     es.type = SALOME::BAD_PARAM;
1859     es.text = "Invalid case context";
1860     throw SALOME::SALOME_Exception(es);
1861     return 0;
1862   };
1863   const char* nomDirCase = myCase->GetDirName();
1864
1865   // Controle du nom :
1866   if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1867   {
1868     SALOME::ExceptionStruct es;
1869     es.type = SALOME::BAD_PARAM;
1870     es.text = "This iteration has already been defined.";
1871     throw SALOME::SALOME_Exception(es);
1872     return 0;
1873   };
1874
1875    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1876    if (CORBA::is_nil(myIteration))
1877   {
1878     SALOME::ExceptionStruct es;
1879     es.type = SALOME::BAD_PARAM;
1880     es.text = "Unable to create the iteration";
1881     throw SALOME::SALOME_Exception(es);
1882     return 0;
1883   };
1884   myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1885 // Nom de l'iteration et du maillage
1886   myIteration->SetName(NomIteration);
1887   myIteration->SetMeshName(NomIteration);
1888   myIteration->SetState(1);
1889
1890   int numero = myIterationParent->GetNumber() + 1;
1891   myIteration->SetNumber(numero);
1892
1893 // Nombre d'iterations deja connues pour le cas, permettant
1894 // la creation d'un sous-repertoire unique
1895   int nbitercase = myCase->GetNumberofIter();
1896   char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1897   myIteration->SetDirNameLoc(nomDirIter);
1898
1899 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1900 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1901 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1902 // situation la plus frequente.
1903 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1904 // le nombre d'iterations du cas permet d'eviter les collisions.
1905   int jaux ;
1906   if      ( nbitercase <    100 ) { jaux = 2 ; }
1907   else if ( nbitercase <   1000 ) { jaux = 3 ; }
1908   else if ( nbitercase <  10000 ) { jaux = 4 ; }
1909   else if ( nbitercase < 100000 ) { jaux = 5 ; }
1910   else                            { jaux = 9 ; }
1911   std::ostringstream iaux ;
1912   iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1913   std::stringstream MeshFile;
1914   MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1915   myIteration->SetMeshFile(MeshFile.str().c_str());
1916
1917 // Association avec le cas
1918   std::string label = "IterationHomard_" + std::string(nomIterParent);
1919   AssociateCaseIter(nomCas, NomIteration, label.c_str());
1920 // Lien avec l'iteration precedente
1921   myIterationParent->LinkNextIteration(NomIteration);
1922   myIteration->SetIterParentName(nomIterParent);
1923   // Gestion de l'arbre d'etudes
1924   SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1925   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1926   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1927   aStudyBuilder->NewCommand();
1928   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1929   aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1930   aStudyBuilder->CommitCommand();
1931
1932   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1933 }
1934 //=============================================================================
1935 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1936 {
1937   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1938   IsValidStudy () ;
1939
1940   // Controle du nom :
1941   if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1942   {
1943     MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1944     SALOME::ExceptionStruct es;
1945     es.type = SALOME::BAD_PARAM;
1946     es.text = "This boundary has already been defined";
1947     throw SALOME::SALOME_Exception(es);
1948     return 0;
1949   };
1950
1951   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1952   myBoundary->SetName(BoundaryName);
1953   myBoundary->SetType(BoundaryType);
1954
1955   myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1956
1957   SALOMEDS::SObject_var aSO;
1958   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1959
1960   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1961 }
1962 //=============================================================================
1963 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1964 {
1965   INFOS ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << "MeshName = " << MeshName );
1966   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1967   myBoundary->SetMeshFile( MeshFile ) ;
1968   myBoundary->SetMeshName( MeshName ) ;
1969
1970   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1971 }
1972 //=============================================================================
1973 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1974                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1975                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1976                                       CORBA::Double Rayon)
1977 {
1978   INFOS ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
1979 //
1980   SALOME::ExceptionStruct es;
1981   int error = 0 ;
1982   if ( Rayon <= 0.0 )
1983   { es.text = "The radius must be positive." ;
1984     error = 1 ; }
1985   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1986   if ( daux < 0.0000001 )
1987   { es.text = "The axis must be a non 0 vector." ;
1988     error = 2 ; }
1989   if ( error != 0 )
1990   {
1991     es.type = SALOME::BAD_PARAM;
1992     throw SALOME::SALOME_Exception(es);
1993     return 0;
1994   };
1995 //
1996   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1997   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1998
1999   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2000 }
2001 //=============================================================================
2002 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
2003                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2004                                       CORBA::Double Rayon)
2005 {
2006   INFOS ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
2007 //
2008   SALOME::ExceptionStruct es;
2009   int error = 0 ;
2010   if ( Rayon <= 0.0 )
2011   { es.text = "The radius must be positive." ;
2012     error = 1 ; }
2013   if ( error != 0 )
2014   {
2015     es.type = SALOME::BAD_PARAM;
2016     throw SALOME::SALOME_Exception(es);
2017     return 0;
2018   };
2019 //
2020   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
2021   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2022
2023   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2024 }
2025 //=============================================================================
2026 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
2027                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
2028                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2029 {
2030   INFOS ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
2031 //
2032   SALOME::ExceptionStruct es;
2033   int error = 0 ;
2034   if ( Angle <= 0.0 || Angle >= 90.0 )
2035   { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2036     error = 1 ; }
2037   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2038   if ( daux < 0.0000001 )
2039   { es.text = "The axis must be a non 0 vector." ;
2040     error = 2 ; }
2041   if ( error != 0 )
2042   {
2043     es.type = SALOME::BAD_PARAM;
2044     throw SALOME::SALOME_Exception(es);
2045     return 0;
2046   };
2047 //
2048   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2049   myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2050
2051   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2052 }
2053 //=============================================================================
2054 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2055                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2056                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2057 {
2058   INFOS ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
2059 //
2060   SALOME::ExceptionStruct es;
2061   int error = 0 ;
2062   if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2063   { es.text = "The radius must be positive." ;
2064     error = 1 ; }
2065   double daux = fabs(Rayon2-Rayon1) ;
2066   if ( daux < 0.0000001 )
2067   { es.text = "The radius must be different." ;
2068     error = 2 ; }
2069   daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2070   if ( daux < 0.0000001 )
2071   { es.text = "The centers must be different." ;
2072     error = 3 ; }
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, 4) ;
2081   myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2082
2083   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2084 }
2085 //=============================================================================
2086 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2087                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2088                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2089                                       CORBA::Double RayonRev, CORBA::Double RayonPri)
2090 {
2091   INFOS ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName ) ;
2092 //
2093   SALOME::ExceptionStruct es;
2094   int error = 0 ;
2095   if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2096   { es.text = "The radius must be positive." ;
2097     error = 1 ; }
2098   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2099   if ( daux < 0.0000001 )
2100   { es.text = "The axis must be a non 0 vector." ;
2101     error = 2 ; }
2102   if ( error != 0 )
2103   {
2104     es.type = SALOME::BAD_PARAM;
2105     throw SALOME::SALOME_Exception(es);
2106     return 0;
2107   };
2108 //
2109   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2110   myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2111
2112   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2113 }
2114 //=============================================================================
2115 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2116 {
2117   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
2118   IsValidStudy () ;
2119
2120   // Controle du nom :
2121   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2122   {
2123     SALOME::ExceptionStruct es;
2124     es.type = SALOME::BAD_PARAM;
2125     es.text = "This zone has already been defined";
2126     throw SALOME::SALOME_Exception(es);
2127     return 0;
2128   };
2129
2130   HOMARD::HOMARD_Zone_var myZone = newZone();
2131   myZone->SetName(ZoneName);
2132   myZone->SetType(ZoneType);
2133
2134   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2135
2136   SALOMEDS::SObject_var aSO;
2137   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2138
2139   return HOMARD::HOMARD_Zone::_duplicate(myZone);
2140 }
2141 //=============================================================================
2142 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2143                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
2144                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
2145                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
2146 {
2147   INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
2148 //
2149   SALOME::ExceptionStruct es;
2150   int error = 0 ;
2151   if ( Xmini > Xmaxi )
2152   { es.text = "The X coordinates are not coherent." ;
2153     error = 1 ; }
2154   if ( Ymini > Ymaxi )
2155   { es.text = "The Y coordinates are not coherent." ;
2156     error = 2 ; }
2157   if ( Zmini > Zmaxi )
2158   { es.text = "The Z coordinates are not coherent." ;
2159     error = 3 ; }
2160   if ( error != 0 )
2161   {
2162     es.type = SALOME::BAD_PARAM;
2163     throw SALOME::SALOME_Exception(es);
2164     return 0;
2165   };
2166 //
2167   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2168   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2169
2170   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2171 }
2172 //=============================================================================
2173 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2174                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2175 {
2176   INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
2177 //
2178   SALOME::ExceptionStruct es;
2179   int error = 0 ;
2180   if ( Rayon <= 0.0 )
2181   { es.text = "The radius must be positive." ;
2182     error = 1 ; }
2183   if ( error != 0 )
2184   {
2185     es.type = SALOME::BAD_PARAM;
2186     throw SALOME::SALOME_Exception(es);
2187     return 0;
2188   };
2189 //
2190   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2191   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2192
2193   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2194 }
2195 //=============================================================================
2196 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2197                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2198                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2199                                       CORBA::Double Rayon, CORBA::Double Haut)
2200 {
2201   INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
2202 //
2203   SALOME::ExceptionStruct es;
2204   int error = 0 ;
2205   if ( Rayon <= 0.0 )
2206   { es.text = "The radius must be positive." ;
2207     error = 1 ; }
2208   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2209   if ( daux < 0.0000001 )
2210   { es.text = "The axis must be a non 0 vector." ;
2211     error = 2 ; }
2212   if ( Haut <= 0.0 )
2213   { es.text = "The height must be positive." ;
2214     error = 3 ; }
2215   if ( error != 0 )
2216   {
2217     es.type = SALOME::BAD_PARAM;
2218     throw SALOME::SALOME_Exception(es);
2219     return 0;
2220   };
2221 //
2222   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2223   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2224
2225   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2226 }
2227 //=============================================================================
2228 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2229                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2230                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2231                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2232 {
2233   INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
2234 //
2235   SALOME::ExceptionStruct es;
2236   int error = 0 ;
2237   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2238   { es.text = "The radius must be positive." ;
2239     error = 1 ; }
2240   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2241   if ( daux < 0.0000001 )
2242   { es.text = "The axis must be a non 0 vector." ;
2243     error = 2 ; }
2244   if ( Haut <= 0.0 )
2245   { es.text = "The height must be positive." ;
2246     error = 3 ; }
2247   if ( Rayon <= Rayonint )
2248   { es.text = "The external radius must be higher than the internal radius." ;
2249     error = 4 ; }
2250   if ( error != 0 )
2251   {
2252     es.type = SALOME::BAD_PARAM;
2253     throw SALOME::SALOME_Exception(es);
2254     return 0;
2255   };
2256 //
2257   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2258   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2259
2260   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2261 }
2262 //=============================================================================
2263 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2264                                       CORBA::Double Umini, CORBA::Double Umaxi,
2265                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
2266                                       CORBA::Long Orient)
2267 {
2268   INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
2269 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2270 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2271 //   MESSAGE ("Orient = " << Orient ) ;
2272 //
2273   SALOME::ExceptionStruct es;
2274   int error = 0 ;
2275   if ( Umini > Umaxi )
2276   { es.text = "The first coordinates are not coherent." ;
2277     error = 1 ; }
2278   if ( Vmini > Vmaxi )
2279   { es.text = "The second coordinates are not coherent." ;
2280     error = 2 ; }
2281   if ( Orient < 1 || Orient > 3 )
2282   { es.text = "The orientation must be 1, 2 or 3." ;
2283     error = 3 ; }
2284   if ( error != 0 )
2285   {
2286     es.type = SALOME::BAD_PARAM;
2287     throw SALOME::SALOME_Exception(es);
2288     return 0;
2289   };
2290 //
2291   double Xmini, Xmaxi ;
2292   double Ymini, Ymaxi ;
2293   double Zmini, Zmaxi ;
2294   if ( Orient == 1 )
2295   { Xmini = Umini ;
2296     Xmaxi = Umaxi ;
2297     Ymini = Vmini ;
2298     Ymaxi = Vmaxi ;
2299     Zmini = 0. ;
2300     Zmaxi = 0. ; }
2301   else if ( Orient == 2 )
2302   { Xmini = 0. ;
2303     Xmaxi = 0. ;
2304     Ymini = Umini ;
2305     Ymaxi = Umaxi ;
2306     Zmini = Vmini ;
2307     Zmaxi = Vmaxi ; }
2308   else if ( Orient == 3 )
2309   { Xmini = Vmini ;
2310     Xmaxi = Vmaxi ;
2311     Ymini = 0. ;
2312     Ymaxi = 0. ;
2313     Zmini = Umini ;
2314     Zmaxi = Umaxi ; }
2315   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2316
2317   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2318   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2319
2320   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2321 }
2322 //=============================================================================
2323 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2324                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2325                                       CORBA::Double Rayon,
2326                                       CORBA::Long Orient)
2327 {
2328   INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
2329 //
2330   SALOME::ExceptionStruct es;
2331   int error = 0 ;
2332   if ( Rayon <= 0.0 )
2333   { es.text = "The radius must be positive." ;
2334     error = 1 ; }
2335   if ( Orient < 1 || Orient > 3 )
2336   { es.text = "The orientation must be 1, 2 or 3." ;
2337     error = 3 ; }
2338   if ( error != 0 )
2339   {
2340     es.type = SALOME::BAD_PARAM;
2341     throw SALOME::SALOME_Exception(es);
2342     return 0;
2343   };
2344 //
2345   double Xcentre ;
2346   double Ycentre ;
2347   double Zcentre ;
2348   if ( Orient == 1 )
2349   { Xcentre = Ucentre ;
2350     Ycentre = Vcentre ;
2351     Zcentre = 0. ; }
2352   else if ( Orient == 2 )
2353   { Xcentre = 0. ;
2354     Ycentre = Ucentre ;
2355     Zcentre = Vcentre ; }
2356   else if ( Orient == 3 )
2357   { Xcentre = Vcentre ;
2358     Ycentre = 0. ;
2359     Zcentre = Ucentre ; }
2360   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2361
2362   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2363   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2364
2365   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2366 }
2367 //=============================================================================
2368 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2369                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2370                                       CORBA::Double Rayon, CORBA::Double Rayonint,
2371                                       CORBA::Long Orient)
2372 {
2373   INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
2374 //
2375   SALOME::ExceptionStruct es;
2376   int error = 0 ;
2377   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2378   { es.text = "The radius must be positive." ;
2379     error = 1 ; }
2380   if ( Orient < 1 || Orient > 3 )
2381   { es.text = "The orientation must be 1, 2 or 3." ;
2382     error = 3 ; }
2383   if ( Rayon <= Rayonint )
2384   { es.text = "The external radius must be higher than the internal radius." ;
2385     error = 4 ; }
2386   if ( error != 0 )
2387   {
2388     es.type = SALOME::BAD_PARAM;
2389     throw SALOME::SALOME_Exception(es);
2390     return 0;
2391   };
2392 //
2393   double Xcentre ;
2394   double Ycentre ;
2395   double Zcentre ;
2396   if ( Orient == 1 )
2397   { Xcentre = Ucentre ;
2398     Ycentre = Vcentre ;
2399     Zcentre = 0. ; }
2400   else if ( Orient == 2 )
2401   { Xcentre = 0. ;
2402     Ycentre = Ucentre ;
2403     Zcentre = Vcentre ; }
2404   else if ( Orient == 3 )
2405   { Xcentre = Vcentre ;
2406     Ycentre = 0. ;
2407     Zcentre = Ucentre ; }
2408   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2409
2410   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2411   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2412
2413   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2414 }
2415 //=============================================================================
2416 //=============================================================================
2417
2418
2419
2420
2421 //=============================================================================
2422 //=============================================================================
2423 // Traitement d'une iteration
2424 // etatMenage = 1 : destruction du repertoire d'execution
2425 // modeHOMARD  = 1 : adaptation
2426 //            != 1 : information avec les options modeHOMARD
2427 // Option1 >0 : appel depuis python
2428 //         <0 : appel depuis GUI
2429 // Option2 : multiple de nombres premiers
2430 //         1 : aucune option
2431 //        x2 : publication du maillage dans SMESH
2432 //=============================================================================
2433 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2434 {
2435   INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2436
2437   // A. Prealable
2438   int codret = 0;
2439
2440   // A.1. L'objet iteration
2441   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2442   ASSERT(!CORBA::is_nil(myIteration));
2443
2444   // A.2. Controle de la possibilite d'agir
2445   // A.2.1. Etat de l'iteration
2446   int etat = myIteration->GetState();
2447   MESSAGE ( "etat = "<<etat );
2448   // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2449   if ( modeHOMARD == 1 )
2450   {
2451     if ( etat <= 0 )
2452     {
2453       SALOME::ExceptionStruct es;
2454       es.type = SALOME::BAD_PARAM;
2455       es.text = "This iteration is the first of the case and cannot be computed.";
2456       throw SALOME::SALOME_Exception(es);
2457       return 1 ;
2458     }
2459     else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2460     {
2461       SALOME::ExceptionStruct es;
2462       es.type = SALOME::BAD_PARAM;
2463       es.text = "This iteration is already computed.";
2464       throw SALOME::SALOME_Exception(es);
2465       return 1 ;
2466     }
2467   }
2468   // A.2.3. On n'analyse pas une iteration non calculee
2469   else
2470   {
2471     if ( etat == 1 )
2472     {
2473       SALOME::ExceptionStruct es;
2474       es.type = SALOME::BAD_PARAM;
2475       es.text = "This iteration is not computed.";
2476       throw SALOME::SALOME_Exception(es);
2477       return 1 ;
2478     }
2479   }
2480
2481   // A.3. Numero de l'iteration
2482   //     siterp1 : numero de l'iteration a traiter
2483   //     Si adaptation :
2484   //        siter   : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2485   //     Ou si information :
2486   //        siter = siterp1
2487   int NumeIter = myIteration->GetNumber();
2488   std::string siterp1 ;
2489   std::stringstream saux1 ;
2490   saux1 << NumeIter ;
2491   siterp1 = saux1.str() ;
2492   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2493
2494   std::string siter ;
2495   if ( modeHOMARD==1 )
2496   {
2497     std::stringstream saux0 ;
2498     int iaux = max(0, NumeIter-1) ;
2499     saux0 << iaux ;
2500     siter = saux0.str() ;
2501     if (NumeIter < 11) { siter = "0" + siter ; }
2502   }
2503   else
2504   { siter = siterp1 ; }
2505
2506   // A.4. Le cas
2507   const char* nomCas = myIteration->GetCaseName();
2508   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2509   ASSERT(!CORBA::is_nil(myCase));
2510
2511   // B. Les repertoires
2512   // B.1. Le repertoire courant
2513   std::string nomDirWork = getenv("PWD") ;
2514   // B.2. Le sous-repertoire de l'iteration a traiter
2515   char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2516   MESSAGE( ". DirCompute = " << DirCompute );
2517
2518   // C. Le fichier des messages
2519   // C.1. Le deroulement de l'execution de HOMARD
2520   std::string LogFile = DirCompute ;
2521   LogFile += "/Liste" ;
2522   if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2523   LogFile += ".log" ;
2524   MESSAGE (". LogFile = " << LogFile);
2525   if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2526   // C.2. Le bilan de l'analyse du maillage
2527   std::string FileInfo = DirCompute ;
2528   FileInfo += "/" ;
2529   if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2530   else
2531   { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2532     else                 { FileInfo += "info_ap" ; }
2533   }
2534   FileInfo += "." + siterp1 + ".bilan" ;
2535   myIteration->SetFileInfo(FileInfo.c_str());
2536
2537    // D. On passe dans le repertoire de l'iteration a calculer
2538   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2539 #ifndef WIN32
2540   chdir(DirCompute);
2541 #else
2542   _chdir(DirCompute);
2543 #endif
2544
2545   // E. Les donnees de l'execution HOMARD
2546   // E.1. L'objet du texte du fichier de configuration
2547   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2548   myDriver->TexteInit(DirCompute, LogFile, _Langue);
2549
2550   // E.2. Le maillage associe a l'iteration
2551   const char* NomMesh = myIteration->GetMeshName();
2552   MESSAGE ( ". NomMesh = " << NomMesh );
2553   const char* MeshFile = myIteration->GetMeshFile();
2554   MESSAGE ( ". MeshFile = " << MeshFile );
2555
2556   // E.3. Les donnees du traitement HOMARD
2557   int iaux ;
2558   if ( modeHOMARD == 1 )
2559   {
2560     iaux = 1 ;
2561     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2562     myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2563     codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2564   }
2565   else
2566   {
2567     InvalideIterInfo(NomIteration);
2568     myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2569     iaux = 0 ;
2570     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2571     myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2572     myDriver->CreeFichierDonn();
2573   }
2574
2575   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2576   DriverTexteBoundary(myCase, myDriver) ;
2577
2578   // E.5. Ecriture du texte dans le fichier
2579   MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2580   if (codret == 0)
2581   { myDriver->CreeFichier(); }
2582
2583 // G. Execution
2584 //
2585   int codretexec = 12 ;
2586   if (codret == 0)
2587   {
2588     codretexec = myDriver->ExecuteHomard(Option1);
2589 //
2590     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2591     // En mode adaptation, on ajuste l'etat de l'iteration
2592     if ( modeHOMARD == 1 )
2593     {
2594       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2595       else                 { SetEtatIter(NomIteration,1); }
2596       // GERALD -- QMESSAGE BOX
2597     }
2598   }
2599
2600   // H. Gestion des resultats
2601   if (codret == 0)
2602   {
2603     std::string Commentaire ;
2604     // H.1. Le fichier des messages, dans tous les cas
2605     Commentaire = "log" ;
2606     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2607     else                   { Commentaire += "Info" ; }
2608     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2609
2610     // H.2. Si tout s'est bien passe :
2611     if (codretexec == 0)
2612     {
2613     // H.2.1. Le fichier de bilan
2614       Commentaire = "Summary" ;
2615       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2616       else                   { Commentaire += "Info" ; }
2617       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2618     // H.2.2. Le fichier de  maillage obtenu
2619       if ( modeHOMARD == 1 )
2620       {
2621         std::stringstream saux0 ;
2622         Commentaire = "Mesh" ;
2623         Commentaire += " " + siterp1 ;
2624         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2625         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2626       }
2627     }
2628   // H.3 Message d'erreur
2629     if (codretexec != 0)
2630     {
2631       std::string text = "" ;
2632       // Message d'erreur en cas de probleme en adaptation
2633       if ( modeHOMARD == 1 )
2634       {
2635         text = "Error during the adaptation.\n" ;
2636         bool stopvu = false ;
2637         std::ifstream fichier( LogFile.c_str() );
2638         if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2639         {
2640           std::string ligne; // variable contenant chaque ligne lue
2641           while ( std::getline( fichier, ligne ) )
2642           {
2643 //             INFOS(ligne);
2644             if ( stopvu )
2645             { text += ligne+ "\n"; }
2646             else
2647             {
2648               int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2649               if ( position > 0 ) { stopvu = true ; }
2650             }
2651           }
2652         }
2653       }
2654       text += "\n\nSee the file " + LogFile + "\n" ;
2655       INFOS ( text ) ;
2656       SALOME::ExceptionStruct es;
2657       es.type = SALOME::BAD_PARAM;
2658       es.text = CORBA::string_dup(text.c_str());
2659       throw SALOME::SALOME_Exception(es);
2660 //
2661       // En mode information, on force le succes pour pouvoir consulter le fichier log
2662       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2663     }
2664   }
2665
2666   // I. Menage et retour dans le repertoire du cas
2667   if (codret == 0)
2668   {
2669     delete myDriver;
2670     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2671
2672 #ifndef WIN32
2673     chdir(nomDirWork.c_str());
2674 #else
2675     _chdir(nomDirWork.c_str());
2676 #endif
2677   }
2678
2679   return codretexec ;
2680 }
2681 //=============================================================================
2682 // Calcul d'une iteration : partie specifique a l'adaptation
2683 //=============================================================================
2684 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)
2685 {
2686   MESSAGE ( "ComputeAdap" );
2687
2688   // A. Prealable
2689   // A.1. Bases
2690   int codret = 0;
2691   // Numero de l'iteration
2692   int NumeIter = myIteration->GetNumber();
2693   std::stringstream saux0 ;
2694   saux0 << NumeIter-1 ;
2695   std::string siter = saux0.str() ;
2696   if (NumeIter < 11) { siter = "0" + siter ; }
2697
2698   // A.2. On verifie qu il y a une hypothese (erreur improbable);
2699   const char* nomHypo = myIteration->GetHypoName();
2700   if (std::string(nomHypo) == std::string(""))
2701   {
2702       SALOME::ExceptionStruct es;
2703       es.type = SALOME::BAD_PARAM;
2704       es.text = "This iteration does not have any associated hypothesis.";
2705       throw SALOME::SALOME_Exception(es);
2706       return 2;
2707   };
2708   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2709   ASSERT(!CORBA::is_nil(myHypo));
2710
2711   // B. L'iteration parent
2712   const char* nomIterationParent = myIteration->GetIterParentName();
2713   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2714   ASSERT(!CORBA::is_nil(myIterationParent));
2715   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2716   if ( myIterationParent->GetState() == 1 )
2717   {
2718     int iaux = 1 ;
2719     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2720     if (codret != 0)
2721     {
2722       // GERALD -- QMESSAGE BOX
2723       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2724     }
2725   };
2726
2727   // C. Le sous-repertoire de l'iteration precedente
2728   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2729   MESSAGE( ". DirComputePa = " << DirComputePa );
2730
2731   // D. Les donnees de l'adaptation HOMARD
2732   // D.1. Le type de conformite
2733   int ConfType = myCase->GetConfType();
2734   MESSAGE ( ". ConfType = " << ConfType );
2735
2736   // D.2. Le maillage de depart
2737   const char* NomMeshParent = myIterationParent->GetMeshName();
2738   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2739   const char* MeshFileParent = myIterationParent->GetMeshFile();
2740   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2741
2742   // D.3. Le maillage associe a l'iteration
2743   const char* MeshFile = myIteration->GetMeshFile();
2744   MESSAGE ( ". MeshFile = " << MeshFile );
2745   FILE *file = fopen(MeshFile,"r");
2746   if (file != NULL)
2747   {
2748     fclose(file);
2749     if (etatMenage == 0)
2750     {
2751       SALOME::ExceptionStruct es;
2752       es.type = SALOME::BAD_PARAM;
2753       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2754       es.text = CORBA::string_dup(text.c_str());
2755       throw SALOME::SALOME_Exception(es);
2756       return 4;
2757     }
2758     else
2759     {
2760       std::string commande = "rm -f " + std::string(MeshFile);
2761       codret = system(commande.c_str());
2762       if (codret != 0)
2763       {
2764         SALOME::ExceptionStruct es;
2765         es.type = SALOME::BAD_PARAM;
2766         es.text = "The mesh file cannot be deleted.";
2767         throw SALOME::SALOME_Exception(es);
2768         return 5;
2769       }
2770     }
2771   }
2772
2773   // D.4. Les types de raffinement et de deraffinement
2774   // Les appels corba sont lourds, il vaut mieux les grouper
2775   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2776   ASSERT(ListTypes->length() == 3);
2777   int TypeAdap = (*ListTypes)[0];
2778   int TypeRaff = (*ListTypes)[1];
2779   int TypeDera = (*ListTypes)[2];
2780 //   MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera  );
2781
2782   // E. Texte du fichier de configuration
2783   // E.1. Incontournables du texte
2784   myDriver->TexteAdap();
2785   int iaux = 0 ;
2786   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2787   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2788   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2789
2790   // E.2. Ajout des informations liees aux zones eventuelles
2791   if ( TypeAdap == 0 )
2792   { DriverTexteZone(myHypo, myDriver) ; }
2793
2794   // E.3. Ajout des informations liees aux champs eventuels
2795   if ( TypeAdap == 1 )
2796   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2797
2798   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2799   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2800   int numberOfGroups = listeGroupes->length();
2801   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2802   if (numberOfGroups > 0)
2803   {
2804     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2805     {
2806       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2807       MESSAGE( "... GroupName = " << GroupName );
2808       myDriver->TexteGroup(GroupName);
2809     }
2810   }
2811
2812   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2813   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2814
2815   // E.6. Ajout des options avancees
2816   int Pyram = myCase->GetPyram();
2817   MESSAGE ( ". Pyram = " << Pyram );
2818   int NivMax = myHypo->GetNivMax();
2819   MESSAGE ( ". NivMax = " << NivMax );
2820   double DiamMin = myHypo->GetDiamMin() ;
2821   MESSAGE ( ". DiamMin = " << DiamMin );
2822   int AdapInit = myHypo->GetAdapInit();
2823   MESSAGE ( ". AdapInit = " << AdapInit );
2824   int LevelOutput = myHypo->GetLevelOutput();
2825   MESSAGE ( ". LevelOutput = " << LevelOutput );
2826   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2827
2828   // E.7. Ajout des informations sur le deroulement de l'execution
2829   int MessInfo = myIteration->GetInfoCompute();
2830   MESSAGE ( ". MessInfo = " << MessInfo );
2831   myDriver->TexteInfoCompute(MessInfo);
2832
2833   return codret ;
2834 }
2835 //=============================================================================
2836 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2837 //  nomrep : nom du repertoire parent
2838 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2839 //=============================================================================
2840 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2841 {
2842   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2843   // On verifie que le repertoire parent existe
2844 #ifndef WIN32
2845   int codret = chdir(nomrep) ;
2846 #else
2847   int codret = _chdir(nomrep) ;
2848 #endif
2849   if ( codret != 0 )
2850   {
2851     SALOME::ExceptionStruct es;
2852     es.type = SALOME::BAD_PARAM;
2853     es.text = "The directory of the case does not exist.";
2854     throw SALOME::SALOME_Exception(es);
2855     return 0;
2856   };
2857   std::string nomDirActuel = getenv("PWD") ;
2858   std::string DirName ;
2859   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2860   bool a_chercher = true ;
2861   while ( a_chercher )
2862   {
2863     // On passe dans le repertoire parent
2864
2865 #ifndef WIN32
2866   chdir(nomrep);
2867 #else
2868   _chdir(nomrep);
2869 #endif
2870     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2871     int jaux ;
2872     if      ( num <    100 ) { jaux = 2 ; }
2873     else if ( num <   1000 ) { jaux = 3 ; }
2874     else if ( num <  10000 ) { jaux = 4 ; }
2875     else if ( num < 100000 ) { jaux = 5 ; }
2876     else                     { jaux = 9 ; }
2877     std::ostringstream iaux ;
2878     iaux << std::setw(jaux) << std::setfill('0') << num ;
2879     std::ostringstream DirNameA ;
2880     DirNameA << "I" << iaux.str();
2881     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2882     // que c'est bien un probleme d'absence
2883 #ifndef WIN32
2884     if ( chdir(DirNameA.str().c_str()) != 0 )
2885 #else
2886     if ( _chdir(DirNameA.str().c_str()) != 0 )
2887 #endif
2888     {
2889       bool existe = false ;
2890 #ifndef WIN32
2891       DIR *dp;
2892       struct dirent *dirp;
2893       dp  = opendir(nomrep);
2894       while ( (dirp = readdir(dp)) != NULL )
2895       {
2896         std::string file_name(dirp->d_name);
2897 #else
2898       HANDLE hFind = INVALID_HANDLE_VALUE;
2899       WIN32_FIND_DATA ffd;
2900       hFind = FindFirstFile(nomrep, &ffd);
2901       if (INVALID_HANDLE_VALUE != hFind) {
2902         while (FindNextFile(hFind, &ffd) != 0) {
2903          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2904          std::string file_name(ffd.cFileName);
2905 #endif
2906         if ( file_name == DirNameA.str() ) { existe = true ; }
2907       }
2908 #ifndef WIN32
2909       closedir(dp);
2910 #else
2911       }
2912       FindClose(hFind);
2913 #endif
2914       if ( !existe )
2915       {
2916         DirName = DirNameA.str() ;
2917         a_chercher = false ;
2918         break ;
2919       }
2920     }
2921     num += 1;
2922   }
2923
2924   MESSAGE ( "==> DirName = " << DirName);
2925   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2926 #ifndef WIN32
2927   chdir(nomDirActuel.c_str());
2928 #else
2929   _chdir(nomDirActuel.c_str());
2930 #endif
2931   return CORBA::string_dup( DirName.c_str() );
2932 }
2933 //=============================================================================
2934 // Calcul d'une iteration : gestion du repertoire de calcul
2935 //        Si le sous-repertoire existe :
2936 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2937 //         etatMenage =  1 : on fait le menage du repertoire
2938 //         etatMenage = -1 : on ne fait rien
2939 //=============================================================================
2940 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2941 {
2942   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2943   // B.2. Le repertoire du cas
2944   const char* nomDirCase = myCase->GetDirName();
2945   MESSAGE ( ". nomDirCase = " << nomDirCase );
2946
2947   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2948   // B.3.1. Le nom du sous-repertoire
2949   const char* nomDirIt = myIteration->GetDirNameLoc();
2950
2951   // B.3.2. Le nom complet du sous-repertoire
2952   std::stringstream DirCompute ;
2953   DirCompute << nomDirCase << "/" << nomDirIt;
2954   MESSAGE (". DirCompute = " << DirCompute.str() );
2955
2956   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2957 #ifndef WIN32
2958   if (chdir(DirCompute.str().c_str()) != 0)
2959   {
2960     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2961 #else
2962   if (_chdir(DirCompute.str().c_str()) != 0)
2963   {
2964     if (_mkdir(DirCompute.str().c_str()) != 0)
2965 #endif
2966     {
2967        // GERALD -- QMESSAGE BOX
2968        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2969        VERIFICATION("Pb a la creation du repertoire" == 0);
2970     }
2971   }
2972   else
2973   {
2974 //  Le repertoire existe
2975 //  On demande de faire le menage de son contenu :
2976     if (etatMenage == 1)
2977     {
2978       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2979       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2980       int codret = system(commande.c_str());
2981       if (codret != 0)
2982       {
2983         // GERALD -- QMESSAGE BOX
2984         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2985         VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2986       }
2987     }
2988 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2989     else
2990     {
2991       if (etatMenage == 0)
2992       {
2993 #ifndef WIN32
2994         DIR *dp;
2995         struct dirent *dirp;
2996         dp  = opendir(DirCompute.str().c_str());
2997         bool result = true;
2998         while ((dirp = readdir(dp)) != NULL && result )
2999         {
3000           std::string file_name(dirp->d_name);
3001           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3002         }
3003         closedir(dp);
3004 #else
3005        HANDLE hFind = INVALID_HANDLE_VALUE;
3006        WIN32_FIND_DATA ffd;
3007        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3008        bool result = true;
3009        if (INVALID_HANDLE_VALUE != hFind) {
3010          while (FindNextFile(hFind, &ffd) != 0) {
3011           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3012           std::string file_name(ffd.cFileName);
3013           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3014          }
3015        }
3016        FindClose(hFind);
3017 #endif
3018         if ( result == false)
3019         {
3020           SALOME::ExceptionStruct es;
3021           es.type = SALOME::BAD_PARAM;
3022           std::string text = "Directory : " + DirCompute.str() + " is not empty";
3023           es.text = CORBA::string_dup(text.c_str());
3024           throw SALOME::SALOME_Exception(es);
3025           VERIFICATION("Directory is not empty" == 0);
3026         }
3027       }
3028     }
3029   }
3030
3031   return CORBA::string_dup( DirCompute.str().c_str() );
3032 }
3033 //=============================================================================
3034 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
3035 //=============================================================================
3036 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3037 {
3038   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
3039   // Le repertoire du cas
3040   const char* nomDirCase = myCase->GetDirName();
3041   MESSAGE ( ". nomDirCase = " << nomDirCase );
3042
3043   // Le sous-repertoire de l'iteration precedente
3044
3045   const char* nomIterationParent = myIteration->GetIterParentName();
3046   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
3047   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3048   std::stringstream DirComputePa ;
3049   DirComputePa << nomDirCase << "/" << nomDirItPa;
3050   MESSAGE( ". nomDirItPa = " << nomDirItPa);
3051   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3052
3053   return CORBA::string_dup( DirComputePa.str().c_str() );
3054 }
3055 //=============================================================================
3056 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3057 //=============================================================================
3058 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3059 {
3060   MESSAGE ( "... DriverTexteZone" );
3061   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3062   int numberOfZonesx2 = ListZone->length();
3063   int NumZone ;
3064
3065   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3066   {
3067     std::string ZoneName = std::string((*ListZone)[iaux]);
3068     MESSAGE ( "... ZoneName = " << ZoneName);
3069     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3070     ASSERT(!CORBA::is_nil(myZone));
3071
3072     int ZoneType = myZone->GetType();
3073     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3074     int TypeUse = atoi( TypeUsestr.c_str() );
3075     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3076     NumZone = iaux/2 + 1 ;
3077     HOMARD::double_array* zone = myZone->GetCoords();
3078     if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3079     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3080     else if ( ZoneType == 4 ) // Cas d une sphere
3081     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3082     else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3083     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3084     else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3085     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3086     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3087     iaux += 1 ;
3088   }
3089   return ;
3090 }
3091 //=============================================================================
3092 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3093 //=============================================================================
3094 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3095 {
3096   MESSAGE ( "... DriverTexteField" );
3097 //  Le fichier du champ
3098   char* FieldFile = myIteration->GetFieldFile();
3099   MESSAGE ( ". FieldFile = " << FieldFile );
3100   if (strlen(FieldFile) == 0)
3101   {
3102     // GERALD -- QMESSAGE BOX
3103     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3104     VERIFICATION("The file for the field is not given." == 0);
3105   }
3106 //  Les caracteristiques d'instants du champ de pilotage
3107   int TimeStep = myIteration->GetTimeStep();
3108   MESSAGE( ". TimeStep = " << TimeStep );
3109   int Rank = myIteration->GetRank();
3110   MESSAGE( ". Rank = " << Rank );
3111 //  Les informations sur les champs
3112   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3113 //  Le nom
3114   const char* FieldName = aInfosHypo->FieldName;
3115 //  Les seuils
3116   int TypeThR = aInfosHypo->TypeThR;
3117   double ThreshR = aInfosHypo->ThreshR;
3118   int TypeThC = aInfosHypo->TypeThC;
3119   double ThreshC = aInfosHypo->ThreshC;
3120 //  Saut entre mailles ou non ?
3121   int UsField = aInfosHypo->UsField;
3122   MESSAGE( ". UsField = " << UsField );
3123 //  L'usage des composantes
3124   int UsCmpI = aInfosHypo->UsCmpI;
3125   MESSAGE( ". UsCmpI = " << UsCmpI );
3126 //
3127   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3128 //
3129 //  Les composantes
3130   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3131   int numberOfCompos = mescompo->length();
3132   MESSAGE( ". numberOfCompos = " << numberOfCompos );
3133   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3134   {
3135     std::string nomCompo = std::string((*mescompo)[NumeComp]);
3136     MESSAGE( "... nomCompo = " << nomCompo );
3137     myDriver->TexteCompo(NumeComp, nomCompo);
3138   }
3139   return ;
3140 }
3141 //=============================================================================
3142 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3143 // On ecrit dans l'ordre :
3144 //    1. la definition des frontieres
3145 //    2. les liens avec les groupes
3146 //    3. un entier resumant le type de comportement pour les frontieres
3147 //=============================================================================
3148 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3149 {
3150   MESSAGE ( "... DriverTexteBoundary" );
3151   // 1. Recuperation des frontieres
3152   std::list<std::string>  ListeBoundaryTraitees ;
3153   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3154   int numberOfitems = ListBoundaryGroupType->length();
3155   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3156   int BoundaryOption = 1 ;
3157   // 2. Parcours des frontieres pour ecrire leur description
3158   int NumBoundaryAnalytical = 0 ;
3159   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3160   {
3161     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3162     MESSAGE ( "... BoundaryName = " << BoundaryName);
3163     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3164     //      Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3165     int A_faire = 1 ;
3166     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3167     while (it != ListeBoundaryTraitees.end())
3168     {
3169       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3170       if ( BoundaryName == *it ) { A_faire = 0 ; }
3171       it++;
3172     }
3173     // 2.2. Ecriture de la frontiere
3174     if ( A_faire == 1 )
3175     {
3176       // 2.2.1. Caracteristiques de la frontiere
3177       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3178       ASSERT(!CORBA::is_nil(myBoundary));
3179       int BoundaryType = myBoundary->GetType();
3180       MESSAGE ( "... BoundaryType = " << BoundaryType );
3181       // 2.2.2. Ecriture selon le type
3182       // 2.2.2.1. Cas d une frontiere discrete
3183       if (BoundaryType == 0)
3184       {
3185         const char* MeshName = myBoundary->GetMeshName() ;
3186         const char* MeshFile = myBoundary->GetMeshFile() ;
3187         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3188         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3189       }
3190       // 2.2.2.1. Cas d une frontiere analytique
3191       else
3192       {
3193         NumBoundaryAnalytical++ ;
3194         HOMARD::double_array* coor = myBoundary->GetCoords();
3195         if (BoundaryType == 1) // Cas d un cylindre
3196         {
3197           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3198           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3199         }
3200         else if (BoundaryType == 2) // Cas d une sphere
3201         {
3202           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3203           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3204         }
3205         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3206         {
3207           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3208           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3209         }
3210         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3211         {
3212           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3213           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3214         }
3215         else if (BoundaryType == 5) // Cas d un tore
3216         {
3217           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3218           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3219         }
3220       }
3221       // 2.2.3. Memorisation du traitement
3222       ListeBoundaryTraitees.push_back( BoundaryName );
3223     }
3224   }
3225   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3226   NumBoundaryAnalytical = 0 ;
3227   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3228   {
3229     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3230     MESSAGE ( "... BoundaryName = " << BoundaryName);
3231     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3232     ASSERT(!CORBA::is_nil(myBoundary));
3233     int BoundaryType = myBoundary->GetType();
3234     MESSAGE ( "... BoundaryType = " << BoundaryType );
3235     // 3.1. Recuperation du nom du groupe
3236     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3237     MESSAGE ( "... GroupName = " << GroupName);
3238     // 3.2. Cas d une frontiere discrete
3239     if ( BoundaryType == 0 )
3240     {
3241       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3242     }
3243     // 3.3. Cas d une frontiere analytique
3244     else
3245     {
3246       NumBoundaryAnalytical++ ;
3247       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3248     }
3249   }
3250   // 4. Ecriture de l'option finale
3251   myDriver->TexteBoundaryOption(BoundaryOption);
3252 //
3253   return ;
3254 }
3255 //=============================================================================
3256 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3257 //=============================================================================
3258 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3259 {
3260   MESSAGE ( "... DriverTexteFieldInterp" );
3261   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3262   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3263   if (TypeFieldInterp != 0)
3264   {
3265 //  Le fichier des champs
3266     char* FieldFile = myIteration->GetFieldFile();
3267     MESSAGE ( ". FieldFile = " << FieldFile );
3268     if (strlen(FieldFile) == 0)
3269     {
3270       // GERALD -- QMESSAGE BOX
3271       VERIFICATION("The file for the field is not given." == 0);
3272     }
3273   //
3274     const char* MeshFile = myIteration->GetMeshFile();
3275     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3276
3277   // Les champs
3278   // Interpolation de tous les champs
3279     if ( TypeFieldInterp == 1 )
3280     {
3281       myDriver->TexteFieldInterpAll();
3282     }
3283   // Interpolation de certains champs
3284     else if (TypeFieldInterp == 2)
3285     {
3286       // Les champs et leurs instants pour l'iteration
3287       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3288       int numberOfFieldsx3 = ListFieldTSR->length();
3289       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3290       // Les champs pour l'hypothese
3291       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3292       int numberOfFieldsx2 = ListField->length();
3293       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3294       // On parcourt tous les champs de  l'hypothese
3295       int NumField = 0 ;
3296       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3297       {
3298         // Le nom du champ
3299         std::string FieldName = std::string((*ListField)[iaux]) ;
3300         // Le type d'interpolation
3301         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3302         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3303         // On cherche à savoir si des instants ont été précisés pour cette itération
3304         int tsrvu = 0;
3305         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3306         {
3307         // Le nom du champ
3308           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3309           MESSAGE( "..... FieldName2 = " << FieldName2 );
3310         // Quand c'est le bon champ, on ecrit le pas de temps
3311           if ( FieldName == FieldName2 )
3312           {
3313             tsrvu = 1 ;
3314             // Le pas de temps
3315             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3316             // Le numero d'ordre
3317             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3318             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3319             NumField += 1 ;
3320             int TimeStep = atoi( TimeStepstr.c_str() );
3321             int Rank = atoi( Rankstr.c_str() );
3322             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3323           }
3324           jaux += 2 ;
3325         }
3326         // Si aucun instant n'a été défini
3327         if ( tsrvu == 0 )
3328         {
3329           NumField += 1 ;
3330           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3331         }
3332         iaux++ ;
3333       }
3334     }
3335   }
3336   return ;
3337 }
3338 //===========================================================================
3339 //===========================================================================
3340
3341
3342 //===========================================================================
3343 //===========================================================================
3344 // Publications
3345 //===========================================================================
3346 //===========================================================================
3347 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3348                                                    SALOMEDS::SObject_ptr theSObject,
3349                                                    CORBA::Object_ptr theObject,
3350                                                    const char* theName)
3351 {
3352   MESSAGE("PublishInStudy pour " << theName);
3353   SALOMEDS::SObject_var aResultSO;
3354   if (CORBA::is_nil(theStudy))
3355   {
3356     SALOME::ExceptionStruct es;
3357     es.type = SALOME::BAD_PARAM;
3358     es.text = "Invalid study context";
3359     throw SALOME::SALOME_Exception(es);
3360     return 0;
3361   };
3362
3363 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3364 // Rq : Iteration est publiee ailleurs
3365   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3366   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3367   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3368   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3369   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3370
3371    addInStudy(theStudy);
3372
3373 // Controle de la non publication d'un objet de meme nom
3374    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3375   {
3376     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3377     if (listSO->length() >= 1)
3378     {
3379       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3380       aResultSO = listSO[0];
3381       return aResultSO._retn();
3382     }
3383   }
3384
3385   // Caracteristiques de l'etude
3386   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3387   aStudyBuilder->NewCommand();
3388   if(!aBoundary->_is_nil())
3389     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3390   else if(!aCase->_is_nil())
3391     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3392   else if(!aHypo->_is_nil())
3393     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3394   else if(!aYACS->_is_nil())
3395     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3396   else if(!aZone->_is_nil())
3397     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3398
3399   aStudyBuilder->CommitCommand();
3400
3401   return aResultSO._retn();
3402 };
3403 //=============================================================================
3404 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3405                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3406                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3407 {
3408   MESSAGE("PublishBoundaryStudy pour "<<theName);
3409   SALOMEDS::SObject_var aResultSO;
3410
3411   // Caracteristique de la Boundary
3412   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3413
3414   // On recupere le module pere dans l etude
3415   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3416   if (theFatherHomard->_is_nil())
3417   {
3418     MESSAGE("theFatherHomard->_is_nil()");
3419     return aResultSO._retn();
3420   }
3421
3422   // On ajoute la categorie des boundarys dans l etude si necessaire
3423   if ( _tag_boun == 0 )
3424   {
3425     _tag_gene += 1 ;
3426     _tag_boun = _tag_gene ;
3427   }
3428   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3429   SALOMEDS::SObject_var aSObject;
3430   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3431   {
3432     MESSAGE("Ajout de la categorie des boundarys");
3433     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3434     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3435   }
3436   else { MESSAGE("La categorie des boundarys existe deja."); }
3437
3438   CORBA::Long BoundaryType = myBoundary->GetType();
3439 //   MESSAGE("BoundaryType : "<<BoundaryType);
3440   std::string icone ;
3441   std::string value ;
3442   switch (BoundaryType)
3443   {
3444     case 0 :
3445     { value = "BoundaryDiHomard" ;
3446       icone = "mesh_tree_mesh.png" ;
3447       break;
3448     }
3449     case 1 :
3450     { value = "BoundaryAnHomard" ;
3451       icone = "cylinderpointvector_2.png" ;
3452       break;
3453     }
3454     case 2 :
3455     { value = "BoundaryAnHomard" ;
3456       icone = "spherepoint_2.png" ;
3457       break;
3458     }
3459     case 3 :
3460     { value = "BoundaryAnHomard" ;
3461       icone = "conepointvector.png" ;
3462       break;
3463     }
3464     case 4 :
3465     { value = "BoundaryAnHomard" ;
3466       icone = "conedxyz.png" ;
3467       break;
3468     }
3469     case 5 :
3470     { value = "BoundaryAnHomard" ;
3471       icone = "toruspointvector.png" ;
3472       break;
3473     }
3474   }
3475   aResultSO = aStudyBuilder->NewObject(aSObject);
3476   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3477   return aResultSO._retn();
3478 }
3479 //=============================================================================
3480 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3481                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3482                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3483 {
3484   MESSAGE("PublishCaseInStudy pour "<<theName);
3485   SALOMEDS::SObject_var aResultSO;
3486
3487   if (CORBA::is_nil(theObject)) {
3488     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3489     return aResultSO._retn();
3490   }
3491   if (theStudy->_is_nil()) {
3492     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3493     return aResultSO._retn();
3494   }
3495
3496   // On recupere le module pere dans l etude
3497   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3498   if (theFatherHomard->_is_nil())
3499   {
3500     MESSAGE("theFatherHomard->_is_nil()");
3501     return aResultSO._retn();
3502   }
3503
3504   _tag_gene += 1 ;
3505   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3506   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3507   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3508                      _orb->object_to_string(theObject) ) ;
3509
3510   return aResultSO._retn();
3511 }
3512 //=============================================================================
3513 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3514                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3515                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3516 {
3517   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3518   SALOMEDS::SObject_var aResultSO;
3519
3520   // On recupere le module pere dans l etude
3521   // On ajoute la categorie des hypotheses dans l etude si necessaire
3522   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3523   if (theFatherHomard->_is_nil())
3524   {
3525     MESSAGE("theFatherHomard->_is_nil()");
3526     return aResultSO._retn();
3527   }
3528
3529   // On ajoute la categorie des hypotheses dans l etude si necessaire
3530   SALOMEDS::SObject_var aSObject;
3531   if ( _tag_hypo == 0 )
3532   {
3533     _tag_gene += 1 ;
3534     _tag_hypo = _tag_gene ;
3535   }
3536   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3537   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3538   {
3539     MESSAGE("Ajout de la categorie des hypotheses");
3540     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3541     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3542   }
3543   else { MESSAGE("La categorie des hypotheses existe deja."); }
3544
3545 // Creation du resultat dans l'etude
3546   aResultSO = aStudyBuilder->NewObject(aSObject);
3547   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3548
3549   return aResultSO._retn();
3550 }
3551 //=============================================================================
3552 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3553                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3554                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3555 {
3556   MESSAGE("PublishYACSInStudy pour "<<theName);
3557   SALOMEDS::SObject_var aResultSO;
3558
3559   // On recupere le module pere dans l etude
3560   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3561   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3562   if (theFatherHomard->_is_nil())
3563   {
3564     MESSAGE("theFatherHomard->_is_nil()");
3565     return aResultSO._retn();
3566   }
3567   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3568   if ( _tag_yacs == 0 )
3569   {
3570     _tag_gene += 1 ;
3571     _tag_yacs = _tag_gene ;
3572   }
3573   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3574   SALOMEDS::SObject_var aSObject;
3575   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3576   {
3577     MESSAGE("Ajout de la categorie des schemas YACS");
3578     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3579     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3580   }
3581   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3582
3583 // Creation du resultat dans l'etude
3584   aResultSO = aStudyBuilder->NewObject(aSObject);
3585   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3586
3587   return aResultSO._retn();
3588 }
3589
3590 //=============================================================================
3591 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3592                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3593                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3594 {
3595   MESSAGE("PublishZoneStudy pour "<<theName);
3596   SALOMEDS::SObject_var aResultSO;
3597   if (CORBA::is_nil(theObject))
3598   {
3599     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3600     return aResultSO._retn();
3601   }
3602   if (theStudy->_is_nil())
3603   {
3604     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3605     return aResultSO._retn();
3606   }
3607   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3608   if (theFatherHomard->_is_nil())
3609   {
3610     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3611     return aResultSO._retn();
3612   }
3613
3614   // Caracteristique de la zone
3615   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3616   CORBA::Long ZoneType = myZone->GetType();
3617
3618   // On ajoute la categorie des zones dans l etude si necessaire
3619   if ( _tag_zone == 0 )
3620   {
3621     _tag_gene += 1 ;
3622     _tag_zone = _tag_gene ;
3623   }
3624   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3625   SALOMEDS::SObject_var aSObject;
3626   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3627   {
3628     MESSAGE("Ajout de la categorie des zones");
3629     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3630     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3631   }
3632   else { MESSAGE("La categorie des zones existe deja."); }
3633
3634   aResultSO = aStudyBuilder->NewObject(aSObject);
3635   std::string icone ;
3636   switch (ZoneType)
3637   {
3638     case 11 :
3639     { }
3640     case 12 :
3641     { }
3642     case 13 :
3643     { icone = "boxdxy_2.png" ;
3644       break ;
3645     }
3646     case 2 :
3647     { icone = "boxdxyz_2.png" ;
3648       break ;
3649     }
3650     case 31 :
3651     { }
3652     case 32 :
3653     { }
3654     case 33 :
3655     { icone = "disk_2.png" ;
3656       break ;
3657      }
3658     case 4 :
3659     { icone = "spherepoint_2.png" ;
3660       break ;
3661     }
3662     case 5 :
3663     { icone = "cylinderpointvector_2.png" ;
3664       break ;
3665     }
3666     case 61 :
3667     { }
3668     case 62 :
3669     { }
3670     case 63 :
3671     { icone = "diskwithhole_2.png" ;
3672       break ;
3673      }
3674     case 7 :
3675     { icone = "pipe_2.png" ;
3676       break ;
3677     }
3678   }
3679   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3680
3681   return aResultSO._retn();
3682 }
3683 //===========================================================================
3684 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3685                                       SALOMEDS::SObject_var aResultSO,
3686                                       const char* name, const char* comment, const char* icone, const char* ior)
3687 {
3688   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3689 //   MESSAGE("icone = "<<icone);
3690 //   MESSAGE("ior   = "<<ior);
3691   SALOMEDS::GenericAttribute_var anAttr ;
3692 //  Ajout du nom
3693   if ( name != NULL )
3694   {
3695     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3696     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3697     aNameAttrib->SetValue(name);
3698   }
3699
3700 //  Ajout du commentaire
3701   if ( comment != NULL )
3702   {
3703     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3704     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3705     aCommentAttrib->SetValue(comment);
3706   }
3707
3708 //  Ajout de l'icone
3709   if ( icone != NULL  )
3710   {
3711     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3712     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3713     aPixmap->SetPixMap(icone);
3714   }
3715
3716 //  Ajout de l ior
3717   if ( ior != NULL  )
3718   {
3719     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3720     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3721     anIOR->SetValue(ior);
3722   }
3723 };
3724
3725 //=====================================================================================
3726 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3727 {
3728   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3729
3730   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3731   ASSERT(!CORBA::is_nil(myCase));
3732   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3733   ASSERT(!CORBA::is_nil(aCaseSO));
3734
3735   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3736   ASSERT(!CORBA::is_nil(myBoundary));
3737   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3738   ASSERT(!CORBA::is_nil(aBoundarySO));
3739
3740   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3741
3742   aStudyBuilder->NewCommand();
3743
3744   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3745   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3746 //   aStudyBuilder->RemoveReference(aSubSO);
3747
3748   aStudyBuilder->CommitCommand();
3749
3750 };
3751 //=====================================================================================
3752 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3753 {
3754   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3755
3756   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3757   ASSERT(!CORBA::is_nil(myYACS));
3758   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3759   ASSERT(!CORBA::is_nil(aYACSSO));
3760
3761   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3762   ASSERT(!CORBA::is_nil(myCase));
3763   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3764   ASSERT(!CORBA::is_nil(aCaseSO));
3765
3766   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3767
3768   aStudyBuilder->NewCommand();
3769
3770   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3771   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3772
3773   aStudyBuilder->CommitCommand();
3774
3775 };
3776 //=============================================================================
3777 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3778 //  Option = 0 : fichier issu d'une importation
3779 //  Option = 1 : fichier issu d'une execution HOMARD
3780 {
3781   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3782   if (CORBA::is_nil(myCurrentStudy))
3783   {
3784     SALOME::ExceptionStruct es;
3785     es.type = SALOME::BAD_PARAM;
3786     es.text = "Invalid study context";
3787     throw SALOME::SALOME_Exception(es);
3788     return ;
3789   };
3790
3791 // Le module SMESH est-il actif ?
3792   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3793 //
3794   if (!CORBA::is_nil(aSmeshSO))
3795   {
3796 // On verifie que le fichier n est pas deja publie
3797     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3798     for (; aIter->More(); aIter->Next())
3799     {
3800       SALOMEDS::SObject_var  aSO = aIter->Value();
3801       SALOMEDS::GenericAttribute_var aGAttr;
3802       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3803       {
3804         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3805         CORBA::String_var value=anAttr->Value();
3806         if (strcmp((const char*)value,NomFich) == 0)
3807         {
3808           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3809           // Pour un fichier importe, on ne republie pas
3810           if ( Option == 0 ) { return; }
3811           // Pour un fichier calcule, on commence par faire la depublication
3812           else
3813           {
3814             MESSAGE ( "PublishResultInSmesh : depublication" );
3815             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3816             CORBA::String_var value2=anAttr2->Value();
3817             std::string MeshName = string(value2) ;
3818             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3819             DeleteResultInSmesh(NomFich, MeshName) ;
3820           }
3821         }
3822       }
3823     }
3824   }
3825
3826 // On enregistre le fichier
3827   MESSAGE( "Enregistrement du fichier");
3828   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3829   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3830   ASSERT(!CORBA::is_nil(aSmeshEngine));
3831   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3832   SMESH::DriverMED_ReadStatus theStatus;
3833   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3834
3835 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3836   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3837   for (int i = 0; i < mesMaillages->length();  i++)
3838   {
3839     MESSAGE( ". Mise a jour des attributs du maillage");
3840     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3841     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3842     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3843     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3844     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3845     anAttr->SetValue(NomFich);
3846     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3847     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3848     const char* icone ;
3849     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3850     else               { icone = "mesh_tree_mesh.png" ; }
3851     anAttr2->SetPixMap( icone );
3852   }
3853
3854 }
3855 //=============================================================================
3856 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3857 {
3858   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3859   if (CORBA::is_nil(myCurrentStudy))
3860   {
3861       SALOME::ExceptionStruct es;
3862       es.type = SALOME::BAD_PARAM;
3863       es.text = "Invalid study context";
3864       throw SALOME::SALOME_Exception(es);
3865       return ;
3866   };
3867
3868 // Le module SMESH est-il actif ?
3869   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3870 //
3871   if (CORBA::is_nil(aSmeshSO))
3872   {
3873       return ;
3874   };
3875 // On verifie que le fichier est deja publie
3876   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3877   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3878   for (; aIter->More(); aIter->Next())
3879   {
3880      SALOMEDS::SObject_var  aSO = aIter->Value();
3881      SALOMEDS::GenericAttribute_var aGAttr;
3882      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3883      {
3884        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3885        CORBA::String_var value=anAttr->Value();
3886        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3887        {
3888          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3889          {
3890            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3891            CORBA::String_var value2=anAttr2->Value();
3892            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3893            {
3894              myBuilder->RemoveObjectWithChildren( aSO ) ;
3895            }
3896          }
3897        }
3898      }
3899   }
3900   return ;
3901 }
3902 //=============================================================================
3903 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3904 {
3905   MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3906   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3907
3908   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3909   if (CORBA::is_nil(myIteration))
3910   {
3911       SALOME::ExceptionStruct es;
3912       es.type = SALOME::BAD_PARAM;
3913       es.text = "Invalid iterationStudy Object";
3914       throw SALOME::SALOME_Exception(es);
3915       return ;
3916   };
3917   const char* MeshFile = myIteration->GetMeshFile() ;
3918   const char* MeshName = myIteration->GetMeshName() ;
3919   CORBA::Long Option = -1 ;
3920   int etat = myIteration->GetState();
3921 // Iteration initiale
3922   if ( etat <= 0 )      { Option = 0 ; }
3923 // ou iteration calculee
3924   else if ( etat == 2 ) { Option = 1 ; }
3925 // Publication effective apres menage eventuel
3926   if ( Option >= 0 )
3927   {
3928     DeleteResultInSmesh(MeshFile, MeshName) ;
3929     PublishResultInSmesh(MeshFile, Option) ;
3930   }
3931
3932 }
3933 //=============================================================================
3934 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3935 {
3936 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3937   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3938
3939   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3940   if (CORBA::is_nil(myIteration))
3941   {
3942       SALOME::ExceptionStruct es;
3943       es.type = SALOME::BAD_PARAM;
3944       es.text = "Invalid iterationStudy Object";
3945       throw SALOME::SALOME_Exception(es);
3946       return ;
3947   };
3948
3949   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3950
3951   aStudyBuilder->NewCommand();
3952
3953   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3954 // Pour les fichiers med, on affiche une icone de maillage
3955 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3956 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3957   std::string icone ;
3958   std::string ior = " " ;
3959   if ( Commentaire[0] == 'I' )
3960   { icone = "med.png" ; }
3961   else
3962   { icone = "texte_2.png" ; }
3963   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3964
3965   aStudyBuilder->CommitCommand();
3966 }
3967 //
3968 //=============================================================================
3969 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3970 {
3971 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3972   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3973
3974   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3975   if (CORBA::is_nil(myYACS))
3976   {
3977       SALOME::ExceptionStruct es;
3978       es.type = SALOME::BAD_PARAM;
3979       es.text = "Invalid YACSStudy Object";
3980       throw SALOME::SALOME_Exception(es);
3981       return ;
3982   };
3983
3984   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3985
3986   aStudyBuilder->NewCommand();
3987
3988   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3989   std::string icone = "texte_2.png" ;
3990   std::string ior = " " ;
3991   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3992
3993   aStudyBuilder->CommitCommand();
3994 }
3995 //
3996 //=============================================================================
3997 //=============================================================================
3998 // YACS
3999 //=============================================================================
4000 //=============================================================================
4001 //=============================================================================
4002 // Creation d'un schema YACS
4003 // nomCas : nom du cas a traiter
4004 // FileName : nom du fichier contenant le script de lancement du calcul
4005 // DirName : le repertoire de lancement des calculs du schéma
4006 //=============================================================================
4007 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4008 {
4009   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4010   INFOS ( ". nomCas     : " << nomCas);
4011   INFOS ( ". ScriptFile : " << ScriptFile);
4012   INFOS ( ". DirName    : " << DirName);
4013   INFOS ( ". MeshFile   : " << MeshFile);
4014
4015   // A. Controle du nom :
4016   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
4017   {
4018     SALOME::ExceptionStruct es;
4019     es.type = SALOME::BAD_PARAM;
4020     es.text = "This schema YACS has already been defined.";
4021     throw SALOME::SALOME_Exception(es);
4022     return 0;
4023   }
4024
4025   // B. Creation de l'objet
4026   HOMARD::HOMARD_YACS_var myYACS = newYACS();
4027   if (CORBA::is_nil(myYACS))
4028   {
4029     SALOME::ExceptionStruct es;
4030     es.type = SALOME::BAD_PARAM;
4031     es.text = "Unable to create the schema YACS";
4032     throw SALOME::SALOME_Exception(es);
4033     return 0;
4034   };
4035   myYACS->SetName( nomYACS ) ;
4036
4037   // C. Enregistrement
4038   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
4039
4040   SALOMEDS::SObject_var aSO;
4041   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
4042
4043   PublishCaseUnderYACS(nomYACS, nomCas);
4044
4045   // D. Caracterisation
4046   // D.1. Options
4047   myYACS->SetDirName( DirName ) ;
4048   myYACS->SetMeshFile( MeshFile ) ;
4049   myYACS->SetScriptFile( ScriptFile ) ;
4050   myYACS->SetCaseName( nomCas ) ;
4051   // D.2. Defaut
4052   int defaut_i ;
4053   // D.2.1. Type constant
4054   myYACS->SetType( 1 ) ;
4055   // D.2.2. Convergence
4056   defaut_i = GetYACSMaxIter() ;
4057   myYACS->SetMaxIter( defaut_i ) ;
4058   defaut_i = GetYACSMaxNode() ;
4059   myYACS->SetMaxNode( defaut_i ) ;
4060   defaut_i = GetYACSMaxElem() ;
4061   myYACS->SetMaxElem( defaut_i ) ;
4062   // D.3. Fichier de sauvegarde dans le repertoire du cas
4063   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4064   std::string dirnamecase = caseyacs->GetDirName() ;
4065   std::string XMLFile ;
4066   XMLFile = dirnamecase + "/schema.xml" ;
4067   myYACS->SetXMLFile( XMLFile.c_str() ) ;
4068
4069   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4070 }
4071 //=============================================================================
4072 // Ecriture d'un schema YACS
4073 //=============================================================================
4074 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4075 {
4076   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4077 // Le repertoire du cas
4078   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4079   ASSERT(!CORBA::is_nil(myYACS));
4080 // Le nom du fichier du schema
4081   std::string XMLFile ;
4082   XMLFile = myYACS->GetXMLFile() ;
4083
4084   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4085
4086   return codret ;
4087 }
4088 //=============================================================================
4089 // Ecriture d'un schema YACS sur un fichier donne
4090 //=============================================================================
4091 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4092 {
4093   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4094
4095   // A. Prealable
4096   int codret = 0;
4097
4098   // B. L'objet YACS
4099   // B.1. L'objet
4100   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4101   ASSERT(!CORBA::is_nil(myYACS));
4102   // B.2. Les caracteristiques
4103   std::string DirName = myYACS->GetDirName() ;
4104   std::string MeshFile = myYACS->GetMeshFile() ;
4105   std::string ScriptFile = myYACS->GetScriptFile() ;
4106   // B.3. Les caracteristiques de convergence
4107   int MaxIter = myYACS->GetMaxIter() ;
4108   int MaxNode = myYACS->GetMaxNode() ;
4109   int MaxElem = myYACS->GetMaxElem() ;
4110
4111   // C. Le cas
4112   // C.1. L'objet cas
4113   const char* nomCas = myYACS->GetCaseName();
4114   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4115   ASSERT(!CORBA::is_nil(myCase));
4116   // C.2. Les instructions python associees au cas
4117   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4118   std::string pythonCas = dumpCorbaCase.in();
4119   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4120
4121   // D. Les iterations
4122   // D.1. L'iteration initiale
4123   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4124   std::string Iter0Name = myCase->GetIter0Name() ;
4125   MESSAGE (". Iter0Name = " << Iter0Name);
4126   std::string MeshName = Iter0->GetMeshName();
4127   MESSAGE (". MeshName = " << MeshName);
4128   // D.2. L'iteration numero 1
4129   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4130   int numberOfIter = maListe->length();
4131   if ( numberOfIter > 1 )
4132   {
4133     MESSAGE (". numberOfIter = " << numberOfIter);
4134     SALOME::ExceptionStruct es ;
4135     es.type = SALOME::BAD_PARAM;
4136     std::string text = "Une seule iteration est permise." ;
4137     es.text = CORBA::string_dup(text.c_str());
4138     throw SALOME::SALOME_Exception(es);
4139     return 0;
4140   }
4141   std::string Iter1Name = std::string((*maListe)[0]);
4142   MESSAGE ("... Iter1Name = " << Iter1Name);
4143   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4144   // D.3. Les instructions python associees a l'iteration
4145   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4146   std::string pythonIter = dumpCorbaIter.in();
4147   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4148
4149   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4150   // E.1. La structure
4151   std::string nomHypo = Iter1->GetHypoName();
4152   MESSAGE (". nomHypo = " << nomHypo);
4153   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4154   ASSERT(!CORBA::is_nil(myHypo));
4155   // E.2. Les caracteristiques de l'adaptation
4156   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4157   ASSERT(ListTypes->length() == 3);
4158   int TypeAdap = (*ListTypes)[0];
4159 //   int TypeRaff = (*ListTypes)[1];
4160 //   int TypeDera = (*ListTypes)[2];
4161   // E.3. Les instructions python associees a l'hypothese
4162   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4163   std::string pythonHypo = dumpCorbaHypo.in();
4164   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4165
4166   // F. Le fichier du schema de reference
4167   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4168   std::string XMLFile_base ;
4169   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4170   else
4171   {
4172     SALOME::ExceptionStruct es ;
4173     es.type = SALOME::BAD_PARAM;
4174     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4175     es.text = CORBA::string_dup(text.c_str());
4176     throw SALOME::SALOME_Exception(es);
4177     return 0;
4178   }
4179   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4180 //   if ( _Langue ==
4181   MESSAGE("XMLFile_base ="<<XMLFile_base);
4182
4183   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4184   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4185   std::ifstream fichier( XMLFile_base.c_str() );
4186   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4187   {
4188     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4189     std::string ligne; // variable contenant chaque ligne lue
4190     std::string mot_cle;
4191     while ( std::getline( fichier, ligne ) )
4192     {
4193       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4194       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4195       ligne_bis >> mot_cle ;
4196       // G.1.2. Le maillage initial
4197       if ( mot_cle == "DataInit_MeshFile" )
4198       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4199       // G.1.3. Le script de lancement
4200       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4201       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4202       // G.1.4. Les options du cas
4203       else if ( mot_cle == "Iter_1_Case_Options" )
4204       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4205       // G.1.5. Execution de HOMARD : le repertoire du cas
4206       else if ( mot_cle == "HOMARD_Exec_DirName" )
4207       { myDriver->Texte_HOMARD_Exec_DirName(); }
4208       // G.1.6. Execution de HOMARD : le nom du maillage
4209       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4210       {
4211         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4212         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4213         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4214       }
4215       // G.1.7. Execution de HOMARD : les options de l'hypothese
4216       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4217       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4218       // G.1.8. Execution de HOMARD : les options de l'iteration
4219       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4220       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4221       // G.1.9. Zones et frontieres : les creations
4222       else if ( mot_cle == "Iter_1" )
4223       {
4224         std::string texte_control = myDriver->Texte_Iter_1_control() ;
4225         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4226         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4227         myDriver->TexteAdd(texte_control);
4228       }
4229       // G.1.10. Les tests de convergence
4230       else if ( mot_cle == "Analyse_Test_Convergence" )
4231       { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4232       // G.1.11. Les parametres
4233       else if ( mot_cle == "PARAMETRES" )
4234       { myDriver->TexteAddParametres(); }
4235       // G.1.n. La ligne est recopiee telle quelle
4236       else { myDriver->TexteAdd(ligne);  }
4237     }
4238     // G.2. Ecriture du texte dans le fichier
4239     if ( codret == 0 )
4240     { myDriver->CreeFichier(); }
4241   }
4242   else
4243   {
4244     SALOME::ExceptionStruct es;
4245     es.type = SALOME::BAD_PARAM;
4246     std::string text = "The reference file for the YACS schema cannot be read." ;
4247     es.text = CORBA::string_dup(text.c_str());
4248     throw SALOME::SALOME_Exception(es);
4249   }
4250
4251   delete myDriver;
4252
4253   // H. Publication du fichier dans l'arbre
4254
4255     std::string Commentaire = "xml" ;
4256     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4257
4258   return codret ;
4259 }
4260 //=============================================================================
4261 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4262 //=============================================================================
4263 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4264 {
4265   MESSAGE ( "YACSDriverTexteZone" );
4266   // A. Les zones associees a cette hypothese
4267   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4268   int numberOfZonesx2 = ListZone->length();
4269
4270   // B. Parcours des zones
4271   std::string texte_control ;
4272   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4273   {
4274     // 1. Reperage de la zone
4275     std::string ZoneName = std::string((*ListZone)[iaux]);
4276     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4277     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4278     ASSERT(!CORBA::is_nil(myZone));
4279     // 2. Les instructions python associees a la zone
4280     //    La premiere ligne est un commentaire a eliminer
4281     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4282     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4283     std::string pythonStructure_0 = dumpCorbaZone.in();
4284     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4285     std::istringstream tout (pythonStructure_0) ;
4286     std::string ligne ;
4287     std::string pythonStructure ;
4288     while ( std::getline( tout, ligne ) )
4289     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4290     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4291     // 3. Decodage du nom du service
4292     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4293     MESSAGE ( "... methode = " << methode);
4294     // 4. Mise en place des instructions
4295     int ZoneType = myZone->GetType();
4296     MESSAGE ( "... ZoneType = " << ZoneType);
4297     std::string texte_control_0 ;
4298     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4299     texte_control += texte_control_0 ;
4300     // 5. Decalage
4301     iaux ++ ;
4302   }
4303
4304   return texte_control ;
4305 }
4306 //=============================================================================
4307 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4308 //=============================================================================
4309 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4310 {
4311   MESSAGE ( "YACSDriverTexteBoundary" );
4312   // A. Les frontieres associees au cas
4313   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4314   int numberOfitems = ListBoundaryGroupType->length();
4315
4316   // B. Parcours des frontieres
4317   std::string texte_control ;
4318   std::list<std::string>  ListeBoundaryTraitees ;
4319   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4320   {
4321     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4322     MESSAGE ( "... BoundaryName = " << BoundaryName);
4323     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4324     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4325     int A_faire = 1 ;
4326     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4327     while (it != ListeBoundaryTraitees.end())
4328     {
4329       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4330       if ( BoundaryName == *it ) { A_faire = 0 ; }
4331       it++;
4332     }
4333     if ( A_faire == 1 )
4334     {
4335     // 1. Caracteristiques de la frontiere
4336       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4337       ASSERT(!CORBA::is_nil(myBoundary));
4338       // 2. Les instructions python associees a la frontiere
4339       //    La premiere ligne est un commentaire a eliminer
4340       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4341       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4342       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4343       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4344       std::istringstream tout (pythonStructure_0) ;
4345       std::string ligne ;
4346       std::string pythonStructure ;
4347       while ( std::getline( tout, ligne ) )
4348       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4349       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4350       // 3. Decodage du nom du service
4351       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4352       MESSAGE ( "... methode = " << methode);
4353       // 4. Mise en place des instructions
4354       int BoundaryType = myBoundary->GetType();
4355       MESSAGE ( "... BoundaryType = " << BoundaryType);
4356       std::string texte_control_0 ;
4357       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4358       texte_control += texte_control_0 ;
4359       // 5. Memorisation du traitement
4360       ListeBoundaryTraitees.push_back( BoundaryName );
4361     }
4362   }
4363
4364   return texte_control ;
4365 }
4366 //
4367 //=============================================================================
4368 //=============================================================================
4369 // Next functions are inherited from SALOMEDS::Driver interface
4370 //=============================================================================
4371 //=============================================================================
4372 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4373                                       const char* theURL,
4374                                       CORBA::Boolean isMultiFile)
4375 {
4376   MESSAGE ("Save for theURL = "<< theURL);
4377   SALOMEDS::TMPFile_var aStreamFile;
4378
4379   // get temporary directory name
4380   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4381
4382   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4383   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4384
4385   // HOMARD data file name
4386   std::string aFileName = "";
4387   if (isMultiFile)
4388     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4389   aFileName += "_HOMARD.dat";
4390
4391   // initialize sequence of file names
4392   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4393   aFileSeq->length(1);
4394   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4395
4396   // get full path to the data file
4397   aFileName = tmpDir + aFileName;
4398
4399   // save data
4400   // -> create file
4401   std::ofstream f(aFileName.c_str());
4402
4403   // clear temporary id map
4404   context._idmap.clear();
4405
4406   int id = 1;
4407
4408   // -> save cases
4409   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4410   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4411     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4412     PortableServer::ServantBase_var aServant = GetServant(aCas);
4413     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4414     if (aCasServant) {
4415       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4416       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4417     }
4418   }
4419   // -> save zones
4420   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4421   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4422     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4423     PortableServer::ServantBase_var aServant = GetServant(aZone);
4424     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4425     if (aZoneServant) {
4426       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4427       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4428     }
4429   }
4430   // -> save hypotheses
4431   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4432   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4433     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4434     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4435     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4436     if (aHypoServant) {
4437       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4438       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4439     }
4440   }
4441   // -> save iterations
4442   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4443   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4444     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4445     PortableServer::ServantBase_var aServant = GetServant(aIter);
4446     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4447     if (aIterServant) {
4448       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4449       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4450     }
4451   }
4452   // -> save boundaries
4453   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4454   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4455     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4456     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4457     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4458     if (aBoundaryServant) {
4459       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4460       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4461     }
4462   }
4463   // -> close file
4464   MESSAGE ("close file");
4465   f.close();
4466
4467   // put temporary files to the stream
4468   MESSAGE ("put temporary files to the stream");
4469   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4470
4471   // remove temporary files
4472   MESSAGE ("remove temporary files");
4473   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4474
4475   // return data stream
4476   MESSAGE ("return data stream");
4477   return aStreamFile._retn();
4478 };
4479
4480 //===========================================================================
4481 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4482                                            const char* theURL,
4483                                            CORBA::Boolean isMultiFile)
4484 {
4485   // No specific ASCII persistence
4486   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4487   return aStreamFile._retn();
4488 };
4489
4490 //===========================================================================
4491 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4492                                    const SALOMEDS::TMPFile& theStream,
4493                                    const char* theURL,
4494                                    CORBA::Boolean isMultiFile)
4495 {
4496   MESSAGE ("Load pour theURL = "<< theURL);
4497   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4498
4499   // set current study
4500   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4501     SetCurrentStudy(aStudy);
4502
4503   // get temporary directory name
4504   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4505
4506   // Convert the stream into sequence of files to process
4507   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4508                                                                             tmpDir.c_str(),
4509                                                                             isMultiFile);
4510   // HOMARD data file name
4511   std::string aFileName = "";
4512   if (isMultiFile)
4513     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4514   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4515
4516   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4517
4518   // save data
4519   // -> create file
4520   std::ifstream f(aFileName.c_str());
4521
4522   // clear context
4523   context._mesCas.clear();
4524   context._mesHypotheses.clear();
4525   context._mesIterations.clear();
4526   context._mesZones.clear();
4527   context._mesBoundarys.clear();
4528   context._idmap.clear();
4529
4530   int id = 1;
4531   std::string line;
4532
4533   while (f) {
4534     std::getline(f, line);
4535     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4536     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4537     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4538     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4539     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4540     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4541     if (line.substr(0, bounSignature.size()) == bounSignature) {
4542       // re-create boundary
4543       MESSAGE ("Recreation de la frontiere" );
4544       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4545       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4546       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4547       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4548         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4549         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4550       }
4551     }
4552     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4553       // re-create case
4554       MESSAGE ("Recreation du cas" );
4555       HOMARD::HOMARD_Cas_var aCase = newCase();
4556       PortableServer::ServantBase_var aServant = GetServant(aCase);
4557       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4558       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4559         context._mesCas[aCase->GetName()] = aCase;
4560         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4561       }
4562     }
4563     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4564       // re-create hypothesis
4565       MESSAGE ("Recreation de l hypothese" );
4566       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4567       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4568       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4569       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4570         context._mesHypotheses[aHypo->GetName()] = aHypo;
4571         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4572       }
4573     }
4574     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4575       // re-create iteration
4576       MESSAGE ("Recreation de l'iteration" );
4577       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4578       PortableServer::ServantBase_var aServant = GetServant(aIter);
4579       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4580       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4581         context._mesIterations[aIter->GetName()] = aIter;
4582         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4583       }
4584     }
4585     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4586       MESSAGE ("Recreation de la zone" );
4587       // re-create zone
4588       HOMARD::HOMARD_Zone_var aZone = newZone();
4589       PortableServer::ServantBase_var aServant = GetServant(aZone);
4590       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4591       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4592         context._mesZones[aZone->GetName()] = aZone;
4593         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4594       }
4595     }
4596     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4597       MESSAGE ("Recreation du schema YACS" );
4598       // re-create YACS
4599       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4600       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4601       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4602       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4603         context._mesYACSs[aYACS->GetName()] = aYACS;
4604         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4605       }
4606     }
4607     id++;
4608   }
4609
4610   // -> close file
4611   f.close();
4612
4613   // Remove temporary files created from the stream
4614   if (!isMultiFile)
4615     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4616
4617   return true;
4618 };
4619
4620 //===========================================================================
4621 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4622                                         const SALOMEDS::TMPFile& theStream,
4623                                         const char* theURL,
4624                                         CORBA::Boolean isMultiFile)
4625 {
4626   // No specific ASCII persistence
4627   return Load(theComponent, theStream, theURL, isMultiFile);
4628 };
4629
4630 //===========================================================================
4631 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4632 {
4633   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4634     // clearing study context should be done here:
4635     // - destroy all servants and related CORBA objects
4636     // ... (TODO)
4637     // - remove context from myContextMap
4638     myContextMap.erase(theComponent->GetStudy()->StudyId());
4639     // - nullify myCurrentStudy
4640     myCurrentStudy = SALOMEDS::Study::_nil();
4641   }
4642 };
4643
4644 //===========================================================================
4645 char* HOMARD_Gen_i::ComponentDataType()
4646 {
4647   return CORBA::string_dup("HOMARD");
4648 };
4649
4650 //===========================================================================
4651 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4652                                             const char* IORString,
4653                                             CORBA::Boolean isMultiFile,
4654                                             CORBA::Boolean isASCII)
4655 {
4656   CORBA::String_var aString("");
4657   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4658     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4659     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4660     if (!CORBA::is_nil(anObj)) {
4661       PortableServer::ServantBase_var aServant = GetServant(anObj);
4662       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4663       if (aStorable) {
4664         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4665         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4666           if (it->second == aStorable) {
4667             std::stringstream os;
4668             os << it->first;
4669             aString = CORBA::string_dup(os.str().c_str());
4670           }
4671         }
4672       }
4673     }
4674   }
4675   return aString._retn();
4676 };
4677
4678 //===========================================================================
4679 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4680                                             const char* aLocalPersistentID,
4681                                             CORBA::Boolean isMultiFile,
4682                                             CORBA::Boolean isASCII)
4683 {
4684   CORBA::String_var aString("");
4685   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4686     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4687     int id = atoi(aLocalPersistentID);
4688     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4689       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4690       if (!CORBA::is_nil(object)) {
4691         aString = _orb->object_to_string(object);
4692       }
4693     }
4694   }
4695   return aString._retn();
4696 };
4697
4698 //===========================================================================
4699 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4700 {
4701   if(CORBA::is_nil(myCurrentStudy))
4702     return false;
4703
4704   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4705   if(!aCas->_is_nil())
4706     return true;
4707
4708   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4709   if(!aHypo->_is_nil())
4710     return true;
4711
4712   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4713   if(!aZone->_is_nil())
4714     return true;
4715
4716   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4717   if(!aBoundary->_is_nil())
4718     return true;
4719
4720   /* Iteration is not published directly
4721   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4722   if(!aIter->_is_nil())
4723     return true;
4724   */
4725   return false;
4726 };
4727
4728 //===========================================================================
4729 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4730 {
4731   // No Copy/Paste support
4732   return false;
4733 };
4734
4735 //===========================================================================
4736 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4737                                            CORBA::Long& theObjectID)
4738 {
4739   // No Copy/Paste support
4740   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4741   return aStreamFile._retn();
4742 };
4743
4744 //===========================================================================
4745 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4746                                         CORBA::Long theObjectID)
4747 {
4748   // No Copy/Paste support
4749   return false;
4750 };
4751
4752 //===========================================================================
4753 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4754                                                CORBA::Long theObjectID,
4755                                                SALOMEDS::SObject_ptr theSObject)
4756 {
4757   // No Copy/Paste support
4758   SALOMEDS::SObject_var aResultSO;
4759   return aResultSO._retn();
4760 };
4761
4762 //===========================================================================
4763 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4764 {
4765   PortableServer::Servant aServant = 0;
4766   if (!CORBA::is_nil(theObject)) {
4767     try {
4768       aServant = _poa->reference_to_servant(theObject);
4769     }
4770     catch (...) {
4771     }
4772   }
4773   return aServant;
4774 }
4775
4776 //==========================================================================
4777 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4778                                        CORBA::Boolean isPublished,
4779                                        CORBA::Boolean isMultiFile,
4780                                        CORBA::Boolean& isValidScript)
4781 {
4782    MESSAGE ("Entree dans DumpPython");
4783    isValidScript=1;
4784    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4785    if(CORBA::is_nil(aStudy))
4786      return new Engines::TMPFile(0);
4787
4788    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4789    if(CORBA::is_nil(aSO))
4790       return new Engines::TMPFile(0);
4791
4792    std::string aScript = "\"\"\"\n";
4793    aScript += "Python script for HOMARD\n";
4794    aScript += "Copyright EDF-R&D 1996, 2011, 2014\n";
4795    aScript += "\"\"\"\n";
4796    aScript += "__revision__ = \"V1.2\"\n";
4797    aScript += "import HOMARD\n";
4798    if( isMultiFile )
4799       aScript += "import salome\n";
4800    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4801    if( isMultiFile ) {
4802       aScript += "def RebuildData(theStudy):\n";
4803       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4804    }
4805    else
4806       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4807    MESSAGE (". Au depart \n"<<aScript);
4808
4809
4810    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4811    {
4812     MESSAGE (". Ecritures des frontieres");
4813     aScript += "#\n# Creation of the boundaries";
4814     aScript +=  "\n# ==========================";
4815    }
4816    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4817    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4818         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4819    {
4820     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4821     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4822     std::string dumpBoundary = dumpCorbaBoundary.in();
4823     MESSAGE (dumpBoundary<<"\n");
4824     aScript += dumpBoundary;
4825    }
4826
4827
4828    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4829    {
4830     MESSAGE (". Ecritures des zones");
4831     aScript += "#\n# Creation of the zones";
4832     aScript +=  "\n# =====================";
4833    }
4834    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4835    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4836          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4837    {
4838     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4839     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4840     std::string dumpZone = dumpCorbaZone.in();
4841     MESSAGE (dumpZone<<"\n");
4842     aScript += dumpZone;
4843    }
4844
4845
4846    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4847    {
4848     MESSAGE (". Ecritures des hypotheses");
4849     aScript += "#\n# Creation of the hypotheses";
4850     aScript +=  "\n# ==========================";
4851    }
4852    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4853    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4854          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4855    {
4856     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4857     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4858     std::string dumpHypo = dumpCorbaHypo.in();
4859     MESSAGE (dumpHypo<<"\n");
4860     aScript += dumpHypo;
4861    }
4862
4863
4864    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4865    {
4866     MESSAGE (". Ecritures des cas");
4867     aScript += "#\n# Creation of the cases";
4868     aScript += "\n# =====================";
4869    }
4870    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4871    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4872         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4873         {
4874            std::string nomCas = (*it_cas).first;
4875            std::string dumpCas = std::string("\n# Creation of the case ") ;
4876            dumpCas +=  nomCas + std::string("\n");
4877            dumpCas += std::string("\t") + nomCas;
4878            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4879
4880            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4881            CORBA::String_var cIter0= myCase->GetIter0Name();
4882            std::string iter0 = cIter0.in();
4883
4884            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4885            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4886            std::string mesh0 = cMesh0.in();
4887            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4888            std::string meshName0 = cMeshName0.in();
4889            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4890            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4891            std::string dumpCas2= dumpCorbaCase.in();
4892
4893            MESSAGE (dumpCas<<dumpCas2<<"\n");
4894            aScript += dumpCas + dumpCas2;
4895         };
4896
4897
4898    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4899    {
4900     MESSAGE (". Ecritures des iterations");
4901     aScript += "#\n# Creation of the iterations" ;
4902     aScript += "\n# ==========================";
4903    }
4904    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4905    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4906         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4907    {
4908     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4909     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4910     std::string dumpIter = dumpCorbaIter.in();
4911     MESSAGE (dumpIter<<"\n");
4912     aScript += dumpIter;
4913    }
4914
4915
4916    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4917    {
4918     MESSAGE (". Ecritures des schemas YACS");
4919     aScript += "#\n# Creation of the schemas YACS";
4920     aScript +=  "\n# ============================";
4921    }
4922    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4923    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4924          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4925    {
4926     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4927     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4928     std::string dumpYACS = dumpCorbaYACS.in();
4929     MESSAGE (dumpYACS<<"\n");
4930     aScript += dumpYACS;
4931    }
4932
4933   MESSAGE (". Ecritures finales");
4934   if( isMultiFile )
4935     aScript += "\n\tpass";
4936   aScript += "\n";
4937
4938   if( !isMultiFile ) // remove unnecessary tabulation
4939     aScript = RemoveTabulation( aScript );
4940
4941 //   MESSAGE ("A ecrire \n"<<aScript);
4942   const size_t aLen = strlen(aScript.c_str());
4943   char* aBuffer = new char[aLen+1];
4944   strcpy(aBuffer, aScript.c_str());
4945
4946   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4947   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4948
4949   MESSAGE ("Sortie de DumpPython");
4950   return aStreamFile._retn();
4951 }
4952
4953
4954 //=============================================================================
4955 //=============================================================================
4956 // Utilitaires
4957 //=============================================================================
4958 //=============================================================================
4959 void HOMARD_Gen_i::IsValidStudy( )
4960 {
4961 //   MESSAGE( "IsValidStudy" );
4962   if (CORBA::is_nil(myCurrentStudy))
4963   {
4964     SALOME::ExceptionStruct es;
4965     es.type = SALOME::BAD_PARAM;
4966     es.text = "Invalid study context";
4967     throw SALOME::SALOME_Exception(es);
4968   };
4969   return ;
4970 }
4971
4972 //=============================================================================
4973 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4974 {
4975   std::string casename = std::string("") ;
4976   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4977   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4978   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4979   {
4980    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4981    {
4982      casename = std::string(it->second->GetName()) ;
4983      break ;
4984    }
4985   }
4986   return CORBA::string_dup( casename.c_str() );
4987 }
4988 /*//=============================================================================
4989 void SALOMEException( std::string message )
4990 {
4991   SALOME::ExceptionStruct es;
4992   es.type = SALOME::BAD_PARAM;
4993   es.text = message;
4994   throw SALOME::SALOME_Exception(es);
4995   return ;
4996 }*/
4997 //=============================================================================
4998 char* HOMARD_Gen_i::getVersion()
4999 {
5000 #if HOMARD_DEVELOPMENT
5001   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5002 #else
5003   return CORBA::string_dup(HOMARD_VERSION_STR);
5004 #endif
5005 }
5006 //===============================================================================
5007 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5008 // ligne : la ligne a manipuler
5009 // caractere : le caractere a reperer
5010 // option : 0 : la chaine avant la premiere apparition du caractere
5011 //          1 : la chaine apres la premiere apparition du caractere
5012 //          2 : la chaine avant la derniere apparition du caractere
5013 //          3 : la chaine apres la derniere apparition du caractere
5014 // Si le caractere est absent, on retourne la chaine totale
5015 //===============================================================================
5016 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5017 {
5018 //   MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5019 //
5020   std::string chaine = ligne ;
5021   int position ;
5022   if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5023   else              { position = ligne.find_last_of( caractere ) ; }
5024 //   MESSAGE("position = "<<position);
5025 //   MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5026 //   MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5027 //
5028   if ( position != std::string::npos )
5029   {
5030     if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5031     else                                      { chaine = ligne.substr( position+1 ) ; }
5032   }
5033   return chaine ;
5034 //
5035 }
5036 //=============================================================================
5037 //=============================================================================
5038 // Gestion des preferences
5039 //=============================================================================
5040 //=============================================================================
5041 // Decodage du fichier d'arcihvage des preferences
5042 //
5043 void HOMARD_Gen_i::SetPreferences( )
5044 {
5045   MESSAGE ( "SetPreferences" );
5046
5047   std::string ligne, mot_cle, salome_version ;
5048   bool ok = true ;
5049
5050   // A. Les valeurs par defaut ; elles doivent etre coherentes
5051   std::string LanguageShort = "en" ;
5052   int PublisMeshIN = 0 ;
5053   int PublisMeshOUT = 0 ;
5054   int YACSMaxIter = 0 ;
5055   int YACSMaxNode = 0 ;
5056   int YACSMaxElem = 0 ;
5057   std::string YACSTypeTestchaine = "None" ;
5058
5059   // B. La version de salome
5060   // Cela se presente sous la forme :
5061   // [SALOME KERNEL] : 7.3.0
5062   std::string File ;
5063   File  = getenv("KERNEL_ROOT_DIR") ;
5064   File += "/bin/salome/VERSION" ;
5065   MESSAGE ( "File = "<<File ) ;
5066   std::ifstream fichier0( File.c_str() ) ;
5067   if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5068   {
5069     std::string ligne; // variable contenant chaque ligne lue
5070     while ( std::getline( fichier0, ligne ) )
5071     {
5072       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5073       ligne_bis >> mot_cle ;
5074       if ( mot_cle == "[SALOME" )
5075       {
5076         salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5077 //         MESSAGE ( "salome_version = "<<salome_version<<"|||");
5078         break ;
5079       }
5080     }
5081   }
5082   else { ok = false ; }
5083
5084   // B. Decodage du fichier de preferences
5085   if ( ok )
5086   {
5087     std::string PrefFile ;
5088     PrefFile  = getenv("HOME") ;
5089     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5090     MESSAGE ( "PrefFile = "<<PrefFile ) ;
5091
5092     std::ifstream fichier( PrefFile.c_str() );
5093     if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5094     {
5095       bool section_langue = false ;
5096       bool section_homard = false ;
5097       while ( std::getline( fichier, ligne ) )
5098       {
5099         std::string chaine ;
5100         // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5101         std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5102         ligne_bis >> mot_cle ;
5103
5104         // 2. Les sections
5105         // 2.1. Debut d'une section
5106   //       MESSAGE(mot_cle);
5107         if ( mot_cle == "<section" )
5108         { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5109           ligne_bis >> mot_cle ;
5110           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5111           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5112           if ( chaine == "language" ) { section_langue = true ; }
5113           if ( chaine == "HOMARD" )   { section_homard = true ; }
5114   //         MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5115         }
5116         // 2.2. Fin d'une section
5117         else if ( mot_cle == "</section>" )
5118         { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5119           section_langue = false ;
5120           section_homard = false ; }
5121
5122         // 3. Parametres
5123         // 3.1. La langue
5124         else if ( section_langue || section_homard )
5125         { MESSAGE ( "a decoder : "<< ligne);
5126 //        La valeur : entre les deux premieres quotes
5127           chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5128 //           MESSAGE("chaine 1 = |"<<chaine<<"|");
5129           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5130 //           MESSAGE("chaine = |"<<chaine<<"|");
5131 //        Le mot_cle : entre les deux dernieres quotes
5132           std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5133 //           MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5134           chaine2 = GetStringInTexte ( chaine2,  "\"", 3 ) ;
5135 //           MESSAGE("chaine2 = |"<<chaine2<<"|");
5136           // 3.1. La langue
5137           if ( section_langue )
5138           { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5139           // 3.2. HOMARD
5140           if ( section_homard )
5141           {
5142             std::istringstream chainebis( chaine ) ;
5143             // 3.2.1. Les publications
5144             if ( chaine2 == "publish_mesh_in" )  { chainebis >> PublisMeshIN ; }
5145             if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5146             // 3.2.2. Les maximum pour YACS
5147             if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5148             if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5149             if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5150             if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5151           }
5152         }
5153       }
5154     }
5155   }
5156
5157   // C. Enregistrements
5158   MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5159   SetLanguageShort( LanguageShort.c_str() ) ;
5160
5161   MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5162   SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5163
5164   MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5165   SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5166
5167   MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5168   int YACSTypeTest ;
5169   if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest &gt; VRef" ) )      { YACSTypeTest = 1 ; }
5170   else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest &lt; VRef" ) ) { YACSTypeTest = 2 ; }
5171   else                                                                                                { YACSTypeTest = 0 ; }
5172   MESSAGE ("==> TypeTest = " << YACSTypeTest );
5173   SetYACSConvergenceType( YACSTypeTest ) ;
5174
5175   return ;
5176 }
5177 //===============================================================================
5178 // Langue de SALOME
5179 //===============================================================================
5180 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5181 {
5182 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5183   _LangueShort = LanguageShort ;
5184   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5185   else                        { _Langue = "English" ; }
5186   return ;
5187 }
5188 char* HOMARD_Gen_i::GetLanguageShort()
5189 {
5190 //   MESSAGE ("GetLanguageShort");
5191   return CORBA::string_dup( _LangueShort.c_str() );
5192 }
5193 //===============================================================================
5194 // Options de publications
5195 //===============================================================================
5196 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5197 {
5198   _PublisMeshIN  = PublisMeshIN  ;
5199   _PublisMeshOUT = PublisMeshOUT ;
5200   return ;
5201 }
5202 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5203 {
5204   return _PublisMeshIN ;
5205 }
5206 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5207 {
5208   return _PublisMeshOUT ;
5209 }
5210 //===============================================================================
5211 // YACS - test de convergence
5212 //===============================================================================
5213 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5214 {
5215   _YACSMaxIter = YACSMaxIter ;
5216   _YACSMaxNode = YACSMaxNode ;
5217   _YACSMaxElem = YACSMaxElem ;
5218   return ;
5219 }
5220 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5221 {
5222   return _YACSMaxIter ;
5223 }
5224 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5225 {
5226   return _YACSMaxNode ;
5227 }
5228 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5229 {
5230   return _YACSMaxElem ;
5231 }
5232 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5233 {
5234   _YACSTypeTest = YACSTypeTest ;
5235   return ;
5236 }
5237 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5238 {
5239   return _YACSTypeTest ;
5240 }
5241
5242 //=============================================================================
5243 extern "C"
5244 {
5245   HOMARDENGINE_EXPORT
5246   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5247                                                   PortableServer::POA_ptr poa,
5248                                                   PortableServer::ObjectId* contId,
5249                                                   const char* instanceName,
5250                                                   const char* interfaceName)
5251   {
5252     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5253     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5254     return myHOMARD_Gen->getId();
5255   }
5256 }