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