Salome HOME
3f54b8d5d7ffa780523abf6c2ac3aed993b0b9e6
[modules/homard.git] / src / HOMARD_I / HOMARD_Gen_i.cxx
1 // Copyright (C) 2011-2012  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 "HomardDriver.hxx"
27 #include "HOMARD_DriverTools.hxx"
28 #include "HomardMedCommun.h"
29
30 #include "HOMARD_version.h"
31
32 #include "utilities.h"
33 #include "Utils_SINGLETON.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "SALOMEDS_Tool.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOMEconfig.h"
38 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include CORBA_CLIENT_HEADER(SMESH_Gen)
40
41 #include <stdlib.h>
42 #include <sys/stat.h>
43 #include <dirent.h>
44 #include <string>
45 #include <iostream>
46 #include <iomanip>
47 #include <sys/stat.h>
48 #include <set>
49 #include <vector>
50 #include <stdio.h>
51
52 using  namespace std;
53
54 //=============================================================================
55 //functions
56 //=============================================================================
57 std::string RemoveTabulation( std::string theScript )
58 {
59   std::string::size_type aPos = 0;
60   while( aPos < theScript.length() )
61   {
62     aPos = theScript.find( "\n\t", aPos );
63     if( aPos == std::string::npos )
64       break;
65     theScript.replace( aPos, 2, "\n" );
66     aPos++;
67   }
68   return theScript;
69 }
70 //=============================================================================
71 /*!
72  *  standard constructor
73  */
74 //=============================================================================
75 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
76                             PortableServer::POA_ptr poa,
77                             PortableServer::ObjectId * contId,
78                             const char *instanceName,
79                             const char *interfaceName) :
80 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
81 {
82   MESSAGE("constructor");
83   _thisObj = this;
84   _id = _poa->activate_object(_thisObj);
85
86   myHomard = new ::HOMARD_Gen();
87   _NS = SINGLETON_<SALOME_NamingService>::Instance();
88   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
89   _NS->init_orb(_orb);
90 }
91 //=================================
92 /*!
93  *  standard destructor
94  */
95 //================================
96 HOMARD_Gen_i::~HOMARD_Gen_i()
97 {
98 }
99 //=============================================================================
100 //=============================================================================
101 // Utilitaires pour l'étude
102 //=============================================================================
103 //=============================================================================
104 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
105 {
106   ASSERT(!CORBA::is_nil(theStudy));
107   MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
108   SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
109
110   // Create SComponent labelled 'homard' if it doesn't already exit
111   SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
112   if (CORBA::is_nil(homardFather))
113   {
114     myBuilder->NewCommand();
115     MESSAGE("Add Component HOMARD");
116
117     bool aLocked = theStudy->GetProperties()->IsLocked();
118     if (aLocked) theStudy->GetProperties()->SetLocked(false);
119
120     homardFather = myBuilder->NewComponent(ComponentDataType());
121     SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
122     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
123     CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
124     SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
125                 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
126     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
127     if (!Comp->_is_nil())
128     {
129       aName->SetValue(ComponentDataType());
130     }
131
132     anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
133     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
134     aPixmap->SetPixMap("HOMARD_2.png");
135     myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
136
137     if (aLocked) theStudy->GetProperties()->SetLocked(true);
138     myBuilder->CommitCommand();
139   }
140 }
141 //=============================================================================
142 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
143 {
144   MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
145   myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
146   this->addInStudy(myCurrentStudy);
147 }
148 //=============================================================================
149 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
150 //=============================================================================
151 {
152   MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
153   return SALOMEDS::Study::_duplicate(myCurrentStudy);
154 }
155 //=============================================================================
156 CORBA::Long HOMARD_Gen_i::GetCurrentStudyID()
157 //=============================================================================
158 {
159   return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
160 }
161 //=============================================================================
162 //=============================================================================
163
164 //=============================================================================
165 //=============================================================================
166 // Utilitaires pour l'iteration
167 //=============================================================================
168 //=============================================================================
169 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const CORBA::Boolean EtatCalcul)
170 //=====================================================================================
171 {
172   MESSAGE( "SetEtatIter : affectation de l etat " << EtatCalcul << " a l iteration " << nomIter );
173   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
174   if (CORBA::is_nil(myIteration))
175   {
176       SALOME::ExceptionStruct es;
177       es.type = SALOME::BAD_PARAM;
178       es.text = "Invalid Iteration ";
179       throw SALOME::SALOME_Exception(es);
180       return ;
181   };
182
183   myIteration->SetEtat(EtatCalcul);
184
185   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
186   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
187
188   int number = myIteration->GetNumber() ;
189   const char* icone ;
190   if ( number == 0 )
191     icone = "iter0.png" ;
192   else if (EtatCalcul)
193     icone = "iter_calculee.png" ;
194   else
195     icone = "iter_non_calculee.png" ;
196   PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone, NULL) ;
197
198   aStudyBuilder->CommitCommand();
199
200 }
201 //=============================================================================
202 //=============================================================================
203 //
204 //=============================================================================
205 //=============================================================================
206 // Destruction des structures identifiees par leurs noms
207 //=============================================================================
208 //=============================================================================
209 CORBA::Long HOMARD_Gen_i::DeleteBoundary(const char* BoundaryName)
210 {
211   MESSAGE ( "DeleteBoundary : BoundaryName = " << BoundaryName );
212   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
213   if (CORBA::is_nil(myBoundary))
214   {
215 //     const char* message = "Invalid Boundary " ;
216 //     SALOMEException(message) ;
217     SALOME::ExceptionStruct es;
218     es.type = SALOME::BAD_PARAM;
219     es.text = "Invalid Boundary ";
220     throw SALOME::SALOME_Exception(es);
221     return 1 ;
222   };
223
224 // On verifie que la frontiere n'est plus utilisee
225   HOMARD::listeCases* maListe = GetAllCasesName();
226   int numberOfCases = maListe->length();
227   MESSAGE ( ".. Nombre de cas = " << numberOfCases );
228   std::string CaseName ;
229   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType ;
230   int numberOfitems ;
231   HOMARD::HOMARD_Cas_var myCase ;
232   for (int NumeCas = 0; NumeCas< numberOfCases; NumeCas++)
233   {
234     CaseName = std::string((*maListe)[NumeCas]);
235     MESSAGE ( "... Examen du cas = " << CaseName.c_str() );
236     myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
237     ASSERT(!CORBA::is_nil(myCase));
238     ListBoundaryGroupType = myCase->GetBoundaryGroup();
239     numberOfitems = ListBoundaryGroupType->length();
240     MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
241     for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
242     {
243       if ( std::string((*ListBoundaryGroupType)[NumBoundary]) == BoundaryName )
244       {
245         SALOME::ExceptionStruct es;
246         es.type = SALOME::BAD_PARAM;
247         es.text = "This boundary is used in a case and cannot be deleted.";
248         throw SALOME::SALOME_Exception(es);
249         return 2 ;
250       };
251     };
252   }
253
254   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
255   myContextMap[GetCurrentStudyID()]._mesBoundarys.erase(BoundaryName);
256   SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(BoundaryName, ComponentDataType());
257   SALOMEDS::SObject_var aSO =listSO[0];
258   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
259   myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
260
261   return 0 ;
262 }
263 //=============================================================================
264 CORBA::Long HOMARD_Gen_i::DeleteCase(const char* nomCas)
265 {
266   // Pour detruire un cas
267   MESSAGE ( "DeleteCase : nomCas = " << nomCas );
268   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
269   if (CORBA::is_nil(myCase))
270   {
271     SALOME::ExceptionStruct es;
272     es.type = SALOME::BAD_PARAM;
273     es.text = "Invalid Case Context ";
274     throw SALOME::SALOME_Exception(es);
275     return 1;
276   };
277   // On commence par detruire toutes les iterations en partant de l'initiale et y compris elle
278   CORBA::String_var nomIter = myCase->GetIter0Name();
279   CORBA::Long Option = 0 ;
280   if ( DeleteIterationOption(nomIter, Option) != 0 )
281   {
282     return 2;
283   };
284
285   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
286   myContextMap[GetCurrentStudyID()]._mesCas.erase(nomCas);
287   SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomCas, ComponentDataType());
288   SALOMEDS::SObject_var aSO =listSO[0];
289   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
290   myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
291
292   return 0 ;
293 }
294 //=============================================================================
295 CORBA::Long HOMARD_Gen_i::DeleteHypo(const char* nomHypo)
296 {
297   MESSAGE ( "DeleteHypo : nomHypo = " << nomHypo );
298   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
299   if (CORBA::is_nil(myHypo))
300   {
301     SALOME::ExceptionStruct es;
302     es.type = SALOME::BAD_PARAM;
303     es.text = "Invalid Hypothesis ";
304     throw SALOME::SALOME_Exception(es);
305     return 1 ;
306   };
307
308 // On verifie que l'hypothese n'est plus utilisee
309   HOMARD::listeIters* maListeIter = myHypo->GetIterations();
310   int numberOfIter = maListeIter->length();
311   if ( numberOfIter > 0 )
312   {
313     SALOME::ExceptionStruct es;
314     es.type = SALOME::BAD_PARAM;
315     es.text = "This hypothesis is used and cannot be deleted.";
316     throw SALOME::SALOME_Exception(es);
317     return 2 ;
318   };
319
320   // suppression du lien avec les zones eventuelles
321   HOMARD::listeZonesHypo* maListe = myHypo->GetZones();
322   int numberOfZones = maListe->length();
323   MESSAGE ( ".. Nombre de zones = " << numberOfZones );
324   for (int NumeZone = 0; NumeZone< numberOfZones; NumeZone++)
325   {
326     std::string ZoneName = std::string((*maListe)[NumeZone]);
327     MESSAGE ( ".. suppression du lien avec la zone = " << ZoneName.c_str() );
328     DissociateHypoZone(nomHypo, ZoneName.c_str()) ;
329     NumeZone += 1 ;
330   }
331
332   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
333   myContextMap[GetCurrentStudyID()]._mesHypotheses.erase(nomHypo);
334   SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomHypo, ComponentDataType());
335   SALOMEDS::SObject_var aSO =listSO[0];
336   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
337   myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
338
339   return 0 ;
340 }
341 //=============================================================================
342 CORBA::Long HOMARD_Gen_i::DeleteIteration(const char* nomIter)
343 {
344   // Pour detruire une iteration courante
345   MESSAGE ( "DeleteIteration : nomIter = " << nomIter );
346   CORBA::Long Option = 1 ;
347   return DeleteIterationOption(nomIter, Option);
348 }
349 //=============================================================================
350 CORBA::Long HOMARD_Gen_i::DeleteIterationOption(const char* nomIter, CORBA::Long Option)
351 {
352   //  Option = 0 : On autorise la destruction de l'iteration 0
353   //  Option = 1 : On interdit la destruction de l'iteration 0
354   MESSAGE ( "DeleteIterationOption : nomIter = " << nomIter << ", avec option = " << Option );
355   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
356   if (CORBA::is_nil(myIteration))
357   {
358     SALOME::ExceptionStruct es;
359     es.type = SALOME::BAD_PARAM;
360     es.text = "Invalid Iteration ";
361     throw SALOME::SALOME_Exception(es);
362     return 1 ;
363   };
364
365   int numero = myIteration->GetNumber();
366   MESSAGE ( "DeleteIterationOption : numero = " << numero );
367   if ( numero == 0 and Option == 1 )
368   {
369     SALOME::ExceptionStruct es;
370     es.type = SALOME::BAD_PARAM;
371     es.text = "This iteration cannot be deleted.";
372     throw SALOME::SALOME_Exception(es);
373     return 2 ;
374   };
375
376   // On detruit recursivement toutes les filles
377   HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
378   int numberOfIter = maListe->length();
379   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
380   {
381     std::string nomIterFille = std::string((*maListe)[NumeIter]);
382     MESSAGE ( ".. appel recursif de DeleteIterationOption pour nomIter = " << nomIterFille.c_str() );
383     DeleteIterationOption(nomIterFille.c_str(), Option);
384   }
385
386   // On arrive ici pour une iteration sans fille
387   MESSAGE ( "Destruction effective de " << nomIter );
388   // On commence par invalider l'iteration pour faire le menage des dependances
389   // et des publications dans SMESH
390   InvalideIter(nomIter) ;
391
392   // Retrait dans la descendance de l'iteration parent
393   if ( numero > 0 )
394   {
395     const char* nomIterationParent = myIteration->GetIterParentName();
396     MESSAGE ( "Retrait dans la descendance de nomIterationParent " << nomIterationParent );
397     HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
398     if (CORBA::is_nil(myIterationParent))
399     {
400       SALOME::ExceptionStruct es;
401       es.type = SALOME::BAD_PARAM;
402       es.text = "Invalid Iteration ";
403       throw SALOME::SALOME_Exception(es);
404       return 3 ;
405     };
406     myIterationParent->UnLinkNextIteration(nomIter);
407   }
408
409   // suppression du lien avec l'hypothese
410   if ( numero > 0 )
411   {
412     const char* nomHypo = myIteration->GetHypoName();
413     HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
414     ASSERT(!CORBA::is_nil(myHypo));
415     myHypo->UnLinkIteration(nomIter);
416   }
417
418   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
419   myContextMap[GetCurrentStudyID()]._mesIterations.erase(nomIter);
420   SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomIter, ComponentDataType());
421   SALOMEDS::SObject_var aSO =listSO[0];
422   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
423   myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
424   // on peut aussi faire RemoveObject
425 //   MESSAGE ( "Au final" );
426 //   HOMARD::listeIterations* Liste = GetAllIterationsName() ;
427 //   numberOfIter = Liste->length();
428 //   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
429 //   {
430 //       std::string nomIterFille = std::string((*Liste)[NumeIter]);
431 //       MESSAGE ( ".. nomIter = " << nomIterFille.c_str() );
432 //   }
433
434   return 0 ;
435 }
436 //=============================================================================
437 CORBA::Long HOMARD_Gen_i::DeleteZone(const char* nomZone)
438 {
439   MESSAGE ( "DeleteZone : nomZone = " << nomZone );
440   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[nomZone];
441   if (CORBA::is_nil(myZone))
442   {
443     SALOME::ExceptionStruct es;
444     es.type = SALOME::BAD_PARAM;
445     es.text = "Invalid Zone ";
446     throw SALOME::SALOME_Exception(es);
447     return 1 ;
448   };
449
450 // On verifie que la zone n'est plus utilisee
451   HOMARD::listeHypo* maListe = myZone->GetHypo();
452   int numberOfHypo = maListe->length();
453   MESSAGE ( ".. Nombre d'hypotheses = " << numberOfHypo );
454   if ( numberOfHypo > 0 )
455   {
456     SALOME::ExceptionStruct es;
457     es.type = SALOME::BAD_PARAM;
458     es.text = "This zone is used and cannot be deleted.";
459     throw SALOME::SALOME_Exception(es);
460     return 2 ;
461   };
462 //
463   // comme on a un _var comme pointeur CORBA, on ne se preoccupe pas du delete
464   myContextMap[GetCurrentStudyID()]._mesZones.erase(nomZone);
465   SALOMEDS::Study::ListOfSObject_var listSO = myCurrentStudy->FindObjectByName(nomZone, ComponentDataType());
466   SALOMEDS::SObject_var aSO =listSO[0];
467   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
468   myCurrentStudy->NewBuilder()->RemoveObjectWithChildren(aSO);
469
470   return 0 ;
471 }
472 //=============================================================================
473 //=============================================================================
474 //
475 //=============================================================================
476 //=============================================================================
477 // Invalidation des structures identifiees par leurs noms
478 //=============================================================================
479 //=============================================================================
480 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
481 {
482   MESSAGE( "InvalideBoundary : BoundaryName = " << BoundaryName  );
483   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
484   if (CORBA::is_nil(myBoundary))
485   {
486     SALOME::ExceptionStruct es;
487     es.type = SALOME::BAD_PARAM;
488     es.text = "Invalid Boundary ";
489     throw SALOME::SALOME_Exception(es);
490     return ;
491   }
492   else
493   {
494     SALOME::ExceptionStruct es;
495     es.type = SALOME::BAD_PARAM;
496     es.text = "No change is allowed in a boundary. Ask for evolution.";
497     throw SALOME::SALOME_Exception(es);
498     return ;
499   };
500 }
501 //=============================================================================
502 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
503 {
504   MESSAGE( "InvalideZone : ZoneName    = " << ZoneName );
505   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
506   if (CORBA::is_nil(myZone))
507   {
508       SALOME::ExceptionStruct es;
509       es.type = SALOME::BAD_PARAM;
510       es.text = "Invalid Zone ";
511       throw SALOME::SALOME_Exception(es);
512       return ;
513   };
514   HOMARD::listeHypo* maListe = myZone->GetHypo();
515   int numberOfHypo = maListe->length();
516   MESSAGE( ".. numberOfHypo = " << numberOfHypo );
517   for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
518   {
519       std::string nomHypo = std::string((*maListe)[NumeHypo]);
520       MESSAGE( ".. nomHypo = " << nomHypo );
521       InvalideHypo(nomHypo.c_str());
522   }
523 }
524 //=============================================================================
525 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
526 {
527   MESSAGE( "InvalideHypo : nomHypo    = " << nomHypo  );
528   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
529   if (CORBA::is_nil(myHypo))
530   {
531       SALOME::ExceptionStruct es;
532       es.type = SALOME::BAD_PARAM;
533       es.text = "Invalid Hypothesis ";
534       throw SALOME::SALOME_Exception(es);
535       return ;
536   };
537
538   HOMARD::listeIters* maListe = myHypo->GetIterations();
539   int numberOfIter = maListe->length();
540   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
541   {
542       std::string nomIter = std::string((*maListe)[NumeIter]);
543       MESSAGE( ".. nomIter = " << nomIter );
544       InvalideIter(nomIter.c_str());
545   }
546 }
547 //=============================================================================
548 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
549 {
550   MESSAGE("InvalideIter : nomIter = " << nomIter);
551   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
552   if (CORBA::is_nil(myIteration))
553   {
554       SALOME::ExceptionStruct es;
555       es.type = SALOME::BAD_PARAM;
556       es.text = "Invalid Iteration ";
557       throw SALOME::SALOME_Exception(es);
558       return ;
559   };
560
561   HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
562   int numberOfIter = maListe->length();
563   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
564   {
565       std::string nomIterFille = std::string((*maListe)[NumeIter]);
566       MESSAGE ( ".. appel recursif de InvalideIter pour nomIter = " << nomIterFille.c_str() );
567       InvalideIter(nomIterFille.c_str());
568   }
569
570   // On arrive ici pour une iteration sans fille
571   MESSAGE ( "Invalidation effective de " << nomIter );
572   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
573   SALOMEDS::ChildIterator_var  aIter = myCurrentStudy->NewChildIterator(aIterSO);
574   for (; aIter->More(); aIter->Next())
575   {
576       SALOMEDS::SObject_var so = aIter->Value();
577       SALOMEDS::GenericAttribute_var anAttr;
578       if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
579       SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
580       std::string value (aCommentAttr->Value());
581       if(value == std::string("HypoHomard")) continue;
582       SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
583       aStudyBuilder->RemoveObject(so);
584   }
585
586   int number = myIteration->GetNumber();
587   if ( number > 0 )
588   {
589     SetEtatIter(nomIter,false);
590     const char * nomCas = myIteration->GetCaseName();
591     HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
592     if (CORBA::is_nil(myCase))
593     {
594         SALOME::ExceptionStruct es;
595         es.type = SALOME::BAD_PARAM;
596         es.text = "Invalid Case Context ";
597         throw SALOME::SALOME_Exception(es);
598         return ;
599     };
600     const char* dirParent  = myCase->GetDirName();
601     const char* nomDir     = myIteration->GetDirName();
602     const char* nomFichier = myIteration->GetMeshFile();
603     std::string commande= "rm -rf " + std::string(dirParent) + "/" + std::string(nomDir);
604     commande = commande + ";rm -rf " + std::string(nomFichier);
605     if ((system(commande.c_str())) != 0)
606     {
607           SALOME::ExceptionStruct es;
608           es.type = SALOME::BAD_PARAM;
609           es.text = "Menage du repertoire de calcul impossible" ;
610           throw SALOME::SALOME_Exception(es);
611           return ;
612     }
613   // Suppression du maillage publie dans SMESH
614     const char* MeshName = myIteration->GetMeshName();
615     DeleteResultInSmesh(nomFichier, MeshName) ;
616   };
617
618 }
619 //=============================================================================
620 //=============================================================================
621 //
622 //=============================================================================
623 //=============================================================================
624 // Association de lien entre des structures identifiees par leurs noms
625 //=============================================================================
626 //=============================================================================
627 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
628 {
629   MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << ","  << labelIter );
630
631   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
632   if (CORBA::is_nil(myCase))
633   {
634       SALOME::ExceptionStruct es;
635       es.type = SALOME::BAD_PARAM;
636       es.text = "Invalid Case ";
637       throw SALOME::SALOME_Exception(es);
638       return ;
639   };
640
641   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
642   if (CORBA::is_nil(myIteration))
643   {
644       SALOME::ExceptionStruct es;
645       es.type = SALOME::BAD_PARAM;
646       es.text = "Invalid iteration ";
647       throw SALOME::SALOME_Exception(es);
648       return ;
649   };
650
651   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
652   SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
653   if (CORBA::is_nil(aCasSO))
654   {
655       SALOME::ExceptionStruct es;
656       es.type = SALOME::BAD_PARAM;
657       es.text = "Invalid Case ";
658       throw SALOME::SALOME_Exception(es);
659       return ;
660   };
661
662   aStudyBuilder->NewCommand();
663   SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
664   PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
665                      "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
666   aStudyBuilder->CommitCommand();
667
668   myCase->AddIteration(nomIter);
669   myIteration->SetCaseName(nomCas);
670 }
671 //=====================================================================================
672 void HOMARD_Gen_i::AssociateHypoZone(const char* nomHypothesis, const char* ZoneName, CORBA::Long TypeUse)
673 {
674   MESSAGE ( "AssociateHypoZone : nomHypo = " << nomHypothesis << ", ZoneName= " << ZoneName << ", TypeUse = " << TypeUse);
675
676   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
677   ASSERT(!CORBA::is_nil(myHypo));
678   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
679   ASSERT(!CORBA::is_nil(aHypoSO));
680
681   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
682   ASSERT(!CORBA::is_nil(myZone));
683   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
684   ASSERT(!CORBA::is_nil(aZoneSO));
685
686   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
687
688   aStudyBuilder->NewCommand();
689
690   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
691   aStudyBuilder->Addreference(aSubSO, aZoneSO);
692
693   aStudyBuilder->CommitCommand();
694
695   myZone->AddHypo(nomHypothesis);
696   myHypo->AddZone0(ZoneName, TypeUse);
697 };
698 //=============================================================================
699 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
700 {
701   MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
702
703   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
704   ASSERT(!CORBA::is_nil(myHypo));
705   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
706   ASSERT(!CORBA::is_nil(aHypoSO));
707
708   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
709   ASSERT(!CORBA::is_nil(myIteration));
710   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
711   ASSERT(!CORBA::is_nil(aIterSO));
712
713   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
714
715   aStudyBuilder->NewCommand();
716
717   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
718   aStudyBuilder->Addreference(aSubSO, aHypoSO);
719
720   aStudyBuilder->CommitCommand();
721
722   myIteration->SetHypoName(nomHypo);
723   myHypo->LinkIteration(nomIter);
724 };
725 //=============================================================================
726 //=============================================================================
727 //
728 //=============================================================================
729 //=============================================================================
730 // Dissociation de lien entre des structures identifiees par leurs noms
731 //=============================================================================
732 //=============================================================================
733 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
734 {
735   MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
736
737   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
738   ASSERT(!CORBA::is_nil(myHypo));
739   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
740   ASSERT(!CORBA::is_nil(aHypoSO));
741
742   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
743   ASSERT(!CORBA::is_nil(myZone));
744   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
745   ASSERT(!CORBA::is_nil(aZoneSO));
746
747   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
748
749   SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
750   for (; it->More(); it->Next())
751   {
752     SALOMEDS::SObject_var aHypObj = it->Value();
753     SALOMEDS::SObject_var ptrObj;
754     if (aHypObj->ReferencedObject(ptrObj))
755     {
756       if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
757       {
758         aStudyBuilder->NewCommand();
759         aStudyBuilder->RemoveObject(aHypObj);
760         aStudyBuilder->CommitCommand();
761         break;
762       }
763     }
764   }
765
766   myZone->SupprHypo(nomHypothesis);
767   myHypo->SupprZone(ZoneName);
768 };
769 //=============================================================================
770 //=============================================================================
771 //
772
773 //=============================================================================
774 //=============================================================================
775 // Recuperation des listes
776 //=============================================================================
777 //=============================================================================
778 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
779 {
780   MESSAGE("GetAllCasesName");
781   IsValidStudy () ;
782
783   HOMARD::listeCases_var ret = new HOMARD::listeCases;
784   ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
785   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
786   int i = 0;
787   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
788   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
789   {
790     ret[i++] = CORBA::string_dup((*it).first.c_str());
791   }
792
793   return ret._retn();
794 }
795 //=============================================================================
796 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
797 {
798   MESSAGE("GetAllHypothesesName");
799   IsValidStudy () ;
800
801   HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
802   ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
803   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
804   int i = 0;
805   for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
806   it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
807   {
808     ret[i++] = CORBA::string_dup((*it).first.c_str());
809   }
810
811   return ret._retn();
812 }
813 //=============================================================================
814 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
815 {
816   MESSAGE("GetAllZonesName");
817   IsValidStudy () ;
818
819   HOMARD::listeZones_var ret = new HOMARD::listeZones;
820   ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
821   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
822   int i = 0;
823   for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
824   it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
825   {
826     ret[i++] = CORBA::string_dup((*it).first.c_str());
827   }
828
829   return ret._retn();
830 }
831 //=============================================================================
832 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
833 {
834   MESSAGE("GetAllIterationsName");
835   IsValidStudy () ;
836
837   HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
838   ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
839   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
840   int i = 0;
841   for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
842   it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
843   {
844     ret[i++] = CORBA::string_dup((*it).first.c_str());
845   }
846
847   return ret._retn();
848 }
849 //=============================================================================
850 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
851 {
852   MESSAGE("GetAllBoundarysName");
853   IsValidStudy () ;
854
855   HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
856   ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
857   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
858   int i = 0;
859   for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
860   it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
861   {
862     ret[i++] = CORBA::string_dup((*it).first.c_str());
863   }
864
865   return ret._retn();
866 }
867 //=============================================================================
868 //=============================================================================
869
870 //=============================================================================
871 //=============================================================================
872 // Recuperation des structures identifiees par leurs noms
873 //=============================================================================
874 //=============================================================================
875 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
876 {
877   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
878   ASSERT(!CORBA::is_nil(myCase));
879   return HOMARD::HOMARD_Cas::_duplicate(myCase);
880 }
881 //=============================================================================
882 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
883 {
884   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
885   ASSERT(!CORBA::is_nil(myZone));
886   return HOMARD::HOMARD_Zone::_duplicate(myZone);
887 }
888 //=============================================================================
889 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
890 {
891   HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
892   ASSERT(!CORBA::is_nil(myHypothesis));
893   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
894 }
895 //=============================================================================
896 HOMARD::HOMARD_Iteration_ptr  HOMARD_Gen_i::GetIteration(const char* NomIterationation)
897 {
898   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
899   ASSERT(!CORBA::is_nil(myIteration));
900   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
901 }
902 //=============================================================================
903 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
904 {
905   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
906   ASSERT(!CORBA::is_nil(myBoundary));
907   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
908 }
909 //=============================================================================
910 //=============================================================================
911
912 //=============================================================================
913 //=============================================================================
914 // Recuperation des structures par le contexte
915 //=============================================================================
916 //=============================================================================
917 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
918 {
919   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
920   ASSERT(!CORBA::is_nil(myCase));
921 //
922   HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
923   ASSERT(!CORBA::is_nil(myIteration));
924 //
925   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
926 }
927 //=============================================================================
928 //=============================================================================
929
930 //=============================================================================
931 //=============================================================================
932 // Nouvelles structures
933 //=============================================================================
934 //=============================================================================
935 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
936 {
937   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
938   HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
939   HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
940   return aCase._retn();
941 }
942 //=============================================================================
943 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
944 {
945   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
946   HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
947   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
948   return aHypo._retn();
949 }
950 //=============================================================================
951 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
952 {
953   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
954   HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
955   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
956   return aIter._retn();
957 }
958 //=============================================================================
959 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
960 {
961   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
962   HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
963   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
964   return aBoundary._retn();
965 }
966 //=============================================================================
967 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
968 {
969   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
970   HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
971   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
972   return aZone._retn();
973 }
974 //=============================================================================
975 //=============================================================================
976
977 //=============================================================================
978 //=============================================================================
979 // Creation des structures identifiees par leurs noms
980 //=============================================================================
981 //=============================================================================
982 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
983 {
984   MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
985   IsValidStudy () ;
986
987   if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
988   {
989     SALOME::ExceptionStruct es;
990     es.type = SALOME::BAD_PARAM;
991     es.text = "This case has already been defined";
992     throw SALOME::SALOME_Exception(es);
993     return 0;
994   };
995
996   int existe = MEDFileExist ( MeshFile ) ;
997   if ( existe == 0 )
998   {
999     SALOME::ExceptionStruct es;
1000     es.type = SALOME::BAD_PARAM;
1001     es.text = "The mesh file does not exist.";
1002     throw SALOME::SALOME_Exception(es);
1003     return 0;
1004   }
1005
1006   HOMARD::HOMARD_Cas_var myCase = newCase();
1007   myCase->SetName(nomCas);
1008   SALOMEDS::SObject_var aSO;
1009   PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1010   myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1011
1012   std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
1013   HOMARD::extrema_var aSeq = new HOMARD::extrema();
1014   if (LesExtremes.size()!=10) { return false; }
1015   aSeq->length(10);
1016   for (int i =0; i< LesExtremes.size(); i++)
1017        aSeq[i]=LesExtremes[i];
1018   myCase->SetBoundingBox(aSeq);
1019
1020   std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile);
1021   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
1022   aSeqGroupe->length(LesGroupes.size());
1023   std::set<std::string>::const_iterator it;
1024   int i = 0;
1025   for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
1026      aSeqGroupe[i++]=(*it).c_str();
1027   myCase->SetGroups(aSeqGroupe);
1028
1029 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
1030 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
1031   int monNum=0;
1032   std::string NomIteration = std::string(MeshName) ;
1033   while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
1034   {
1035      std::ostringstream nom;
1036      nom << MeshName << monNum;
1037      NomIteration=nom.str();
1038      monNum = monNum+1;
1039   }
1040   MESSAGE ( "CreateCase : NomIteration = " << NomIteration );
1041
1042   HOMARD::HOMARD_Iteration_var anIter = newIteration();
1043   myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1044   std::ostringstream DirName;
1045   DirName << "I_00";
1046
1047   anIter->SetDirName(DirName.str().c_str());
1048   anIter->SetName(NomIteration.c_str());
1049   anIter->SetMeshFile(MeshFile);
1050   anIter->SetMeshName(MeshName);
1051   anIter->SetNumber(0);
1052
1053   AssociateCaseIter (nomCas,NomIteration.c_str(),"IterationHomard");
1054   SetEtatIter(NomIteration.c_str(),true);
1055 //
1056   PublishResultInSmesh(MeshFile, 0);
1057
1058 // Valeurs par defaut des filtrages
1059   myCase->SetPyram(0);
1060
1061   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1062 }
1063 //=============================================================================
1064 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1065 {
1066   MESSAGE ( "CreateHypothesis : nomHypothesis  = " << nomHypothesis );
1067   IsValidStudy () ;
1068
1069   if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1070   {
1071       SALOME::ExceptionStruct es;
1072       es.type = SALOME::BAD_PARAM;
1073       es.text = "This hypothesis is already defined.";
1074       throw SALOME::SALOME_Exception(es);
1075       return 0;
1076     }
1077
1078   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1079   myHypothesis->SetName(nomHypothesis);
1080   myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1081   SALOMEDS::SObject_var aSO;
1082   PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1083
1084 // Valeurs par defaut des options avancees
1085   myHypothesis->SetNivMax(-1);
1086   myHypothesis->SetDiamMin(-1.0);
1087   myHypothesis->SetAdapInit(0);
1088   myHypothesis->SetLevelOutput(0);
1089
1090   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1091 }
1092
1093 //=============================================================================
1094 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1095 //=============================================================================
1096 {
1097   MESSAGE ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
1098   IsValidStudy () ;
1099
1100   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1101   if (CORBA::is_nil(myIterationParent))
1102   {
1103       SALOME::ExceptionStruct es;
1104       es.type = SALOME::BAD_PARAM;
1105       es.text = "The parent iteration is not defined.";
1106       throw SALOME::SALOME_Exception(es);
1107       return 0;
1108   };
1109
1110   const char* nomCas = myIterationParent->GetCaseName();
1111   MESSAGE ("CreateIteration : nomCas = " << nomCas);
1112   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1113   if (CORBA::is_nil(myCase))
1114   {
1115       SALOME::ExceptionStruct es;
1116       es.type = SALOME::BAD_PARAM;
1117       es.text = "Invalid Case Context ";
1118       throw SALOME::SALOME_Exception(es);
1119       return 0;
1120   };
1121
1122   if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1123   {
1124       SALOME::ExceptionStruct es;
1125       es.type = SALOME::BAD_PARAM;
1126       es.text = "This iteration is already defined. ";
1127       throw SALOME::SALOME_Exception(es);
1128       return 0;
1129   };
1130
1131    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1132    if (CORBA::is_nil(myIteration))
1133   {
1134       SALOME::ExceptionStruct es;
1135       es.type = SALOME::BAD_PARAM;
1136       es.text = "Unable to create Iteration ";
1137       throw SALOME::SALOME_Exception(es);
1138       return 0;
1139   };
1140   myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1141 // Nom de l'iteration et du maillage
1142   myIteration->SetName(NomIteration);
1143   myIteration->SetMeshName(NomIteration);
1144
1145   int numero = myIterationParent->GetNumber() + 1;
1146   myIteration->SetNumber(numero);
1147
1148 // Nombre d'iterations deja connues pour le cas, permettant
1149 // la creation d'un sous-repertoire unique
1150    int nbitercase = myCase->GetNumber();
1151    std::ostringstream iaux ;
1152    iaux << std::setw(2) << std::setfill('0') << nbitercase ;
1153    std::stringstream DirName;
1154    DirName << "I" << iaux.str();
1155    myIteration->SetDirName(DirName.str().c_str());
1156
1157 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1158 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1159 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1160 // situation la plus frequente.
1161 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1162 // le nombre d'iterations du cas permet d'eviter les collisions.
1163    std::stringstream MeshFile;
1164    const char* nomDir = myCase->GetDirName();
1165    MeshFile << nomDir << "/maill." << iaux.str() << ".med";
1166    myIteration->SetMeshFile(MeshFile.str().c_str());
1167
1168 // Association avec le cas
1169   std::string label = "IterationHomard_" + std::string(nomIterParent);
1170   AssociateCaseIter(nomCas, NomIteration, label.c_str());
1171 // Lien avec l'iteration precedente
1172   myIterationParent->LinkNextIteration(NomIteration);
1173   myIteration->SetIterParentName(nomIterParent);
1174
1175   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1176 }
1177 //=============================================================================
1178 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1179 {
1180   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1181   IsValidStudy () ;
1182
1183   if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1184   {
1185       SALOME::ExceptionStruct es;
1186       es.type = SALOME::BAD_PARAM;
1187       es.text = "This boundary has already been defined";
1188       throw SALOME::SALOME_Exception(es);
1189       return 0;
1190   };
1191
1192   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1193   myBoundary->SetName(BoundaryName);
1194   myBoundary->SetType(BoundaryType);
1195
1196   myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1197
1198   SALOMEDS::SObject_var aSO;
1199   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1200
1201   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1202 }
1203 //=============================================================================
1204 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1205 {
1206   MESSAGE ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << "MeshName = " << MeshName );
1207   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1208   myBoundary->SetMeshFile( MeshFile ) ;
1209   myBoundary->SetMeshName( MeshName ) ;
1210
1211   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1212 }
1213 //=============================================================================
1214 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1215                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1216                                       CORBA::Double Xaxis, CORBA::Double Yaxis, CORBA::Double Zaxis,
1217                                       CORBA::Double Rayon)
1218 {
1219   MESSAGE ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
1220   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1221   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
1222
1223   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1224 }
1225 //=============================================================================
1226 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1227                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1228                                       CORBA::Double Rayon)
1229 {
1230   MESSAGE ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
1231   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1232   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1233
1234   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1235 }
1236 //=============================================================================
1237 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1238 {
1239   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
1240   IsValidStudy () ;
1241
1242   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1243   {
1244       SALOME::ExceptionStruct es;
1245       es.type = SALOME::BAD_PARAM;
1246       es.text = "This zone has already been defined";
1247       throw SALOME::SALOME_Exception(es);
1248       return 0;
1249   };
1250
1251   HOMARD::HOMARD_Zone_var myZone = newZone();
1252   myZone->SetName(ZoneName);
1253   myZone->SetType(ZoneType);
1254
1255   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1256
1257   SALOMEDS::SObject_var aSO;
1258   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1259
1260   return HOMARD::HOMARD_Zone::_duplicate(myZone);
1261 }
1262 //=============================================================================
1263 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1264                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
1265                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
1266                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
1267 {
1268   MESSAGE ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
1269   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1270   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1271
1272   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1273 }
1274 //=============================================================================
1275 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1276                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1277 {
1278   MESSAGE ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
1279   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1280   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1281
1282   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1283 }
1284 //=============================================================================
1285 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1286                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1287                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1288                                       CORBA::Double Rayon, CORBA::Double Haut)
1289 {
1290   MESSAGE ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
1291   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1292   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1293
1294   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1295 }
1296 //=============================================================================
1297 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1298                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1299                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1300                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1301 {
1302   MESSAGE ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
1303   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1304   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1305
1306   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1307 }
1308 //=============================================================================
1309 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1310                                       CORBA::Double Umini, CORBA::Double Umaxi,
1311                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
1312                                       CORBA::Long Orient)
1313 {
1314   MESSAGE ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
1315 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1316 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1317 //   MESSAGE ("Orient = " << Orient ) ;
1318
1319   double Xmini, Xmaxi ;
1320   double Ymini, Ymaxi ;
1321   double Zmini, Zmaxi ;
1322   if ( Orient == 1 )
1323   { Xmini = Umini ;
1324     Xmaxi = Umaxi ;
1325     Ymini = Vmini ;
1326     Ymaxi = Vmaxi ;
1327     Zmini = 0. ;
1328     Zmaxi = 0. ; }
1329   else if ( Orient == 2 )
1330   { Xmini = 0. ;
1331     Xmaxi = 0. ;
1332     Ymini = Umini ;
1333     Ymaxi = Umaxi ;
1334     Zmini = Vmini ;
1335     Zmaxi = Vmaxi ; }
1336   else if ( Orient == 3 )
1337   { Xmini = Vmini ;
1338     Xmaxi = Vmaxi ;
1339     Ymini = 0. ;
1340     Ymaxi = 0. ;
1341     Zmini = Umini ;
1342     Zmaxi = Umaxi ; }
1343   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1344
1345   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
1346   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1347
1348   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1349 }
1350 //=============================================================================
1351 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
1352                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
1353                                       CORBA::Double Rayon,
1354                                       CORBA::Long Orient)
1355 {
1356   MESSAGE ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
1357   double Xcentre ;
1358   double Ycentre ;
1359   double Zcentre ;
1360   if ( Orient == 1 )
1361   { Xcentre = Ucentre ;
1362     Ycentre = Vcentre ;
1363     Zcentre = 0. ; }
1364   else if ( Orient == 2 )
1365   { Xcentre = 0. ;
1366     Ycentre = Ucentre ;
1367     Zcentre = Vcentre ; }
1368   else if ( Orient == 3 )
1369   { Xcentre = Vcentre ;
1370     Ycentre = 0. ;
1371     Zcentre = Ucentre ; }
1372   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1373
1374   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
1375   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
1376
1377   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1378 }
1379 //=============================================================================
1380 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
1381                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
1382                                       CORBA::Double Rayon, CORBA::Double Rayonint,
1383                                       CORBA::Long Orient)
1384 {
1385   MESSAGE ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
1386   double Xcentre ;
1387   double Ycentre ;
1388   double Zcentre ;
1389   if ( Orient == 1 )
1390   { Xcentre = Ucentre ;
1391     Ycentre = Vcentre ;
1392     Zcentre = 0. ; }
1393   else if ( Orient == 2 )
1394   { Xcentre = 0. ;
1395     Ycentre = Ucentre ;
1396     Zcentre = Vcentre ; }
1397   else if ( Orient == 3 )
1398   { Xcentre = Vcentre ;
1399     Ycentre = 0. ;
1400     Zcentre = Ucentre ; }
1401   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
1402
1403   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
1404   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
1405
1406   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1407 }
1408 //=============================================================================
1409 //=============================================================================
1410
1411
1412
1413
1414 //=============================================================================
1415 //=============================================================================
1416 // Calcul d'une iteration
1417 //=============================================================================
1418 //=============================================================================
1419 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage)
1420 {
1421   MESSAGE ( "Compute : calcul de " << NomIteration );
1422
1423 // A. Prealable
1424 // A.1. La base
1425   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
1426   ASSERT(!CORBA::is_nil(myIteration));
1427
1428 // A.2. On ne calcule pas l iteration 0
1429   int NumeIter = myIteration->GetNumber();
1430   if ( NumeIter == 0 )
1431   {
1432       SALOME::ExceptionStruct es;
1433       es.type = SALOME::BAD_PARAM;
1434       es.text = "This iteration is the first of the case and cannot be computed.";
1435       throw SALOME::SALOME_Exception(es);
1436       return 1;
1437   };
1438
1439 // A.3. On verifie qu il y a une hypothese (erreur improbable);
1440   const char* nomHypo = myIteration->GetHypoName();
1441   if (std::string(nomHypo) == std::string(""))
1442   {
1443       SALOME::ExceptionStruct es;
1444       es.type = SALOME::BAD_PARAM;
1445       es.text= "This iteration does not have any associated hypothesis.";
1446       throw SALOME::SALOME_Exception(es);
1447       return 2;
1448   }
1449   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1450   ASSERT(!CORBA::is_nil(myHypo));
1451
1452   // A.4. L'iteration parent
1453   const char* nomIterationParent = myIteration->GetIterParentName();
1454   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1455   ASSERT(!CORBA::is_nil(myIterationParent));
1456   if ( ! myIterationParent->GetEtat() )
1457   {
1458       int codret = Compute(nomIterationParent, etatMenage);
1459       if (codret != 0)
1460       {
1461         // GERALD -- QMESSAGE BOX
1462         ASSERT("Pb au calcul de l'iteration precedente" == 0);
1463       }
1464   };
1465
1466   // A.5. Le cas
1467   const char* nomCas = myIteration->GetCaseName();
1468   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1469   ASSERT(!CORBA::is_nil(myCase));
1470
1471   // A.6. Les numeros d'iterations
1472   int codret = 0;
1473   std::stringstream saux0 ;
1474   saux0 << NumeIter - 1 ;
1475   std::string siter = saux0.str() ;
1476   if (NumeIter < 11) { siter = "0" + siter ; }
1477 //
1478   std::stringstream saux1 ;
1479   saux1 << NumeIter ;
1480   std::string siterp1 = saux1.str() ;
1481   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1482
1483   // B. Les repertoires
1484   // B.1. Le repertoire courant
1485   char* nomDirWork = getenv("PWD") ;
1486   // B.2. Le repertoire du cas
1487   const char* nomDirCase = myCase->GetDirName();
1488   MESSAGE ( ". nomDirCase = " << nomDirCase );
1489
1490   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1491   // B.3.1. Le nom du sous-repertoire
1492   const char* nomDirIt = myIteration->GetDirName();
1493
1494   // B.3.2. Le nom complet du sous-repertoire
1495   std::stringstream DirCompute ;
1496   DirCompute << nomDirCase << "/" << nomDirIt;
1497   MESSAGE (". DirCompute = " << DirCompute.str() );
1498
1499   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
1500   //        Si le sous-repertoire existe :
1501   //         etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1502   //         etatMenage = 1 : on fait le menage du repertoire
1503   if (chdir(DirCompute.str().c_str()) != 0)
1504   {
1505 //  Creation du repertoire car il n'existe pas :
1506     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1507     {
1508        // GERALD -- QMESSAGE BOX
1509        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1510        ASSERT("Pb a la creation du repertoire" == 0);
1511     }
1512   }
1513   else
1514   {
1515 //  Le repertoire existe
1516 //  On demande de faire le menage de son contenu :
1517     if (etatMenage != 0)
1518     {
1519        MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1520        std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1521        int codret = system(commande.c_str());
1522        if (codret != 0)
1523        {
1524          // GERALD -- QMESSAGE BOX
1525          std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1526          ASSERT("Pb au menage du repertoire de calcul" == 0);
1527        }
1528     }
1529 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
1530     else
1531     {
1532        DIR *dp;
1533        struct dirent *dirp;
1534        dp  = opendir(DirCompute.str().c_str());
1535        bool result = true;
1536        while ((dirp = readdir(dp)) != NULL && result )
1537        {
1538             std::string file_name(dirp->d_name);
1539             result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1540        }
1541        closedir(dp);
1542        if ( result == false)
1543        {
1544           SALOME::ExceptionStruct es;
1545           es.type = SALOME::BAD_PARAM;
1546           std::string text = "Directory : " + DirCompute.str() + "is not empty";
1547           es.text = CORBA::string_dup(text.c_str());
1548           throw SALOME::SALOME_Exception(es);
1549           return 3;
1550        }
1551     }
1552   }
1553
1554   // B.4. Le sous-repertoire de l'iteration precedente
1555   const char* nomDirItPa ;
1556   std::stringstream DirComputePa ;
1557   if (NumeIter == 1)
1558   {
1559     nomDirItPa = nomDirIt;
1560     DirComputePa << DirCompute.str();
1561   }
1562   else
1563   {
1564     nomDirItPa = myIterationParent->GetDirName();
1565     DirComputePa << nomDirCase << "/" << nomDirItPa;
1566   }
1567   MESSAGE( ". nomDirItPa = " << nomDirItPa);
1568   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1569
1570   // B.5. Le fichier des messages
1571   std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1572   MESSAGE (". MessFile = " << MessFile);
1573   myIteration->SetMessFile(MessFile.c_str());
1574
1575    // C. On passe dans le repertoire de l'iteration a calculer
1576   MESSAGE ( ". On passe dans DirCompute = " << DirCompute.str() );
1577   chdir(DirCompute.str().c_str()) ;
1578
1579   // D. Les donnees du calcul HOMARD
1580   // D.1. Le type de conformite
1581   int ConfType = myCase->GetConfType();
1582   MESSAGE ( ". ConfType = " << ConfType );
1583
1584   // D.2. Le maillage n
1585   const char* NomMeshParent = myIterationParent->GetMeshName();
1586   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1587   const char* MeshFileParent = myIterationParent->GetMeshFile();
1588   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1589
1590   // D.3. Le maillage n+1
1591   const char* NomMesh = myIteration->GetMeshName();
1592   MESSAGE ( ". NomMesh = " << NomMesh );
1593   const char* MeshFile = myIteration->GetMeshFile();
1594   MESSAGE ( ". MeshFile = " << MeshFile );
1595   FILE *file = fopen(MeshFile,"r");
1596   if (file != NULL)
1597   {
1598      fclose(file);
1599      if (etatMenage == 0)
1600      {
1601           SALOME::ExceptionStruct es;
1602           es.type = SALOME::BAD_PARAM;
1603           std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1604           es.text = CORBA::string_dup(text.c_str());
1605           throw SALOME::SALOME_Exception(es);
1606           return 4;
1607      }
1608      else
1609      {
1610          std::string commande = "rm -f " + std::string(MeshFile);
1611          codret = system(commande.c_str());
1612          if (codret != 0)
1613          {
1614           SALOME::ExceptionStruct es;
1615           es.type = SALOME::BAD_PARAM;
1616           std::string text = "PB with meshfile destruction ";
1617           es.text = CORBA::string_dup(text.c_str());
1618           throw SALOME::SALOME_Exception(es);
1619           return 5;
1620          }
1621       }
1622   }
1623   else
1624   {
1625      codret = 0 ;
1626   };
1627
1628   // D.4. Les types de raffinement et de deraffinement
1629   // Les appels corba sont lourds, il vaut mieux les grouper
1630   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1631   ASSERT(ListTypes->length() == 3);
1632   int TypeAdap = (*ListTypes)[0];
1633   int TypeRaff = (*ListTypes)[1];
1634   int TypeDera = (*ListTypes)[2];
1635
1636   // D.5. L'option d'interpolation des champs
1637   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1638
1639   // E. Texte du fichier de configuration
1640   // E.1. Incontournables du texte
1641   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1642   myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1643   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1644   myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1645   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1646
1647   // E.2. Ajout des informations liees aux zones eventuelles
1648   if (TypeAdap == 0)
1649   {
1650     HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1651     int numberOfZonesx2 = ListZone->length();
1652     int NumZone ;
1653
1654     for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1655     {
1656       std::string ZoneName = std::string((*ListZone)[iaux]);
1657       MESSAGE ( "... ZoneName = " << ZoneName);
1658       HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1659       ASSERT(!CORBA::is_nil(myZone));
1660
1661       int ZoneType = myZone->GetType();
1662       std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1663       int TypeUse = atoi( TypeUsestr.c_str() );
1664       MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1665       NumZone = iaux/2 + 1 ;
1666       HOMARD::double_array* zone = myZone->GetCoords();
1667       if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1668       {
1669         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1670       }
1671       else if ( ZoneType == 4 ) // Cas d une sphere
1672       {
1673         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1674       }
1675       else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1676       {
1677         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1678       }
1679       else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1680       {
1681         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1682       }
1683       else { ASSERT("ZoneType est incorrect." == 0) ; }
1684       iaux += 1 ;
1685     }
1686   }
1687   // E.3. Ajout des informations liees aux champs eventuels
1688   if (TypeAdap == 1)
1689   {
1690 //  Le fichier du champ
1691     char* FieldFile = myIteration->GetFieldFile();
1692     MESSAGE ( ". FieldFile = " << FieldFile );
1693     if (strlen(FieldFile) == 0)
1694     {
1695       // GERALD -- QMESSAGE BOX
1696       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1697       ASSERT("The file for the field is not given." == 0);
1698     }
1699 //  Les caracteristiques d'instants
1700     int TimeStep = myIteration->GetTimeStep();
1701     MESSAGE( ". TimeStep = " << TimeStep );
1702     int Rank = myIteration->GetRank();
1703     MESSAGE( ". Rank = " << Rank );
1704 //  Les informations sur les champ
1705     HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1706 //  Le nom
1707     const char* FieldName = aInfosHypo->FieldName;
1708 //  Les seuils
1709     int TypeThR = aInfosHypo->TypeThR;
1710     double ThreshR = aInfosHypo->ThreshR;
1711     int TypeThC = aInfosHypo->TypeThC;
1712     double ThreshC = aInfosHypo->ThreshC;
1713 //  Saut entre mailles ou non ?
1714     int UsField = aInfosHypo->UsField;
1715     MESSAGE( ". UsField = " << UsField );
1716 //  L'usage des composantes
1717     int UsCmpI = aInfosHypo->UsCmpI;
1718     MESSAGE( ". UsCmpI = " << UsCmpI );
1719 //
1720     myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1721 //
1722 //  Les composantes
1723     HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1724     int numberOfCompos = mescompo->length();
1725     MESSAGE( ". numberOfCompos = " << numberOfCompos );
1726     for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1727     {
1728       std::string nomCompo = std::string((*mescompo)[NumeComp]);
1729       MESSAGE( "... nomCompo = " << nomCompo );
1730       myDriver->TexteCompo(NumeComp, nomCompo);
1731     }
1732   }
1733   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1734   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1735   int numberOfGroups = listeGroupes->length();
1736   MESSAGE( ". numberOfGroups = " << numberOfGroups );
1737   if (numberOfGroups > 0)
1738   {
1739
1740     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1741     {
1742       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1743       MESSAGE( "... GroupName = " << GroupName );
1744       myDriver->TexteGroup(GroupName);
1745     }
1746   }
1747
1748   // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1749   // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1750   std::list<std::string>  ListeBoundaryTraitees ;
1751   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1752   int numberOfitems = ListBoundaryGroupType->length();
1753   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1754   int BoundaryOption = 1 ;
1755   int NumBoundaryAnalytical = 0 ;
1756   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1757   {
1758     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1759     MESSAGE ( "... BoundaryName = " << BoundaryName);
1760     int A_faire = 1 ;
1761     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1762     while (it != ListeBoundaryTraitees.end())
1763     {
1764       MESSAGE ( "... BoundaryNameTraitee = " << *it);
1765       if ( BoundaryName == *it ) { A_faire = 0 ; }
1766       it++;
1767     }
1768     if ( A_faire == 1 )
1769     {
1770 // Caracteristiques de la frontiere
1771       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1772       ASSERT(!CORBA::is_nil(myBoundary));
1773       int BoundaryType = myBoundary->GetType();
1774       MESSAGE ( "... BoundaryType = " << BoundaryType );
1775 // Ecriture selon le type
1776       if (BoundaryType == 0) // Cas d une frontiere discrete
1777       {
1778         const char* MeshName = myBoundary->GetMeshName() ;
1779         const char* MeshFile = myBoundary->GetMeshFile() ;
1780         myDriver->TexteBoundaryDi( MeshName, MeshFile);
1781         BoundaryOption = BoundaryOption*2 ;
1782       }
1783       else // Cas d une frontiere analytique
1784       {
1785         NumBoundaryAnalytical++ ;
1786         HOMARD::double_array* coor = myBoundary->GetCoords();
1787         if (BoundaryType == 1) // Cas d un cylindre
1788         {
1789           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1790           BoundaryOption = BoundaryOption*3 ;
1791         }
1792         else if (BoundaryType == 2) // Cas d une sphere
1793         {
1794           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1795           BoundaryOption = BoundaryOption*3 ;
1796         }
1797       }
1798 // Memorisation du traitement
1799       ListeBoundaryTraitees.push_back( BoundaryName );
1800     }
1801   }
1802   NumBoundaryAnalytical = 0 ;
1803   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1804   {
1805     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1806     MESSAGE ( "... BoundaryName = " << BoundaryName);
1807     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1808     ASSERT(!CORBA::is_nil(myBoundary));
1809     int BoundaryType = myBoundary->GetType();
1810     MESSAGE ( "... BoundaryType = " << BoundaryType );
1811 //  Recuperation du nom du groupe
1812     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1813     MESSAGE ( "... GroupName = " << GroupName);
1814     if (BoundaryType == 0) // Cas d une frontiere discrete
1815     {
1816       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1817     }
1818     else // Cas d une frontiere analytique
1819     {
1820       NumBoundaryAnalytical++ ;
1821       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1822     }
1823   }
1824   myDriver->TexteBoundaryOption(BoundaryOption);
1825
1826   // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1827   MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1828   if (TypeFieldInterp != 0)
1829   {
1830 //  Le fichier des champs
1831     char* FieldFile = myIteration->GetFieldFile();
1832     MESSAGE ( ". FieldFile = " << FieldFile );
1833     if (strlen(FieldFile) == 0)
1834     {
1835       // GERALD -- QMESSAGE BOX
1836       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1837       ASSERT("The file for the field is not given." == 0);
1838     }
1839 //  Les caracteristiques d'instants
1840     int TimeStep = myIteration->GetTimeStep();
1841     MESSAGE( ". TimeStep = " << TimeStep );
1842     int Rank = myIteration->GetRank();
1843     MESSAGE( ". Rank = " << Rank );
1844 //
1845     myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1846 //  Les champs
1847     if (TypeFieldInterp == 2)
1848     {
1849       HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1850       int numberOfFields = meschamps->length();
1851       MESSAGE( ". numberOfFields = " << numberOfFields );
1852       for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1853       {
1854         std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1855         MESSAGE( "... nomChamp = " << nomChamp );
1856         myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1857       }
1858     }
1859   }
1860   // E.7. Ajout des options avancees
1861   int Pyram = myCase->GetPyram();
1862   MESSAGE ( ". Pyram = " << Pyram );
1863   int NivMax = myHypo->GetNivMax();
1864   MESSAGE ( ". NivMax = " << NivMax );
1865   double DiamMin = myHypo->GetDiamMin() ;
1866   MESSAGE ( ". DiamMin = " << DiamMin );
1867   int AdapInit = myHypo->GetAdapInit();
1868   MESSAGE ( ". AdapInit = " << AdapInit );
1869   int LevelOutput = myHypo->GetLevelOutput();
1870   MESSAGE ( ". LevelOutput = " << LevelOutput );
1871   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1872
1873   // F. Ecriture du texte dans le fichier
1874   if (codret == 0)
1875   {
1876     myDriver->CreeFichier();
1877   }
1878
1879 // G. Execution
1880 //
1881   int codretexec = 12 ;
1882   if (codret == 0)
1883   {
1884     codretexec = myDriver->ExecuteHomard();
1885 //
1886     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1887     if (codretexec == 0)
1888     {
1889       SetEtatIter(NomIteration,true);
1890     }
1891     else
1892     {
1893       // GERALD -- QMESSAGE BOX
1894       SetEtatIter(NomIteration,false);
1895     }
1896   }
1897
1898   // H. Gestion des resultats
1899   if (codret == 0)
1900   {
1901     // H.1. Le fichier des messages, dans tous les cas
1902     std::stringstream saux1 ;
1903     saux1 << "Mess " << NumeIter ;
1904     PublishFileUnderIteration(NomIteration, MessFile.c_str(), saux1.str().c_str());
1905
1906     // H.2. Si tout s'est bien passe :
1907     if (codretexec == 0)
1908     {
1909     // H.2.1. Le fichier de bilan
1910       std::stringstream saux2 ;
1911       saux2 << "Summary " << NumeIter ;
1912       std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1913       PublishFileUnderIteration(NomIteration, SummaryFile.c_str(), saux2.str().c_str());
1914     // H.2.2. Le fichier de  maillage obtenu
1915       std::stringstream saux0 ;
1916       saux0 <<"Iteration " << NumeIter ;
1917       PublishFileUnderIteration(NomIteration, MeshFile, saux0.str().c_str());
1918       PublishResultInSmesh(MeshFile, 1);
1919     }
1920   // H.3 Message d'erreur en cas de probleme
1921     else
1922     {
1923       SALOME::ExceptionStruct es;
1924       es.type = SALOME::BAD_PARAM;
1925       std::string text = "Error during the adaptation.\n" ;
1926       try
1927       {
1928           ifstream fichier(MessFile.c_str(), ios::in);
1929           string ligne;
1930           while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1931           while (getline(fichier, ligne)) { text += ligne+ "\n";};
1932       }
1933       catch (...) {
1934         text += "no log file ....";
1935       }
1936       es.text = CORBA::string_dup(text.c_str());
1937       throw SALOME::SALOME_Exception(es);
1938     }
1939   }
1940
1941   // I. Menage et retour dans le repertoire du cas
1942   if (codret == 0)
1943   {
1944     delete myDriver;
1945     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
1946     chdir(nomDirWork);
1947   }
1948
1949   return codretexec ;
1950 }
1951 //===========================================================================
1952
1953 //===========================================================================
1954 //===========================================================================
1955 // Publications
1956 //===========================================================================
1957 //===========================================================================
1958 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1959                                                    SALOMEDS::SObject_ptr theSObject,
1960                                                    CORBA::Object_ptr theObject,
1961                                                    const char* theName)
1962 {
1963   MESSAGE("PublishInStudy pour " << theName);
1964   SALOMEDS::SObject_var aResultSO;
1965   if (CORBA::is_nil(theStudy))
1966   {
1967     SALOME::ExceptionStruct es;
1968     es.type = SALOME::BAD_PARAM;
1969     es.text = "Invalid Study Context ";
1970     throw SALOME::SALOME_Exception(es);
1971     return 0;
1972   };
1973
1974 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1975 // Rq : Iteration est publiee ailleurs
1976   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
1977   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1978   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1979   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1980
1981    addInStudy(theStudy);
1982
1983 // Controle de la non publication d'un objet de meme nom
1984    if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1985     {
1986       SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1987       if (listSO->length() >= 1)
1988       {
1989           MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1990           std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1991           aResultSO = listSO[0];
1992           return aResultSO._retn();
1993       }
1994     }
1995
1996   // Caracteristiques de l'etude
1997   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1998   aStudyBuilder->NewCommand();
1999   if(!aCase->_is_nil())
2000     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2001   else if(!aHypo->_is_nil())
2002     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2003   else if(!aZone->_is_nil())
2004     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2005   else if(!aBoundary->_is_nil())
2006     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2007
2008     aStudyBuilder->CommitCommand();
2009   return aResultSO._retn();
2010 };
2011 //=============================================================================
2012 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2013                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
2014                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2015 {
2016   MESSAGE("PublishCaseInStudy pour "<<theName);
2017   SALOMEDS::SObject_var aResultSO;
2018   SALOMEDS::GenericAttribute_var anAttr;
2019
2020   if (CORBA::is_nil(theObject)) {
2021     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2022     return aResultSO._retn();
2023   }
2024   if (theStudy->_is_nil()) {
2025     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2026     return aResultSO._retn();
2027   }
2028
2029   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2030   if (theFatherHomard->_is_nil())
2031   {
2032     MESSAGE("theFatherHomard->_is_nil()");
2033     return aResultSO._retn();
2034   }
2035
2036   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2037   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2038                      _orb->object_to_string(theObject) ) ;
2039   return aResultSO._retn();
2040 }
2041
2042 //=============================================================================
2043 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2044                     SALOMEDS::StudyBuilder_var aStudyBuilder,
2045                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2046 {
2047   MESSAGE("PublishZoneStudy pour "<<theName);
2048   SALOMEDS::SObject_var aResultSO;
2049   SALOMEDS::GenericAttribute_var anAttr;
2050
2051   if (CORBA::is_nil(theObject))
2052   {
2053     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
2054     return aResultSO._retn();
2055   }
2056   if (theStudy->_is_nil())
2057   {
2058     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
2059     return aResultSO._retn();
2060   }
2061   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2062   if (theFatherHomard->_is_nil())
2063   {
2064     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
2065     return aResultSO._retn();
2066   }
2067
2068   // Caracteristique de la zone
2069   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
2070   CORBA::Long ZoneType = myZone->GetType();
2071
2072   // On ajoute la categorie des zones dans l etude si necessaire
2073   SALOMEDS::SObject_var aSOZone;
2074   if (!theFatherHomard->FindSubObject(100, aSOZone))
2075   {
2076     MESSAGE("Ajout de la categorie des zones");
2077     aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
2078     PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
2079   }
2080   else { MESSAGE("La categorie des zones existe deja."); }
2081
2082   aResultSO = aStudyBuilder->NewObject(aSOZone);
2083   const char* icone ;
2084   switch (ZoneType)
2085   {
2086     case 11 :
2087     { }
2088     case 12 :
2089     { }
2090     case 13 :
2091     { icone = "boxdxy_2.png" ;
2092       break ;
2093     }
2094     case 2 :
2095     { icone = "boxdxyz_2.png" ;
2096       break ;
2097     }
2098     case 31 :
2099     { }
2100     case 32 :
2101     { }
2102     case 33 :
2103     { icone = "disk_2.png" ;
2104       break ;
2105      }
2106     case 4 :
2107     { icone = "spherepoint_2.png" ;
2108       break ;
2109     }
2110     case 5 :
2111     { icone = "cylinderpointvector_2.png" ;
2112       break ;
2113     }
2114     case 61 :
2115     { }
2116     case 62 :
2117     { }
2118     case 63 :
2119     { icone = "diskwithhole_2.png" ;
2120       break ;
2121      }
2122     case 7 :
2123     { icone = "pipe_2.png" ;
2124       break ;
2125     }
2126   }
2127   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
2128
2129   return aResultSO._retn();
2130 }
2131 //=============================================================================
2132 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
2133                    SALOMEDS::StudyBuilder_var aStudyBuilder,
2134                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
2135 {
2136   MESSAGE("PublishBoundaryStudy pour "<<theName);
2137   SALOMEDS::SObject_var aResultSO;
2138   SALOMEDS::GenericAttribute_var anAttr;
2139
2140   // Caracteristique de la Boundary
2141   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
2142
2143   // On recupere le module pere dans l etude
2144   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
2145   if (theFatherHomard->_is_nil())
2146   {
2147     MESSAGE("theFatherHomard->_is_nil()");
2148     return aResultSO._retn();
2149   }
2150
2151   // On ajoute la categorie des boundarys dans l etude si necessaire
2152   SALOMEDS::SObject_var aSOBoundary;
2153   if (!theFatherHomard->FindSubObject(101, aSOBoundary))
2154   {
2155     MESSAGE("Ajout de la categorie des boundarys");
2156     aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
2157     PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
2158   }
2159   else { MESSAGE("La categorie des boundarys existe deja."); }
2160
2161   aResultSO = aStudyBuilder->NewObject(aSOBoundary);
2162   CORBA::Long BoundaryType = myBoundary->GetType();
2163 //   MESSAGE("BoundaryType : "<<BoundaryType);
2164   const char* icone ;
2165   const char* value ;
2166   switch (BoundaryType)
2167   {
2168     case 0 :
2169     { value = "BoundaryDiHomard" ;
2170       icone = "mesh_tree_mesh.png" ;
2171       break;
2172     }
2173     case 1 :
2174     { value = "BoundaryAnHomard" ;
2175       icone = "cylinderpointvector_2.png" ;
2176       break;
2177     }
2178     case 2 :
2179     { value = "BoundaryAnHomard" ;
2180       icone = "spherepoint_2.png" ;
2181       break;
2182     }
2183   }
2184   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
2185   return aResultSO._retn();
2186 }
2187
2188 //=============================================================================
2189 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
2190                    SALOMEDS::StudyBuilder_var aStudyBuilder,
2191                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
2192 {
2193   MESSAGE("PublishHypotheseInStudy pour "<<theName);
2194   SALOMEDS::SObject_var aResultSO;
2195   SALOMEDS::GenericAttribute_var anAttr;
2196
2197   // On recupere le module pere dans l etude
2198   // On ajoute la categorie des hypotheses dans l etude si necessaire
2199   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2200   if (theFatherHomard->_is_nil())
2201   {
2202     MESSAGE("theFatherHomard->_is_nil()");
2203     return aResultSO._retn();
2204   }
2205   SALOMEDS::SObject_var aSOHypothese;
2206   if (!theFatherHomard->FindSubObject(0, aSOHypothese))
2207   {
2208     MESSAGE("Ajout de la categorie des hypotheses");
2209     aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
2210     PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
2211   }
2212   else { MESSAGE("La categorie des hypotheses existe deja."); }
2213
2214 // Creation du resultat dans l'etude
2215   aResultSO = aStudyBuilder->NewObject(aSOHypothese);
2216   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
2217
2218   return aResultSO._retn();
2219 }
2220 //===========================================================================
2221 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
2222                                       SALOMEDS::SObject_var aResultSO,
2223                                       const char* name, const char* value, const char* icone, const char* ior)
2224 {
2225   SALOMEDS::GenericAttribute_var anAttr ;
2226 //  Ajout du nom
2227   if ( name != NULL )
2228   {
2229     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
2230     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
2231     aNameAttrib->SetValue(name);
2232   }
2233
2234 //  Ajout du commentaire
2235   if ( value != NULL )
2236   {
2237     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
2238     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
2239     aCommentAttrib->SetValue(value);
2240   }
2241
2242 //  Ajout de l'icone
2243   if ( icone != NULL  )
2244   {
2245     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
2246     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2247     aPixmap->SetPixMap(icone);
2248   }
2249
2250 //  Ajout de l ior
2251   if ( ior != NULL  )
2252   {
2253     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
2254     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2255     anIOR->SetValue(ior);
2256   }
2257 };
2258
2259 //=====================================================================================
2260 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
2261 {
2262   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
2263
2264   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
2265   ASSERT(!CORBA::is_nil(myCase));
2266   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
2267   ASSERT(!CORBA::is_nil(aCaseSO));
2268
2269   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2270   ASSERT(!CORBA::is_nil(myBoundary));
2271   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
2272   ASSERT(!CORBA::is_nil(aBoundarySO));
2273
2274   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2275
2276   aStudyBuilder->NewCommand();
2277
2278   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
2279   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
2280
2281   aStudyBuilder->CommitCommand();
2282
2283 };
2284 //=============================================================================
2285 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
2286 {
2287   MESSAGE( "PublishResultInSmesh " << NomFich);
2288   if (CORBA::is_nil(myCurrentStudy))
2289   {
2290       SALOME::ExceptionStruct es;
2291       es.type = SALOME::BAD_PARAM;
2292       es.text = "Invalid Study Context ";
2293       throw SALOME::SALOME_Exception(es);
2294       return ;
2295   };
2296
2297 // Le module SMESH est-il actif ?
2298   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2299 //
2300   if (!CORBA::is_nil(aSmeshSO))
2301   {
2302 // On verifie que le fichier n est pas deja publie
2303     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2304     for (; aIter->More(); aIter->Next())
2305     {
2306        SALOMEDS::SObject_var  aSO = aIter->Value();
2307        SALOMEDS::GenericAttribute_var aGAttr;
2308        if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2309        {
2310            SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2311            CORBA::String_var value=anAttr->Value();
2312            if (strcmp((const char*)value,NomFich) == 0)
2313            {
2314                 // GERALD -- QMESSAGE BOX
2315                 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
2316                 return;
2317            }
2318        }
2319      }
2320
2321   }
2322
2323 // On enregistre le fichier
2324   MESSAGE( "Enregistrement du fichier");
2325   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
2326   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
2327   ASSERT(!CORBA::is_nil(aSmeshEngine));
2328   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
2329   SMESH::DriverMED_ReadStatus theStatus;
2330   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2331
2332 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2333   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2334   for (int i = 0; i < mesMaillages->length();  i++)
2335   {
2336     MESSAGE( ". Mise a jour des attributs du maillage");
2337     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2338     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2339     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2340     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2341     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2342     anAttr->SetValue(NomFich);
2343     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2344     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2345 //  IconeType = 0 : fichier issu d'une importation
2346 //  IconeType = 1 : fichier issu d'une execution HOMARD
2347     const char* icone ;
2348     if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2349     else                  { icone = "mesh_tree_mesh.png" ; }
2350     anAttr2->SetPixMap( icone );
2351   }
2352
2353 }
2354 //=============================================================================
2355 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2356 {
2357   MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
2358   if (CORBA::is_nil(myCurrentStudy))
2359   {
2360       SALOME::ExceptionStruct es;
2361       es.type = SALOME::BAD_PARAM;
2362       es.text = "Invalid Study Context ";
2363       throw SALOME::SALOME_Exception(es);
2364       return ;
2365   };
2366
2367 // Le module SMESH est-il actif ?
2368   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2369 //
2370   if (CORBA::is_nil(aSmeshSO))
2371   {
2372       return ;
2373   };
2374 // On verifie que le fichier est deja publie
2375   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2376   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2377   for (; aIter->More(); aIter->Next())
2378   {
2379      SALOMEDS::SObject_var  aSO = aIter->Value();
2380      SALOMEDS::GenericAttribute_var aGAttr;
2381      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2382      {
2383        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2384        CORBA::String_var value=anAttr->Value();
2385        if (strcmp((const char*)value,NomFich) == 0)
2386        {
2387          if (aSO->FindAttribute(aGAttr,"AttributeName"))
2388          {
2389            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2390            CORBA::String_var value2=anAttr2->Value();
2391            if (strcmp((const char*)value2,MeshName) == 0)
2392            {
2393              myBuilder->RemoveObjectWithChildren( aSO ) ;
2394            }
2395          }
2396        }
2397      }
2398   }
2399
2400 }
2401 //=============================================================================
2402 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2403 {
2404   if (CORBA::is_nil(myCurrentStudy))
2405   {
2406       SALOME::ExceptionStruct es;
2407       es.type = SALOME::BAD_PARAM;
2408       es.text = "Invalid Study Context ";
2409       throw SALOME::SALOME_Exception(es);
2410       return ;
2411   };
2412
2413   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2414   if (CORBA::is_nil(myIteration))
2415   {
2416       SALOME::ExceptionStruct es;
2417       es.type = SALOME::BAD_PARAM;
2418       es.text = "Invalid Iteration ";
2419       throw SALOME::SALOME_Exception(es);
2420       return ;
2421   };
2422   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2423   if (CORBA::is_nil(myIteration))
2424   {
2425       SALOME::ExceptionStruct es;
2426       es.type = SALOME::BAD_PARAM;
2427       es.text = "Invalid Iteration Study Object";
2428       throw SALOME::SALOME_Exception(es);
2429       return ;
2430   };
2431
2432   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2433
2434   aStudyBuilder->NewCommand();
2435
2436   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2437 // Pour les fichiers med, on affiche une icone de maillage
2438 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2439 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2440   const char* icone ;
2441   const char* ior = " " ;
2442   if ( Commentaire[0] == 'I' )
2443   { icone = "med.png" ; }
2444   else
2445   { icone = "texte_2.png" ; }
2446   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2447
2448   aStudyBuilder->CommitCommand();
2449 }
2450 //=============================================================================
2451 //=============================================================================
2452 //
2453 //=============================================================================
2454 //=============================================================================
2455 // Next functions are inherited from SALOMEDS::Driver interface
2456 //=============================================================================
2457 //=============================================================================
2458 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2459                                       const char* theURL,
2460                                       CORBA::Boolean isMultiFile)
2461 {
2462   MESSAGE (" Save for theURL = "<< theURL);
2463   SALOMEDS::TMPFile_var aStreamFile;
2464
2465   // get temporary directory name
2466   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2467
2468   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2469   StudyContext& context = myContextMap[ aStudy->StudyId() ];
2470
2471   // HOMARD data file name
2472   std::string aFileName = "";
2473   if (isMultiFile)
2474     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2475   aFileName += "_HOMARD.dat";
2476
2477   // initialize sequence of file names
2478   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2479   aFileSeq->length(1);
2480   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2481
2482   // get full path to the data file
2483   aFileName = tmpDir + aFileName;
2484
2485   // save data
2486   // -> create file
2487   std::ofstream f(aFileName.c_str());
2488
2489   // clear temporary id map
2490   context._idmap.clear();
2491
2492   int id = 1;
2493
2494   // -> save cases
2495   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2496   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2497     HOMARD::HOMARD_Cas_var aCas = it_case->second;
2498     PortableServer::ServantBase_var aServant = GetServant(aCas);
2499     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2500     if (aCasServant) {
2501       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2502       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2503     }
2504   }
2505   // -> save zones
2506   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2507   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2508     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2509     PortableServer::ServantBase_var aServant = GetServant(aZone);
2510     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2511     if (aZoneServant) {
2512       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2513       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2514     }
2515   }
2516   // -> save hypotheses
2517   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2518   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2519     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2520     PortableServer::ServantBase_var aServant = GetServant(aHypo);
2521     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2522     if (aHypoServant) {
2523       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2524       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2525     }
2526   }
2527   // -> save iterations
2528   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2529   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2530     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2531     PortableServer::ServantBase_var aServant = GetServant(aIter);
2532     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2533     if (aIterServant) {
2534       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2535       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2536     }
2537   }
2538   // -> save boundaries
2539   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2540   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2541     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2542     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2543     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2544     if (aBoundaryServant) {
2545       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2546       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2547     }
2548   }
2549   // -> close file
2550   MESSAGE ("close file");
2551   f.close();
2552
2553   // put temporary files to the stream
2554   MESSAGE ("put temporary files to the stream");
2555   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2556
2557   // remove temporary files
2558   MESSAGE ("remove temporary files");
2559   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2560
2561   // return data stream
2562   MESSAGE ("return data stream");
2563   return aStreamFile._retn();
2564 };
2565
2566 //===========================================================================
2567 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2568                                            const char* theURL,
2569                                            CORBA::Boolean isMultiFile)
2570 {
2571   // No specific ASCII persistence
2572   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2573   return aStreamFile._retn();
2574 };
2575
2576 //===========================================================================
2577 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2578                                    const SALOMEDS::TMPFile& theStream,
2579                                    const char* theURL,
2580                                    CORBA::Boolean isMultiFile)
2581 {
2582   MESSAGE (" Load pour theURL = "<< theURL);
2583   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2584
2585   // set current study
2586   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2587     SetCurrentStudy(aStudy);
2588
2589   // get temporary directory name
2590   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2591
2592   // Convert the stream into sequence of files to process
2593   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2594                                                                             tmpDir.c_str(),
2595                                                                             isMultiFile);
2596   // HOMARD data file name
2597   std::string aFileName = "";
2598   if (isMultiFile)
2599     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2600   aFileName = tmpDir + aFileName + "_HOMARD.dat";
2601
2602   StudyContext& context = myContextMap[ aStudy->StudyId() ];
2603
2604   // save data
2605   // -> create file
2606   std::ifstream f(aFileName.c_str());
2607
2608   // clear context
2609   context._mesCas.clear();
2610   context._mesHypotheses.clear();
2611   context._mesIterations.clear();
2612   context._mesZones.clear();
2613   context._mesBoundarys.clear();
2614   context._idmap.clear();
2615
2616   int id = 1;
2617   std::string line;
2618
2619   while (f) {
2620     std::getline(f, line);
2621     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2622     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2623     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2624     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2625     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2626     if (line.substr(0, caseSignature.size()) == caseSignature) {
2627       // re-create case
2628       MESSAGE (" Recreation du cas" );
2629       HOMARD::HOMARD_Cas_var aCase = newCase();
2630       PortableServer::ServantBase_var aServant = GetServant(aCase);
2631       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2632       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2633         context._mesCas[aCase->GetName()] = aCase;
2634         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2635       }
2636     }
2637     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2638       MESSAGE (" Recreation de la zone" );
2639       // re-create zone
2640       HOMARD::HOMARD_Zone_var aZone = newZone();
2641       PortableServer::ServantBase_var aServant = GetServant(aZone);
2642       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2643       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2644         context._mesZones[aZone->GetName()] = aZone;
2645         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2646       }
2647     }
2648     else if (line.substr(0, iterSignature.size()) == iterSignature) {
2649       // re-create iteration
2650       MESSAGE (" Recreation de l iteration" );
2651       HOMARD::HOMARD_Iteration_var aIter = newIteration();
2652       PortableServer::ServantBase_var aServant = GetServant(aIter);
2653       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2654       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2655         context._mesIterations[aIter->GetName()] = aIter;
2656         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2657       }
2658     }
2659     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2660       // re-create hypothesis
2661       MESSAGE (" Recreation de l hypothese" );
2662       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2663       PortableServer::ServantBase_var aServant = GetServant(aHypo);
2664       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2665       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2666         context._mesHypotheses[aHypo->GetName()] = aHypo;
2667         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2668       }
2669     }
2670     else if (line.substr(0, bounSignature.size()) == bounSignature) {
2671       // re-create boundary
2672       MESSAGE (" Recreation de la frontiere" );
2673       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2674       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2675       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2676       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2677         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2678         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2679       }
2680     }
2681     id++;
2682   }
2683
2684   // -> close file
2685   f.close();
2686
2687   // Remove temporary files created from the stream
2688   if (!isMultiFile)
2689     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2690
2691   return true;
2692 };
2693
2694 //===========================================================================
2695 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2696                                         const SALOMEDS::TMPFile& theStream,
2697                                         const char* theURL,
2698                                         CORBA::Boolean isMultiFile)
2699 {
2700   // No specific ASCII persistence
2701   return Load(theComponent, theStream, theURL, isMultiFile);
2702 };
2703
2704 //===========================================================================
2705 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2706 {
2707   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2708     // clearing study context should be done here:
2709     // - destroy all servants and related CORBA objects
2710     // ... (TODO)
2711     // - remove context from myContextMap
2712     myContextMap.erase(theComponent->GetStudy()->StudyId());
2713     // - nullify myCurrentStudy
2714     myCurrentStudy = SALOMEDS::Study::_nil();
2715   }
2716 };
2717
2718 //===========================================================================
2719 char* HOMARD_Gen_i::ComponentDataType()
2720 {
2721   return CORBA::string_dup("HOMARD");
2722 };
2723
2724 //===========================================================================
2725 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2726                                             const char* IORString,
2727                                             CORBA::Boolean isMultiFile,
2728                                             CORBA::Boolean isASCII)
2729 {
2730   CORBA::String_var aString("");
2731   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2732     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2733     CORBA::Object_var anObj = _orb->string_to_object(IORString);
2734     if (!CORBA::is_nil(anObj)) {
2735       PortableServer::ServantBase_var aServant = GetServant(anObj);
2736       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2737       if (aStorable) {
2738         std::map<int, PortableServer::ServantBase*>::const_iterator it;
2739         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2740           if (it->second == aStorable) {
2741             std::stringstream os;
2742             os << it->first;
2743             aString = CORBA::string_dup(os.str().c_str());
2744           }
2745         }
2746       }
2747     }
2748   }
2749   return aString._retn();
2750 };
2751
2752 //===========================================================================
2753 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2754                                             const char* aLocalPersistentID,
2755                                             CORBA::Boolean isMultiFile,
2756                                             CORBA::Boolean isASCII)
2757 {
2758   CORBA::String_var aString("");
2759   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2760     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2761     int id = atoi(aLocalPersistentID);
2762     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2763       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2764       if (!CORBA::is_nil(object)) {
2765         aString = _orb->object_to_string(object);
2766       }
2767     }
2768   }
2769   return aString._retn();
2770 };
2771
2772 //===========================================================================
2773 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2774 {
2775   if(CORBA::is_nil(myCurrentStudy))
2776     return false;
2777
2778   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2779   if(!aCas->_is_nil())
2780     return true;
2781
2782   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2783   if(!aHypo->_is_nil())
2784     return true;
2785
2786   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2787   if(!aZone->_is_nil())
2788     return true;
2789
2790   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2791   if(!aBoundary->_is_nil())
2792     return true;
2793
2794   /* Iteration is not published directly
2795   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2796   if(!aIter->_is_nil())
2797     return true;
2798   */
2799   return false;
2800 };
2801
2802 //===========================================================================
2803 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2804 {
2805   // No Copy/Paste support
2806   return false;
2807 };
2808
2809 //===========================================================================
2810 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2811                                            CORBA::Long& theObjectID)
2812 {
2813   // No Copy/Paste support
2814   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2815   return aStreamFile._retn();
2816 };
2817
2818 //===========================================================================
2819 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
2820                                         CORBA::Long theObjectID)
2821 {
2822   // No Copy/Paste support
2823   return false;
2824 };
2825
2826 //===========================================================================
2827 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2828                                                CORBA::Long theObjectID,
2829                                                SALOMEDS::SObject_ptr theSObject)
2830 {
2831   // No Copy/Paste support
2832   SALOMEDS::SObject_var aResultSO;
2833   return aResultSO._retn();
2834 };
2835
2836 //===========================================================================
2837 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2838 {
2839   PortableServer::Servant aServant = 0;
2840   if (!CORBA::is_nil(theObject)) {
2841     try {
2842       aServant = _poa->reference_to_servant(theObject);
2843     }
2844     catch (...) {
2845     }
2846   }
2847   return aServant;
2848 }
2849
2850 //==========================================================================
2851 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2852                                        CORBA::Boolean isPublished,
2853                                        CORBA::Boolean isMultiFile,
2854                                        CORBA::Boolean& isValidScript)
2855 {
2856    MESSAGE ("Entree dans DumpPython");
2857    isValidScript=1;
2858    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2859    if(CORBA::is_nil(aStudy))
2860      return new Engines::TMPFile(0);
2861
2862    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2863    if(CORBA::is_nil(aSO))
2864       return new Engines::TMPFile(0);
2865
2866    std::string aScript = "\"\"\"\n";
2867    aScript += "Python script for HOMARD\n";
2868    aScript += "Copyright EDF-R&D 2013\n";
2869    aScript += "\"\"\"\n";
2870    aScript += "__revision__ = \"V1.2\"\n";
2871    aScript += "import HOMARD\n";
2872    if( isMultiFile )
2873       aScript += "import salome\n";
2874    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2875    if( isMultiFile ) {
2876       aScript += "def RebuildData(theStudy):\n";
2877       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2878    }
2879    else
2880       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2881    MESSAGE (". Au depart \n"<<aScript);
2882
2883
2884    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2885    {
2886     MESSAGE (". Ecritures des frontieres");
2887     aScript += "#\n# Creation of the boundaries";
2888     aScript +=  "\n# ==========================";
2889    }
2890    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2891    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2892         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2893    {
2894     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2895     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2896     std::string dumpBoundary = dumpCorbaBoundary.in();
2897     MESSAGE (dumpBoundary<<"\n");
2898     aScript += dumpBoundary;
2899    }
2900
2901
2902    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2903    {
2904     MESSAGE (". Ecritures des zones");
2905     aScript += "#\n# Creation of the zones";
2906     aScript +=  "\n# =====================";
2907    }
2908    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2909    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2910          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2911    {
2912     HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2913     CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2914     std::string dumpZone = dumpCorbaZone.in();
2915     MESSAGE (dumpZone<<"\n");
2916     aScript += dumpZone;
2917    }
2918
2919
2920    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
2921    {
2922     MESSAGE (". Ecritures des hypotheses");
2923     aScript += "#\n# Creation of the hypotheses";
2924     aScript +=  "\n# ==========================";
2925    }
2926    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2927    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2928          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2929    {
2930     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2931     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2932     std::string dumpHypo = dumpCorbaHypo.in();
2933     MESSAGE (dumpHypo<<"\n");
2934     aScript += dumpHypo;
2935    }
2936
2937
2938    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
2939    {
2940     MESSAGE (". Ecritures des cas");
2941     aScript += "#\n# Creation of the cases";
2942     aScript += "\n# =====================";
2943    }
2944    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2945    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2946         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2947         {
2948            std::string nomCas = (*it_cas).first;
2949            std::string dumpCas = std::string("\n# Creation of the case ") ;
2950            dumpCas +=  nomCas + std::string("\n");
2951            dumpCas += std::string("\t") + nomCas;
2952            dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2953
2954            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2955            CORBA::String_var cIter0= myCase->GetIter0Name();
2956            std::string iter0 = cIter0.in();
2957
2958            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2959            CORBA::String_var cMesh0= myIteration->GetMeshFile();
2960            std::string mesh0 = cMesh0.in();
2961            CORBA::String_var cMeshName0= myIteration->GetMeshName();
2962            std::string meshName0 = cMeshName0.in();
2963            dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2964            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2965            std::string dumpCas2= dumpCorbaCase.in();
2966
2967            MESSAGE (dumpCas<<dumpCas2<<"\n");
2968            aScript += dumpCas + dumpCas2;
2969         };
2970
2971
2972    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
2973    {
2974     MESSAGE (". Ecritures des iterations");
2975     aScript += "#\n# Creation of the iterations" ;
2976     aScript += "\n# ==========================";
2977    }
2978    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2979    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2980         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2981    {
2982     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2983     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2984     std::string dumpIter = dumpCorbaIter.in();
2985     MESSAGE (dumpIter<<"\n");
2986     aScript += dumpIter;
2987    }
2988
2989   MESSAGE (". Ecritures finales");
2990   if( isMultiFile )
2991     aScript += "\n\tpass";
2992   aScript += "\n";
2993
2994   if( !isMultiFile ) // remove unnecessary tabulation
2995     aScript = RemoveTabulation( aScript );
2996
2997 //   MESSAGE ("A ecrire \n"<<aScript);
2998   const size_t aLen = strlen(aScript.c_str());
2999   char* aBuffer = new char[aLen+1];
3000   strcpy(aBuffer, aScript.c_str());
3001
3002   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
3003   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
3004
3005   MESSAGE ("Sortie de DumpPython");
3006   return aStreamFile._retn();
3007 }
3008
3009
3010 //=============================================================================
3011 //=============================================================================
3012 // Utilitaires
3013 //=============================================================================
3014 //=============================================================================
3015 void HOMARD_Gen_i::IsValidStudy( )
3016 {
3017 //   MESSAGE( "IsValidStudy" );
3018   if (CORBA::is_nil(myCurrentStudy))
3019   {
3020     SALOME::ExceptionStruct es;
3021     es.type = SALOME::BAD_PARAM;
3022     es.text = "Invalid Study Context";
3023     throw SALOME::SALOME_Exception(es);
3024   };
3025   return ;
3026 }
3027
3028 //=============================================================================
3029 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
3030 {
3031   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
3032   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3033   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
3034   {
3035    if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
3036   }
3037   return true;
3038 }
3039 /*//=============================================================================
3040 void SALOMEException( std::string message )
3041 {
3042   SALOME::ExceptionStruct es;
3043   es.type = SALOME::BAD_PARAM;
3044   es.text = message;
3045   throw SALOME::SALOME_Exception(es);
3046   return ;
3047 }*/
3048 //=============================================================================
3049 char* HOMARD_Gen_i::getVersion()
3050 {
3051 #if HOMARD_DEVELOPMENT
3052   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
3053 #else
3054   return CORBA::string_dup(HOMARD_VERSION_STR);
3055 #endif
3056 }
3057
3058 //=============================================================================
3059 extern "C"
3060 {
3061   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
3062                                                   PortableServer::POA_ptr poa,
3063                                                   PortableServer::ObjectId* contId,
3064                                                   const char* instanceName,
3065                                                   const char* interfaceName)
3066   {
3067     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
3068     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
3069     return myHOMARD_Gen->getId();
3070   }
3071 }