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