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