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