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