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