Salome HOME
Update copyrights 2014.
[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       else
2655       {
2656         text = "Voir le fichier Liste.log.\n" ;
2657       }
2658       INFOS ( text ) ;
2659       SALOME::ExceptionStruct es;
2660       es.type = SALOME::BAD_PARAM;
2661       es.text = CORBA::string_dup(text.c_str());
2662       throw SALOME::SALOME_Exception(es);
2663 //
2664       // En mode information, on force le succes pour pouvoir consulter le fichier log
2665       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2666     }
2667   }
2668
2669   // I. Menage et retour dans le repertoire du cas
2670   if (codret == 0)
2671   {
2672     delete myDriver;
2673     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2674
2675 #ifndef WIN32
2676     chdir(nomDirWork.c_str());
2677 #else
2678     _chdir(nomDirWork.c_str());
2679 #endif
2680   }
2681
2682   return codretexec ;
2683 }
2684 //=============================================================================
2685 // Calcul d'une iteration : partie specifique a l'adaptation
2686 //=============================================================================
2687 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)
2688 {
2689   MESSAGE ( "ComputeAdap" );
2690
2691   // A. Prealable
2692   // A.1. Bases
2693   int codret = 0;
2694   // Numero de l'iteration
2695   int NumeIter = myIteration->GetNumber();
2696   std::stringstream saux0 ;
2697   saux0 << NumeIter-1 ;
2698   std::string siter = saux0.str() ;
2699   if (NumeIter < 11) { siter = "0" + siter ; }
2700
2701   // A.2. On verifie qu il y a une hypothese (erreur improbable);
2702   const char* nomHypo = myIteration->GetHypoName();
2703   if (std::string(nomHypo) == std::string(""))
2704   {
2705       SALOME::ExceptionStruct es;
2706       es.type = SALOME::BAD_PARAM;
2707       es.text = "This iteration does not have any associated hypothesis.";
2708       throw SALOME::SALOME_Exception(es);
2709       return 2;
2710   };
2711   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2712   ASSERT(!CORBA::is_nil(myHypo));
2713
2714   // B. L'iteration parent
2715   const char* nomIterationParent = myIteration->GetIterParentName();
2716   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2717   ASSERT(!CORBA::is_nil(myIterationParent));
2718   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2719   if ( myIterationParent->GetState() == 1 )
2720   {
2721     int iaux = 1 ;
2722     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2723     if (codret != 0)
2724     {
2725       // GERALD -- QMESSAGE BOX
2726       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2727     }
2728   };
2729
2730   // C. Le sous-repertoire de l'iteration precedente
2731   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2732   MESSAGE( ". DirComputePa = " << DirComputePa );
2733
2734   // D. Les donnees de l'adaptation HOMARD
2735   // D.1. Le type de conformite
2736   int ConfType = myCase->GetConfType();
2737   MESSAGE ( ". ConfType = " << ConfType );
2738
2739   // D.2. Le maillage de depart
2740   const char* NomMeshParent = myIterationParent->GetMeshName();
2741   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2742   const char* MeshFileParent = myIterationParent->GetMeshFile();
2743   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2744
2745   // D.3. Le maillage associe a l'iteration
2746   const char* MeshFile = myIteration->GetMeshFile();
2747   MESSAGE ( ". MeshFile = " << MeshFile );
2748   FILE *file = fopen(MeshFile,"r");
2749   if (file != NULL)
2750   {
2751     fclose(file);
2752     if (etatMenage == 0)
2753     {
2754       SALOME::ExceptionStruct es;
2755       es.type = SALOME::BAD_PARAM;
2756       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2757       es.text = CORBA::string_dup(text.c_str());
2758       throw SALOME::SALOME_Exception(es);
2759       return 4;
2760     }
2761     else
2762     {
2763       std::string commande = "rm -f " + std::string(MeshFile);
2764       codret = system(commande.c_str());
2765       if (codret != 0)
2766       {
2767         SALOME::ExceptionStruct es;
2768         es.type = SALOME::BAD_PARAM;
2769         es.text = "The mesh file cannot be deleted.";
2770         throw SALOME::SALOME_Exception(es);
2771         return 5;
2772       }
2773     }
2774   }
2775
2776   // D.4. Les types de raffinement et de deraffinement
2777   // Les appels corba sont lourds, il vaut mieux les grouper
2778   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2779   ASSERT(ListTypes->length() == 3);
2780   int TypeAdap = (*ListTypes)[0];
2781   int TypeRaff = (*ListTypes)[1];
2782   int TypeDera = (*ListTypes)[2];
2783
2784   // E. Texte du fichier de configuration
2785   // E.1. Incontournables du texte
2786   myDriver->TexteAdap();
2787   int iaux = 0 ;
2788   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2789   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2790   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2791
2792   // E.2. Ajout des informations liees aux zones eventuelles
2793   if ( TypeAdap == 0 )
2794   { DriverTexteZone(myHypo, myDriver) ; }
2795
2796   // E.3. Ajout des informations liees aux champs eventuels
2797   if ( TypeAdap == 1 )
2798   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2799
2800   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2801   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2802   int numberOfGroups = listeGroupes->length();
2803   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2804   if (numberOfGroups > 0)
2805   {
2806     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2807     {
2808       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2809       MESSAGE( "... GroupName = " << GroupName );
2810       myDriver->TexteGroup(GroupName);
2811     }
2812   }
2813
2814   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2815   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2816
2817   // E.6. Ajout des options avancees
2818   int Pyram = myCase->GetPyram();
2819   MESSAGE ( ". Pyram = " << Pyram );
2820   int NivMax = myHypo->GetNivMax();
2821   MESSAGE ( ". NivMax = " << NivMax );
2822   double DiamMin = myHypo->GetDiamMin() ;
2823   MESSAGE ( ". DiamMin = " << DiamMin );
2824   int AdapInit = myHypo->GetAdapInit();
2825   MESSAGE ( ". AdapInit = " << AdapInit );
2826   int LevelOutput = myHypo->GetLevelOutput();
2827   MESSAGE ( ". LevelOutput = " << LevelOutput );
2828   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2829
2830   // E.7. Ajout des informations sur le deroulement de l'execution
2831   int MessInfo = myIteration->GetInfoCompute();
2832   MESSAGE ( ". MessInfo = " << MessInfo );
2833   myDriver->TexteInfoCompute(MessInfo);
2834
2835   return codret ;
2836 }
2837 //=============================================================================
2838 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2839 //  nomrep : nom du repertoire parent
2840 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2841 //=============================================================================
2842 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2843 {
2844   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2845   // On verifie que le repertoire parent existe
2846 #ifndef WIN32
2847   int codret = chdir(nomrep) ;
2848 #else
2849   int codret = _chdir(nomrep) ;
2850 #endif
2851   if ( codret != 0 )
2852   {
2853     SALOME::ExceptionStruct es;
2854     es.type = SALOME::BAD_PARAM;
2855     es.text = "The directory of the case does not exist.";
2856     throw SALOME::SALOME_Exception(es);
2857     return 0;
2858   };
2859   std::string nomDirActuel = getenv("PWD") ;
2860   std::string DirName ;
2861   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2862   bool a_chercher = true ;
2863   while ( a_chercher )
2864   {
2865     // On passe dans le repertoire parent
2866
2867 #ifndef WIN32
2868   chdir(nomrep);
2869 #else
2870   _chdir(nomrep);
2871 #endif
2872     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2873     int jaux ;
2874     if      ( num <    100 ) { jaux = 2 ; }
2875     else if ( num <   1000 ) { jaux = 3 ; }
2876     else if ( num <  10000 ) { jaux = 4 ; }
2877     else if ( num < 100000 ) { jaux = 5 ; }
2878     else                     { jaux = 9 ; }
2879     std::ostringstream iaux ;
2880     iaux << std::setw(jaux) << std::setfill('0') << num ;
2881     std::ostringstream DirNameA ;
2882     DirNameA << "I" << iaux.str();
2883     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2884     // que c'est bien un probleme d'absence
2885 #ifndef WIN32
2886     if ( chdir(DirNameA.str().c_str()) != 0 )
2887     {
2888 #else
2889     if ( _chdir(DirNameA.str().c_str()) != 0 )
2890     {
2891 #endif
2892       bool existe = false ;
2893 #ifndef WIN32
2894       DIR *dp;
2895       struct dirent *dirp;
2896       dp  = opendir(nomrep);
2897       while ( (dirp = readdir(dp)) != NULL )
2898       {
2899         std::string file_name(dirp->d_name);
2900 #else
2901       HANDLE hFind = INVALID_HANDLE_VALUE;
2902       WIN32_FIND_DATA ffd;
2903       hFind = FindFirstFile(nomrep, &ffd);
2904       if (INVALID_HANDLE_VALUE != hFind) {
2905         while (FindNextFile(hFind, &ffd) != 0) {
2906          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2907          std::string file_name(ffd.cFileName);
2908 #endif
2909         if ( file_name == DirNameA.str() ) { existe = true ; }
2910       }
2911 #ifndef WIN32
2912       closedir(dp);
2913 #else
2914       }
2915       FindClose(hFind);
2916 #endif
2917       if ( !existe )
2918       {
2919         DirName = DirNameA.str() ;
2920         a_chercher = false ;
2921         break ;
2922       }
2923     }
2924     num += 1;
2925   }
2926
2927   MESSAGE ( "==> DirName = " << DirName);
2928   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2929 #ifndef WIN32
2930   chdir(nomDirActuel.c_str());
2931 #else
2932   _chdir(nomDirActuel.c_str());
2933 #endif
2934   return CORBA::string_dup( DirName.c_str() );
2935 }
2936 //=============================================================================
2937 // Calcul d'une iteration : gestion du repertoire de calcul
2938 //        Si le sous-repertoire existe :
2939 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2940 //         etatMenage =  1 : on fait le menage du repertoire
2941 //         etatMenage = -1 : on ne fait rien
2942 //=============================================================================
2943 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2944 {
2945   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2946   // B.2. Le repertoire du cas
2947   const char* nomDirCase = myCase->GetDirName();
2948   MESSAGE ( ". nomDirCase = " << nomDirCase );
2949
2950   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2951   // B.3.1. Le nom du sous-repertoire
2952   const char* nomDirIt = myIteration->GetDirNameLoc();
2953
2954   // B.3.2. Le nom complet du sous-repertoire
2955   std::stringstream DirCompute ;
2956   DirCompute << nomDirCase << "/" << nomDirIt;
2957   MESSAGE (". DirCompute = " << DirCompute.str() );
2958
2959   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2960 #ifndef WIN32
2961   if (chdir(DirCompute.str().c_str()) != 0)
2962   {
2963 //  Creation du repertoire car il n'existe pas :
2964     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2965     {
2966 #else
2967   if (_chdir(DirCompute.str().c_str()) != 0)
2968   {
2969 //  Creation du repertoire car il n'existe pas :
2970     if (_mkdir(DirCompute.str().c_str()) != 0)
2971     {
2972 #endif
2973        // GERALD -- QMESSAGE BOX
2974        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2975        VERIFICATION("Pb a la creation du repertoire" == 0);
2976     }
2977   }
2978   else
2979   {
2980 //  Le repertoire existe
2981 //  On demande de faire le menage de son contenu :
2982     if (etatMenage == 1)
2983     {
2984       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2985       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2986       int codret = system(commande.c_str());
2987       if (codret != 0)
2988       {
2989         // GERALD -- QMESSAGE BOX
2990         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2991         VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2992       }
2993     }
2994 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2995     else
2996     {
2997       if (etatMenage == 0)
2998       {
2999 #ifndef WIN32
3000         DIR *dp;
3001         struct dirent *dirp;
3002         dp  = opendir(DirCompute.str().c_str());
3003         bool result = true;
3004         while ((dirp = readdir(dp)) != NULL && result )
3005         {
3006           std::string file_name(dirp->d_name);
3007           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3008         }
3009         closedir(dp);
3010 #else
3011        HANDLE hFind = INVALID_HANDLE_VALUE;
3012        WIN32_FIND_DATA ffd;
3013        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
3014        bool result = true;
3015        if (INVALID_HANDLE_VALUE != hFind) {
3016          while (FindNextFile(hFind, &ffd) != 0) {
3017           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
3018           std::string file_name(ffd.cFileName);
3019           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
3020          }
3021        }
3022        FindClose(hFind);
3023 #endif
3024         if ( result == false)
3025         {
3026           SALOME::ExceptionStruct es;
3027           es.type = SALOME::BAD_PARAM;
3028           std::string text = "Directory : " + DirCompute.str() + " is not empty";
3029           es.text = CORBA::string_dup(text.c_str());
3030           throw SALOME::SALOME_Exception(es);
3031           VERIFICATION("Directory is not empty" == 0);
3032         }
3033       }
3034     }
3035   }
3036
3037   return CORBA::string_dup( DirCompute.str().c_str() );
3038 }
3039 //=============================================================================
3040 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
3041 //=============================================================================
3042 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3043 {
3044   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
3045   // Le repertoire du cas
3046   const char* nomDirCase = myCase->GetDirName();
3047   MESSAGE ( ". nomDirCase = " << nomDirCase );
3048
3049   // Le sous-repertoire de l'iteration precedente
3050
3051   const char* nomIterationParent = myIteration->GetIterParentName();
3052   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
3053   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3054   std::stringstream DirComputePa ;
3055   DirComputePa << nomDirCase << "/" << nomDirItPa;
3056   MESSAGE( ". nomDirItPa = " << nomDirItPa);
3057   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3058
3059   return CORBA::string_dup( DirComputePa.str().c_str() );
3060 }
3061 //=============================================================================
3062 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3063 //=============================================================================
3064 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3065 {
3066   MESSAGE ( "... DriverTexteZone" );
3067   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3068   int numberOfZonesx2 = ListZone->length();
3069   int NumZone ;
3070
3071   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3072   {
3073     std::string ZoneName = std::string((*ListZone)[iaux]);
3074     MESSAGE ( "... ZoneName = " << ZoneName);
3075     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3076     ASSERT(!CORBA::is_nil(myZone));
3077
3078     int ZoneType = myZone->GetType();
3079     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3080     int TypeUse = atoi( TypeUsestr.c_str() );
3081     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3082     NumZone = iaux/2 + 1 ;
3083     HOMARD::double_array* zone = myZone->GetCoords();
3084     if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3085     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3086     else if ( ZoneType == 4 ) // Cas d une sphere
3087     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3088     else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3089     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3090     else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3091     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3092     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3093     iaux += 1 ;
3094   }
3095   return ;
3096 }
3097 //=============================================================================
3098 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3099 //=============================================================================
3100 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3101 {
3102   MESSAGE ( "... DriverTexteField" );
3103 //  Le fichier du champ
3104   char* FieldFile = myIteration->GetFieldFile();
3105   MESSAGE ( ". FieldFile = " << FieldFile );
3106   if (strlen(FieldFile) == 0)
3107   {
3108     // GERALD -- QMESSAGE BOX
3109     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3110     VERIFICATION("The file for the field is not given." == 0);
3111   }
3112 //  Les caracteristiques d'instants du champ de pilotage
3113   int TimeStep = myIteration->GetTimeStep();
3114   MESSAGE( ". TimeStep = " << TimeStep );
3115   int Rank = myIteration->GetRank();
3116   MESSAGE( ". Rank = " << Rank );
3117 //  Les informations sur les champs
3118   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3119 //  Le nom
3120   const char* FieldName = aInfosHypo->FieldName;
3121 //  Les seuils
3122   int TypeThR = aInfosHypo->TypeThR;
3123   double ThreshR = aInfosHypo->ThreshR;
3124   int TypeThC = aInfosHypo->TypeThC;
3125   double ThreshC = aInfosHypo->ThreshC;
3126 //  Saut entre mailles ou non ?
3127   int UsField = aInfosHypo->UsField;
3128   MESSAGE( ". UsField = " << UsField );
3129 //  L'usage des composantes
3130   int UsCmpI = aInfosHypo->UsCmpI;
3131   MESSAGE( ". UsCmpI = " << UsCmpI );
3132 //
3133   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3134 //
3135 //  Les composantes
3136   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3137   int numberOfCompos = mescompo->length();
3138   MESSAGE( ". numberOfCompos = " << numberOfCompos );
3139   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3140   {
3141     std::string nomCompo = std::string((*mescompo)[NumeComp]);
3142     MESSAGE( "... nomCompo = " << nomCompo );
3143     myDriver->TexteCompo(NumeComp, nomCompo);
3144   }
3145   return ;
3146 }
3147 //=============================================================================
3148 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3149 // On ecrit dans l'ordre :
3150 //    1. la definition des frontieres
3151 //    2. les liens avec les groupes
3152 //    3. un entier resumant le type de comportement pour les frontieres
3153 //=============================================================================
3154 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3155 {
3156   MESSAGE ( "... DriverTexteBoundary" );
3157   // 1. Recuperation des frontieres
3158   std::list<std::string>  ListeBoundaryTraitees ;
3159   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3160   int numberOfitems = ListBoundaryGroupType->length();
3161   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3162   int BoundaryOption = 1 ;
3163   // 2. Parcours des frontieres pour ecrire leur description
3164   int NumBoundaryAnalytical = 0 ;
3165   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3166   {
3167     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3168     MESSAGE ( "... BoundaryName = " << BoundaryName);
3169     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3170     //      Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3171     int A_faire = 1 ;
3172     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3173     while (it != ListeBoundaryTraitees.end())
3174     {
3175       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3176       if ( BoundaryName == *it ) { A_faire = 0 ; }
3177       it++;
3178     }
3179     // 2.2. Ecriture de la frontiere
3180     if ( A_faire == 1 )
3181     {
3182       // 2.2.1. Caracteristiques de la frontiere
3183       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3184       ASSERT(!CORBA::is_nil(myBoundary));
3185       int BoundaryType = myBoundary->GetType();
3186       MESSAGE ( "... BoundaryType = " << BoundaryType );
3187       // 2.2.2. Ecriture selon le type
3188       // 2.2.2.1. Cas d une frontiere discrete
3189       if (BoundaryType == 0)
3190       {
3191         const char* MeshName = myBoundary->GetMeshName() ;
3192         const char* MeshFile = myBoundary->GetMeshFile() ;
3193         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3194         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3195       }
3196       // 2.2.2.1. Cas d une frontiere analytique
3197       else
3198       {
3199         NumBoundaryAnalytical++ ;
3200         HOMARD::double_array* coor = myBoundary->GetCoords();
3201         if (BoundaryType == 1) // Cas d un cylindre
3202         {
3203           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3204           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3205         }
3206         else if (BoundaryType == 2) // Cas d une sphere
3207         {
3208           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3209           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3210         }
3211         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3212         {
3213           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3214           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3215         }
3216         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3217         {
3218           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3219           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3220         }
3221         else if (BoundaryType == 5) // Cas d un tore
3222         {
3223           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3224           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3225         }
3226       }
3227       // 2.2.3. Memorisation du traitement
3228       ListeBoundaryTraitees.push_back( BoundaryName );
3229     }
3230   }
3231   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3232   NumBoundaryAnalytical = 0 ;
3233   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3234   {
3235     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3236     MESSAGE ( "... BoundaryName = " << BoundaryName);
3237     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3238     ASSERT(!CORBA::is_nil(myBoundary));
3239     int BoundaryType = myBoundary->GetType();
3240     MESSAGE ( "... BoundaryType = " << BoundaryType );
3241     // 3.1. Recuperation du nom du groupe
3242     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3243     MESSAGE ( "... GroupName = " << GroupName);
3244     // 3.2. Cas d une frontiere discrete
3245     if ( BoundaryType == 0 )
3246     {
3247       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3248     }
3249     // 3.3. Cas d une frontiere analytique
3250     else
3251     {
3252       NumBoundaryAnalytical++ ;
3253       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3254     }
3255   }
3256   // 4. Ecriture de l'option finale
3257   myDriver->TexteBoundaryOption(BoundaryOption);
3258 //
3259   return ;
3260 }
3261 //=============================================================================
3262 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3263 //=============================================================================
3264 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3265 {
3266   MESSAGE ( "... DriverTexteFieldInterp" );
3267   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3268   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3269   if (TypeFieldInterp != 0)
3270   {
3271 //  Le fichier des champs
3272     char* FieldFile = myIteration->GetFieldFile();
3273     MESSAGE ( ". FieldFile = " << FieldFile );
3274     if (strlen(FieldFile) == 0)
3275     {
3276       // GERALD -- QMESSAGE BOX
3277       VERIFICATION("The file for the field is not given." == 0);
3278     }
3279   //
3280     const char* MeshFile = myIteration->GetMeshFile();
3281     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3282
3283   // Les champs
3284   // Interpolation de tous les champs
3285     if ( TypeFieldInterp == 1 )
3286     {
3287       myDriver->TexteFieldInterpAll();
3288     }
3289   // Interpolation de certains champs
3290     else if (TypeFieldInterp == 2)
3291     {
3292       // Les champs et leurs instants pour l'iteration
3293       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3294       int numberOfFieldsx3 = ListFieldTSR->length();
3295       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3296       // Les champs pour l'hypothese
3297       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3298       int numberOfFieldsx2 = ListField->length();
3299       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3300       // On parcourt tous les champs de  l'hypothese
3301       int NumField = 0 ;
3302       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3303       {
3304         // Le nom du champ
3305         std::string FieldName = std::string((*ListField)[iaux]) ;
3306         // Le type d'interpolation
3307         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3308         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3309         // On cherche à savoir si des instants ont été précisés pour cette itération
3310         int tsrvu = 0;
3311         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3312         {
3313         // Le nom du champ
3314           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3315           MESSAGE( "..... FieldName2 = " << FieldName2 );
3316         // Quand c'est le bon champ, on ecrit le pas de temps
3317           if ( FieldName == FieldName2 )
3318           {
3319             tsrvu = 1 ;
3320             // Le pas de temps
3321             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3322             // Le numero d'ordre
3323             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3324             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3325             NumField += 1 ;
3326             int TimeStep = atoi( TimeStepstr.c_str() );
3327             int Rank = atoi( Rankstr.c_str() );
3328             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3329           }
3330           jaux += 2 ;
3331         }
3332         // Si aucun instant n'a été défini
3333         if ( tsrvu == 0 )
3334         {
3335           NumField += 1 ;
3336           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3337         }
3338         iaux++ ;
3339       }
3340     }
3341   }
3342   return ;
3343 }
3344 //===========================================================================
3345 //===========================================================================
3346
3347
3348 //===========================================================================
3349 //===========================================================================
3350 // Publications
3351 //===========================================================================
3352 //===========================================================================
3353 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3354                                                    SALOMEDS::SObject_ptr theSObject,
3355                                                    CORBA::Object_ptr theObject,
3356                                                    const char* theName)
3357 {
3358   MESSAGE("PublishInStudy pour " << theName);
3359   SALOMEDS::SObject_var aResultSO;
3360   if (CORBA::is_nil(theStudy))
3361   {
3362     SALOME::ExceptionStruct es;
3363     es.type = SALOME::BAD_PARAM;
3364     es.text = "Invalid study context";
3365     throw SALOME::SALOME_Exception(es);
3366     return 0;
3367   };
3368
3369 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3370 // Rq : Iteration est publiee ailleurs
3371   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3372   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3373   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3374   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3375   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3376
3377    addInStudy(theStudy);
3378
3379 // Controle de la non publication d'un objet de meme nom
3380    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3381   {
3382     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3383     if (listSO->length() >= 1)
3384     {
3385       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3386       aResultSO = listSO[0];
3387       return aResultSO._retn();
3388     }
3389   }
3390
3391   // Caracteristiques de l'etude
3392   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3393   aStudyBuilder->NewCommand();
3394   if(!aBoundary->_is_nil())
3395     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3396   else if(!aCase->_is_nil())
3397     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3398   else if(!aHypo->_is_nil())
3399     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3400   else if(!aYACS->_is_nil())
3401     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3402   else if(!aZone->_is_nil())
3403     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3404
3405   aStudyBuilder->CommitCommand();
3406
3407   return aResultSO._retn();
3408 };
3409 //=============================================================================
3410 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3411                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3412                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3413 {
3414   MESSAGE("PublishBoundaryStudy pour "<<theName);
3415   SALOMEDS::SObject_var aResultSO;
3416
3417   // Caracteristique de la Boundary
3418   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3419
3420   // On recupere le module pere dans l etude
3421   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3422   if (theFatherHomard->_is_nil())
3423   {
3424     MESSAGE("theFatherHomard->_is_nil()");
3425     return aResultSO._retn();
3426   }
3427
3428   // On ajoute la categorie des boundarys dans l etude si necessaire
3429   if ( _tag_boun == 0 )
3430   {
3431     _tag_gene += 1 ;
3432     _tag_boun = _tag_gene ;
3433   }
3434   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3435   SALOMEDS::SObject_var aSObject;
3436   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3437   {
3438     MESSAGE("Ajout de la categorie des boundarys");
3439     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3440     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3441   }
3442   else { MESSAGE("La categorie des boundarys existe deja."); }
3443
3444   CORBA::Long BoundaryType = myBoundary->GetType();
3445 //   MESSAGE("BoundaryType : "<<BoundaryType);
3446   std::string icone ;
3447   std::string value ;
3448   switch (BoundaryType)
3449   {
3450     case 0 :
3451     { value = "BoundaryDiHomard" ;
3452       icone = "mesh_tree_mesh.png" ;
3453       break;
3454     }
3455     case 1 :
3456     { value = "BoundaryAnHomard" ;
3457       icone = "cylinderpointvector_2.png" ;
3458       break;
3459     }
3460     case 2 :
3461     { value = "BoundaryAnHomard" ;
3462       icone = "spherepoint_2.png" ;
3463       break;
3464     }
3465     case 3 :
3466     { value = "BoundaryAnHomard" ;
3467       icone = "conepointvector.png" ;
3468       break;
3469     }
3470     case 4 :
3471     { value = "BoundaryAnHomard" ;
3472       icone = "conedxyz.png" ;
3473       break;
3474     }
3475     case 5 :
3476     { value = "BoundaryAnHomard" ;
3477       icone = "toruspointvector.png" ;
3478       break;
3479     }
3480   }
3481   aResultSO = aStudyBuilder->NewObject(aSObject);
3482   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3483   return aResultSO._retn();
3484 }
3485 //=============================================================================
3486 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3487                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3488                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3489 {
3490   MESSAGE("PublishCaseInStudy pour "<<theName);
3491   SALOMEDS::SObject_var aResultSO;
3492
3493   if (CORBA::is_nil(theObject)) {
3494     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3495     return aResultSO._retn();
3496   }
3497   if (theStudy->_is_nil()) {
3498     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3499     return aResultSO._retn();
3500   }
3501
3502   // On recupere le module pere dans l etude
3503   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3504   if (theFatherHomard->_is_nil())
3505   {
3506     MESSAGE("theFatherHomard->_is_nil()");
3507     return aResultSO._retn();
3508   }
3509
3510   _tag_gene += 1 ;
3511   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3512   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3513   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3514                      _orb->object_to_string(theObject) ) ;
3515
3516   return aResultSO._retn();
3517 }
3518 //=============================================================================
3519 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3520                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3521                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3522 {
3523   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3524   SALOMEDS::SObject_var aResultSO;
3525
3526   // On recupere le module pere dans l etude
3527   // On ajoute la categorie des hypotheses dans l etude si necessaire
3528   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3529   if (theFatherHomard->_is_nil())
3530   {
3531     MESSAGE("theFatherHomard->_is_nil()");
3532     return aResultSO._retn();
3533   }
3534
3535   // On ajoute la categorie des hypotheses dans l etude si necessaire
3536   SALOMEDS::SObject_var aSObject;
3537   if ( _tag_hypo == 0 )
3538   {
3539     _tag_gene += 1 ;
3540     _tag_hypo = _tag_gene ;
3541   }
3542   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3543   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3544   {
3545     MESSAGE("Ajout de la categorie des hypotheses");
3546     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3547     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3548   }
3549   else { MESSAGE("La categorie des hypotheses existe deja."); }
3550
3551 // Creation du resultat dans l'etude
3552   aResultSO = aStudyBuilder->NewObject(aSObject);
3553   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3554
3555   return aResultSO._retn();
3556 }
3557 //=============================================================================
3558 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3559                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3560                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3561 {
3562   MESSAGE("PublishYACSInStudy pour "<<theName);
3563   SALOMEDS::SObject_var aResultSO;
3564
3565   // On recupere le module pere dans l etude
3566   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3567   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3568   if (theFatherHomard->_is_nil())
3569   {
3570     MESSAGE("theFatherHomard->_is_nil()");
3571     return aResultSO._retn();
3572   }
3573   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3574   if ( _tag_yacs == 0 )
3575   {
3576     _tag_gene += 1 ;
3577     _tag_yacs = _tag_gene ;
3578   }
3579   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3580   SALOMEDS::SObject_var aSObject;
3581   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3582   {
3583     MESSAGE("Ajout de la categorie des schemas YACS");
3584     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3585     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3586   }
3587   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3588
3589 // Creation du resultat dans l'etude
3590   aResultSO = aStudyBuilder->NewObject(aSObject);
3591   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3592
3593   return aResultSO._retn();
3594 }
3595
3596 //=============================================================================
3597 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3598                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3599                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3600 {
3601   MESSAGE("PublishZoneStudy pour "<<theName);
3602   SALOMEDS::SObject_var aResultSO;
3603   if (CORBA::is_nil(theObject))
3604   {
3605     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3606     return aResultSO._retn();
3607   }
3608   if (theStudy->_is_nil())
3609   {
3610     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3611     return aResultSO._retn();
3612   }
3613   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3614   if (theFatherHomard->_is_nil())
3615   {
3616     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3617     return aResultSO._retn();
3618   }
3619
3620   // Caracteristique de la zone
3621   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3622   CORBA::Long ZoneType = myZone->GetType();
3623
3624   // On ajoute la categorie des zones dans l etude si necessaire
3625   if ( _tag_zone == 0 )
3626   {
3627     _tag_gene += 1 ;
3628     _tag_zone = _tag_gene ;
3629   }
3630   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3631   SALOMEDS::SObject_var aSObject;
3632   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3633   {
3634     MESSAGE("Ajout de la categorie des zones");
3635     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3636     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3637   }
3638   else { MESSAGE("La categorie des zones existe deja."); }
3639
3640   aResultSO = aStudyBuilder->NewObject(aSObject);
3641   std::string icone ;
3642   switch (ZoneType)
3643   {
3644     case 11 :
3645     { }
3646     case 12 :
3647     { }
3648     case 13 :
3649     { icone = "boxdxy_2.png" ;
3650       break ;
3651     }
3652     case 2 :
3653     { icone = "boxdxyz_2.png" ;
3654       break ;
3655     }
3656     case 31 :
3657     { }
3658     case 32 :
3659     { }
3660     case 33 :
3661     { icone = "disk_2.png" ;
3662       break ;
3663      }
3664     case 4 :
3665     { icone = "spherepoint_2.png" ;
3666       break ;
3667     }
3668     case 5 :
3669     { icone = "cylinderpointvector_2.png" ;
3670       break ;
3671     }
3672     case 61 :
3673     { }
3674     case 62 :
3675     { }
3676     case 63 :
3677     { icone = "diskwithhole_2.png" ;
3678       break ;
3679      }
3680     case 7 :
3681     { icone = "pipe_2.png" ;
3682       break ;
3683     }
3684   }
3685   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3686
3687   return aResultSO._retn();
3688 }
3689 //===========================================================================
3690 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3691                                       SALOMEDS::SObject_var aResultSO,
3692                                       const char* name, const char* comment, const char* icone, const char* ior)
3693 {
3694   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3695 //   MESSAGE("icone = "<<icone);
3696 //   MESSAGE("ior   = "<<ior);
3697   SALOMEDS::GenericAttribute_var anAttr ;
3698 //  Ajout du nom
3699   if ( name != NULL )
3700   {
3701     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3702     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3703     aNameAttrib->SetValue(name);
3704   }
3705
3706 //  Ajout du commentaire
3707   if ( comment != NULL )
3708   {
3709     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3710     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3711     aCommentAttrib->SetValue(comment);
3712   }
3713
3714 //  Ajout de l'icone
3715   if ( icone != NULL  )
3716   {
3717     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3718     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3719     aPixmap->SetPixMap(icone);
3720   }
3721
3722 //  Ajout de l ior
3723   if ( ior != NULL  )
3724   {
3725     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3726     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3727     anIOR->SetValue(ior);
3728   }
3729 };
3730
3731 //=====================================================================================
3732 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3733 {
3734   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3735
3736   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3737   ASSERT(!CORBA::is_nil(myCase));
3738   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3739   ASSERT(!CORBA::is_nil(aCaseSO));
3740
3741   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3742   ASSERT(!CORBA::is_nil(myBoundary));
3743   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3744   ASSERT(!CORBA::is_nil(aBoundarySO));
3745
3746   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3747
3748   aStudyBuilder->NewCommand();
3749
3750   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3751   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3752 //   aStudyBuilder->RemoveReference(aSubSO);
3753
3754   aStudyBuilder->CommitCommand();
3755
3756 };
3757 //=====================================================================================
3758 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3759 {
3760   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3761
3762   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3763   ASSERT(!CORBA::is_nil(myYACS));
3764   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3765   ASSERT(!CORBA::is_nil(aYACSSO));
3766
3767   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3768   ASSERT(!CORBA::is_nil(myCase));
3769   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3770   ASSERT(!CORBA::is_nil(aCaseSO));
3771
3772   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3773
3774   aStudyBuilder->NewCommand();
3775
3776   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3777   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3778
3779   aStudyBuilder->CommitCommand();
3780
3781 };
3782 //=============================================================================
3783 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3784 //  Option = 0 : fichier issu d'une importation
3785 //  Option = 1 : fichier issu d'une execution HOMARD
3786 {
3787   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3788   if (CORBA::is_nil(myCurrentStudy))
3789   {
3790     SALOME::ExceptionStruct es;
3791     es.type = SALOME::BAD_PARAM;
3792     es.text = "Invalid study context";
3793     throw SALOME::SALOME_Exception(es);
3794     return ;
3795   };
3796
3797 // Le module SMESH est-il actif ?
3798   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3799 //
3800   if (!CORBA::is_nil(aSmeshSO))
3801   {
3802 // On verifie que le fichier n est pas deja publie
3803     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3804     for (; aIter->More(); aIter->Next())
3805     {
3806       SALOMEDS::SObject_var  aSO = aIter->Value();
3807       SALOMEDS::GenericAttribute_var aGAttr;
3808       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3809       {
3810         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3811         CORBA::String_var value=anAttr->Value();
3812         if (strcmp((const char*)value,NomFich) == 0)
3813         {
3814           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3815           // Pour un fichier importe, on ne republie pas
3816           if ( Option == 0 ) { return; }
3817           // Pour un fichier calcule, on commence par faire la depublication
3818           else
3819           {
3820             MESSAGE ( "PublishResultInSmesh : depublication" );
3821             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3822             CORBA::String_var value2=anAttr2->Value();
3823             std::string MeshName = string(value2) ;
3824             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3825             DeleteResultInSmesh(NomFich, MeshName) ;
3826           }
3827         }
3828       }
3829     }
3830   }
3831
3832 // On enregistre le fichier
3833   MESSAGE( "Enregistrement du fichier");
3834   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3835   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3836   ASSERT(!CORBA::is_nil(aSmeshEngine));
3837   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3838   SMESH::DriverMED_ReadStatus theStatus;
3839   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3840
3841 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3842   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3843   for (int i = 0; i < mesMaillages->length();  i++)
3844   {
3845     MESSAGE( ". Mise a jour des attributs du maillage");
3846     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3847     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3848     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3849     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3850     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3851     anAttr->SetValue(NomFich);
3852     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3853     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3854     const char* icone ;
3855     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3856     else               { icone = "mesh_tree_mesh.png" ; }
3857     anAttr2->SetPixMap( icone );
3858   }
3859
3860 }
3861 //=============================================================================
3862 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3863 {
3864   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3865   if (CORBA::is_nil(myCurrentStudy))
3866   {
3867       SALOME::ExceptionStruct es;
3868       es.type = SALOME::BAD_PARAM;
3869       es.text = "Invalid study context";
3870       throw SALOME::SALOME_Exception(es);
3871       return ;
3872   };
3873
3874 // Le module SMESH est-il actif ?
3875   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3876 //
3877   if (CORBA::is_nil(aSmeshSO))
3878   {
3879       return ;
3880   };
3881 // On verifie que le fichier est deja publie
3882   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3883   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3884   for (; aIter->More(); aIter->Next())
3885   {
3886      SALOMEDS::SObject_var  aSO = aIter->Value();
3887      SALOMEDS::GenericAttribute_var aGAttr;
3888      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3889      {
3890        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3891        CORBA::String_var value=anAttr->Value();
3892        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3893        {
3894          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3895          {
3896            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3897            CORBA::String_var value2=anAttr2->Value();
3898            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3899            {
3900              myBuilder->RemoveObjectWithChildren( aSO ) ;
3901            }
3902          }
3903        }
3904      }
3905   }
3906   return ;
3907 }
3908 //=============================================================================
3909 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3910 {
3911   MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3912   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3913
3914   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3915   if (CORBA::is_nil(myIteration))
3916   {
3917       SALOME::ExceptionStruct es;
3918       es.type = SALOME::BAD_PARAM;
3919       es.text = "Invalid iterationStudy Object";
3920       throw SALOME::SALOME_Exception(es);
3921       return ;
3922   };
3923   const char* MeshFile = myIteration->GetMeshFile() ;
3924   const char* MeshName = myIteration->GetMeshName() ;
3925   CORBA::Long Option = -1 ;
3926   int etat = myIteration->GetState();
3927 // Iteration initiale
3928   if ( etat <= 0 )      { Option = 0 ; }
3929 // ou iteration calculee
3930   else if ( etat == 2 ) { Option = 1 ; }
3931 // Publication effective apres menage eventuel
3932   if ( Option >= 0 )
3933   {
3934     DeleteResultInSmesh(MeshFile, MeshName) ;
3935     PublishResultInSmesh(MeshFile, Option) ;
3936   }
3937
3938 }
3939 //=============================================================================
3940 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3941 {
3942 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3943   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3944
3945   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3946   if (CORBA::is_nil(myIteration))
3947   {
3948       SALOME::ExceptionStruct es;
3949       es.type = SALOME::BAD_PARAM;
3950       es.text = "Invalid iterationStudy Object";
3951       throw SALOME::SALOME_Exception(es);
3952       return ;
3953   };
3954
3955   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3956
3957   aStudyBuilder->NewCommand();
3958
3959   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3960 // Pour les fichiers med, on affiche une icone de maillage
3961 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3962 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3963   std::string icone ;
3964   std::string ior = " " ;
3965   if ( Commentaire[0] == 'I' )
3966   { icone = "med.png" ; }
3967   else
3968   { icone = "texte_2.png" ; }
3969   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3970
3971   aStudyBuilder->CommitCommand();
3972 }
3973 //
3974 //=============================================================================
3975 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3976 {
3977 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3978   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3979
3980   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3981   if (CORBA::is_nil(myYACS))
3982   {
3983       SALOME::ExceptionStruct es;
3984       es.type = SALOME::BAD_PARAM;
3985       es.text = "Invalid YACSStudy Object";
3986       throw SALOME::SALOME_Exception(es);
3987       return ;
3988   };
3989
3990   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3991
3992   aStudyBuilder->NewCommand();
3993
3994   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3995   std::string icone = "texte_2.png" ;
3996   std::string ior = " " ;
3997   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3998
3999   aStudyBuilder->CommitCommand();
4000 }
4001 //
4002 //=============================================================================
4003 //=============================================================================
4004 // YACS
4005 //=============================================================================
4006 //=============================================================================
4007 //=============================================================================
4008 // Creation d'un schema YACS
4009 // nomCas : nom du cas a traiter
4010 // FileName : nom du fichier contenant le script de lancement du calcul
4011 // DirName : le repertoire de lancement des calculs du schéma
4012 //=============================================================================
4013 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
4014 {
4015   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
4016   INFOS ( ". nomCas     : " << nomCas);
4017   INFOS ( ". ScriptFile : " << ScriptFile);
4018   INFOS ( ". DirName    : " << DirName);
4019   INFOS ( ". MeshFile   : " << MeshFile);
4020
4021   // A. Controle du nom :
4022   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
4023   {
4024     SALOME::ExceptionStruct es;
4025     es.type = SALOME::BAD_PARAM;
4026     es.text = "This schema YACS has already been defined.";
4027     throw SALOME::SALOME_Exception(es);
4028     return 0;
4029   }
4030
4031   // B. Creation de l'objet
4032   HOMARD::HOMARD_YACS_var myYACS = newYACS();
4033   if (CORBA::is_nil(myYACS))
4034   {
4035     SALOME::ExceptionStruct es;
4036     es.type = SALOME::BAD_PARAM;
4037     es.text = "Unable to create the schema YACS";
4038     throw SALOME::SALOME_Exception(es);
4039     return 0;
4040   };
4041   myYACS->SetName( nomYACS ) ;
4042
4043   // C. Enregistrement
4044   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
4045
4046   SALOMEDS::SObject_var aSO;
4047   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
4048
4049   PublishCaseUnderYACS(nomYACS, nomCas);
4050
4051   // D. Caracterisation
4052   // D.1. Options
4053   myYACS->SetDirName( DirName ) ;
4054   myYACS->SetMeshFile( MeshFile ) ;
4055   myYACS->SetScriptFile( ScriptFile ) ;
4056   myYACS->SetCaseName( nomCas ) ;
4057   // D.2. Defaut
4058   int defaut_i ;
4059   // D.2.1. Type constant
4060   myYACS->SetType( 1 ) ;
4061   // D.2.2. Convergence
4062   defaut_i = GetYACSMaxIter() ;
4063   myYACS->SetMaxIter( defaut_i ) ;
4064   defaut_i = GetYACSMaxNode() ;
4065   myYACS->SetMaxNode( defaut_i ) ;
4066   defaut_i = GetYACSMaxElem() ;
4067   myYACS->SetMaxElem( defaut_i ) ;
4068   // D.3. Fichier de sauvegarde dans le repertoire du cas
4069   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4070   std::string dirnamecase = caseyacs->GetDirName() ;
4071   std::string XMLFile ;
4072   XMLFile = dirnamecase + "/schema.xml" ;
4073   myYACS->SetXMLFile( XMLFile.c_str() ) ;
4074
4075   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4076 }
4077 //=============================================================================
4078 // Ecriture d'un schema YACS
4079 //=============================================================================
4080 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4081 {
4082   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4083 // Le repertoire du cas
4084   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4085   ASSERT(!CORBA::is_nil(myYACS));
4086 // Le nom du fichier du schema
4087   std::string XMLFile ;
4088   XMLFile = myYACS->GetXMLFile() ;
4089
4090   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4091
4092   return codret ;
4093 }
4094 //=============================================================================
4095 // Ecriture d'un schema YACS sur un fichier donne
4096 //=============================================================================
4097 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4098 {
4099   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4100
4101   // A. Prealable
4102   int codret = 0;
4103
4104   // B. L'objet YACS
4105   // B.1. L'objet
4106   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4107   ASSERT(!CORBA::is_nil(myYACS));
4108   // B.2. Les caracteristiques
4109   std::string DirName = myYACS->GetDirName() ;
4110   std::string MeshFile = myYACS->GetMeshFile() ;
4111   std::string ScriptFile = myYACS->GetScriptFile() ;
4112   // B.3. Les caracteristiques de convergence
4113   int MaxIter = myYACS->GetMaxIter() ;
4114   int MaxNode = myYACS->GetMaxNode() ;
4115   int MaxElem = myYACS->GetMaxElem() ;
4116
4117   // C. Le cas
4118   // C.1. L'objet cas
4119   const char* nomCas = myYACS->GetCaseName();
4120   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4121   ASSERT(!CORBA::is_nil(myCase));
4122   // C.2. Les instructions python associees au cas
4123   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4124   std::string pythonCas = dumpCorbaCase.in();
4125   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4126
4127   // D. Les iterations
4128   // D.1. L'iteration initiale
4129   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4130   std::string Iter0Name = myCase->GetIter0Name() ;
4131   MESSAGE (". Iter0Name = " << Iter0Name);
4132   std::string MeshName = Iter0->GetMeshName();
4133   MESSAGE (". MeshName = " << MeshName);
4134   // D.2. L'iteration numero 1
4135   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4136   int numberOfIter = maListe->length();
4137   if ( numberOfIter > 1 )
4138   {
4139     MESSAGE (". numberOfIter = " << numberOfIter);
4140     SALOME::ExceptionStruct es ;
4141     es.type = SALOME::BAD_PARAM;
4142     std::string text = "Une seule iteration est permise." ;
4143     es.text = CORBA::string_dup(text.c_str());
4144     throw SALOME::SALOME_Exception(es);
4145     return 0;
4146   }
4147   std::string Iter1Name = std::string((*maListe)[0]);
4148   MESSAGE ("... Iter1Name = " << Iter1Name);
4149   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4150   // D.3. Les instructions python associees a l'iteration
4151   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4152   std::string pythonIter = dumpCorbaIter.in();
4153   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4154
4155   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4156   // E.1. La structure
4157   std::string nomHypo = Iter1->GetHypoName();
4158   MESSAGE (". nomHypo = " << nomHypo);
4159   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4160   ASSERT(!CORBA::is_nil(myHypo));
4161   // E.2. Les caracteristiques de l'adaptation
4162   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4163   ASSERT(ListTypes->length() == 3);
4164   int TypeAdap = (*ListTypes)[0];
4165 //   int TypeRaff = (*ListTypes)[1];
4166 //   int TypeDera = (*ListTypes)[2];
4167   // E.3. Les instructions python associees a l'hypothese
4168   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4169   std::string pythonHypo = dumpCorbaHypo.in();
4170   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4171
4172   // F. Le fichier du schema de reference
4173   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4174   std::string XMLFile_base ;
4175   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4176   else
4177   {
4178     SALOME::ExceptionStruct es ;
4179     es.type = SALOME::BAD_PARAM;
4180     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4181     es.text = CORBA::string_dup(text.c_str());
4182     throw SALOME::SALOME_Exception(es);
4183     return 0;
4184   }
4185   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4186 //   if ( _Langue ==
4187   MESSAGE("XMLFile_base ="<<XMLFile_base);
4188
4189   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4190   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4191   std::ifstream fichier( XMLFile_base.c_str() );
4192   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4193   {
4194     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4195     std::string ligne; // variable contenant chaque ligne lue
4196     std::string mot_cle;
4197     while ( std::getline( fichier, ligne ) )
4198     {
4199       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4200       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4201       ligne_bis >> mot_cle ;
4202       // G.1.2. Le maillage initial
4203       if ( mot_cle == "DataInit_MeshFile" )
4204       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4205       // G.1.3. Le script de lancement
4206       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4207       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4208       // G.1.4. Les options du cas
4209       else if ( mot_cle == "Iter_1_Case_Options" )
4210       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4211       // G.1.5. Execution de HOMARD : le repertoire du cas
4212       else if ( mot_cle == "HOMARD_Exec_DirName" )
4213       { myDriver->Texte_HOMARD_Exec_DirName(); }
4214       // G.1.6. Execution de HOMARD : le nom du maillage
4215       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4216       {
4217         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4218         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4219         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4220       }
4221       // G.1.7. Execution de HOMARD : les options de l'hypothese
4222       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4223       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4224       // G.1.8. Execution de HOMARD : les options de l'iteration
4225       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4226       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4227       // G.1.9. Zones et frontieres : les creations
4228       else if ( mot_cle == "Iter_1" )
4229       {
4230         std::string texte_control = myDriver->Texte_Iter_1_control() ;
4231         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4232         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4233         myDriver->TexteAdd(texte_control);
4234       }
4235       // G.1.10. Les tests de convergence
4236       else if ( mot_cle == "Analyse_Test_Convergence" )
4237       { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4238       // G.1.11. Les parametres
4239       else if ( mot_cle == "PARAMETRES" )
4240       { myDriver->TexteAddParametres(); }
4241       // G.1.n. La ligne est recopiee telle quelle
4242       else { myDriver->TexteAdd(ligne);  }
4243     }
4244     // G.2. Ecriture du texte dans le fichier
4245     if ( codret == 0 )
4246     { myDriver->CreeFichier(); }
4247   }
4248   else
4249   {
4250     SALOME::ExceptionStruct es;
4251     es.type = SALOME::BAD_PARAM;
4252     std::string text = "The reference file for the YACS schema cannot be read." ;
4253     es.text = CORBA::string_dup(text.c_str());
4254     throw SALOME::SALOME_Exception(es);
4255   }
4256
4257   delete myDriver;
4258
4259   // H. Publication du fichier dans l'arbre
4260
4261     std::string Commentaire = "xml" ;
4262     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4263
4264   return codret ;
4265 }
4266 //=============================================================================
4267 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4268 //=============================================================================
4269 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4270 {
4271   MESSAGE ( "YACSDriverTexteZone" );
4272   // A. Les zones associees a cette hypothese
4273   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4274   int numberOfZonesx2 = ListZone->length();
4275
4276   // B. Parcours des zones
4277   std::string texte_control ;
4278   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4279   {
4280     // 1. Reperage de la zone
4281     std::string ZoneName = std::string((*ListZone)[iaux]);
4282     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4283     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4284     ASSERT(!CORBA::is_nil(myZone));
4285     // 2. Les instructions python associees a la zone
4286     //    La premiere ligne est un commentaire a eliminer
4287     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4288     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4289     std::string pythonStructure_0 = dumpCorbaZone.in();
4290     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4291     std::istringstream tout (pythonStructure_0) ;
4292     std::string ligne ;
4293     std::string pythonStructure ;
4294     while ( std::getline( tout, ligne ) )
4295     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4296     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4297     // 3. Decodage du nom du service
4298     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4299     MESSAGE ( "... methode = " << methode);
4300     // 4. Mise en place des instructions
4301     int ZoneType = myZone->GetType();
4302     MESSAGE ( "... ZoneType = " << ZoneType);
4303     std::string texte_control_0 ;
4304     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4305     texte_control += texte_control_0 ;
4306     // 5. Decalage
4307     iaux ++ ;
4308   }
4309
4310   return texte_control ;
4311 }
4312 //=============================================================================
4313 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4314 //=============================================================================
4315 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4316 {
4317   MESSAGE ( "YACSDriverTexteBoundary" );
4318   // A. Les frontieres associees au cas
4319   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4320   int numberOfitems = ListBoundaryGroupType->length();
4321
4322   // B. Parcours des frontieres
4323   std::string texte_control ;
4324   std::list<std::string>  ListeBoundaryTraitees ;
4325   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4326   {
4327     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4328     MESSAGE ( "... BoundaryName = " << BoundaryName);
4329     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4330     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4331     int A_faire = 1 ;
4332     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4333     while (it != ListeBoundaryTraitees.end())
4334     {
4335       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4336       if ( BoundaryName == *it ) { A_faire = 0 ; }
4337       it++;
4338     }
4339     if ( A_faire == 1 )
4340     {
4341     // 1. Caracteristiques de la frontiere
4342       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4343       ASSERT(!CORBA::is_nil(myBoundary));
4344       // 2. Les instructions python associees a la frontiere
4345       //    La premiere ligne est un commentaire a eliminer
4346       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4347       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4348       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4349       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4350       std::istringstream tout (pythonStructure_0) ;
4351       std::string ligne ;
4352       std::string pythonStructure ;
4353       while ( std::getline( tout, ligne ) )
4354       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4355       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4356       // 3. Decodage du nom du service
4357       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4358       MESSAGE ( "... methode = " << methode);
4359       // 4. Mise en place des instructions
4360       int BoundaryType = myBoundary->GetType();
4361       MESSAGE ( "... BoundaryType = " << BoundaryType);
4362       std::string texte_control_0 ;
4363       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4364       texte_control += texte_control_0 ;
4365       // 5. Memorisation du traitement
4366       ListeBoundaryTraitees.push_back( BoundaryName );
4367     }
4368   }
4369
4370   return texte_control ;
4371 }
4372 //
4373 //=============================================================================
4374 //=============================================================================
4375 // Next functions are inherited from SALOMEDS::Driver interface
4376 //=============================================================================
4377 //=============================================================================
4378 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4379                                       const char* theURL,
4380                                       CORBA::Boolean isMultiFile)
4381 {
4382   MESSAGE ("Save for theURL = "<< theURL);
4383   SALOMEDS::TMPFile_var aStreamFile;
4384
4385   // get temporary directory name
4386   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4387
4388   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4389   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4390
4391   // HOMARD data file name
4392   std::string aFileName = "";
4393   if (isMultiFile)
4394     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4395   aFileName += "_HOMARD.dat";
4396
4397   // initialize sequence of file names
4398   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4399   aFileSeq->length(1);
4400   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4401
4402   // get full path to the data file
4403   aFileName = tmpDir + aFileName;
4404
4405   // save data
4406   // -> create file
4407   std::ofstream f(aFileName.c_str());
4408
4409   // clear temporary id map
4410   context._idmap.clear();
4411
4412   int id = 1;
4413
4414   // -> save cases
4415   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4416   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4417     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4418     PortableServer::ServantBase_var aServant = GetServant(aCas);
4419     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4420     if (aCasServant) {
4421       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4422       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4423     }
4424   }
4425   // -> save zones
4426   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4427   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4428     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4429     PortableServer::ServantBase_var aServant = GetServant(aZone);
4430     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4431     if (aZoneServant) {
4432       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4433       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4434     }
4435   }
4436   // -> save hypotheses
4437   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4438   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4439     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4440     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4441     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4442     if (aHypoServant) {
4443       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4444       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4445     }
4446   }
4447   // -> save iterations
4448   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4449   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4450     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4451     PortableServer::ServantBase_var aServant = GetServant(aIter);
4452     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4453     if (aIterServant) {
4454       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4455       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4456     }
4457   }
4458   // -> save boundaries
4459   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4460   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4461     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4462     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4463     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4464     if (aBoundaryServant) {
4465       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4466       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4467     }
4468   }
4469   // -> close file
4470   MESSAGE ("close file");
4471   f.close();
4472
4473   // put temporary files to the stream
4474   MESSAGE ("put temporary files to the stream");
4475   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4476
4477   // remove temporary files
4478   MESSAGE ("remove temporary files");
4479   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4480
4481   // return data stream
4482   MESSAGE ("return data stream");
4483   return aStreamFile._retn();
4484 };
4485
4486 //===========================================================================
4487 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4488                                            const char* theURL,
4489                                            CORBA::Boolean isMultiFile)
4490 {
4491   // No specific ASCII persistence
4492   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4493   return aStreamFile._retn();
4494 };
4495
4496 //===========================================================================
4497 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4498                                    const SALOMEDS::TMPFile& theStream,
4499                                    const char* theURL,
4500                                    CORBA::Boolean isMultiFile)
4501 {
4502   MESSAGE ("Load pour theURL = "<< theURL);
4503   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4504
4505   // set current study
4506   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4507     SetCurrentStudy(aStudy);
4508
4509   // get temporary directory name
4510   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4511
4512   // Convert the stream into sequence of files to process
4513   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4514                                                                             tmpDir.c_str(),
4515                                                                             isMultiFile);
4516   // HOMARD data file name
4517   std::string aFileName = "";
4518   if (isMultiFile)
4519     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4520   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4521
4522   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4523
4524   // save data
4525   // -> create file
4526   std::ifstream f(aFileName.c_str());
4527
4528   // clear context
4529   context._mesCas.clear();
4530   context._mesHypotheses.clear();
4531   context._mesIterations.clear();
4532   context._mesZones.clear();
4533   context._mesBoundarys.clear();
4534   context._idmap.clear();
4535
4536   int id = 1;
4537   std::string line;
4538
4539   while (f) {
4540     std::getline(f, line);
4541     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4542     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4543     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4544     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4545     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4546     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4547     if (line.substr(0, bounSignature.size()) == bounSignature) {
4548       // re-create boundary
4549       MESSAGE ("Recreation de la frontiere" );
4550       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4551       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4552       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4553       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4554         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4555         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4556       }
4557     }
4558     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4559       // re-create case
4560       MESSAGE ("Recreation du cas" );
4561       HOMARD::HOMARD_Cas_var aCase = newCase();
4562       PortableServer::ServantBase_var aServant = GetServant(aCase);
4563       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4564       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4565         context._mesCas[aCase->GetName()] = aCase;
4566         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4567       }
4568     }
4569     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4570       // re-create hypothesis
4571       MESSAGE ("Recreation de l hypothese" );
4572       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4573       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4574       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4575       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4576         context._mesHypotheses[aHypo->GetName()] = aHypo;
4577         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4578       }
4579     }
4580     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4581       // re-create iteration
4582       MESSAGE ("Recreation de l'iteration" );
4583       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4584       PortableServer::ServantBase_var aServant = GetServant(aIter);
4585       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4586       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4587         context._mesIterations[aIter->GetName()] = aIter;
4588         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4589       }
4590     }
4591     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4592       MESSAGE ("Recreation de la zone" );
4593       // re-create zone
4594       HOMARD::HOMARD_Zone_var aZone = newZone();
4595       PortableServer::ServantBase_var aServant = GetServant(aZone);
4596       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4597       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4598         context._mesZones[aZone->GetName()] = aZone;
4599         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4600       }
4601     }
4602     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4603       MESSAGE ("Recreation du schema YACS" );
4604       // re-create YACS
4605       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4606       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4607       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4608       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4609         context._mesYACSs[aYACS->GetName()] = aYACS;
4610         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4611       }
4612     }
4613     id++;
4614   }
4615
4616   // -> close file
4617   f.close();
4618
4619   // Remove temporary files created from the stream
4620   if (!isMultiFile)
4621     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4622
4623   return true;
4624 };
4625
4626 //===========================================================================
4627 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4628                                         const SALOMEDS::TMPFile& theStream,
4629                                         const char* theURL,
4630                                         CORBA::Boolean isMultiFile)
4631 {
4632   // No specific ASCII persistence
4633   return Load(theComponent, theStream, theURL, isMultiFile);
4634 };
4635
4636 //===========================================================================
4637 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4638 {
4639   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4640     // clearing study context should be done here:
4641     // - destroy all servants and related CORBA objects
4642     // ... (TODO)
4643     // - remove context from myContextMap
4644     myContextMap.erase(theComponent->GetStudy()->StudyId());
4645     // - nullify myCurrentStudy
4646     myCurrentStudy = SALOMEDS::Study::_nil();
4647   }
4648 };
4649
4650 //===========================================================================
4651 char* HOMARD_Gen_i::ComponentDataType()
4652 {
4653   return CORBA::string_dup("HOMARD");
4654 };
4655
4656 //===========================================================================
4657 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4658                                             const char* IORString,
4659                                             CORBA::Boolean isMultiFile,
4660                                             CORBA::Boolean isASCII)
4661 {
4662   CORBA::String_var aString("");
4663   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4664     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4665     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4666     if (!CORBA::is_nil(anObj)) {
4667       PortableServer::ServantBase_var aServant = GetServant(anObj);
4668       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4669       if (aStorable) {
4670         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4671         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4672           if (it->second == aStorable) {
4673             std::stringstream os;
4674             os << it->first;
4675             aString = CORBA::string_dup(os.str().c_str());
4676           }
4677         }
4678       }
4679     }
4680   }
4681   return aString._retn();
4682 };
4683
4684 //===========================================================================
4685 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4686                                             const char* aLocalPersistentID,
4687                                             CORBA::Boolean isMultiFile,
4688                                             CORBA::Boolean isASCII)
4689 {
4690   CORBA::String_var aString("");
4691   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4692     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4693     int id = atoi(aLocalPersistentID);
4694     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4695       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4696       if (!CORBA::is_nil(object)) {
4697         aString = _orb->object_to_string(object);
4698       }
4699     }
4700   }
4701   return aString._retn();
4702 };
4703
4704 //===========================================================================
4705 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4706 {
4707   if(CORBA::is_nil(myCurrentStudy))
4708     return false;
4709
4710   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4711   if(!aCas->_is_nil())
4712     return true;
4713
4714   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4715   if(!aHypo->_is_nil())
4716     return true;
4717
4718   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4719   if(!aZone->_is_nil())
4720     return true;
4721
4722   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4723   if(!aBoundary->_is_nil())
4724     return true;
4725
4726   /* Iteration is not published directly
4727   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4728   if(!aIter->_is_nil())
4729     return true;
4730   */
4731   return false;
4732 };
4733
4734 //===========================================================================
4735 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4736 {
4737   // No Copy/Paste support
4738   return false;
4739 };
4740
4741 //===========================================================================
4742 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4743                                            CORBA::Long& theObjectID)
4744 {
4745   // No Copy/Paste support
4746   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4747   return aStreamFile._retn();
4748 };
4749
4750 //===========================================================================
4751 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4752                                         CORBA::Long theObjectID)
4753 {
4754   // No Copy/Paste support
4755   return false;
4756 };
4757
4758 //===========================================================================
4759 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4760                                                CORBA::Long theObjectID,
4761                                                SALOMEDS::SObject_ptr theSObject)
4762 {
4763   // No Copy/Paste support
4764   SALOMEDS::SObject_var aResultSO;
4765   return aResultSO._retn();
4766 };
4767
4768 //===========================================================================
4769 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4770 {
4771   PortableServer::Servant aServant = 0;
4772   if (!CORBA::is_nil(theObject)) {
4773     try {
4774       aServant = _poa->reference_to_servant(theObject);
4775     }
4776     catch (...) {
4777     }
4778   }
4779   return aServant;
4780 }
4781
4782 //==========================================================================
4783 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4784                                        CORBA::Boolean isPublished,
4785                                        CORBA::Boolean isMultiFile,
4786                                        CORBA::Boolean& isValidScript)
4787 {
4788    MESSAGE ("Entree dans DumpPython");
4789    isValidScript=1;
4790    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4791    if(CORBA::is_nil(aStudy))
4792      return new Engines::TMPFile(0);
4793
4794    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4795    if(CORBA::is_nil(aSO))
4796       return new Engines::TMPFile(0);
4797
4798    std::string aScript = "\"\"\"\n";
4799    aScript += "Python script for HOMARD\n";
4800    aScript += "Copyright EDF-R&D 1996, 2011, 2014\n";
4801    aScript += "\"\"\"\n";
4802    aScript += "__revision__ = \"V1.2\"\n";
4803    aScript += "import HOMARD\n";
4804    if( isMultiFile )
4805       aScript += "import salome\n";
4806    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4807    if( isMultiFile ) {
4808       aScript += "def RebuildData(theStudy):\n";
4809       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4810    }
4811    else
4812       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4813    MESSAGE (". Au depart \n"<<aScript);
4814
4815
4816    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4817    {
4818     MESSAGE (". Ecritures des frontieres");
4819     aScript += "#\n# Creation of the boundaries";
4820     aScript +=  "\n# ==========================";
4821    }
4822    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4823    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4824         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4825    {
4826     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4827     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4828     std::string dumpBoundary = dumpCorbaBoundary.in();
4829     MESSAGE (dumpBoundary<<"\n");
4830     aScript += dumpBoundary;
4831    }
4832
4833
4834    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4835    {
4836     MESSAGE (". Ecritures des zones");
4837     aScript += "#\n# Creation of the zones";
4838     aScript +=  "\n# =====================";
4839    }
4840    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4841    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4842          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4843    {
4844     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4845     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4846     std::string dumpZone = dumpCorbaZone.in();
4847     MESSAGE (dumpZone<<"\n");
4848     aScript += dumpZone;
4849    }
4850
4851
4852    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4853    {
4854     MESSAGE (". Ecritures des hypotheses");
4855     aScript += "#\n# Creation of the hypotheses";
4856     aScript +=  "\n# ==========================";
4857    }
4858    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4859    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4860          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4861    {
4862     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4863     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4864     std::string dumpHypo = dumpCorbaHypo.in();
4865     MESSAGE (dumpHypo<<"\n");
4866     aScript += dumpHypo;
4867    }
4868
4869
4870    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4871    {
4872     MESSAGE (". Ecritures des cas");
4873     aScript += "#\n# Creation of the cases";
4874     aScript += "\n# =====================";
4875    }
4876    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4877    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4878         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4879         {
4880            std::string nomCas = (*it_cas).first;
4881            std::string dumpCas = std::string("\n# Creation of the case ") ;
4882            dumpCas +=  nomCas + std::string("\n");
4883            dumpCas += std::string("\t") + nomCas;
4884            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4885
4886            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4887            CORBA::String_var cIter0= myCase->GetIter0Name();
4888            std::string iter0 = cIter0.in();
4889
4890            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4891            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4892            std::string mesh0 = cMesh0.in();
4893            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4894            std::string meshName0 = cMeshName0.in();
4895            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4896            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4897            std::string dumpCas2= dumpCorbaCase.in();
4898
4899            MESSAGE (dumpCas<<dumpCas2<<"\n");
4900            aScript += dumpCas + dumpCas2;
4901         };
4902
4903
4904    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4905    {
4906     MESSAGE (". Ecritures des iterations");
4907     aScript += "#\n# Creation of the iterations" ;
4908     aScript += "\n# ==========================";
4909    }
4910    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4911    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4912         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4913    {
4914     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4915     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4916     std::string dumpIter = dumpCorbaIter.in();
4917     MESSAGE (dumpIter<<"\n");
4918     aScript += dumpIter;
4919    }
4920
4921
4922    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4923    {
4924     MESSAGE (". Ecritures des schemas YACS");
4925     aScript += "#\n# Creation of the schemas YACS";
4926     aScript +=  "\n# ============================";
4927    }
4928    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4929    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4930          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4931    {
4932     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4933     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4934     std::string dumpYACS = dumpCorbaYACS.in();
4935     MESSAGE (dumpYACS<<"\n");
4936     aScript += dumpYACS;
4937    }
4938
4939   MESSAGE (". Ecritures finales");
4940   if( isMultiFile )
4941     aScript += "\n\tpass";
4942   aScript += "\n";
4943
4944   if( !isMultiFile ) // remove unnecessary tabulation
4945     aScript = RemoveTabulation( aScript );
4946
4947 //   MESSAGE ("A ecrire \n"<<aScript);
4948   const size_t aLen = strlen(aScript.c_str());
4949   char* aBuffer = new char[aLen+1];
4950   strcpy(aBuffer, aScript.c_str());
4951
4952   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4953   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4954
4955   MESSAGE ("Sortie de DumpPython");
4956   return aStreamFile._retn();
4957 }
4958
4959
4960 //=============================================================================
4961 //=============================================================================
4962 // Utilitaires
4963 //=============================================================================
4964 //=============================================================================
4965 void HOMARD_Gen_i::IsValidStudy( )
4966 {
4967 //   MESSAGE( "IsValidStudy" );
4968   if (CORBA::is_nil(myCurrentStudy))
4969   {
4970     SALOME::ExceptionStruct es;
4971     es.type = SALOME::BAD_PARAM;
4972     es.text = "Invalid study context";
4973     throw SALOME::SALOME_Exception(es);
4974   };
4975   return ;
4976 }
4977
4978 //=============================================================================
4979 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4980 {
4981   std::string casename = std::string("") ;
4982   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4983   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4984   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4985   {
4986    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4987    {
4988      casename = std::string(it->second->GetName()) ;
4989      break ;
4990    }
4991   }
4992   return CORBA::string_dup( casename.c_str() );
4993 }
4994 /*//=============================================================================
4995 void SALOMEException( std::string message )
4996 {
4997   SALOME::ExceptionStruct es;
4998   es.type = SALOME::BAD_PARAM;
4999   es.text = message;
5000   throw SALOME::SALOME_Exception(es);
5001   return ;
5002 }*/
5003 //=============================================================================
5004 char* HOMARD_Gen_i::getVersion()
5005 {
5006 #if HOMARD_DEVELOPMENT
5007   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
5008 #else
5009   return CORBA::string_dup(HOMARD_VERSION_STR);
5010 #endif
5011 }
5012 //===============================================================================
5013 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
5014 // ligne : la ligne a manipuler
5015 // caractere : le caractere a reperer
5016 // option : 0 : la chaine avant la premiere apparition du caractere
5017 //          1 : la chaine apres la premiere apparition du caractere
5018 //          2 : la chaine avant la derniere apparition du caractere
5019 //          3 : la chaine apres la derniere apparition du caractere
5020 // Si le caractere est absent, on retourne la chaine totale
5021 //===============================================================================
5022 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
5023 {
5024 //   MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
5025 //
5026   std::string chaine = ligne ;
5027   int position ;
5028   if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
5029   else              { position = ligne.find_last_of( caractere ) ; }
5030 //   MESSAGE("position = "<<position);
5031 //   MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
5032 //   MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
5033 //
5034   if ( position != std::string::npos )
5035   {
5036     if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
5037     else                                      { chaine = ligne.substr( position+1 ) ; }
5038   }
5039   return chaine ;
5040 //
5041 }
5042 //=============================================================================
5043 //=============================================================================
5044 // Gestion des preferences
5045 //=============================================================================
5046 //=============================================================================
5047 // Decodage du fichier d'arcihvage des preferences
5048 //
5049 void HOMARD_Gen_i::SetPreferences( )
5050 {
5051   MESSAGE ( "SetPreferences" );
5052
5053   std::string ligne, mot_cle, salome_version ;
5054   bool ok = true ;
5055
5056   // A. Les valeurs par defaut ; elles doivent etre coherentes
5057   std::string LanguageShort = "en" ;
5058   int PublisMeshIN = 0 ;
5059   int PublisMeshOUT = 0 ;
5060   int YACSMaxIter = 0 ;
5061   int YACSMaxNode = 0 ;
5062   int YACSMaxElem = 0 ;
5063   std::string YACSTypeTestchaine = "None" ;
5064
5065   // B. La version de salome
5066   // Cela se presente sous la forme :
5067   // [SALOME KERNEL] : 7.3.0
5068   std::string File ;
5069   File  = getenv("KERNEL_ROOT_DIR") ;
5070   File += "/bin/salome/VERSION" ;
5071   MESSAGE ( "File = "<<File ) ;
5072   std::ifstream fichier0( File.c_str() ) ;
5073   if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5074   {
5075     std::string ligne; // variable contenant chaque ligne lue
5076     while ( std::getline( fichier0, ligne ) )
5077     {
5078       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5079       ligne_bis >> mot_cle ;
5080       if ( mot_cle == "[SALOME" )
5081       {
5082         salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5083 //         MESSAGE ( "salome_version = "<<salome_version<<"|||");
5084         break ;
5085       }
5086     }
5087   }
5088   else { ok = false ; }
5089
5090   // B. Decodage du fichier de preferences
5091   if ( ok )
5092   {
5093     std::string PrefFile ;
5094     PrefFile  = getenv("HOME") ;
5095     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5096     MESSAGE ( "PrefFile = "<<PrefFile ) ;
5097
5098     std::ifstream fichier( PrefFile.c_str() );
5099     if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5100     {
5101       bool section_langue = false ;
5102       bool section_homard = false ;
5103       while ( std::getline( fichier, ligne ) )
5104       {
5105         std::string chaine ;
5106         // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5107         std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5108         ligne_bis >> mot_cle ;
5109
5110         // 2. Les sections
5111         // 2.1. Debut d'une section
5112   //       MESSAGE(mot_cle);
5113         if ( mot_cle == "<section" )
5114         { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5115           ligne_bis >> mot_cle ;
5116           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5117           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5118           if ( chaine == "language" ) { section_langue = true ; }
5119           if ( chaine == "HOMARD" )   { section_homard = true ; }
5120   //         MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5121         }
5122         // 2.2. Fin d'une section
5123         else if ( mot_cle == "</section>" )
5124         { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5125           section_langue = false ;
5126           section_homard = false ; }
5127
5128         // 3. Parametres
5129         // 3.1. La langue
5130         else if ( section_langue || section_homard )
5131         { MESSAGE ( "a decoder : "<< ligne);
5132 //        La valeur : entre les deux premieres quotes
5133           chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5134 //           MESSAGE("chaine 1 = |"<<chaine<<"|");
5135           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5136 //           MESSAGE("chaine = |"<<chaine<<"|");
5137 //        Le mot_cle : entre les deux dernieres quotes
5138           std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5139 //           MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5140           chaine2 = GetStringInTexte ( chaine2,  "\"", 3 ) ;
5141 //           MESSAGE("chaine2 = |"<<chaine2<<"|");
5142           // 3.1. La langue
5143           if ( section_langue )
5144           { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5145           // 3.2. HOMARD
5146           if ( section_homard )
5147           {
5148             std::istringstream chainebis( chaine ) ;
5149             // 3.2.1. Les publications
5150             if ( chaine2 == "publish_mesh_in" )  { chainebis >> PublisMeshIN ; }
5151             if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5152             // 3.2.2. Les maximum pour YACS
5153             if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5154             if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5155             if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5156             if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5157           }
5158         }
5159       }
5160     }
5161   }
5162
5163   // C. Enregistrements
5164   MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5165   SetLanguageShort( LanguageShort.c_str() ) ;
5166
5167   MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5168   SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5169
5170   MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5171   SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5172
5173   MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5174   int YACSTypeTest ;
5175   if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest &gt; VRef" ) )      { YACSTypeTest = 1 ; }
5176   else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest &lt; VRef" ) ) { YACSTypeTest = 2 ; }
5177   else                                                                                                { YACSTypeTest = 0 ; }
5178   MESSAGE ("==> TypeTest = " << YACSTypeTest );
5179   SetYACSConvergenceType( YACSTypeTest ) ;
5180
5181   return ;
5182 }
5183 //===============================================================================
5184 // Langue de SALOME
5185 //===============================================================================
5186 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5187 {
5188 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5189   _LangueShort = LanguageShort ;
5190   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5191   else                        { _Langue = "English" ; }
5192   return ;
5193 }
5194 char* HOMARD_Gen_i::GetLanguageShort()
5195 {
5196 //   MESSAGE ("GetLanguageShort");
5197   return CORBA::string_dup( _LangueShort.c_str() );
5198 }
5199 //===============================================================================
5200 // Options de publications
5201 //===============================================================================
5202 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5203 {
5204   _PublisMeshIN  = PublisMeshIN  ;
5205   _PublisMeshOUT = PublisMeshOUT ;
5206   return ;
5207 }
5208 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5209 {
5210   return _PublisMeshIN ;
5211 }
5212 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5213 {
5214   return _PublisMeshOUT ;
5215 }
5216 //===============================================================================
5217 // YACS - test de convergence
5218 //===============================================================================
5219 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5220 {
5221   _YACSMaxIter = YACSMaxIter ;
5222   _YACSMaxNode = YACSMaxNode ;
5223   _YACSMaxElem = YACSMaxElem ;
5224   return ;
5225 }
5226 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5227 {
5228   return _YACSMaxIter ;
5229 }
5230 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5231 {
5232   return _YACSMaxNode ;
5233 }
5234 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5235 {
5236   return _YACSMaxElem ;
5237 }
5238 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5239 {
5240   _YACSTypeTest = YACSTypeTest ;
5241   return ;
5242 }
5243 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5244 {
5245   return _YACSTypeTest ;
5246 }
5247
5248 //=============================================================================
5249 extern "C"
5250 {
5251   HOMARDENGINE_EXPORT
5252   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5253                                                   PortableServer::POA_ptr poa,
5254                                                   PortableServer::ObjectId* contId,
5255                                                   const char* instanceName,
5256                                                   const char* interfaceName)
5257   {
5258     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5259     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5260     return myHOMARD_Gen->getId();
5261   }
5262 }