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