Salome HOME
9b53284b9ce92c10fd90fc950dced2ba0595124b
[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   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
1424   ASSERT(!CORBA::is_nil(myIteration));
1425
1426 // on ne calcule pas l iteration 0
1427   int NumeIter = myIteration->GetNumber();
1428   if ( NumeIter == 0 )
1429   {
1430       SALOME::ExceptionStruct es;
1431       es.type = SALOME::BAD_PARAM;
1432       es.text = "This iteration is the first of the case and cannot be computed.";
1433       throw SALOME::SALOME_Exception(es);
1434       return 1;
1435   };
1436
1437 // on verifie qu il y a une hypothese (erreur improbable);
1438   const char* nomHypo = myIteration->GetHypoName();
1439   if (std::string(nomHypo) == std::string(""))
1440   {
1441       SALOME::ExceptionStruct es;
1442       es.type = SALOME::BAD_PARAM;
1443       es.text= "This iteration does not have any associated hypothesis.";
1444       throw SALOME::SALOME_Exception(es);
1445       return 2;
1446   }
1447   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1448   ASSERT(!CORBA::is_nil(myHypo));
1449
1450   // A.4. L'iteration parent
1451   const char* nomIterationParent = myIteration->GetIterParentName();
1452   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1453   ASSERT(!CORBA::is_nil(myIterationParent));
1454   if ( ! myIterationParent->GetEtat() )
1455   {
1456       int codret = Compute(nomIterationParent, etatMenage);
1457       if (codret != 0)
1458       {
1459         // GERALD -- QMESSAGE BOX
1460         ASSERT("Pb au calcul de l'iteration precedente" == 0);
1461       }
1462   };
1463
1464   const char* nomCas = myIteration->GetCaseName();
1465   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1466   ASSERT(!CORBA::is_nil(myCase));
1467
1468   int codret = 0;
1469   std::stringstream saux0 ;
1470   saux0 << NumeIter - 1 ;
1471   std::string siter = saux0.str() ;
1472   if (NumeIter < 11) { siter = "0" + siter ; }
1473 //
1474   std::stringstream saux1 ;
1475   saux1 << NumeIter ;
1476   std::string siterp1 = saux1.str() ;
1477   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1478
1479   // B. Les repertoires
1480   // B.1. Le repertoire du cas
1481   const char* nomDirCase = myCase->GetDirName();
1482   MESSAGE ( ". nomDirCase = " << nomDirCase );
1483
1484   // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1485   // B.2.1. Le nom du sous-repertoire
1486   const char* nomDirIt = myIteration->GetDirName();
1487
1488   // B.2.2. Le nom complet du sous-repertoire
1489   std::stringstream DirCompute ;
1490   DirCompute << nomDirCase << "/" << nomDirIt;
1491   MESSAGE (". DirCompute = " << DirCompute.str() );
1492
1493   // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1494   //        Si le sous-repertoire existe :
1495   //         etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1496   //         etatMenage = 1 : on fait le menage du repertoire
1497   if (chdir(DirCompute.str().c_str()) != 0)
1498   {
1499 //  Creation du repertoire car il n'existe pas :
1500     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1501     {
1502        // GERALD -- QMESSAGE BOX
1503        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1504        ASSERT("Pb a la creation du repertoire" == 0);
1505     }
1506   }
1507   else
1508   {
1509 //  Le repertoire existe et on fait le menage de son contenu :
1510     if (etatMenage != 0)
1511     {
1512        MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1513        std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1514        int codret = system(commande.c_str());
1515        if (codret != 0)
1516        {
1517          // GERALD -- QMESSAGE BOX
1518          std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1519          ASSERT("Pb au menage du repertoire de calcul" == 0);
1520        }
1521     }
1522     else
1523     {
1524 //  Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1525        DIR *dp;
1526        struct dirent *dirp;
1527        dp  = opendir(DirCompute.str().c_str());
1528        bool result = true;
1529        while ((dirp = readdir(dp)) != NULL && result )
1530        {
1531             std::string file_name(dirp->d_name);
1532             result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1533        }
1534        closedir(dp);
1535        if ( result == false)
1536        {
1537           SALOME::ExceptionStruct es;
1538           es.type = SALOME::BAD_PARAM;
1539           std::string text = "Directory : " + DirCompute.str() + "is not empty";
1540           es.text = CORBA::string_dup(text.c_str());
1541           throw SALOME::SALOME_Exception(es);
1542           return 3;
1543        }
1544     }
1545   }
1546
1547   // B.3. Le sous-repertoire de l'iteration precedente
1548   const char* nomDirItPa ;
1549   std::stringstream DirComputePa ;
1550   if (NumeIter == 1)
1551   {
1552     nomDirItPa = nomDirIt;
1553     DirComputePa << DirCompute.str();
1554   }
1555   else
1556   {
1557     nomDirItPa = myIterationParent->GetDirName();
1558     DirComputePa << nomDirCase << "/" << nomDirItPa;
1559   }
1560   MESSAGE( ". nomDirItPa = " << nomDirItPa);
1561   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1562
1563   // B.4. Le fichier des messages
1564   chdir(DirCompute.str().c_str()) ;
1565   std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1566   MESSAGE (". MessFile = " << MessFile);
1567   myIteration->SetMessFile(MessFile.c_str());
1568
1569    // C. On passe dans le repertoire de l'iteration a calculer
1570   chdir(DirCompute.str().c_str()) ;
1571
1572   // D. Les donnees du calcul HOMARD
1573   // D.1. Le type de conformite
1574   int ConfType = myCase->GetConfType();
1575   MESSAGE ( ". ConfType = " << ConfType );
1576
1577   // D.2. Le maillage n
1578   const char* NomMeshParent = myIterationParent->GetMeshName();
1579   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1580   const char* MeshFileParent = myIterationParent->GetMeshFile();
1581   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1582
1583   // D.3. Le maillage n+1
1584   const char* NomMesh = myIteration->GetMeshName();
1585   MESSAGE ( ". NomMesh = " << NomMesh );
1586   const char* MeshFile = myIteration->GetMeshFile();
1587   MESSAGE ( ". MeshFile = " << MeshFile );
1588   FILE *file = fopen(MeshFile,"r");
1589   if (file != NULL)
1590   {
1591      fclose(file);
1592      if (etatMenage == 0)
1593      {
1594           SALOME::ExceptionStruct es;
1595           es.type = SALOME::BAD_PARAM;
1596           std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1597           es.text = CORBA::string_dup(text.c_str());
1598           throw SALOME::SALOME_Exception(es);
1599           return 4;
1600      }
1601      else
1602      {
1603          std::string commande = "rm -f " + std::string(MeshFile);
1604          codret = system(commande.c_str());
1605          if (codret != 0)
1606          {
1607           SALOME::ExceptionStruct es;
1608           es.type = SALOME::BAD_PARAM;
1609           std::string text = "PB with meshfile destruction ";
1610           es.text = CORBA::string_dup(text.c_str());
1611           throw SALOME::SALOME_Exception(es);
1612           return 5;
1613          }
1614       }
1615   }
1616   else
1617   {
1618      codret = 0 ;
1619   };
1620
1621   // D.4. Les types de raffinement et de deraffinement
1622   // Les appels corba sont lourds, il vaut mieux les grouper
1623   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1624   ASSERT(ListTypes->length() == 3);
1625   int TypeAdap = (*ListTypes)[0];
1626   int TypeRaff = (*ListTypes)[1];
1627   int TypeDera = (*ListTypes)[2];
1628
1629   // D.6. L'option d'interpolation des champs
1630   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1631
1632   // E. Texte du fichier de configuration
1633   // E.1. Incontournables du texte
1634   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1635   myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1636   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1637   myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1638   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1639
1640   // E.2. Ajout des informations liees aux zones eventuelles
1641   if (TypeAdap == 0)
1642   {
1643     HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1644     int numberOfZonesx2 = ListZone->length();
1645     int NumZone ;
1646
1647     for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
1648     {
1649       std::string ZoneName = std::string((*ListZone)[iaux]);
1650       MESSAGE ( "... ZoneName = " << ZoneName);
1651       HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1652       ASSERT(!CORBA::is_nil(myZone));
1653
1654       int ZoneType = myZone->GetType();
1655       std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
1656       int TypeUse = atoi( TypeUsestr.c_str() );
1657       MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
1658       NumZone = iaux/2 + 1 ;
1659       HOMARD::double_array* zone = myZone->GetCoords();
1660       if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1661       {
1662         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1663       }
1664       else if ( ZoneType == 4 ) // Cas d une sphere
1665       {
1666         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1667       }
1668       else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1669       {
1670         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1671       }
1672       else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1673       {
1674         myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1675       }
1676       else { ASSERT("ZoneType est incorrect." == 0) ; }
1677       iaux += 1 ;
1678     }
1679   }
1680   // E.3. Ajout des informations liees aux champs eventuels
1681   if (TypeAdap == 1)
1682   {
1683 //  Le fichier du champ
1684     char* FieldFile = myIteration->GetFieldFile();
1685     MESSAGE ( ". FieldFile = " << FieldFile );
1686     if (strlen(FieldFile) == 0)
1687     {
1688       // GERALD -- QMESSAGE BOX
1689       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1690       ASSERT("The file for the field is not given." == 0);
1691     }
1692 //  Les caracteristiques d'instants
1693     int TimeStep = myIteration->GetTimeStep();
1694     MESSAGE( ". TimeStep = " << TimeStep );
1695     int Rank = myIteration->GetRank();
1696     MESSAGE( ". Rank = " << Rank );
1697 //  Les informations sur les champ
1698     HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1699 //  Le nom
1700     const char* FieldName = aInfosHypo->FieldName;
1701 //  Les seuils
1702     int TypeThR = aInfosHypo->TypeThR;
1703     double ThreshR = aInfosHypo->ThreshR;
1704     int TypeThC = aInfosHypo->TypeThC;
1705     double ThreshC = aInfosHypo->ThreshC;
1706 //  Saut entre mailles ou non ?
1707     int UsField = aInfosHypo->UsField;
1708     MESSAGE( ". UsField = " << UsField );
1709 //  L'usage des composantes
1710     int UsCmpI = aInfosHypo->UsCmpI;
1711     MESSAGE( ". UsCmpI = " << UsCmpI );
1712 //
1713     myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1714 //
1715 //  Les composantes
1716     HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1717     int numberOfCompos = mescompo->length();
1718     MESSAGE( ". numberOfCompos = " << numberOfCompos );
1719     for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1720     {
1721       std::string nomCompo = std::string((*mescompo)[NumeComp]);
1722       MESSAGE( "... nomCompo = " << nomCompo );
1723       myDriver->TexteCompo(NumeComp, nomCompo);
1724     }
1725   }
1726   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1727   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1728   int numberOfGroups = listeGroupes->length();
1729   MESSAGE( ". numberOfGroups = " << numberOfGroups );
1730   if (numberOfGroups > 0)
1731   {
1732
1733     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1734     {
1735       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1736       MESSAGE( "... GroupName = " << GroupName );
1737       myDriver->TexteGroup(GroupName);
1738     }
1739   }
1740
1741   // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1742   // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1743   std::list<std::string>  ListeBoundaryTraitees ;
1744   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1745   int numberOfitems = ListBoundaryGroupType->length();
1746   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1747   int BoundaryOption = 1 ;
1748   int NumBoundaryAnalytical = 0 ;
1749   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1750   {
1751     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1752     MESSAGE ( "... BoundaryName = " << BoundaryName);
1753     int A_faire = 1 ;
1754     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1755     while (it != ListeBoundaryTraitees.end())
1756     {
1757       MESSAGE ( "... BoundaryNameTraitee = " << *it);
1758       if ( BoundaryName == *it ) { A_faire = 0 ; }
1759       it++;
1760     }
1761     if ( A_faire == 1 )
1762     {
1763 // Caracteristiques de la frontiere
1764       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1765       ASSERT(!CORBA::is_nil(myBoundary));
1766       int BoundaryType = myBoundary->GetType();
1767       MESSAGE ( "... BoundaryType = " << BoundaryType );
1768 // Ecriture selon le type
1769       if (BoundaryType == 0) // Cas d une frontiere discrete
1770       {
1771         const char* MeshName = myBoundary->GetMeshName() ;
1772         const char* MeshFile = myBoundary->GetMeshFile() ;
1773         myDriver->TexteBoundaryDi( MeshName, MeshFile);
1774         BoundaryOption = BoundaryOption*2 ;
1775       }
1776       else // Cas d une frontiere analytique
1777       {
1778         NumBoundaryAnalytical++ ;
1779         HOMARD::double_array* coor = myBoundary->GetCoords();
1780         if (BoundaryType == 1) // Cas d un cylindre
1781         {
1782           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1783           BoundaryOption = BoundaryOption*3 ;
1784         }
1785         else if (BoundaryType == 2) // Cas d une sphere
1786         {
1787           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1788           BoundaryOption = BoundaryOption*3 ;
1789         }
1790       }
1791 // Memorisation du traitement
1792       ListeBoundaryTraitees.push_back( BoundaryName );
1793     }
1794   }
1795   NumBoundaryAnalytical = 0 ;
1796   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1797   {
1798     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1799     MESSAGE ( "... BoundaryName = " << BoundaryName);
1800     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1801     ASSERT(!CORBA::is_nil(myBoundary));
1802     int BoundaryType = myBoundary->GetType();
1803     MESSAGE ( "... BoundaryType = " << BoundaryType );
1804 //  Recuperation du nom du groupe
1805     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1806     MESSAGE ( "... GroupName = " << GroupName);
1807     if (BoundaryType == 0) // Cas d une frontiere discrete
1808     {
1809       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1810     }
1811     else // Cas d une frontiere analytique
1812     {
1813       NumBoundaryAnalytical++ ;
1814       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1815     }
1816   }
1817   myDriver->TexteBoundaryOption(BoundaryOption);
1818
1819   // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1820   MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1821   if (TypeFieldInterp != 0)
1822   {
1823 //  Le fichier des champs
1824     char* FieldFile = myIteration->GetFieldFile();
1825     MESSAGE ( ". FieldFile = " << FieldFile );
1826     if (strlen(FieldFile) == 0)
1827     {
1828       // GERALD -- QMESSAGE BOX
1829       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1830       ASSERT("The file for the field is not given." == 0);
1831     }
1832 //  Les caracteristiques d'instants
1833     int TimeStep = myIteration->GetTimeStep();
1834     MESSAGE( ". TimeStep = " << TimeStep );
1835     int Rank = myIteration->GetRank();
1836     MESSAGE( ". Rank = " << Rank );
1837 //
1838     myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1839 //  Les champs
1840     if (TypeFieldInterp == 2)
1841     {
1842       HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1843       int numberOfFields = meschamps->length();
1844       MESSAGE( ". numberOfFields = " << numberOfFields );
1845       for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1846       {
1847         std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1848         MESSAGE( "... nomChamp = " << nomChamp );
1849         myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1850       }
1851     }
1852   }
1853   // E.7. Ajout des options avancees
1854   int Pyram = myCase->GetPyram();
1855   MESSAGE ( ". Pyram = " << Pyram );
1856   int NivMax = myHypo->GetNivMax();
1857   MESSAGE ( ". NivMax = " << NivMax );
1858   double DiamMin = myHypo->GetDiamMin() ;
1859   MESSAGE ( ". DiamMin = " << DiamMin );
1860   int AdapInit = myHypo->GetAdapInit();
1861   MESSAGE ( ". AdapInit = " << AdapInit );
1862   int LevelOutput = myHypo->GetLevelOutput();
1863   MESSAGE ( ". LevelOutput = " << LevelOutput );
1864   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
1865
1866   // F. Ecriture du texte dans le fichier
1867   if (codret == 0)
1868   {
1869     myDriver->CreeFichier();
1870   }
1871
1872 // G. Execution
1873 //
1874   int codretexec = 12 ;
1875   if (codret == 0)
1876   {
1877     codretexec = myDriver->ExecuteHomard();
1878 //
1879     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
1880     if (codretexec == 0)
1881     {
1882       SetEtatIter(NomIteration,true);
1883     }
1884     else
1885     {
1886       // GERALD -- QMESSAGE BOX
1887       SetEtatIter(NomIteration,false);
1888     }
1889   }
1890
1891   // H. Gestion des resultats
1892   if (codret == 0)
1893   {
1894     // H.1. Le fichier des messages, dans tous les cas
1895     std::stringstream saux1 ;
1896     saux1 << "Mess " << NumeIter ;
1897     PublishFileUnderIteration(NomIteration, MessFile.c_str(), saux1.str().c_str());
1898
1899     // H.2. Si tout s'est bien passe :
1900     if (codretexec == 0)
1901     {
1902     // H.2.1. Le fichier de bilan
1903       std::stringstream saux2 ;
1904       saux2 << "Summary " << NumeIter ;
1905       std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1906       PublishFileUnderIteration(NomIteration, SummaryFile.c_str(), saux2.str().c_str());
1907     // H.2.2. Le fichier de  maillage obtenu
1908       std::stringstream saux0 ;
1909       saux0 <<"Iteration " << NumeIter ;
1910       PublishFileUnderIteration(NomIteration, MeshFile, saux0.str().c_str());
1911       PublishResultInSmesh(MeshFile, 1);
1912     }
1913   // H.3 Message d'erreur en cas de probleme
1914     else
1915     {
1916       SALOME::ExceptionStruct es;
1917       es.type = SALOME::BAD_PARAM;
1918       std::string text = "Error during the adaptation.\n" ;
1919       try
1920       {
1921           ifstream fichier(MessFile.c_str(), ios::in);
1922           string ligne;
1923           while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1924           while (getline(fichier, ligne)) { text += ligne+ "\n";};
1925       }
1926       catch (...) {
1927         text += "no log file ....";
1928       }
1929       es.text = CORBA::string_dup(text.c_str());
1930       throw SALOME::SALOME_Exception(es);
1931     }
1932   }
1933
1934   // I. Menage et retour dans le repertoire du cas
1935   if (codret == 0)
1936   {
1937     delete myDriver;
1938     chdir(nomDirCase);
1939   }
1940
1941   return codretexec ;
1942 }
1943 //===========================================================================
1944
1945 //===========================================================================
1946 //===========================================================================
1947 // Publications
1948 //===========================================================================
1949 //===========================================================================
1950 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1951                                                    SALOMEDS::SObject_ptr theSObject,
1952                                                    CORBA::Object_ptr theObject,
1953                                                    const char* theName)
1954 {
1955   MESSAGE("PublishInStudy pour " << theName);
1956   SALOMEDS::SObject_var aResultSO;
1957   if (CORBA::is_nil(theStudy))
1958   {
1959     SALOME::ExceptionStruct es;
1960     es.type = SALOME::BAD_PARAM;
1961     es.text = "Invalid Study Context ";
1962     throw SALOME::SALOME_Exception(es);
1963     return 0;
1964   };
1965
1966 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1967 // Rq : Iteration est publiee ailleurs
1968   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
1969   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1970   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1971   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1972
1973    addInStudy(theStudy);
1974
1975 // Controle de la non publication d'un objet de meme nom
1976    if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1977     {
1978       SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1979       if (listSO->length() >= 1)
1980       {
1981           MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1982           std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1983           aResultSO = listSO[0];
1984           return aResultSO._retn();
1985       }
1986     }
1987
1988   // Caracteristiques de l'etude
1989   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1990   aStudyBuilder->NewCommand();
1991   if(!aCase->_is_nil())
1992     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1993   else if(!aHypo->_is_nil())
1994     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1995   else if(!aZone->_is_nil())
1996     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1997   else if(!aBoundary->_is_nil())
1998     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1999
2000     aStudyBuilder->CommitCommand();
2001   return aResultSO._retn();
2002 };
2003 //=============================================================================
2004 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2005                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
2006                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2007 {
2008   MESSAGE("PublishCaseInStudy pour "<<theName);
2009   SALOMEDS::SObject_var aResultSO;
2010   SALOMEDS::GenericAttribute_var anAttr;
2011
2012   if (CORBA::is_nil(theObject)) {
2013     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2014     return aResultSO._retn();
2015   }
2016   if (theStudy->_is_nil()) {
2017     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2018     return aResultSO._retn();
2019   }
2020
2021   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2022   if (theFatherHomard->_is_nil())
2023   {
2024     MESSAGE("theFatherHomard->_is_nil()");
2025     return aResultSO._retn();
2026   }
2027
2028   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2029   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2030                      _orb->object_to_string(theObject) ) ;
2031   return aResultSO._retn();
2032 }
2033
2034 //=============================================================================
2035 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2036                     SALOMEDS::StudyBuilder_var aStudyBuilder,
2037                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2038 {
2039   MESSAGE("PublishZoneStudy pour "<<theName);
2040   SALOMEDS::SObject_var aResultSO;
2041   SALOMEDS::GenericAttribute_var anAttr;
2042
2043   if (CORBA::is_nil(theObject))
2044   {
2045     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
2046     return aResultSO._retn();
2047   }
2048   if (theStudy->_is_nil())
2049   {
2050     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
2051     return aResultSO._retn();
2052   }
2053   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2054   if (theFatherHomard->_is_nil())
2055   {
2056     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
2057     return aResultSO._retn();
2058   }
2059
2060   // Caracteristique de la zone
2061   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
2062   CORBA::Long ZoneType = myZone->GetType();
2063
2064   // On ajoute la categorie des zones dans l etude si necessaire
2065   SALOMEDS::SObject_var aSOZone;
2066   if (!theFatherHomard->FindSubObject(100, aSOZone))
2067   {
2068     MESSAGE("Ajout de la categorie des zones");
2069     aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
2070     PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
2071   }
2072   else { MESSAGE("La categorie des zones existe deja."); }
2073
2074   aResultSO = aStudyBuilder->NewObject(aSOZone);
2075   const char* icone ;
2076   switch (ZoneType)
2077   {
2078     case 11 :
2079     { }
2080     case 12 :
2081     { }
2082     case 13 :
2083     { icone = "boxdxy_2.png" ;
2084       break ;
2085     }
2086     case 2 :
2087     { icone = "boxdxyz_2.png" ;
2088       break ;
2089     }
2090     case 31 :
2091     { }
2092     case 32 :
2093     { }
2094     case 33 :
2095     { icone = "disk_2.png" ;
2096       break ;
2097      }
2098     case 4 :
2099     { icone = "spherepoint_2.png" ;
2100       break ;
2101     }
2102     case 5 :
2103     { icone = "cylinderpointvector_2.png" ;
2104       break ;
2105     }
2106     case 61 :
2107     { }
2108     case 62 :
2109     { }
2110     case 63 :
2111     { icone = "diskwithhole_2.png" ;
2112       break ;
2113      }
2114     case 7 :
2115     { icone = "pipe_2.png" ;
2116       break ;
2117     }
2118   }
2119   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
2120
2121   return aResultSO._retn();
2122 }
2123 //=============================================================================
2124 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
2125                    SALOMEDS::StudyBuilder_var aStudyBuilder,
2126                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
2127 {
2128   MESSAGE("PublishBoundaryStudy pour "<<theName);
2129   SALOMEDS::SObject_var aResultSO;
2130   SALOMEDS::GenericAttribute_var anAttr;
2131
2132   // Caracteristique de la Boundary
2133   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
2134
2135   // On recupere le module pere dans l etude
2136   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
2137   if (theFatherHomard->_is_nil())
2138   {
2139     MESSAGE("theFatherHomard->_is_nil()");
2140     return aResultSO._retn();
2141   }
2142
2143   // On ajoute la categorie des boundarys dans l etude si necessaire
2144   SALOMEDS::SObject_var aSOBoundary;
2145   if (!theFatherHomard->FindSubObject(101, aSOBoundary))
2146   {
2147     MESSAGE("Ajout de la categorie des boundarys");
2148     aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
2149     PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
2150   }
2151   else { MESSAGE("La categorie des boundarys existe deja."); }
2152
2153   aResultSO = aStudyBuilder->NewObject(aSOBoundary);
2154   CORBA::Long BoundaryType = myBoundary->GetType();
2155 //   MESSAGE("BoundaryType : "<<BoundaryType);
2156   const char* icone ;
2157   const char* value ;
2158   switch (BoundaryType)
2159   {
2160     case 0 :
2161     { value = "BoundaryDiHomard" ;
2162       icone = "mesh_tree_mesh.png" ;
2163       break;
2164     }
2165     case 1 :
2166     { value = "BoundaryAnHomard" ;
2167       icone = "cylinderpointvector_2.png" ;
2168       break;
2169     }
2170     case 2 :
2171     { value = "BoundaryAnHomard" ;
2172       icone = "spherepoint_2.png" ;
2173       break;
2174     }
2175   }
2176   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
2177   return aResultSO._retn();
2178 }
2179
2180 //=============================================================================
2181 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
2182                    SALOMEDS::StudyBuilder_var aStudyBuilder,
2183                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
2184 {
2185   MESSAGE("PublishHypotheseInStudy pour "<<theName);
2186   SALOMEDS::SObject_var aResultSO;
2187   SALOMEDS::GenericAttribute_var anAttr;
2188
2189   // On recupere le module pere dans l etude
2190   // On ajoute la categorie des hypotheses dans l etude si necessaire
2191   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2192   if (theFatherHomard->_is_nil())
2193   {
2194     MESSAGE("theFatherHomard->_is_nil()");
2195     return aResultSO._retn();
2196   }
2197   SALOMEDS::SObject_var aSOHypothese;
2198   if (!theFatherHomard->FindSubObject(0, aSOHypothese))
2199   {
2200     MESSAGE("Ajout de la categorie des hypotheses");
2201     aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
2202     PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
2203   }
2204   else { MESSAGE("La categorie des hypotheses existe deja."); }
2205
2206 // Creation du resultat dans l'etude
2207   aResultSO = aStudyBuilder->NewObject(aSOHypothese);
2208   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
2209
2210   return aResultSO._retn();
2211 }
2212 //===========================================================================
2213 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
2214                                       SALOMEDS::SObject_var aResultSO,
2215                                       const char* name, const char* value, const char* icone, const char* ior)
2216 {
2217   SALOMEDS::GenericAttribute_var anAttr ;
2218 //  Ajout du nom
2219   if ( name != NULL )
2220   {
2221     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
2222     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
2223     aNameAttrib->SetValue(name);
2224   }
2225
2226 //  Ajout du commentaire
2227   if ( value != NULL )
2228   {
2229     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
2230     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
2231     aCommentAttrib->SetValue(value);
2232   }
2233
2234 //  Ajout de l'icone
2235   if ( icone != NULL  )
2236   {
2237     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
2238     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2239     aPixmap->SetPixMap(icone);
2240   }
2241
2242 //  Ajout de l ior
2243   if ( ior != NULL  )
2244   {
2245     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
2246     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2247     anIOR->SetValue(ior);
2248   }
2249 };
2250
2251 //=====================================================================================
2252 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
2253 {
2254   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
2255
2256   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
2257   ASSERT(!CORBA::is_nil(myCase));
2258   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
2259   ASSERT(!CORBA::is_nil(aCaseSO));
2260
2261   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2262   ASSERT(!CORBA::is_nil(myBoundary));
2263   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
2264   ASSERT(!CORBA::is_nil(aBoundarySO));
2265
2266   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2267
2268   aStudyBuilder->NewCommand();
2269
2270   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
2271   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
2272
2273   aStudyBuilder->CommitCommand();
2274
2275 };
2276 //=============================================================================
2277 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
2278 {
2279   MESSAGE( "PublishResultInSmesh " << NomFich);
2280   if (CORBA::is_nil(myCurrentStudy))
2281   {
2282       SALOME::ExceptionStruct es;
2283       es.type = SALOME::BAD_PARAM;
2284       es.text = "Invalid Study Context ";
2285       throw SALOME::SALOME_Exception(es);
2286       return ;
2287   };
2288
2289 // Le module SMESH est-il actif ?
2290   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2291 //
2292   if (!CORBA::is_nil(aSmeshSO))
2293   {
2294 // On verifie que le fichier n est pas deja publie
2295     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2296     for (; aIter->More(); aIter->Next())
2297     {
2298        SALOMEDS::SObject_var  aSO = aIter->Value();
2299        SALOMEDS::GenericAttribute_var aGAttr;
2300        if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2301        {
2302            SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2303            CORBA::String_var value=anAttr->Value();
2304            if (strcmp((const char*)value,NomFich) == 0)
2305            {
2306                 // GERALD -- QMESSAGE BOX
2307                 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
2308                 return;
2309            }
2310        }
2311      }
2312
2313   }
2314
2315 // On enregistre le fichier
2316   MESSAGE( "Enregistrement du fichier");
2317   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
2318   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
2319   ASSERT(!CORBA::is_nil(aSmeshEngine));
2320   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
2321   SMESH::DriverMED_ReadStatus theStatus;
2322   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2323
2324 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
2325   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
2326   for (int i = 0; i < mesMaillages->length();  i++)
2327   {
2328     MESSAGE( ". Mise a jour des attributs du maillage");
2329     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
2330     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
2331     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2332     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
2333     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2334     anAttr->SetValue(NomFich);
2335     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
2336     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
2337 //  IconeType = 0 : fichier issu d'une importation
2338 //  IconeType = 1 : fichier issu d'une execution HOMARD
2339     const char* icone ;
2340     if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
2341     else                  { icone = "mesh_tree_mesh.png" ; }
2342     anAttr2->SetPixMap( icone );
2343   }
2344
2345 }
2346 //=============================================================================
2347 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2348 {
2349   MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
2350   if (CORBA::is_nil(myCurrentStudy))
2351   {
2352       SALOME::ExceptionStruct es;
2353       es.type = SALOME::BAD_PARAM;
2354       es.text = "Invalid Study Context ";
2355       throw SALOME::SALOME_Exception(es);
2356       return ;
2357   };
2358
2359 // Le module SMESH est-il actif ?
2360   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2361 //
2362   if (CORBA::is_nil(aSmeshSO))
2363   {
2364       return ;
2365   };
2366 // On verifie que le fichier est deja publie
2367   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2368   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2369   for (; aIter->More(); aIter->Next())
2370   {
2371      SALOMEDS::SObject_var  aSO = aIter->Value();
2372      SALOMEDS::GenericAttribute_var aGAttr;
2373      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2374      {
2375        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2376        CORBA::String_var value=anAttr->Value();
2377        if (strcmp((const char*)value,NomFich) == 0)
2378        {
2379          if (aSO->FindAttribute(aGAttr,"AttributeName"))
2380          {
2381            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2382            CORBA::String_var value2=anAttr2->Value();
2383            if (strcmp((const char*)value2,MeshName) == 0)
2384            {
2385              myBuilder->RemoveObjectWithChildren( aSO ) ;
2386            }
2387          }
2388        }
2389      }
2390   }
2391
2392 }
2393 //=============================================================================
2394 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2395 {
2396   if (CORBA::is_nil(myCurrentStudy))
2397   {
2398       SALOME::ExceptionStruct es;
2399       es.type = SALOME::BAD_PARAM;
2400       es.text = "Invalid Study Context ";
2401       throw SALOME::SALOME_Exception(es);
2402       return ;
2403   };
2404
2405   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2406   if (CORBA::is_nil(myIteration))
2407   {
2408       SALOME::ExceptionStruct es;
2409       es.type = SALOME::BAD_PARAM;
2410       es.text = "Invalid Iteration ";
2411       throw SALOME::SALOME_Exception(es);
2412       return ;
2413   };
2414   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2415   if (CORBA::is_nil(myIteration))
2416   {
2417       SALOME::ExceptionStruct es;
2418       es.type = SALOME::BAD_PARAM;
2419       es.text = "Invalid Iteration Study Object";
2420       throw SALOME::SALOME_Exception(es);
2421       return ;
2422   };
2423
2424   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2425
2426   aStudyBuilder->NewCommand();
2427
2428   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2429 // Pour les fichiers med, on affiche une icone de maillage
2430 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2431 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2432   const char* icone ;
2433   const char* ior = " " ;
2434   if ( Commentaire[0] == 'I' )
2435   { icone = "med.png" ; }
2436   else
2437   { icone = "texte_2.png" ; }
2438   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2439
2440   aStudyBuilder->CommitCommand();
2441 }
2442 //=============================================================================
2443 //=============================================================================
2444 //
2445 //=============================================================================
2446 //=============================================================================
2447 // Next functions are inherited from SALOMEDS::Driver interface
2448 //=============================================================================
2449 //=============================================================================
2450 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2451                                       const char* theURL,
2452                                       CORBA::Boolean isMultiFile)
2453 {
2454   MESSAGE (" Save for theURL = "<< theURL);
2455   SALOMEDS::TMPFile_var aStreamFile;
2456
2457   // get temporary directory name
2458   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2459
2460   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2461   StudyContext& context = myContextMap[ aStudy->StudyId() ];
2462
2463   // HOMARD data file name
2464   std::string aFileName = "";
2465   if (isMultiFile)
2466     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2467   aFileName += "_HOMARD.dat";
2468
2469   // initialize sequence of file names
2470   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2471   aFileSeq->length(1);
2472   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2473
2474   // get full path to the data file
2475   aFileName = tmpDir + aFileName;
2476
2477   // save data
2478   // -> create file
2479   std::ofstream f(aFileName.c_str());
2480
2481   // clear temporary id map
2482   context._idmap.clear();
2483
2484   int id = 1;
2485
2486   // -> save cases
2487   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2488   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2489     HOMARD::HOMARD_Cas_var aCas = it_case->second;
2490     PortableServer::ServantBase_var aServant = GetServant(aCas);
2491     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2492     if (aCasServant) {
2493       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2494       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2495     }
2496   }
2497   // -> save zones
2498   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2499   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2500     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2501     PortableServer::ServantBase_var aServant = GetServant(aZone);
2502     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2503     if (aZoneServant) {
2504       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2505       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2506     }
2507   }
2508   // -> save hypotheses
2509   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2510   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2511     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2512     PortableServer::ServantBase_var aServant = GetServant(aHypo);
2513     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2514     if (aHypoServant) {
2515       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2516       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2517     }
2518   }
2519   // -> save iterations
2520   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2521   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2522     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2523     PortableServer::ServantBase_var aServant = GetServant(aIter);
2524     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2525     if (aIterServant) {
2526       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2527       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2528     }
2529   }
2530   // -> save boundaries
2531   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2532   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2533     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2534     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2535     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2536     if (aBoundaryServant) {
2537       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2538       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2539     }
2540   }
2541   // -> close file
2542   MESSAGE ("close file");
2543   f.close();
2544
2545   // put temporary files to the stream
2546   MESSAGE ("put temporary files to the stream");
2547   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2548
2549   // remove temporary files
2550   MESSAGE ("remove temporary files");
2551   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2552
2553   // return data stream
2554   MESSAGE ("return data stream");
2555   return aStreamFile._retn();
2556 };
2557
2558 //===========================================================================
2559 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2560                                            const char* theURL,
2561                                            CORBA::Boolean isMultiFile)
2562 {
2563   // No specific ASCII persistence
2564   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2565   return aStreamFile._retn();
2566 };
2567
2568 //===========================================================================
2569 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2570                                    const SALOMEDS::TMPFile& theStream,
2571                                    const char* theURL,
2572                                    CORBA::Boolean isMultiFile)
2573 {
2574   MESSAGE (" Load pour theURL = "<< theURL);
2575   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2576
2577   // set current study
2578   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2579     SetCurrentStudy(aStudy);
2580
2581   // get temporary directory name
2582   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2583
2584   // Convert the stream into sequence of files to process
2585   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2586                                                                             tmpDir.c_str(),
2587                                                                             isMultiFile);
2588   // HOMARD data file name
2589   std::string aFileName = "";
2590   if (isMultiFile)
2591     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2592   aFileName = tmpDir + aFileName + "_HOMARD.dat";
2593
2594   StudyContext& context = myContextMap[ aStudy->StudyId() ];
2595
2596   // save data
2597   // -> create file
2598   std::ifstream f(aFileName.c_str());
2599
2600   // clear context
2601   context._mesCas.clear();
2602   context._mesHypotheses.clear();
2603   context._mesIterations.clear();
2604   context._mesZones.clear();
2605   context._mesBoundarys.clear();
2606   context._idmap.clear();
2607
2608   int id = 1;
2609   std::string line;
2610
2611   while (f) {
2612     std::getline(f, line);
2613     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2614     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2615     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2616     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2617     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2618     if (line.substr(0, caseSignature.size()) == caseSignature) {
2619       // re-create case
2620       MESSAGE (" Recreation du cas" );
2621       HOMARD::HOMARD_Cas_var aCase = newCase();
2622       PortableServer::ServantBase_var aServant = GetServant(aCase);
2623       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2624       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2625         context._mesCas[aCase->GetName()] = aCase;
2626         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2627       }
2628     }
2629     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2630       MESSAGE (" Recreation de la zone" );
2631       // re-create zone
2632       HOMARD::HOMARD_Zone_var aZone = newZone();
2633       PortableServer::ServantBase_var aServant = GetServant(aZone);
2634       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2635       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2636         context._mesZones[aZone->GetName()] = aZone;
2637         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2638       }
2639     }
2640     else if (line.substr(0, iterSignature.size()) == iterSignature) {
2641       // re-create iteration
2642       MESSAGE (" Recreation de l iteration" );
2643       HOMARD::HOMARD_Iteration_var aIter = newIteration();
2644       PortableServer::ServantBase_var aServant = GetServant(aIter);
2645       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2646       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2647         context._mesIterations[aIter->GetName()] = aIter;
2648         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2649       }
2650     }
2651     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2652       // re-create hypothesis
2653       MESSAGE (" Recreation de l hypothese" );
2654       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2655       PortableServer::ServantBase_var aServant = GetServant(aHypo);
2656       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2657       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2658         context._mesHypotheses[aHypo->GetName()] = aHypo;
2659         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2660       }
2661     }
2662     else if (line.substr(0, bounSignature.size()) == bounSignature) {
2663       // re-create boundary
2664       MESSAGE (" Recreation de la frontiere" );
2665       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2666       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2667       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2668       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2669         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2670         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2671       }
2672     }
2673     id++;
2674   }
2675
2676   // -> close file
2677   f.close();
2678
2679   // Remove temporary files created from the stream
2680   if (!isMultiFile)
2681     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2682
2683   return true;
2684 };
2685
2686 //===========================================================================
2687 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2688                                         const SALOMEDS::TMPFile& theStream,
2689                                         const char* theURL,
2690                                         CORBA::Boolean isMultiFile)
2691 {
2692   // No specific ASCII persistence
2693   return Load(theComponent, theStream, theURL, isMultiFile);
2694 };
2695
2696 //===========================================================================
2697 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2698 {
2699   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2700     // clearing study context should be done here:
2701     // - destroy all servants and related CORBA objects
2702     // ... (TODO)
2703     // - remove context from myContextMap
2704     myContextMap.erase(theComponent->GetStudy()->StudyId());
2705     // - nullify myCurrentStudy
2706     myCurrentStudy = SALOMEDS::Study::_nil();
2707   }
2708 };
2709
2710 //===========================================================================
2711 char* HOMARD_Gen_i::ComponentDataType()
2712 {
2713   return CORBA::string_dup("HOMARD");
2714 };
2715
2716 //===========================================================================
2717 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2718                                             const char* IORString,
2719                                             CORBA::Boolean isMultiFile,
2720                                             CORBA::Boolean isASCII)
2721 {
2722   CORBA::String_var aString("");
2723   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2724     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2725     CORBA::Object_var anObj = _orb->string_to_object(IORString);
2726     if (!CORBA::is_nil(anObj)) {
2727       PortableServer::ServantBase_var aServant = GetServant(anObj);
2728       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2729       if (aStorable) {
2730         std::map<int, PortableServer::ServantBase*>::const_iterator it;
2731         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2732           if (it->second == aStorable) {
2733             std::stringstream os;
2734             os << it->first;
2735             aString = CORBA::string_dup(os.str().c_str());
2736           }
2737         }
2738       }
2739     }
2740   }
2741   return aString._retn();
2742 };
2743
2744 //===========================================================================
2745 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2746                                             const char* aLocalPersistentID,
2747                                             CORBA::Boolean isMultiFile,
2748                                             CORBA::Boolean isASCII)
2749 {
2750   CORBA::String_var aString("");
2751   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2752     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2753     int id = atoi(aLocalPersistentID);
2754     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2755       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2756       if (!CORBA::is_nil(object)) {
2757         aString = _orb->object_to_string(object);
2758       }
2759     }
2760   }
2761   return aString._retn();
2762 };
2763
2764 //===========================================================================
2765 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2766 {
2767   if(CORBA::is_nil(myCurrentStudy))
2768     return false;
2769
2770   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2771   if(!aCas->_is_nil())
2772     return true;
2773
2774   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2775   if(!aHypo->_is_nil())
2776     return true;
2777
2778   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2779   if(!aZone->_is_nil())
2780     return true;
2781
2782   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2783   if(!aBoundary->_is_nil())
2784     return true;
2785
2786   /* Iteration is not published directly
2787   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2788   if(!aIter->_is_nil())
2789     return true;
2790   */
2791   return false;
2792 };
2793
2794 //===========================================================================
2795 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2796 {
2797   // No Copy/Paste support
2798   return false;
2799 };
2800
2801 //===========================================================================
2802 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2803                                            CORBA::Long& theObjectID)
2804 {
2805   // No Copy/Paste support
2806   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2807   return aStreamFile._retn();
2808 };
2809
2810 //===========================================================================
2811 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
2812                                         CORBA::Long theObjectID)
2813 {
2814   // No Copy/Paste support
2815   return false;
2816 };
2817
2818 //===========================================================================
2819 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2820                                                CORBA::Long theObjectID,
2821                                                SALOMEDS::SObject_ptr theSObject)
2822 {
2823   // No Copy/Paste support
2824   SALOMEDS::SObject_var aResultSO;
2825   return aResultSO._retn();
2826 };
2827
2828 //===========================================================================
2829 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2830 {
2831   PortableServer::Servant aServant = 0;
2832   if (!CORBA::is_nil(theObject)) {
2833     try {
2834       aServant = _poa->reference_to_servant(theObject);
2835     }
2836     catch (...) {
2837     }
2838   }
2839   return aServant;
2840 }
2841
2842 //==========================================================================
2843 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2844                                        CORBA::Boolean isPublished,
2845                                        CORBA::Boolean isMultiFile,
2846                                        CORBA::Boolean& isValidScript)
2847 {
2848    MESSAGE ("Entree dans DumpPython");
2849    isValidScript=1;
2850    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2851    if(CORBA::is_nil(aStudy))
2852      return new Engines::TMPFile(0);
2853
2854    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2855    if(CORBA::is_nil(aSO))
2856       return new Engines::TMPFile(0);
2857
2858    std::string aScript = "\"\"\"\n";
2859    aScript += "Python script for HOMARD\n";
2860    aScript += "Copyright EDF-R&D 2013\n";
2861    aScript += "\"\"\"\n";
2862    aScript += "__revision__ = \"V1.2\"\n";
2863    aScript += "import HOMARD\n";
2864    if( isMultiFile )
2865       aScript += "import salome\n";
2866    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2867    if( isMultiFile ) {
2868       aScript += "def RebuildData(theStudy):\n";
2869       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2870    }
2871    else
2872       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2873    MESSAGE (". Au depart \n"<<aScript);
2874
2875
2876    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2877    {
2878     MESSAGE (". Ecritures des frontieres");
2879     aScript += "#\n# Creation of the boundaries";
2880     aScript +=  "\n# ==========================";
2881    }
2882    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2883    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2884         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2885    {
2886     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2887     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2888     std::string dumpBoundary = dumpCorbaBoundary.in();
2889     MESSAGE (dumpBoundary<<"\n");
2890     aScript += dumpBoundary;
2891    }
2892
2893
2894    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2895    {
2896     MESSAGE (". Ecritures des zones");
2897     aScript += "#\n# Creation of the zones";
2898     aScript +=  "\n# =====================";
2899    }
2900    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2901    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2902          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2903    {
2904     HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2905     CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2906     std::string dumpZone = dumpCorbaZone.in();
2907     MESSAGE (dumpZone<<"\n");
2908     aScript += dumpZone;
2909    }
2910
2911
2912    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
2913    {
2914     MESSAGE (". Ecritures des hypotheses");
2915     aScript += "#\n# Creation of the hypotheses";
2916     aScript +=  "\n# ==========================";
2917    }
2918    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2919    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2920          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2921    {
2922     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2923     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2924     std::string dumpHypo = dumpCorbaHypo.in();
2925     MESSAGE (dumpHypo<<"\n");
2926     aScript += dumpHypo;
2927    }
2928
2929
2930    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
2931    {
2932     MESSAGE (". Ecritures des cas");
2933     aScript += "#\n# Creation of the cases";
2934     aScript += "\n# =====================";
2935    }
2936    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2937    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2938         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2939         {
2940            std::string nomCas = (*it_cas).first;
2941            std::string dumpCas = std::string("\n# Creation of the case ") ;
2942            dumpCas +=  nomCas + std::string("\n");
2943            dumpCas += std::string("\t") + nomCas;
2944            dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2945
2946            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2947            CORBA::String_var cIter0= myCase->GetIter0Name();
2948            std::string iter0 = cIter0.in();
2949
2950            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2951            CORBA::String_var cMesh0= myIteration->GetMeshFile();
2952            std::string mesh0 = cMesh0.in();
2953            CORBA::String_var cMeshName0= myIteration->GetMeshName();
2954            std::string meshName0 = cMeshName0.in();
2955            dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2956            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2957            std::string dumpCas2= dumpCorbaCase.in();
2958
2959            MESSAGE (dumpCas<<dumpCas2<<"\n");
2960            aScript += dumpCas + dumpCas2;
2961         };
2962
2963
2964    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
2965    {
2966     MESSAGE (". Ecritures des iterations");
2967     aScript += "#\n# Creation of the iterations" ;
2968     aScript += "\n# ==========================";
2969    }
2970    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2971    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2972         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2973    {
2974     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2975     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2976     std::string dumpIter = dumpCorbaIter.in();
2977     MESSAGE (dumpIter<<"\n");
2978     aScript += dumpIter;
2979    }
2980
2981   MESSAGE (". Ecritures finales");
2982   if( isMultiFile )
2983     aScript += "\n\tpass";
2984   aScript += "\n";
2985
2986   if( !isMultiFile ) // remove unnecessary tabulation
2987     aScript = RemoveTabulation( aScript );
2988
2989 //   MESSAGE ("A ecrire \n"<<aScript);
2990   const size_t aLen = strlen(aScript.c_str());
2991   char* aBuffer = new char[aLen+1];
2992   strcpy(aBuffer, aScript.c_str());
2993
2994   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
2995   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2996
2997   MESSAGE ("Sortie de DumpPython");
2998   return aStreamFile._retn();
2999 }
3000
3001
3002 //=============================================================================
3003 //=============================================================================
3004 // Utilitaires
3005 //=============================================================================
3006 //=============================================================================
3007 void HOMARD_Gen_i::IsValidStudy( )
3008 {
3009 //   MESSAGE( "IsValidStudy" );
3010   if (CORBA::is_nil(myCurrentStudy))
3011   {
3012     SALOME::ExceptionStruct es;
3013     es.type = SALOME::BAD_PARAM;
3014     es.text = "Invalid Study Context";
3015     throw SALOME::SALOME_Exception(es);
3016   };
3017   return ;
3018 }
3019
3020 //=============================================================================
3021 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
3022 {
3023   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
3024   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
3025   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
3026   {
3027    if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
3028   }
3029   return true;
3030 }
3031 /*//=============================================================================
3032 void SALOMEException( std::string message )
3033 {
3034   SALOME::ExceptionStruct es;
3035   es.type = SALOME::BAD_PARAM;
3036   es.text = message;
3037   throw SALOME::SALOME_Exception(es);
3038   return ;
3039 }*/
3040 //=============================================================================
3041 char* HOMARD_Gen_i::getVersion()
3042 {
3043 #if HOMARD_DEVELOPMENT
3044   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
3045 #else
3046   return CORBA::string_dup(HOMARD_VERSION_STR);
3047 #endif
3048 }
3049
3050 //=============================================================================
3051 extern "C"
3052 {
3053   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
3054                                                   PortableServer::POA_ptr poa,
3055                                                   PortableServer::ObjectId* contId,
3056                                                   const char* instanceName,
3057                                                   const char* interfaceName)
3058   {
3059     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
3060     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
3061     return myHOMARD_Gen->getId();
3062   }
3063 }