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