Salome HOME
Suppression de la publication du maillage à la création du cas
[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   INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile  );
992   INFOS ( "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   INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1084
1085   // Par defaut, on ne publie pas le maillage
1086   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
1087
1088 // Valeurs par defaut des filtrages
1089   myCase->SetPyram(0);
1090
1091   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1092 }
1093 //=============================================================================
1094 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromIteration(const char* nomCas, const char* DirNameStart)
1095 //
1096 // nomCas : nom du cas a creer
1097 // DirNameStart : nom du repertoire contenant l'iteration de reprise
1098 //
1099 {
1100   INFOS ( "CreateCaseFromIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1101   std::string nomDirWork = getenv("PWD") ;
1102   int codret ;
1103
1104   // A. Decodage du point de reprise
1105   // A.1. Controle du repertoire de depart de l'iteration
1106   codret = chdir(DirNameStart) ;
1107   if ( codret != 0 )
1108   {
1109     SALOME::ExceptionStruct es;
1110     es.type = SALOME::BAD_PARAM;
1111     es.text = "The directory of the iteration does not exist.";
1112     throw SALOME::SALOME_Exception(es);
1113     return 0;
1114   };
1115   // A.2. Reperage des fichiers du repertoire de reprise
1116   std::string file_configuration = "" ;
1117   std::string file_maillage_homard = "" ;
1118   int bilan ;
1119   DIR *dp;
1120   struct dirent *dirp;
1121   dp  = opendir(DirNameStart);
1122   while ( (dirp = readdir(dp)) != NULL )
1123   {
1124     std::string file_name(dirp->d_name);
1125 //     MESSAGE ( file_name );
1126     bilan = file_name.find("HOMARD.Configuration.") ;
1127     if ( bilan != string::npos ) { file_configuration = file_name ; }
1128     bilan = file_name.find("maill.") ;
1129     if ( bilan != string::npos )
1130     {
1131       bilan = file_name.find(".hom.med") ;
1132       if ( bilan != string::npos ) { file_maillage_homard = file_name ; }
1133     }
1134   }
1135   closedir(dp);
1136   MESSAGE ( "==> file_configuration   : " << file_configuration ) ;
1137   MESSAGE ( "==> file_maillage_homard : " << file_maillage_homard ) ;
1138   // A.3. Controle
1139   if ( ( file_configuration == "" ) or ( file_maillage_homard == "" ) )
1140   {
1141     SALOME::ExceptionStruct es;
1142     es.type = SALOME::BAD_PARAM;
1143     std::string text ;
1144     if ( file_configuration == "" ) { text = "The configuration file cannot be found." ; }
1145     else                            { text = "The HOMARD mesh file cannot be found." ; }
1146     es.text = CORBA::string_dup(text.c_str());
1147     throw SALOME::SALOME_Exception(es);
1148   }
1149
1150   // B. Lecture du fichier de configuration
1151   // ATTENTION : on doit veiller a la coherence entre HomardDriver et CreateCaseFromIteration
1152   int NumeIter ;
1153   int TypeConf = 0 ;
1154   int Pyram = 0 ;
1155   char* MeshName ;
1156   char* MeshFile ;
1157   // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1158   std::ifstream fichier( file_configuration.c_str() );
1159   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1160   {
1161     std::string ligne; // variable contenant chaque ligne lue
1162     std::string mot_cle;
1163     std::string argument;
1164     int decalage;
1165     // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1166     while ( std::getline( fichier, ligne ) )
1167     {
1168       // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1169       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1170       ligne_bis >> mot_cle ;
1171       // B.2. Des valeurs entieres : le second bloc de la ligne
1172       if ( mot_cle == "NumeIter" )
1173       {
1174         ligne_bis >> NumeIter ;
1175         NumeIter += 1 ;
1176       }
1177       // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1178       else if ( ( mot_cle == "TypeConf" ) or ( mot_cle == "TypeElem" ) )
1179       {
1180         ligne_bis >> argument ;
1181
1182         if ( mot_cle == "TypeConf" )
1183         {
1184           if      ( argument == "conforme" )                { TypeConf = 1 ; }
1185           else if ( argument == "non_conforme_1_noeud" )    { TypeConf = 2 ; }
1186           else if ( argument == "non_conforme_1_arete" )    { TypeConf = 3 ; }
1187           else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1188         }
1189         else if ( mot_cle == "TypeElem" )
1190         {
1191           if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1192           else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1193         }
1194       }
1195       // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1196       //                               il faut les supprimer
1197       else if ( ( mot_cle == "CCNoMNP1" ) or ( mot_cle == "CCMaiNP1" ) )
1198       {
1199         ligne_bis >> argument ;
1200         if ( argument[0] == '"' ) { decalage = 1 ; }
1201         else                      { decalage = 0 ; }
1202         size_t size = argument.size() + 1 - 2*decalage ;
1203
1204         if ( mot_cle == "CCNoMNP1" )
1205         {
1206           MeshName = new char[ size ];
1207           strncpy( MeshName, argument.c_str()+decalage, size );
1208           MeshName[size-1] = '\0' ;
1209         }
1210         else if ( mot_cle == "CCMaiNP1" )
1211         {
1212           MeshFile = new char[ size ];
1213           strncpy( MeshFile, argument.c_str()+decalage, size );
1214           MeshFile[size-1] = '\0' ;
1215         }
1216       }
1217     }
1218     MESSAGE ( "==> TypeConf   : " << TypeConf ) ;
1219     MESSAGE ( "==> MeshName   : " << MeshName ) ;
1220     MESSAGE ( "==> MeshFile   : " << MeshFile ) ;
1221     MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1222     MESSAGE ( "==> Pyram      : " << Pyram ) ;
1223   }
1224   else
1225   {
1226     SALOME::ExceptionStruct es;
1227     es.type = SALOME::BAD_PARAM;
1228     std::string text = "The configuration file cannot be read." ;
1229     es.text = CORBA::string_dup(text.c_str());
1230     throw SALOME::SALOME_Exception(es);
1231   }
1232
1233   // C. Creation effective du cas
1234
1235   // Par defaut, on ne publie pas le maillage
1236   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1237
1238   // D. Parametrages lus dans le fichier de configuration
1239
1240   myCase->SetConfType (TypeConf) ;
1241   myCase->SetPyram (Pyram) ;
1242
1243   // E. Copie du fichier de maillage homard
1244   // E.1. Repertoire associe au cas
1245   char* nomDirCase = myCase->GetDirName() ;
1246   // E.2. Repertoire associe a l'iteration de ce cas
1247   char* IterName ;
1248   IterName = myCase->GetIter0Name() ;
1249   HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1250   char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1251   Iter->SetDirNameLoc(nomDirIter);
1252   std::string nomDirIterTotal ;
1253   nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1254   if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1255   {
1256     MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1257     SALOME::ExceptionStruct es;
1258     es.type = SALOME::BAD_PARAM;
1259     std::string text = "The directory for the computation cannot be created." ;
1260     es.text = CORBA::string_dup(text.c_str());
1261     throw SALOME::SALOME_Exception(es);
1262   }
1263   // E.3. Copie du maillage HOMARD au format MED
1264   codret = chdir(DirNameStart) ;
1265   std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1266   MESSAGE ( "commande : " << commande ) ;
1267   codret = system(commande.c_str()) ;
1268   MESSAGE ( "codret : " << codret ) ;
1269   if ( codret != 0 )
1270   {
1271     SALOME::ExceptionStruct es;
1272     es.type = SALOME::BAD_PARAM;
1273     es.text = "The starting point for the case cannot be copied into the working directory.";
1274     throw SALOME::SALOME_Exception(es);
1275     return 0;
1276   };
1277
1278   // F. Menage
1279
1280   delete[] MeshName ;
1281   delete[] MeshFile ;
1282
1283   chdir(nomDirWork.c_str());
1284
1285   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1286 }
1287 //=============================================================================
1288 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1289 //
1290 // nomCas : nom du cas a creer
1291 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1292 //
1293 {
1294   INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1295
1296   std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1297
1298   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1299   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1300
1301   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1302 }
1303 //=============================================================================
1304 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1305 //
1306 // nomCas : nom du cas a creer
1307 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1308 // Number : numero de l'iteration de depart
1309 //
1310 {
1311   INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1312   if ( Number < 0 )
1313   {
1314     SALOME::ExceptionStruct es;
1315     es.type = SALOME::BAD_PARAM;
1316     es.text = "The number of iteration must be positive.";
1317     throw SALOME::SALOME_Exception(es);
1318     return 0;
1319   };
1320
1321   std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1322
1323   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1324   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1325
1326   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1327 }
1328 //=============================================================================
1329 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1330 //
1331 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1332 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1333 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1334 //
1335 {
1336   MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1337   std::string nomDirWork = getenv("PWD") ;
1338   std::string DirNameStartIter ;
1339   int codret ;
1340   int NumeIterMax = -1 ;
1341
1342   // A.1. Controle du repertoire de depart du cas
1343   codret = chdir(DirNameStart) ;
1344   if ( codret != 0 )
1345   {
1346     SALOME::ExceptionStruct es;
1347     es.type = SALOME::BAD_PARAM;
1348     es.text = "The directory of the case for the pursuit does not exist.";
1349     throw SALOME::SALOME_Exception(es);
1350     return 0;
1351   };
1352   // A.2. Reperage des sous-repertoire du repertoire de reprise
1353   bool existe = false ;
1354   DIR *dp;
1355   struct dirent *dirp;
1356   dp  = opendir(DirNameStart);
1357   while ( (dirp = readdir(dp)) != NULL )
1358   {
1359     std::string DirName_1(dirp->d_name);
1360     if ( ( DirName_1 != "." ) and ( DirName_1 != ".." ) )
1361     {
1362       if ( chdir(DirName_1.c_str()) == 0 )
1363       {
1364   //   On cherche le fichier de configuration dans ce sous-repertoire
1365         codret = chdir(DirNameStart) ;
1366         DIR *dp_1;
1367         struct dirent *dirp_1;
1368         dp_1  = opendir(DirName_1.c_str()) ;
1369         while ( (dirp_1 = readdir(dp_1)) != NULL )
1370         {
1371           std::string file_name_1(dirp_1->d_name);
1372           int bilan = file_name_1.find("HOMARD.Configuration.") ;
1373           if ( bilan != string::npos )
1374           {
1375   // Decodage du fichier pour trouver le numero d'iteration
1376             chdir(DirName_1.c_str()) ;
1377             std::ifstream fichier( file_name_1.c_str() );
1378             if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1379             {
1380               int NumeIter ;
1381               std::string ligne; // variable contenant chaque ligne lue
1382               std::string mot_cle;
1383               // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1384               while ( std::getline( fichier, ligne ) )
1385               {
1386                 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1387                 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1388                 ligne_bis >> mot_cle ;
1389                 if ( mot_cle == "NumeIter" )
1390                 {
1391                   ligne_bis >> NumeIter ;
1392                   NumeIter += 1 ;
1393 //                   MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1394                   if ( Number == - 1 )
1395                   {
1396                     if ( NumeIter >= NumeIterMax )
1397                     {
1398                       NumeIterMax = NumeIter ;
1399                       DirNameStartIter = DirName_1 ;
1400                     }
1401                   }
1402                   else
1403                   {
1404                     if ( NumeIter == Number )
1405                     {
1406                       DirNameStartIter = DirName_1 ;
1407                       existe = true ;
1408                       break ;
1409                     }
1410                   }
1411                 }
1412               }
1413             }
1414             else
1415             {
1416               SALOME::ExceptionStruct es;
1417               es.type = SALOME::BAD_PARAM;
1418               std::string text = "The configuration file cannot be read." ;
1419               es.text = CORBA::string_dup(text.c_str());
1420               throw SALOME::SALOME_Exception(es);
1421             }
1422             chdir(DirNameStart) ;
1423           }
1424           if ( existe ) { break ; }
1425         }
1426         closedir(dp_1);
1427         if ( existe ) { break ; }
1428       }
1429     }
1430   }
1431   closedir(dp);
1432
1433   chdir(nomDirWork.c_str());
1434
1435   if ( ( Number >= 0 and ( not existe ) ) or ( Number < 0 and ( NumeIterMax == -1 ) ) )
1436   {
1437     SALOME::ExceptionStruct es;
1438     es.type = SALOME::BAD_PARAM;
1439     es.text = "The directory of the iteration does not exist.";
1440     throw SALOME::SALOME_Exception(es);
1441     return 0;
1442   };
1443
1444   return DirNameStartIter ;
1445 }
1446 //=============================================================================
1447 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)
1448 //
1449 // nomCas : nom du cas a creer
1450 // MeshName, MeshFile : nom et fichier du maillage correspondant
1451 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1452 //              1 : le maillage fourni peut ne pas exister ==> on continue si absent
1453 //             -1 : le maillage n'est pas fourni
1454 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1455 // Option : multiple de nombres premiers
1456 //         1 : aucune option
1457 //        x2 : publication du maillage dans SMESH
1458 {
1459   MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1460   MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1461   MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1462 //
1463   // A. Controles
1464   // A.1. L'etude
1465   IsValidStudy () ;
1466
1467   // A.2. Controle du nom :
1468   if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1469   {
1470     SALOME::ExceptionStruct es;
1471     es.type = SALOME::BAD_PARAM;
1472     es.text = "This case has already been defined.";
1473     throw SALOME::SALOME_Exception(es);
1474     return 0;
1475   };
1476
1477   // A.3. Controle du fichier du maillage
1478   int existeMeshFile ;
1479   if ( MeshOption >= 0 )
1480   {
1481     existeMeshFile = MEDFileExist ( MeshFile ) ;
1482     MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1483     if ( ( existeMeshFile == 0 ) and ( MeshOption == 0 ) )
1484     {
1485       SALOME::ExceptionStruct es;
1486       es.type = SALOME::BAD_PARAM;
1487       es.text = "The mesh file does not exist.";
1488       throw SALOME::SALOME_Exception(es);
1489       return 0;
1490     }
1491   }
1492   else { existeMeshFile = 0 ; }
1493
1494   // B. Creation de l'objet cas et publication
1495 //   MESSAGE ( "CreateCase0 : Creation de l'objet" );
1496   HOMARD::HOMARD_Cas_var myCase = newCase();
1497   myCase->SetName(nomCas);
1498   SALOMEDS::SObject_var aSO;
1499   PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1500   myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1501
1502   // C. Caracteristiques du maillage
1503   if ( existeMeshFile != 0 )
1504   {
1505   // Les valeurs extremes des coordonnees
1506 //     MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1507     std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1508     HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1509     if (LesExtremes.size()!=10) { return false; }
1510     aSeq->length(10) ;
1511     for (int i =0 ; i< LesExtremes.size() ; i++)
1512         aSeq[i]=LesExtremes[i] ;
1513     myCase->SetBoundingBox(aSeq) ;
1514   // Les groupes
1515 //     MESSAGE ( "CreateCase0 : Les groupes" );
1516     std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile) ;
1517     HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1518     aSeqGroupe->length(LesGroupes.size());
1519     std::set<std::string>::const_iterator it ;
1520     int i = 0 ;
1521     for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1522       aSeqGroupe[i++]=(*it).c_str() ;
1523     myCase->SetGroups(aSeqGroupe) ;
1524   }
1525
1526   // D. L'iteration initiale du cas
1527   MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1528   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1529   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1530   int monNum = 0;
1531   std::string NomIteration = std::string(MeshName) ;
1532   while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1533   {
1534     std::ostringstream nom;
1535     nom << MeshName << monNum;
1536     NomIteration = nom.str();
1537     monNum += 1;
1538   }
1539   MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1540
1541   // D.2. Creation de l'iteration
1542   HOMARD::HOMARD_Iteration_var anIter = newIteration();
1543   myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1544   anIter->SetName(NomIteration.c_str());
1545   AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1546
1547   // D.4. Maillage correspondant
1548   if ( existeMeshFile != 0 )
1549   {
1550     anIter->SetMeshFile(MeshFile);
1551     if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1552   }
1553   anIter->SetMeshName(MeshName);
1554
1555   // D.5. Numero d'iteration
1556   anIter->SetNumber(NumeIter);
1557
1558   // D.6. Etat
1559   SetEtatIter(NomIteration.c_str(), -NumeIter);
1560 //
1561
1562   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1563 }
1564 //=============================================================================
1565 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1566 {
1567   INFOS ( "CreateHypothesis : nomHypothesis  = " << nomHypothesis );
1568   IsValidStudy () ;
1569
1570   // Controle du nom :
1571   if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1572   {
1573     SALOME::ExceptionStruct es;
1574     es.type = SALOME::BAD_PARAM;
1575     es.text = "This hypothesis has already been defined.";
1576     throw SALOME::SALOME_Exception(es);
1577     return 0;
1578   }
1579
1580   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1581   myHypothesis->SetName(nomHypothesis);
1582   myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1583   SALOMEDS::SObject_var aSO;
1584   PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1585
1586 // Valeurs par defaut des options avancees
1587   myHypothesis->SetNivMax(-1);
1588   myHypothesis->SetDiamMin(-1.0);
1589   myHypothesis->SetAdapInit(0);
1590   myHypothesis->SetLevelOutput(0);
1591
1592   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1593 }
1594
1595 //=============================================================================
1596 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1597 //=============================================================================
1598 {
1599   INFOS ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
1600   IsValidStudy () ;
1601
1602   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1603   if (CORBA::is_nil(myIterationParent))
1604   {
1605     SALOME::ExceptionStruct es;
1606     es.type = SALOME::BAD_PARAM;
1607     es.text = "The parent iteration is not defined.";
1608     throw SALOME::SALOME_Exception(es);
1609     return 0;
1610   };
1611
1612   const char* nomCas = myIterationParent->GetCaseName();
1613   MESSAGE ("CreateIteration : nomCas = " << nomCas);
1614   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1615   if (CORBA::is_nil(myCase))
1616   {
1617     SALOME::ExceptionStruct es;
1618     es.type = SALOME::BAD_PARAM;
1619     es.text = "Invalid case context";
1620     throw SALOME::SALOME_Exception(es);
1621     return 0;
1622   };
1623   const char* nomDirCase = myCase->GetDirName();
1624
1625   // Controle du nom :
1626   if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1627   {
1628     SALOME::ExceptionStruct es;
1629     es.type = SALOME::BAD_PARAM;
1630     es.text = "This iteration has already been defined.";
1631     throw SALOME::SALOME_Exception(es);
1632     return 0;
1633   };
1634
1635    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1636    if (CORBA::is_nil(myIteration))
1637   {
1638     SALOME::ExceptionStruct es;
1639     es.type = SALOME::BAD_PARAM;
1640     es.text = "Unable to create the iteration";
1641     throw SALOME::SALOME_Exception(es);
1642     return 0;
1643   };
1644   myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1645 // Nom de l'iteration et du maillage
1646   myIteration->SetName(NomIteration);
1647   myIteration->SetMeshName(NomIteration);
1648   myIteration->SetState(1);
1649
1650   int numero = myIterationParent->GetNumber() + 1;
1651   myIteration->SetNumber(numero);
1652
1653 // Nombre d'iterations deja connues pour le cas, permettant
1654 // la creation d'un sous-repertoire unique
1655   int nbitercase = myCase->GetNumberofIter();
1656   char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1657   myIteration->SetDirNameLoc(nomDirIter);
1658
1659 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1660 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1661 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1662 // situation la plus frequente.
1663 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1664 // le nombre d'iterations du cas permet d'eviter les collisions.
1665   int jaux ;
1666   if      ( nbitercase <    100 ) { jaux = 2 ; }
1667   else if ( nbitercase <   1000 ) { jaux = 3 ; }
1668   else if ( nbitercase <  10000 ) { jaux = 4 ; }
1669   else if ( nbitercase < 100000 ) { jaux = 5 ; }
1670   else                            { jaux = 9 ; }
1671   std::ostringstream iaux ;
1672   iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1673   std::stringstream MeshFile;
1674   MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1675   myIteration->SetMeshFile(MeshFile.str().c_str());
1676
1677 // Association avec le cas
1678   std::string label = "IterationHomard_" + std::string(nomIterParent);
1679   AssociateCaseIter(nomCas, NomIteration, label.c_str());
1680 // Lien avec l'iteration precedente
1681   myIterationParent->LinkNextIteration(NomIteration);
1682   myIteration->SetIterParentName(nomIterParent);
1683
1684   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1685 }
1686 //=============================================================================
1687 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1688 {
1689   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1690   IsValidStudy () ;
1691
1692   // Controle du nom :
1693   if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1694   {
1695     MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1696     SALOME::ExceptionStruct es;
1697     es.type = SALOME::BAD_PARAM;
1698     es.text = "This boundary has already been defined";
1699     throw SALOME::SALOME_Exception(es);
1700     return 0;
1701   };
1702
1703   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1704   myBoundary->SetName(BoundaryName);
1705   myBoundary->SetType(BoundaryType);
1706
1707   myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1708
1709   SALOMEDS::SObject_var aSO;
1710   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1711
1712   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1713 }
1714 //=============================================================================
1715 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1716 {
1717   INFOS ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << "MeshName = " << MeshName );
1718   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1719   myBoundary->SetMeshFile( MeshFile ) ;
1720   myBoundary->SetMeshName( MeshName ) ;
1721
1722   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1723 }
1724 //=============================================================================
1725 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1726                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1727                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1728                                       CORBA::Double Rayon)
1729 {
1730   INFOS ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
1731 //
1732   SALOME::ExceptionStruct es;
1733   int error = 0 ;
1734   if ( Rayon <= 0.0 )
1735   { es.text = "The radius must be positive." ;
1736     error = 1 ; }
1737   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1738   if ( daux < 0.0000001 )
1739   { es.text = "The axis must be a non 0 vector." ;
1740     error = 2 ; }
1741   if ( error != 0 )
1742   {
1743     es.type = SALOME::BAD_PARAM;
1744     throw SALOME::SALOME_Exception(es);
1745     return 0;
1746   };
1747 //
1748   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1749   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1750
1751   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1752 }
1753 //=============================================================================
1754 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1755                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1756                                       CORBA::Double Rayon)
1757 {
1758   INFOS ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
1759 //
1760   SALOME::ExceptionStruct es;
1761   int error = 0 ;
1762   if ( Rayon <= 0.0 )
1763   { es.text = "The radius must be positive." ;
1764     error = 1 ; }
1765   if ( error != 0 )
1766   {
1767     es.type = SALOME::BAD_PARAM;
1768     throw SALOME::SALOME_Exception(es);
1769     return 0;
1770   };
1771 //
1772   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1773   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1774
1775   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1776 }
1777 //=============================================================================
1778 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1779                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1780                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1781 {
1782   INFOS ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
1783 //
1784   SALOME::ExceptionStruct es;
1785   int error = 0 ;
1786   if ( Angle <= 0.0 or Angle >= 90.0 )
1787   { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1788     error = 1 ; }
1789   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1790   if ( daux < 0.0000001 )
1791   { es.text = "The axis must be a non 0 vector." ;
1792     error = 2 ; }
1793   if ( error != 0 )
1794   {
1795     es.type = SALOME::BAD_PARAM;
1796     throw SALOME::SALOME_Exception(es);
1797     return 0;
1798   };
1799 //
1800   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1801   myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1802
1803   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1804 }
1805 //=============================================================================
1806 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
1807                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
1808                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
1809 {
1810   INFOS ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
1811 //
1812   SALOME::ExceptionStruct es;
1813   int error = 0 ;
1814   if ( Rayon1 < 0.0 or Rayon2 < 0.0 )
1815   { es.text = "The radius must be positive." ;
1816     error = 1 ; }
1817   double daux = fabs(Rayon2-Rayon1) ;
1818   if ( daux < 0.0000001 )
1819   { es.text = "The radius must be different." ;
1820     error = 2 ; }
1821   daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
1822   if ( daux < 0.0000001 )
1823   { es.text = "The centers must be different." ;
1824     error = 3 ; }
1825   if ( error != 0 )
1826   {
1827     es.type = SALOME::BAD_PARAM;
1828     throw SALOME::SALOME_Exception(es);
1829     return 0;
1830   };
1831 //
1832   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
1833   myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
1834
1835   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1836 }
1837 //=============================================================================
1838 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
1839 {
1840   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
1841   IsValidStudy () ;
1842
1843   // Controle du nom :
1844   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
1845   {
1846     SALOME::ExceptionStruct es;
1847     es.type = SALOME::BAD_PARAM;
1848     es.text = "This zone has already been defined";
1849     throw SALOME::SALOME_Exception(es);
1850     return 0;
1851   };
1852
1853   HOMARD::HOMARD_Zone_var myZone = newZone();
1854   myZone->SetName(ZoneName);
1855   myZone->SetType(ZoneType);
1856
1857   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
1858
1859   SALOMEDS::SObject_var aSO;
1860   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
1861
1862   return HOMARD::HOMARD_Zone::_duplicate(myZone);
1863 }
1864 //=============================================================================
1865 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
1866                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
1867                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
1868                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
1869 {
1870   INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
1871 //
1872   SALOME::ExceptionStruct es;
1873   int error = 0 ;
1874   if ( Xmini > Xmaxi )
1875   { es.text = "The X coordinates are not coherent." ;
1876     error = 1 ; }
1877   if ( Ymini > Ymaxi )
1878   { es.text = "The Y coordinates are not coherent." ;
1879     error = 2 ; }
1880   if ( Zmini > Zmaxi )
1881   { es.text = "The Z coordinates are not coherent." ;
1882     error = 3 ; }
1883   if ( error != 0 )
1884   {
1885     es.type = SALOME::BAD_PARAM;
1886     throw SALOME::SALOME_Exception(es);
1887     return 0;
1888   };
1889 //
1890   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
1891   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
1892
1893   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1894 }
1895 //=============================================================================
1896 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
1897                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
1898 {
1899   INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
1900 //
1901   SALOME::ExceptionStruct es;
1902   int error = 0 ;
1903   if ( Rayon <= 0.0 )
1904   { es.text = "The radius must be positive." ;
1905     error = 1 ; }
1906   if ( error != 0 )
1907   {
1908     es.type = SALOME::BAD_PARAM;
1909     throw SALOME::SALOME_Exception(es);
1910     return 0;
1911   };
1912 //
1913   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
1914   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1915
1916   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1917 }
1918 //=============================================================================
1919 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
1920                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1921                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1922                                       CORBA::Double Rayon, CORBA::Double Haut)
1923 {
1924   INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
1925 //
1926   SALOME::ExceptionStruct es;
1927   int error = 0 ;
1928   if ( Rayon <= 0.0 )
1929   { es.text = "The radius must be positive." ;
1930     error = 1 ; }
1931   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1932   if ( daux < 0.0000001 )
1933   { es.text = "The axis must be a non 0 vector." ;
1934     error = 2 ; }
1935   if ( Haut <= 0.0 )
1936   { es.text = "The height must be positive." ;
1937     error = 3 ; }
1938   if ( error != 0 )
1939   {
1940     es.type = SALOME::BAD_PARAM;
1941     throw SALOME::SALOME_Exception(es);
1942     return 0;
1943   };
1944 //
1945   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
1946   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
1947
1948   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1949 }
1950 //=============================================================================
1951 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
1952                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1953                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1954                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
1955 {
1956   INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
1957 //
1958   SALOME::ExceptionStruct es;
1959   int error = 0 ;
1960   if ( Rayon <= 0.0 or Rayonint <= 0.0 )
1961   { es.text = "The radius must be positive." ;
1962     error = 1 ; }
1963   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1964   if ( daux < 0.0000001 )
1965   { es.text = "The axis must be a non 0 vector." ;
1966     error = 2 ; }
1967   if ( Haut <= 0.0 )
1968   { es.text = "The height must be positive." ;
1969     error = 3 ; }
1970   if ( Rayon <= Rayonint )
1971   { es.text = "The external radius must be higher than the internal radius." ;
1972     error = 4 ; }
1973   if ( error != 0 )
1974   {
1975     es.type = SALOME::BAD_PARAM;
1976     throw SALOME::SALOME_Exception(es);
1977     return 0;
1978   };
1979 //
1980   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
1981   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
1982
1983   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
1984 }
1985 //=============================================================================
1986 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
1987                                       CORBA::Double Umini, CORBA::Double Umaxi,
1988                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
1989                                       CORBA::Long Orient)
1990 {
1991   INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
1992 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
1993 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
1994 //   MESSAGE ("Orient = " << Orient ) ;
1995 //
1996   SALOME::ExceptionStruct es;
1997   int error = 0 ;
1998   if ( Umini > Umaxi )
1999   { es.text = "The first coordinates are not coherent." ;
2000     error = 1 ; }
2001   if ( Vmini > Vmaxi )
2002   { es.text = "The second coordinates are not coherent." ;
2003     error = 2 ; }
2004   if ( Orient < 1 or Orient > 3 )
2005   { es.text = "The orientation must be 1, 2 or 3." ;
2006     error = 3 ; }
2007   if ( error != 0 )
2008   {
2009     es.type = SALOME::BAD_PARAM;
2010     throw SALOME::SALOME_Exception(es);
2011     return 0;
2012   };
2013 //
2014   double Xmini, Xmaxi ;
2015   double Ymini, Ymaxi ;
2016   double Zmini, Zmaxi ;
2017   if ( Orient == 1 )
2018   { Xmini = Umini ;
2019     Xmaxi = Umaxi ;
2020     Ymini = Vmini ;
2021     Ymaxi = Vmaxi ;
2022     Zmini = 0. ;
2023     Zmaxi = 0. ; }
2024   else if ( Orient == 2 )
2025   { Xmini = 0. ;
2026     Xmaxi = 0. ;
2027     Ymini = Umini ;
2028     Ymaxi = Umaxi ;
2029     Zmini = Vmini ;
2030     Zmaxi = Vmaxi ; }
2031   else if ( Orient == 3 )
2032   { Xmini = Vmini ;
2033     Xmaxi = Vmaxi ;
2034     Ymini = 0. ;
2035     Ymaxi = 0. ;
2036     Zmini = Umini ;
2037     Zmaxi = Umaxi ; }
2038   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2039
2040   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2041   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2042
2043   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2044 }
2045 //=============================================================================
2046 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2047                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2048                                       CORBA::Double Rayon,
2049                                       CORBA::Long Orient)
2050 {
2051   INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
2052 //
2053   SALOME::ExceptionStruct es;
2054   int error = 0 ;
2055   if ( Rayon <= 0.0 )
2056   { es.text = "The radius must be positive." ;
2057     error = 1 ; }
2058   if ( Orient < 1 or Orient > 3 )
2059   { es.text = "The orientation must be 1, 2 or 3." ;
2060     error = 3 ; }
2061   if ( error != 0 )
2062   {
2063     es.type = SALOME::BAD_PARAM;
2064     throw SALOME::SALOME_Exception(es);
2065     return 0;
2066   };
2067 //
2068   double Xcentre ;
2069   double Ycentre ;
2070   double Zcentre ;
2071   if ( Orient == 1 )
2072   { Xcentre = Ucentre ;
2073     Ycentre = Vcentre ;
2074     Zcentre = 0. ; }
2075   else if ( Orient == 2 )
2076   { Xcentre = 0. ;
2077     Ycentre = Ucentre ;
2078     Zcentre = Vcentre ; }
2079   else if ( Orient == 3 )
2080   { Xcentre = Vcentre ;
2081     Ycentre = 0. ;
2082     Zcentre = Ucentre ; }
2083   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2084
2085   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2086   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2087
2088   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2089 }
2090 //=============================================================================
2091 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2092                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2093                                       CORBA::Double Rayon, CORBA::Double Rayonint,
2094                                       CORBA::Long Orient)
2095 {
2096   INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
2097 //
2098   SALOME::ExceptionStruct es;
2099   int error = 0 ;
2100   if ( Rayon <= 0.0 or Rayonint <= 0.0 )
2101   { es.text = "The radius must be positive." ;
2102     error = 1 ; }
2103   if ( Orient < 1 or Orient > 3 )
2104   { es.text = "The orientation must be 1, 2 or 3." ;
2105     error = 3 ; }
2106   if ( Rayon <= Rayonint )
2107   { es.text = "The external radius must be higher than the internal radius." ;
2108     error = 4 ; }
2109   if ( error != 0 )
2110   {
2111     es.type = SALOME::BAD_PARAM;
2112     throw SALOME::SALOME_Exception(es);
2113     return 0;
2114   };
2115 //
2116   double Xcentre ;
2117   double Ycentre ;
2118   double Zcentre ;
2119   if ( Orient == 1 )
2120   { Xcentre = Ucentre ;
2121     Ycentre = Vcentre ;
2122     Zcentre = 0. ; }
2123   else if ( Orient == 2 )
2124   { Xcentre = 0. ;
2125     Ycentre = Ucentre ;
2126     Zcentre = Vcentre ; }
2127   else if ( Orient == 3 )
2128   { Xcentre = Vcentre ;
2129     Ycentre = 0. ;
2130     Zcentre = Ucentre ; }
2131   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
2132
2133   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2134   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2135
2136   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2137 }
2138 //=============================================================================
2139 //=============================================================================
2140
2141
2142
2143
2144 //=============================================================================
2145 //=============================================================================
2146 // Traitement d'une iteration
2147 // etatMenage = 1 : destruction du repertoire d'execution
2148 // modeHOMARD  = 1 : adaptation
2149 //            != 1 : information avec les options modeHOMARD
2150 // Option1 >0 : appel depuis python
2151 //         <0 : appel depuis GUI
2152 // Option2 : multiple de nombres premiers
2153 //         1 : aucune option
2154 //        x2 : publication du maillage dans SMESH
2155 //=============================================================================
2156 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2157 {
2158   INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2159
2160   // A. Prealable
2161   int codret = 0;
2162
2163   // A.1. L'objet iteration
2164   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2165   ASSERT(!CORBA::is_nil(myIteration));
2166
2167   // A.2. Numero de l'iteration
2168   //     siterp1 : numero de l'iteration a traiter
2169   //     Si adaptation :
2170   //        siter   : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2171   //     Ou si information :
2172   //        siter = siterp1
2173   int NumeIter = myIteration->GetNumber();
2174   std::string siterp1 ;
2175   std::stringstream saux1 ;
2176   saux1 << NumeIter ;
2177   siterp1 = saux1.str() ;
2178   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2179
2180   std::string siter ;
2181   if ( modeHOMARD==1 )
2182   {
2183     std::stringstream saux0 ;
2184     int iaux = max(0, NumeIter-1) ;
2185     saux0 << iaux ;
2186     siter = saux0.str() ;
2187     if (NumeIter < 11) { siter = "0" + siter ; }
2188   }
2189   else
2190   { siter = siterp1 ; }
2191
2192   // A.3. Le cas
2193   const char* nomCas = myIteration->GetCaseName();
2194   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2195   ASSERT(!CORBA::is_nil(myCase));
2196
2197   // B. Les repertoires
2198   // B.1. Le repertoire courant
2199   std::string nomDirWork = getenv("PWD") ;
2200   // B.2. Le sous-repertoire de l'iteration a traiter
2201   char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2202   MESSAGE( ". DirCompute = " << DirCompute );
2203
2204   // C. Le fichier des messages
2205   // C.1. Le deroulement de l'execution de HOMARD
2206   std::string LogFile = DirCompute ;
2207   LogFile += "/Liste" ;
2208   if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2209   LogFile += ".log" ;
2210   MESSAGE (". LogFile = " << LogFile);
2211   if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2212   // C.2. Le bilan de l'analyse du maillage
2213   std::string FileInfo = DirCompute ;
2214   FileInfo += "/" ;
2215   if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2216   else
2217   { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2218     else                 { FileInfo += "info_ap" ; }
2219   }
2220   FileInfo += "." + siterp1 + ".bilan" ;
2221   myIteration->SetFileInfo(FileInfo.c_str());
2222
2223    // D. On passe dans le repertoire de l'iteration a calculer
2224   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2225   chdir(DirCompute) ;
2226
2227   // E. Les donnees de l'execution HOMARD
2228   // E.1. L'objet du texte du fichier de configuration
2229   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2230   std::string Langue = "Francais" ;
2231   myDriver->TexteInit(DirCompute, LogFile, Langue);
2232
2233   // E.2. Le maillage associe a l'iteration
2234   const char* NomMesh = myIteration->GetMeshName();
2235   MESSAGE ( ". NomMesh = " << NomMesh );
2236   const char* MeshFile = myIteration->GetMeshFile();
2237   MESSAGE ( ". MeshFile = " << MeshFile );
2238
2239   // E.3. Les donnees du traitement HOMARD
2240   int iaux ;
2241   if ( modeHOMARD == 1 )
2242   {
2243     iaux = 1 ;
2244     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2245     myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2246     codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2247   }
2248   else
2249   {
2250     InvalideIterInfo(NomIteration);
2251     myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2252     iaux = 0 ;
2253     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2254     myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2255     myDriver->CreeFichierDonn();
2256   }
2257
2258   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2259   DriverTexteBoundary(myCase, myDriver) ;
2260
2261   // E.5. Ecriture du texte dans le fichier
2262   if (codret == 0)
2263   { myDriver->CreeFichier(); }
2264
2265 // G. Execution
2266 //
2267   int codretexec = 12 ;
2268   if (codret == 0)
2269   {
2270     codretexec = myDriver->ExecuteHomard(Option1);
2271 //
2272     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2273     if ( modeHOMARD == 1 )
2274     {
2275       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2276       else                 { SetEtatIter(NomIteration,1); }
2277       // GERALD -- QMESSAGE BOX
2278     }
2279   }
2280
2281   // H. Gestion des resultats
2282   if (codret == 0)
2283   {
2284     std::string Commentaire ;
2285     // H.1. Le fichier des messages, dans tous les cas
2286     Commentaire = "log" ;
2287     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2288     else                   { Commentaire += "Info" ; }
2289     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2290
2291     // H.2. Si tout s'est bien passe :
2292     if (codretexec == 0)
2293     {
2294     // H.2.1. Le fichier de bilan
2295       Commentaire = "Summary" ;
2296       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2297       else                   { Commentaire += "Info" ; }
2298       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2299     // H.2.2. Le fichier de  maillage obtenu
2300       if ( modeHOMARD == 1 )
2301       {
2302         std::stringstream saux0 ;
2303         Commentaire = "Iteration" ;
2304         Commentaire += " " + siter ;
2305         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2306         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2307       }
2308     }
2309   // H.3 Message d'erreur en cas de probleme
2310     else
2311     {
2312       SALOME::ExceptionStruct es;
2313       es.type = SALOME::BAD_PARAM;
2314       std::string text = "Error during the adaptation.\n" ;
2315       try
2316       {
2317         ifstream fichier(LogFile.c_str(), ios::in);
2318         string ligne;
2319         while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
2320         while (getline(fichier, ligne)) { text += ligne+ "\n";};
2321       }
2322       catch (...) {
2323         text += "no log file ....";
2324       }
2325       es.text = CORBA::string_dup(text.c_str());
2326       throw SALOME::SALOME_Exception(es);
2327     }
2328   }
2329
2330   // I. Menage et retour dans le repertoire du cas
2331   if (codret == 0)
2332   {
2333     delete myDriver;
2334     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2335     chdir(nomDirWork.c_str());
2336   }
2337
2338   return codretexec ;
2339 }
2340 //=============================================================================
2341 // Calcul d'une iteration : partie specifique a l'adaptation
2342 //=============================================================================
2343 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)
2344 {
2345   MESSAGE ( "ComputeAdap" );
2346
2347   // A. Prealable
2348   // A.1. Bases
2349   int codret = 0;
2350   // Etat de l'iteration
2351   int etat = myIteration->GetState();
2352   // Numero de l'iteration
2353   int NumeIter = myIteration->GetNumber();
2354   std::stringstream saux0 ;
2355   saux0 << NumeIter-1 ;
2356   std::string siter = saux0.str() ;
2357   if (NumeIter < 11) { siter = "0" + siter ; }
2358
2359   // A.2. On ne calcule pas l iteration initiale
2360   if ( etat <= 0 )
2361   {
2362     MESSAGE ( "etat = "<<etat );
2363     SALOME::ExceptionStruct es;
2364     es.type = SALOME::BAD_PARAM;
2365     es.text = "This iteration is the first of the case and cannot be computed.";
2366     throw SALOME::SALOME_Exception(es);
2367     return 1;
2368   };
2369
2370   // A.3. On verifie qu il y a une hypothese (erreur improbable);
2371   const char* nomHypo = myIteration->GetHypoName();
2372   if (std::string(nomHypo) == std::string(""))
2373   {
2374       SALOME::ExceptionStruct es;
2375       es.type = SALOME::BAD_PARAM;
2376       es.text = "This iteration does not have any associated hypothesis.";
2377       throw SALOME::SALOME_Exception(es);
2378       return 2;
2379   };
2380   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2381   ASSERT(!CORBA::is_nil(myHypo));
2382
2383   // B. L'iteration parent
2384   const char* nomIterationParent = myIteration->GetIterParentName();
2385   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2386   ASSERT(!CORBA::is_nil(myIterationParent));
2387   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2388   if ( myIterationParent->GetState() == 1 )
2389   {
2390     int iaux = 1 ;
2391     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2392     if (codret != 0)
2393     {
2394       // GERALD -- QMESSAGE BOX
2395       ASSERT("Pb au calcul de l'iteration precedente" == 0);
2396     }
2397   };
2398
2399   // C. Le sous-repertoire de l'iteration precedente
2400   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2401   MESSAGE( ". DirComputePa = " << DirComputePa );
2402
2403   // D. Les donnees de l'adaptation HOMARD
2404   // D.1. Le type de conformite
2405   int ConfType = myCase->GetConfType();
2406   MESSAGE ( ". ConfType = " << ConfType );
2407
2408   // D.2. Le maillage de depart
2409   const char* NomMeshParent = myIterationParent->GetMeshName();
2410   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2411   const char* MeshFileParent = myIterationParent->GetMeshFile();
2412   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2413
2414   // D.3. Le maillage associe a l'iteration
2415   const char* MeshFile = myIteration->GetMeshFile();
2416   MESSAGE ( ". MeshFile = " << MeshFile );
2417   FILE *file = fopen(MeshFile,"r");
2418   if (file != NULL)
2419   {
2420     fclose(file);
2421     if (etatMenage == 0)
2422     {
2423       SALOME::ExceptionStruct es;
2424       es.type = SALOME::BAD_PARAM;
2425       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2426       es.text = CORBA::string_dup(text.c_str());
2427       throw SALOME::SALOME_Exception(es);
2428       return 4;
2429     }
2430     else
2431     {
2432       std::string commande = "rm -f " + std::string(MeshFile);
2433       codret = system(commande.c_str());
2434       if (codret != 0)
2435       {
2436         SALOME::ExceptionStruct es;
2437         es.type = SALOME::BAD_PARAM;
2438         es.text = "The mesh file cannot be deleted.";
2439         throw SALOME::SALOME_Exception(es);
2440         return 5;
2441       }
2442     }
2443   }
2444
2445   // D.4. Les types de raffinement et de deraffinement
2446   // Les appels corba sont lourds, il vaut mieux les grouper
2447   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2448   ASSERT(ListTypes->length() == 3);
2449   int TypeAdap = (*ListTypes)[0];
2450   int TypeRaff = (*ListTypes)[1];
2451   int TypeDera = (*ListTypes)[2];
2452
2453   // E. Texte du fichier de configuration
2454   // E.1. Incontournables du texte
2455   myDriver->TexteAdap();
2456   int iaux = 0 ;
2457   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2458   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2459   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2460
2461   // E.2. Ajout des informations liees aux zones eventuelles
2462   if ( TypeAdap == 0 )
2463   { DriverTexteZone(myHypo, myDriver) ; }
2464
2465   // E.3. Ajout des informations liees aux champs eventuels
2466   if ( TypeAdap == 1 )
2467   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2468
2469   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2470   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2471   int numberOfGroups = listeGroupes->length();
2472   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2473   if (numberOfGroups > 0)
2474   {
2475     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2476     {
2477       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2478       MESSAGE( "... GroupName = " << GroupName );
2479       myDriver->TexteGroup(GroupName);
2480     }
2481   }
2482
2483   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2484   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2485
2486   // E.6. Ajout des options avancees
2487   int Pyram = myCase->GetPyram();
2488   MESSAGE ( ". Pyram = " << Pyram );
2489   int NivMax = myHypo->GetNivMax();
2490   MESSAGE ( ". NivMax = " << NivMax );
2491   double DiamMin = myHypo->GetDiamMin() ;
2492   MESSAGE ( ". DiamMin = " << DiamMin );
2493   int AdapInit = myHypo->GetAdapInit();
2494   MESSAGE ( ". AdapInit = " << AdapInit );
2495   int LevelOutput = myHypo->GetLevelOutput();
2496   MESSAGE ( ". LevelOutput = " << LevelOutput );
2497   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2498
2499   // E.7. Ajout des informations sur le deroulement de l'execution
2500   int MessInfo = myIteration->GetInfoCompute();
2501   MESSAGE ( ". MessInfo = " << MessInfo );
2502   myDriver->TexteInfoCompute(MessInfo);
2503
2504   return codret ;
2505 }
2506 //=============================================================================
2507 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2508 //  nomrep : nom du repertoire parent
2509 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2510 //=============================================================================
2511 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2512 {
2513   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2514   // On verifie que le repertoire parent existe
2515   int codret = chdir(nomrep) ;
2516   if ( codret != 0 )
2517   {
2518     SALOME::ExceptionStruct es;
2519     es.type = SALOME::BAD_PARAM;
2520     es.text = "The directory of the case does not exist.";
2521     throw SALOME::SALOME_Exception(es);
2522     return 0;
2523   };
2524   std::string nomDirActuel = getenv("PWD") ;
2525   std::string DirName ;
2526   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2527   bool a_chercher = true ;
2528   while ( a_chercher )
2529   {
2530     // On passe dans le repertoire parent
2531     chdir(nomrep);
2532     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2533     int jaux ;
2534     if      ( num <    100 ) { jaux = 2 ; }
2535     else if ( num <   1000 ) { jaux = 3 ; }
2536     else if ( num <  10000 ) { jaux = 4 ; }
2537     else if ( num < 100000 ) { jaux = 5 ; }
2538     else                     { jaux = 9 ; }
2539     std::ostringstream iaux ;
2540     iaux << std::setw(jaux) << std::setfill('0') << num ;
2541     std::ostringstream DirNameA ;
2542     DirNameA << "I" << iaux.str();
2543     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2544     // que c'est bien un probleme d'absence
2545     if ( chdir(DirNameA.str().c_str()) != 0 )
2546     {
2547       bool existe = false ;
2548       DIR *dp;
2549       struct dirent *dirp;
2550       dp  = opendir(nomrep);
2551       while ( (dirp = readdir(dp)) != NULL )
2552       {
2553         std::string file_name(dirp->d_name);
2554         if ( file_name == DirNameA.str() ) { existe = true ; }
2555       }
2556       closedir(dp);
2557       if ( not existe )
2558       {
2559         DirName = DirNameA.str() ;
2560         a_chercher = false ;
2561         break ;
2562       }
2563     }
2564     num += 1;
2565   }
2566
2567   MESSAGE ( "==> DirName = " << DirName);
2568   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2569   chdir(nomDirActuel.c_str());
2570
2571   return CORBA::string_dup( DirName.c_str() );
2572 }
2573 //=============================================================================
2574 // Calcul d'une iteration : gestion du repertoire de calcul
2575 //        Si le sous-repertoire existe :
2576 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2577 //         etatMenage =  1 : on fait le menage du repertoire
2578 //         etatMenage = -1 : on ne fait rien
2579 //=============================================================================
2580 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2581 {
2582   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2583   // B.2. Le repertoire du cas
2584   const char* nomDirCase = myCase->GetDirName();
2585   MESSAGE ( ". nomDirCase = " << nomDirCase );
2586
2587   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2588   // B.3.1. Le nom du sous-repertoire
2589   const char* nomDirIt = myIteration->GetDirNameLoc();
2590
2591   // B.3.2. Le nom complet du sous-repertoire
2592   std::stringstream DirCompute ;
2593   DirCompute << nomDirCase << "/" << nomDirIt;
2594   MESSAGE (". DirCompute = " << DirCompute.str() );
2595
2596   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2597   if (chdir(DirCompute.str().c_str()) != 0)
2598   {
2599 //  Creation du repertoire car il n'existe pas :
2600     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2601     {
2602        // GERALD -- QMESSAGE BOX
2603        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2604        ASSERT("Pb a la creation du repertoire" == 0);
2605     }
2606   }
2607   else
2608   {
2609 //  Le repertoire existe
2610 //  On demande de faire le menage de son contenu :
2611     if (etatMenage == 1)
2612     {
2613       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2614       std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
2615       int codret = system(commande.c_str());
2616       if (codret != 0)
2617       {
2618         // GERALD -- QMESSAGE BOX
2619         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2620         ASSERT("Pb au menage du repertoire de calcul" == 0);
2621       }
2622     }
2623 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2624     else
2625     {
2626       if (etatMenage == 0)
2627       {
2628         DIR *dp;
2629         struct dirent *dirp;
2630         dp  = opendir(DirCompute.str().c_str());
2631         bool result = true;
2632         while ((dirp = readdir(dp)) != NULL && result )
2633         {
2634           std::string file_name(dirp->d_name);
2635           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2636         }
2637         closedir(dp);
2638         if ( result == false)
2639         {
2640           SALOME::ExceptionStruct es;
2641           es.type = SALOME::BAD_PARAM;
2642           std::string text = "Directory : " + DirCompute.str() + "is not empty";
2643           es.text = CORBA::string_dup(text.c_str());
2644           throw SALOME::SALOME_Exception(es);
2645           ASSERT("Directory is not empty" == 0);
2646         }
2647       }
2648     }
2649   }
2650
2651   return CORBA::string_dup( DirCompute.str().c_str() );
2652 }
2653 //=============================================================================
2654 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2655 //=============================================================================
2656 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2657 {
2658   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2659   // Le repertoire du cas
2660   const char* nomDirCase = myCase->GetDirName();
2661   MESSAGE ( ". nomDirCase = " << nomDirCase );
2662
2663   // Le sous-repertoire de l'iteration precedente
2664
2665   const char* nomIterationParent = myIteration->GetIterParentName();
2666   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2667   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2668   std::stringstream DirComputePa ;
2669   DirComputePa << nomDirCase << "/" << nomDirItPa;
2670   MESSAGE( ". nomDirItPa = " << nomDirItPa);
2671   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2672
2673   return CORBA::string_dup( DirComputePa.str().c_str() );
2674 }
2675 //=============================================================================
2676 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2677 //=============================================================================
2678 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2679 {
2680   MESSAGE ( "... DriverTexteZone" );
2681   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2682   int numberOfZonesx2 = ListZone->length();
2683   int NumZone ;
2684
2685   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2686   {
2687     std::string ZoneName = std::string((*ListZone)[iaux]);
2688     MESSAGE ( "... ZoneName = " << ZoneName);
2689     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2690     ASSERT(!CORBA::is_nil(myZone));
2691
2692     int ZoneType = myZone->GetType();
2693     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2694     int TypeUse = atoi( TypeUsestr.c_str() );
2695     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2696     NumZone = iaux/2 + 1 ;
2697     HOMARD::double_array* zone = myZone->GetCoords();
2698     if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2699     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2700     else if ( ZoneType == 4 ) // Cas d une sphere
2701     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2702     else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2703     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2704     else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2705     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2706     else { ASSERT("ZoneType est incorrect." == 0) ; }
2707     iaux += 1 ;
2708   }
2709   return ;
2710 }
2711 //=============================================================================
2712 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2713 //=============================================================================
2714 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2715 {
2716   MESSAGE ( "... DriverTexteField" );
2717 //  Le fichier du champ
2718   char* FieldFile = myIteration->GetFieldFile();
2719   MESSAGE ( ". FieldFile = " << FieldFile );
2720   if (strlen(FieldFile) == 0)
2721   {
2722     // GERALD -- QMESSAGE BOX
2723     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2724     ASSERT("The file for the field is not given." == 0);
2725   }
2726 //  Les caracteristiques d'instants
2727   int TimeStep = myIteration->GetTimeStep();
2728   MESSAGE( ". TimeStep = " << TimeStep );
2729   int Rank = myIteration->GetRank();
2730   MESSAGE( ". Rank = " << Rank );
2731 //  Les informations sur les champs
2732   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2733 //  Le nom
2734   const char* FieldName = aInfosHypo->FieldName;
2735 //  Les seuils
2736   int TypeThR = aInfosHypo->TypeThR;
2737   double ThreshR = aInfosHypo->ThreshR;
2738   int TypeThC = aInfosHypo->TypeThC;
2739   double ThreshC = aInfosHypo->ThreshC;
2740 //  Saut entre mailles ou non ?
2741   int UsField = aInfosHypo->UsField;
2742   MESSAGE( ". UsField = " << UsField );
2743 //  L'usage des composantes
2744   int UsCmpI = aInfosHypo->UsCmpI;
2745   MESSAGE( ". UsCmpI = " << UsCmpI );
2746 //
2747   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2748 //
2749 //  Les composantes
2750   HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
2751   int numberOfCompos = mescompo->length();
2752   MESSAGE( ". numberOfCompos = " << numberOfCompos );
2753   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2754   {
2755     std::string nomCompo = std::string((*mescompo)[NumeComp]);
2756     MESSAGE( "... nomCompo = " << nomCompo );
2757     myDriver->TexteCompo(NumeComp, nomCompo);
2758   }
2759   return ;
2760 }
2761 //=============================================================================
2762 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2763 //=============================================================================
2764 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2765 {
2766   MESSAGE ( "... DriverTexteBoundary" );
2767   // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
2768   std::list<std::string>  ListeBoundaryTraitees ;
2769   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2770   int numberOfitems = ListBoundaryGroupType->length();
2771   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2772   int BoundaryOption = 1 ;
2773   int NumBoundaryAnalytical = 0 ;
2774   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2775   {
2776     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2777     MESSAGE ( "... BoundaryName = " << BoundaryName);
2778     int A_faire = 1 ;
2779     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2780     while (it != ListeBoundaryTraitees.end())
2781     {
2782       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2783       if ( BoundaryName == *it ) { A_faire = 0 ; }
2784       it++;
2785     }
2786     if ( A_faire == 1 )
2787     {
2788 // Caracteristiques de la frontiere
2789       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2790       ASSERT(!CORBA::is_nil(myBoundary));
2791       int BoundaryType = myBoundary->GetType();
2792       MESSAGE ( "... BoundaryType = " << BoundaryType );
2793 // Ecriture selon le type
2794       if (BoundaryType == 0) // Cas d une frontiere discrete
2795       {
2796         const char* MeshName = myBoundary->GetMeshName() ;
2797         const char* MeshFile = myBoundary->GetMeshFile() ;
2798         myDriver->TexteBoundaryDi( MeshName, MeshFile);
2799         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2800       }
2801       else // Cas d une frontiere analytique
2802       {
2803         NumBoundaryAnalytical++ ;
2804         HOMARD::double_array* coor = myBoundary->GetCoords();
2805         if (BoundaryType == 1) // Cas d un cylindre
2806         {
2807           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2808           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2809         }
2810         else if (BoundaryType == 2) // Cas d une sphere
2811         {
2812           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2813           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2814         }
2815         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2816         {
2817           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2818           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2819         }
2820         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2821         {
2822           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2823           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2824         }
2825       }
2826 // Memorisation du traitement
2827       ListeBoundaryTraitees.push_back( BoundaryName );
2828     }
2829   }
2830   NumBoundaryAnalytical = 0 ;
2831   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2832   {
2833     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2834     MESSAGE ( "... BoundaryName = " << BoundaryName);
2835     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2836     ASSERT(!CORBA::is_nil(myBoundary));
2837     int BoundaryType = myBoundary->GetType();
2838     MESSAGE ( "... BoundaryType = " << BoundaryType );
2839 //  Recuperation du nom du groupe
2840     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2841     MESSAGE ( "... GroupName = " << GroupName);
2842     if (BoundaryType == 0) // Cas d une frontiere discrete
2843     {
2844       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2845     }
2846     else // Cas d une frontiere analytique
2847     {
2848       NumBoundaryAnalytical++ ;
2849       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2850     }
2851   }
2852   myDriver->TexteBoundaryOption(BoundaryOption);
2853   return ;
2854 }
2855 //=============================================================================
2856 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
2857 //=============================================================================
2858 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2859 {
2860   MESSAGE ( "... DriverTexteFieldInterp" );
2861   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
2862   if (TypeFieldInterp != 0)
2863   {
2864 //  Le fichier des champs
2865     char* FieldFile = myIteration->GetFieldFile();
2866     MESSAGE ( ". FieldFile = " << FieldFile );
2867     if (strlen(FieldFile) == 0)
2868     {
2869       // GERALD -- QMESSAGE BOX
2870       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2871       ASSERT("The file for the field is not given." == 0);
2872     }
2873   //  Les caracteristiques d'instants
2874     int TimeStep = myIteration->GetTimeStep();
2875     MESSAGE( ". TimeStep = " << TimeStep );
2876     int Rank = myIteration->GetRank();
2877     MESSAGE( ". Rank = " << Rank );
2878   //
2879     const char* MeshFile = myIteration->GetMeshFile();
2880     myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
2881   //  Les champs
2882     if (TypeFieldInterp == 2)
2883     {
2884       HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
2885       int numberOfFields = meschamps->length();
2886       MESSAGE( ". numberOfFields = " << numberOfFields );
2887       for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
2888       {
2889         std::string nomChamp = std::string((*meschamps)[NumeChamp]);
2890         MESSAGE( "... nomChamp = " << nomChamp );
2891         myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
2892       }
2893     }
2894   }
2895   return ;
2896 }
2897 //===========================================================================
2898 //===========================================================================
2899
2900
2901 //===========================================================================
2902 //===========================================================================
2903 // Publications
2904 //===========================================================================
2905 //===========================================================================
2906 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
2907                                                    SALOMEDS::SObject_ptr theSObject,
2908                                                    CORBA::Object_ptr theObject,
2909                                                    const char* theName)
2910 {
2911   MESSAGE("PublishInStudy pour " << theName);
2912   SALOMEDS::SObject_var aResultSO;
2913   if (CORBA::is_nil(theStudy))
2914   {
2915     SALOME::ExceptionStruct es;
2916     es.type = SALOME::BAD_PARAM;
2917     es.text = "Invalid study context";
2918     throw SALOME::SALOME_Exception(es);
2919     return 0;
2920   };
2921
2922 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
2923 // Rq : Iteration est publiee ailleurs
2924   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
2925   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
2926   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
2927   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
2928
2929    addInStudy(theStudy);
2930
2931 // Controle de la non publication d'un objet de meme nom
2932    if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
2933   {
2934     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
2935     if (listSO->length() >= 1)
2936     {
2937       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
2938       std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
2939       aResultSO = listSO[0];
2940       return aResultSO._retn();
2941     }
2942   }
2943
2944   // Caracteristiques de l'etude
2945   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
2946   aStudyBuilder->NewCommand();
2947   if(!aCase->_is_nil())
2948     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
2949   else if(!aHypo->_is_nil())
2950     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
2951   else if(!aZone->_is_nil())
2952     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
2953   else if(!aBoundary->_is_nil())
2954     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
2955
2956     aStudyBuilder->CommitCommand();
2957   return aResultSO._retn();
2958 };
2959 //=============================================================================
2960 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
2961                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
2962                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
2963 {
2964   MESSAGE("PublishCaseInStudy pour "<<theName);
2965   SALOMEDS::SObject_var aResultSO;
2966   SALOMEDS::GenericAttribute_var anAttr;
2967
2968   if (CORBA::is_nil(theObject)) {
2969     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
2970     return aResultSO._retn();
2971   }
2972   if (theStudy->_is_nil()) {
2973     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
2974     return aResultSO._retn();
2975   }
2976
2977   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
2978   if (theFatherHomard->_is_nil())
2979   {
2980     MESSAGE("theFatherHomard->_is_nil()");
2981     return aResultSO._retn();
2982   }
2983
2984   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
2985   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
2986                      _orb->object_to_string(theObject) ) ;
2987   return aResultSO._retn();
2988 }
2989
2990 //=============================================================================
2991 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
2992                     SALOMEDS::StudyBuilder_var aStudyBuilder,
2993                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
2994 {
2995   MESSAGE("PublishZoneStudy pour "<<theName);
2996   SALOMEDS::SObject_var aResultSO;
2997   SALOMEDS::GenericAttribute_var anAttr;
2998
2999   if (CORBA::is_nil(theObject))
3000   {
3001     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3002     return aResultSO._retn();
3003   }
3004   if (theStudy->_is_nil())
3005   {
3006     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3007     return aResultSO._retn();
3008   }
3009   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3010   if (theFatherHomard->_is_nil())
3011   {
3012     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3013     return aResultSO._retn();
3014   }
3015
3016   // Caracteristique de la zone
3017   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3018   CORBA::Long ZoneType = myZone->GetType();
3019
3020   // On ajoute la categorie des zones dans l etude si necessaire
3021   SALOMEDS::SObject_var aSOZone;
3022   if (!theFatherHomard->FindSubObject(100, aSOZone))
3023   {
3024     MESSAGE("Ajout de la categorie des zones");
3025     aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
3026     PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3027   }
3028   else { MESSAGE("La categorie des zones existe deja."); }
3029
3030   aResultSO = aStudyBuilder->NewObject(aSOZone);
3031   std::string icone ;
3032   switch (ZoneType)
3033   {
3034     case 11 :
3035     { }
3036     case 12 :
3037     { }
3038     case 13 :
3039     { icone = "boxdxy_2.png" ;
3040       break ;
3041     }
3042     case 2 :
3043     { icone = "boxdxyz_2.png" ;
3044       break ;
3045     }
3046     case 31 :
3047     { }
3048     case 32 :
3049     { }
3050     case 33 :
3051     { icone = "disk_2.png" ;
3052       break ;
3053      }
3054     case 4 :
3055     { icone = "spherepoint_2.png" ;
3056       break ;
3057     }
3058     case 5 :
3059     { icone = "cylinderpointvector_2.png" ;
3060       break ;
3061     }
3062     case 61 :
3063     { }
3064     case 62 :
3065     { }
3066     case 63 :
3067     { icone = "diskwithhole_2.png" ;
3068       break ;
3069      }
3070     case 7 :
3071     { icone = "pipe_2.png" ;
3072       break ;
3073     }
3074   }
3075   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3076
3077   return aResultSO._retn();
3078 }
3079 //=============================================================================
3080 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3081                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3082                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3083 {
3084   MESSAGE("PublishBoundaryStudy pour "<<theName);
3085   SALOMEDS::SObject_var aResultSO;
3086   SALOMEDS::GenericAttribute_var anAttr;
3087
3088   // Caracteristique de la Boundary
3089   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3090
3091   // On recupere le module pere dans l etude
3092   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3093   if (theFatherHomard->_is_nil())
3094   {
3095     MESSAGE("theFatherHomard->_is_nil()");
3096     return aResultSO._retn();
3097   }
3098
3099   // On ajoute la categorie des boundarys dans l etude si necessaire
3100   SALOMEDS::SObject_var aSOBoundary;
3101   if (!theFatherHomard->FindSubObject(101, aSOBoundary))
3102   {
3103     MESSAGE("Ajout de la categorie des boundarys");
3104     aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
3105     PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3106   }
3107   else { MESSAGE("La categorie des boundarys existe deja."); }
3108
3109   aResultSO = aStudyBuilder->NewObject(aSOBoundary);
3110   CORBA::Long BoundaryType = myBoundary->GetType();
3111 //   MESSAGE("BoundaryType : "<<BoundaryType);
3112   std::string icone ;
3113   std::string value ;
3114   switch (BoundaryType)
3115   {
3116     case 0 :
3117     { value = "BoundaryDiHomard" ;
3118       icone = "mesh_tree_mesh.png" ;
3119       break;
3120     }
3121     case 1 :
3122     { value = "BoundaryAnHomard" ;
3123       icone = "cylinderpointvector_2.png" ;
3124       break;
3125     }
3126     case 2 :
3127     { value = "BoundaryAnHomard" ;
3128       icone = "spherepoint_2.png" ;
3129       break;
3130     }
3131     case 3 :
3132     { value = "BoundaryAnHomard" ;
3133       icone = "conepointvector.png" ;
3134       break;
3135     }
3136     case 4 :
3137     { value = "BoundaryAnHomard" ;
3138       icone = "conedxyz.png" ;
3139       break;
3140     }
3141   }
3142   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3143   return aResultSO._retn();
3144 }
3145
3146 //=============================================================================
3147 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3148                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3149                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3150 {
3151   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3152   SALOMEDS::SObject_var aResultSO;
3153   SALOMEDS::GenericAttribute_var anAttr;
3154
3155   // On recupere le module pere dans l etude
3156   // On ajoute la categorie des hypotheses dans l etude si necessaire
3157   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3158   if (theFatherHomard->_is_nil())
3159   {
3160     MESSAGE("theFatherHomard->_is_nil()");
3161     return aResultSO._retn();
3162   }
3163   SALOMEDS::SObject_var aSOHypothese;
3164   if (!theFatherHomard->FindSubObject(0, aSOHypothese))
3165   {
3166     MESSAGE("Ajout de la categorie des hypotheses");
3167     aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
3168     PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
3169   }
3170   else { MESSAGE("La categorie des hypotheses existe deja."); }
3171
3172 // Creation du resultat dans l'etude
3173   aResultSO = aStudyBuilder->NewObject(aSOHypothese);
3174   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3175
3176   return aResultSO._retn();
3177 }
3178 //===========================================================================
3179 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3180                                       SALOMEDS::SObject_var aResultSO,
3181                                       const char* name, const char* value, const char* icone, const char* ior)
3182 {
3183   SALOMEDS::GenericAttribute_var anAttr ;
3184 //  Ajout du nom
3185   if ( name != NULL )
3186   {
3187     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3188     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3189     aNameAttrib->SetValue(name);
3190   }
3191
3192 //  Ajout du commentaire
3193   if ( value != NULL )
3194   {
3195     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3196     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3197     aCommentAttrib->SetValue(value);
3198   }
3199
3200 //  Ajout de l'icone
3201   if ( icone != NULL  )
3202   {
3203     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
3204     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3205     aPixmap->SetPixMap(icone);
3206   }
3207
3208 //  Ajout de l ior
3209   if ( ior != NULL  )
3210   {
3211     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3212     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3213     anIOR->SetValue(ior);
3214   }
3215 };
3216
3217 //=====================================================================================
3218 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3219 {
3220   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3221
3222   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3223   ASSERT(!CORBA::is_nil(myCase));
3224   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3225   ASSERT(!CORBA::is_nil(aCaseSO));
3226
3227   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3228   ASSERT(!CORBA::is_nil(myBoundary));
3229   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3230   ASSERT(!CORBA::is_nil(aBoundarySO));
3231
3232   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3233
3234   aStudyBuilder->NewCommand();
3235
3236   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3237   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3238
3239   aStudyBuilder->CommitCommand();
3240
3241 };
3242 //=============================================================================
3243 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3244 //  Option = 0 : fichier issu d'une importation
3245 //  Option = 1 : fichier issu d'une execution HOMARD
3246 {
3247   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3248   if (CORBA::is_nil(myCurrentStudy))
3249   {
3250     SALOME::ExceptionStruct es;
3251     es.type = SALOME::BAD_PARAM;
3252     es.text = "Invalid study context";
3253     throw SALOME::SALOME_Exception(es);
3254     return ;
3255   };
3256
3257 // Le module SMESH est-il actif ?
3258   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3259 //
3260   if (!CORBA::is_nil(aSmeshSO))
3261   {
3262 // On verifie que le fichier n est pas deja publie
3263     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3264     for (; aIter->More(); aIter->Next())
3265     {
3266       SALOMEDS::SObject_var  aSO = aIter->Value();
3267       SALOMEDS::GenericAttribute_var aGAttr;
3268       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3269       {
3270         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3271         CORBA::String_var value=anAttr->Value();
3272         if (strcmp((const char*)value,NomFich) == 0)
3273         {
3274           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3275           // Pour un fichier importe, on ne republie pas
3276           if ( Option == 0 )
3277           {
3278             return;
3279           }
3280           // Pour un fichier calcule, on commence par faire la depublication
3281           else
3282           {
3283             MESSAGE ( "PublishResultInSmesh : depublication" );
3284             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3285             CORBA::String_var value2=anAttr2->Value();
3286             std::string MeshName = string(value2) ;
3287             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3288             DeleteResultInSmesh(NomFich, MeshName) ;
3289           }
3290         }
3291       }
3292     }
3293   }
3294
3295 // On enregistre le fichier
3296   MESSAGE( "Enregistrement du fichier");
3297   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3298   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3299   ASSERT(!CORBA::is_nil(aSmeshEngine));
3300   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3301   SMESH::DriverMED_ReadStatus theStatus;
3302   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3303
3304 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3305   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3306   for (int i = 0; i < mesMaillages->length();  i++)
3307   {
3308     MESSAGE( ". Mise a jour des attributs du maillage");
3309     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3310     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3311     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3312     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3313     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3314     anAttr->SetValue(NomFich);
3315     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3316     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3317     const char* icone ;
3318     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3319     else               { icone = "mesh_tree_mesh.png" ; }
3320     anAttr2->SetPixMap( icone );
3321   }
3322
3323 }
3324 //=============================================================================
3325 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3326 {
3327   MESSAGE (" DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3328   if (CORBA::is_nil(myCurrentStudy))
3329   {
3330       SALOME::ExceptionStruct es;
3331       es.type = SALOME::BAD_PARAM;
3332       es.text = "Invalid study context";
3333       throw SALOME::SALOME_Exception(es);
3334       return ;
3335   };
3336
3337 // Le module SMESH est-il actif ?
3338   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3339 //
3340   if (CORBA::is_nil(aSmeshSO))
3341   {
3342       return ;
3343   };
3344 // On verifie que le fichier est deja publie
3345   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3346   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3347   for (; aIter->More(); aIter->Next())
3348   {
3349      SALOMEDS::SObject_var  aSO = aIter->Value();
3350      SALOMEDS::GenericAttribute_var aGAttr;
3351      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3352      {
3353        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3354        CORBA::String_var value=anAttr->Value();
3355        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3356        {
3357          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3358          {
3359            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3360            CORBA::String_var value2=anAttr2->Value();
3361            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3362            {
3363              myBuilder->RemoveObjectWithChildren( aSO ) ;
3364            }
3365          }
3366        }
3367      }
3368   }
3369
3370 }
3371 //=============================================================================
3372 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3373 {
3374 //   MESSAGE (" PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3375   if (CORBA::is_nil(myCurrentStudy))
3376   {
3377       SALOME::ExceptionStruct es;
3378       es.type = SALOME::BAD_PARAM;
3379       es.text = "Invalid study context";
3380       throw SALOME::SALOME_Exception(es);
3381       return ;
3382   };
3383
3384   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3385   if (CORBA::is_nil(myIteration))
3386   {
3387       SALOME::ExceptionStruct es;
3388       es.type = SALOME::BAD_PARAM;
3389       es.text = "Invalid iteration";
3390       throw SALOME::SALOME_Exception(es);
3391       return ;
3392   };
3393   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3394   if (CORBA::is_nil(myIteration))
3395   {
3396       SALOME::ExceptionStruct es;
3397       es.type = SALOME::BAD_PARAM;
3398       es.text = "Invalid iterationStudy Object";
3399       throw SALOME::SALOME_Exception(es);
3400       return ;
3401   };
3402
3403   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3404
3405   aStudyBuilder->NewCommand();
3406
3407   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3408 // Pour les fichiers med, on affiche une icone de maillage
3409 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
3410 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3411   std::string icone ;
3412   std::string ior = " " ;
3413   if ( Commentaire[0] == 'I' )
3414   { icone = "med.png" ; }
3415   else
3416   { icone = "texte_2.png" ; }
3417   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3418
3419   aStudyBuilder->CommitCommand();
3420 }
3421 //
3422 //=============================================================================
3423 //=============================================================================
3424 // YACS
3425 //=============================================================================
3426 //=============================================================================
3427 //=============================================================================
3428 // Ecriture d'un schema YACS
3429 // nomCas : nom du cas a traiter
3430 // FileName : nom du fichier contenant le script de lancement du calcul
3431 // DirName : le repertoire de lancement des calculs du schéma
3432 //=============================================================================
3433 CORBA::Long HOMARD_Gen_i::WriteYACSSchema (const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3434 {
3435   INFOS ( "WriteYACSSchema : Schema YACS pour le cas " << nomCas);
3436   INFOS ( "ScriptFile : " << ScriptFile);
3437   INFOS ( "DirName    : " << DirName);
3438   INFOS ( "MeshFile   : " << MeshFile);
3439
3440   int codret = 0;
3441
3442   // A. Le cas
3443   // A.1. L'objet cas
3444   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3445   ASSERT(!CORBA::is_nil(myCase));
3446   // A.2. Le repertoire du cas
3447   std::string nomDirCase = myCase->GetDirName();
3448   MESSAGE ( ". nomDirCase = " << nomDirCase );
3449   // A.3. Les instructions python associees au cas
3450   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3451   std::string pythonCas = dumpCorbaCase.in();
3452   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3453
3454   // D. Les iterations
3455   // D.1. L'iteration initiale
3456   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3457   std::string Iter0Name = myCase->GetIter0Name() ;
3458   MESSAGE (". Iter0Name = " << Iter0Name);
3459   // D.2. L'iteration numero 1
3460   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3461   int numberOfIter = maListe->length();
3462   if ( numberOfIter > 1 )
3463   {
3464     MESSAGE (". numberOfIter = " << numberOfIter);
3465     SALOME::ExceptionStruct es ;
3466     es.type = SALOME::BAD_PARAM;
3467     std::string text = "Une seule iteration est permise." ;
3468     es.text = CORBA::string_dup(text.c_str());
3469     throw SALOME::SALOME_Exception(es);
3470     return 0;
3471   }
3472   std::string Iter1Name = std::string((*maListe)[0]);
3473   MESSAGE ("... Iter1Name = " << Iter1Name);
3474   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3475   MESSAGE (". Iter1 = " << Iter1);
3476
3477   // C. L'hypothese
3478   // C.1. La structure
3479   std::string nomHypo = Iter1->GetHypoName();
3480   MESSAGE (". nomHypo = " << nomHypo);
3481   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3482   ASSERT(!CORBA::is_nil(myHypo));
3483   // C.2. Les caracteristiques de l'adaptation
3484   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3485   ASSERT(ListTypes->length() == 3);
3486   int TypeAdap = (*ListTypes)[0];
3487 //   int TypeRaff = (*ListTypes)[1];
3488 //   int TypeDera = (*ListTypes)[2];
3489   // C.3. Les instructions python associees a l'hypothese
3490   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3491   std::string pythonHypo = dumpCorbaHypo.in();
3492   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3493
3494   // E. Les fichiers du schema
3495   // E.1. Le fichier du schema de reference
3496   // Le repertoire ou se trouve l'executable HOMARD
3497   std::string YACSFile_base ;
3498   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { YACSFile_base = getenv("HOMARD_ROOT_DIR") ; }
3499   else                                     { ASSERT("HOMARD_ROOT_DIR est inconnu." == 0) ; }
3500   YACSFile_base += "/share/salome/resources/homard/yacs_01.xml" ;
3501   MESSAGE("YACSFile_base ="<<YACSFile_base);
3502   // E.2. Le fichier du schema a creer
3503   std::string YACSFile = nomDirCase ;
3504   YACSFile += "/schema.xml" ;
3505   MESSAGE (". YACSFile = " << YACSFile);
3506   YACSDriver* myDriver = new YACSDriver(YACSFile, DirName);
3507
3508   // F. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3509   std::ifstream fichier( YACSFile_base.c_str() );
3510   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3511   {
3512     // F.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3513     std::string ligne; // variable contenant chaque ligne lue
3514     std::string mot_cle;
3515     while ( std::getline( fichier, ligne ) )
3516     {
3517       // F.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3518       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3519       ligne_bis >> mot_cle ;
3520       // F.1.2. Le maillage initial
3521       if ( mot_cle == "DataInit_MeshFile" )
3522       {
3523         myDriver->Texte_DataInit_MeshFile(MeshFile);
3524       }
3525       // F.1.3. Le script de lancement
3526       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3527       {
3528         myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile);
3529       }
3530       // F.1.4. Les options du cas
3531       else if ( mot_cle == "HOMARD_Init_au_debut_Case_Options" )
3532       {
3533         myDriver->Texte_HOMARD_Init_au_debut_Case_Options(pythonCas);
3534       }
3535       // F.1.5. Execution de HOMARD : le repertoire du cas
3536       else if ( mot_cle == "HOMARD_Exec_DirName" )
3537       {
3538         myDriver->Texte_HOMARD_Exec_DirName();
3539       }
3540       // F.1.6. Execution de HOMARD : les options de l'hypothese
3541       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3542       {
3543         myDriver->Texte_python( pythonHypo, 3, "Hypo" ) ;
3544       }
3545       // F.1.7. Zones et frontieres : les creations
3546       else if ( mot_cle == "HOMARD_Init_au_debut" )
3547       {
3548         std::string texte_control = myDriver->Texte_HOMARD_Init_au_debut_control() ;
3549         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3550         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3551         myDriver->TexteAdd(texte_control);
3552       }
3553       // F.1.8. Zones : les parametres
3554       else if ( mot_cle == "PARAMETRES" )
3555       {
3556         if ( TypeAdap == 0 )
3557         { myDriver->TexteAddParametres(); }
3558       }
3559       // F.1.n. La ligne est recopiee telle quelle
3560       else
3561       {
3562         myDriver->TexteAdd(ligne);
3563       }
3564     }
3565     // F.2. Ecriture du texte dans le fichier
3566     if ( codret == 0 )
3567     { myDriver->CreeFichier(); }
3568   }
3569   else
3570   {
3571     SALOME::ExceptionStruct es;
3572     es.type = SALOME::BAD_PARAM;
3573     std::string text = "The reference file for the YACS schema cannot be read." ;
3574     es.text = CORBA::string_dup(text.c_str());
3575     throw SALOME::SALOME_Exception(es);
3576   }
3577
3578   delete myDriver;
3579
3580   return codret ;
3581 }
3582 //=============================================================================
3583 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3584 //=============================================================================
3585 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3586 {
3587   MESSAGE ( "YACSDriverTexteZone" );
3588   // A. Les zones associees a cette hypothese
3589   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3590   int numberOfZonesx2 = ListZone->length();
3591
3592   // B. Parcours des zones
3593   std::string texte_control ;
3594   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3595   {
3596     // 1. Reperage de la zone
3597     std::string ZoneName = std::string((*ListZone)[iaux]);
3598     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3599     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3600     ASSERT(!CORBA::is_nil(myZone));
3601     // 2. Les instructions python associees a la zone
3602     //    La premiere ligne est un commentaire a eliminer
3603     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3604     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3605     std::string pythonStructure_0 = dumpCorbaZone.in();
3606     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3607     std::istringstream tout (pythonStructure_0) ;
3608     std::string ligne ;
3609     std::string pythonStructure ;
3610     while ( std::getline( tout, ligne ) )
3611     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3612     MESSAGE ("pythonStructure :\n"<<pythonStructure);
3613     // 3. Decodage du nom du service
3614     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3615     MESSAGE ( "... methode = " << methode);
3616     // 4. Mise en place des instructions
3617     int ZoneType = myZone->GetType();
3618     MESSAGE ( "... ZoneType = " << ZoneType);
3619     std::string texte_control_0 ;
3620     texte_control_0 = myDriver->Texte_HOMARD_Init_au_debut_Zone(ZoneType, pythonStructure, methode, ZoneName );
3621     texte_control += texte_control_0 ;
3622     // 5. Decalage
3623     iaux += 1 ;
3624   }
3625
3626   return texte_control ;
3627 }
3628 //=============================================================================
3629 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
3630 //=============================================================================
3631 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
3632 {
3633   MESSAGE ( "YACSDriverTexteBoundary" );
3634   // A. Les frontieres associees au cas
3635   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3636   int numberOfitems = ListBoundaryGroupType->length();
3637
3638   // B. Parcours des frontieres
3639   std::string texte_control ;
3640   std::list<std::string>  ListeBoundaryTraitees ;
3641   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3642   {
3643     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3644     MESSAGE ( "... BoundaryName = " << BoundaryName);
3645     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
3646     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
3647     int A_faire = 1 ;
3648     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3649     while (it != ListeBoundaryTraitees.end())
3650     {
3651       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3652       if ( BoundaryName == *it ) { A_faire = 0 ; }
3653       it++;
3654     }
3655     if ( A_faire == 1 )
3656     {
3657     // 1. Caracteristiques de la frontiere
3658       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3659       ASSERT(!CORBA::is_nil(myBoundary));
3660       // 2. Les instructions python associees a la frontiere
3661       //    La premiere ligne est un commentaire a eliminer
3662       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3663       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
3664       std::string pythonStructure_0 = dumpCorbaBoundary.in();
3665       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3666       std::istringstream tout (pythonStructure_0) ;
3667       std::string ligne ;
3668       std::string pythonStructure ;
3669       while ( std::getline( tout, ligne ) )
3670       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3671       MESSAGE ("pythonStructure :\n"<<pythonStructure);
3672       // 3. Decodage du nom du service
3673       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3674       MESSAGE ( "... methode = " << methode);
3675       // 4. Mise en place des instructions
3676       int BoundaryType = myBoundary->GetType();
3677       MESSAGE ( "... BoundaryType = " << BoundaryType);
3678       std::string texte_control_0 ;
3679       texte_control_0 = myDriver->Texte_HOMARD_Init_au_debut_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
3680       texte_control += texte_control_0 ;
3681       // 5. Memorisation du traitement
3682       ListeBoundaryTraitees.push_back( BoundaryName );
3683     }
3684   }
3685
3686   return texte_control ;
3687 }
3688 //
3689 //=============================================================================
3690 //=============================================================================
3691 // Next functions are inherited from SALOMEDS::Driver interface
3692 //=============================================================================
3693 //=============================================================================
3694 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
3695                                       const char* theURL,
3696                                       CORBA::Boolean isMultiFile)
3697 {
3698   MESSAGE (" Save for theURL = "<< theURL);
3699   SALOMEDS::TMPFile_var aStreamFile;
3700
3701   // get temporary directory name
3702   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3703
3704   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3705   StudyContext& context = myContextMap[ aStudy->StudyId() ];
3706
3707   // HOMARD data file name
3708   std::string aFileName = "";
3709   if (isMultiFile)
3710     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3711   aFileName += "_HOMARD.dat";
3712
3713   // initialize sequence of file names
3714   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
3715   aFileSeq->length(1);
3716   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
3717
3718   // get full path to the data file
3719   aFileName = tmpDir + aFileName;
3720
3721   // save data
3722   // -> create file
3723   std::ofstream f(aFileName.c_str());
3724
3725   // clear temporary id map
3726   context._idmap.clear();
3727
3728   int id = 1;
3729
3730   // -> save cases
3731   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
3732   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
3733     HOMARD::HOMARD_Cas_var aCas = it_case->second;
3734     PortableServer::ServantBase_var aServant = GetServant(aCas);
3735     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3736     if (aCasServant) {
3737       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
3738       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
3739     }
3740   }
3741   // -> save zones
3742   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
3743   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
3744     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
3745     PortableServer::ServantBase_var aServant = GetServant(aZone);
3746     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
3747     if (aZoneServant) {
3748       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
3749       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
3750     }
3751   }
3752   // -> save hypotheses
3753   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
3754   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
3755     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
3756     PortableServer::ServantBase_var aServant = GetServant(aHypo);
3757     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
3758     if (aHypoServant) {
3759       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
3760       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
3761     }
3762   }
3763   // -> save iterations
3764   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
3765   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
3766     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
3767     PortableServer::ServantBase_var aServant = GetServant(aIter);
3768     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
3769     if (aIterServant) {
3770       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
3771       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
3772     }
3773   }
3774   // -> save boundaries
3775   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
3776   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
3777     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
3778     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
3779     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
3780     if (aBoundaryServant) {
3781       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
3782       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
3783     }
3784   }
3785   // -> close file
3786   MESSAGE ("close file");
3787   f.close();
3788
3789   // put temporary files to the stream
3790   MESSAGE ("put temporary files to the stream");
3791   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
3792
3793   // remove temporary files
3794   MESSAGE ("remove temporary files");
3795   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
3796
3797   // return data stream
3798   MESSAGE ("return data stream");
3799   return aStreamFile._retn();
3800 };
3801
3802 //===========================================================================
3803 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
3804                                            const char* theURL,
3805                                            CORBA::Boolean isMultiFile)
3806 {
3807   // No specific ASCII persistence
3808   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
3809   return aStreamFile._retn();
3810 };
3811
3812 //===========================================================================
3813 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
3814                                    const SALOMEDS::TMPFile& theStream,
3815                                    const char* theURL,
3816                                    CORBA::Boolean isMultiFile)
3817 {
3818   MESSAGE (" Load pour theURL = "<< theURL);
3819   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
3820
3821   // set current study
3822   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
3823     SetCurrentStudy(aStudy);
3824
3825   // get temporary directory name
3826   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
3827
3828   // Convert the stream into sequence of files to process
3829   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
3830                                                                             tmpDir.c_str(),
3831                                                                             isMultiFile);
3832   // HOMARD data file name
3833   std::string aFileName = "";
3834   if (isMultiFile)
3835     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
3836   aFileName = tmpDir + aFileName + "_HOMARD.dat";
3837
3838   StudyContext& context = myContextMap[ aStudy->StudyId() ];
3839
3840   // save data
3841   // -> create file
3842   std::ifstream f(aFileName.c_str());
3843
3844   // clear context
3845   context._mesCas.clear();
3846   context._mesHypotheses.clear();
3847   context._mesIterations.clear();
3848   context._mesZones.clear();
3849   context._mesBoundarys.clear();
3850   context._idmap.clear();
3851
3852   int id = 1;
3853   std::string line;
3854
3855   while (f) {
3856     std::getline(f, line);
3857     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
3858     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
3859     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
3860     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
3861     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
3862     if (line.substr(0, caseSignature.size()) == caseSignature) {
3863       // re-create case
3864       MESSAGE (" Recreation du cas" );
3865       HOMARD::HOMARD_Cas_var aCase = newCase();
3866       PortableServer::ServantBase_var aServant = GetServant(aCase);
3867       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
3868       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
3869         context._mesCas[aCase->GetName()] = aCase;
3870         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
3871       }
3872     }
3873     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
3874       MESSAGE (" Recreation de la zone" );
3875       // re-create zone
3876       HOMARD::HOMARD_Zone_var aZone = newZone();
3877       PortableServer::ServantBase_var aServant = GetServant(aZone);
3878       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
3879       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
3880         context._mesZones[aZone->GetName()] = aZone;
3881         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
3882       }
3883     }
3884     else if (line.substr(0, iterSignature.size()) == iterSignature) {
3885       // re-create iteration
3886       MESSAGE (" Recreation de l iteration" );
3887       HOMARD::HOMARD_Iteration_var aIter = newIteration();
3888       PortableServer::ServantBase_var aServant = GetServant(aIter);
3889       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
3890       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
3891         context._mesIterations[aIter->GetName()] = aIter;
3892         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
3893       }
3894     }
3895     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
3896       // re-create hypothesis
3897       MESSAGE (" Recreation de l hypothese" );
3898       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
3899       PortableServer::ServantBase_var aServant = GetServant(aHypo);
3900       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
3901       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
3902         context._mesHypotheses[aHypo->GetName()] = aHypo;
3903         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
3904       }
3905     }
3906     else if (line.substr(0, bounSignature.size()) == bounSignature) {
3907       // re-create boundary
3908       MESSAGE (" Recreation de la frontiere" );
3909       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
3910       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
3911       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
3912       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
3913         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
3914         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
3915       }
3916     }
3917     id++;
3918   }
3919
3920   // -> close file
3921   f.close();
3922
3923   // Remove temporary files created from the stream
3924   if (!isMultiFile)
3925     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
3926
3927   return true;
3928 };
3929
3930 //===========================================================================
3931 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
3932                                         const SALOMEDS::TMPFile& theStream,
3933                                         const char* theURL,
3934                                         CORBA::Boolean isMultiFile)
3935 {
3936   // No specific ASCII persistence
3937   return Load(theComponent, theStream, theURL, isMultiFile);
3938 };
3939
3940 //===========================================================================
3941 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
3942 {
3943   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
3944     // clearing study context should be done here:
3945     // - destroy all servants and related CORBA objects
3946     // ... (TODO)
3947     // - remove context from myContextMap
3948     myContextMap.erase(theComponent->GetStudy()->StudyId());
3949     // - nullify myCurrentStudy
3950     myCurrentStudy = SALOMEDS::Study::_nil();
3951   }
3952 };
3953
3954 //===========================================================================
3955 char* HOMARD_Gen_i::ComponentDataType()
3956 {
3957   return CORBA::string_dup("HOMARD");
3958 };
3959
3960 //===========================================================================
3961 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
3962                                             const char* IORString,
3963                                             CORBA::Boolean isMultiFile,
3964                                             CORBA::Boolean isASCII)
3965 {
3966   CORBA::String_var aString("");
3967   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
3968     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3969     CORBA::Object_var anObj = _orb->string_to_object(IORString);
3970     if (!CORBA::is_nil(anObj)) {
3971       PortableServer::ServantBase_var aServant = GetServant(anObj);
3972       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
3973       if (aStorable) {
3974         std::map<int, PortableServer::ServantBase*>::const_iterator it;
3975         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
3976           if (it->second == aStorable) {
3977             std::stringstream os;
3978             os << it->first;
3979             aString = CORBA::string_dup(os.str().c_str());
3980           }
3981         }
3982       }
3983     }
3984   }
3985   return aString._retn();
3986 };
3987
3988 //===========================================================================
3989 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
3990                                             const char* aLocalPersistentID,
3991                                             CORBA::Boolean isMultiFile,
3992                                             CORBA::Boolean isASCII)
3993 {
3994   CORBA::String_var aString("");
3995   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
3996     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
3997     int id = atoi(aLocalPersistentID);
3998     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
3999       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4000       if (!CORBA::is_nil(object)) {
4001         aString = _orb->object_to_string(object);
4002       }
4003     }
4004   }
4005   return aString._retn();
4006 };
4007
4008 //===========================================================================
4009 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4010 {
4011   if(CORBA::is_nil(myCurrentStudy))
4012     return false;
4013
4014   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4015   if(!aCas->_is_nil())
4016     return true;
4017
4018   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4019   if(!aHypo->_is_nil())
4020     return true;
4021
4022   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4023   if(!aZone->_is_nil())
4024     return true;
4025
4026   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4027   if(!aBoundary->_is_nil())
4028     return true;
4029
4030   /* Iteration is not published directly
4031   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4032   if(!aIter->_is_nil())
4033     return true;
4034   */
4035   return false;
4036 };
4037
4038 //===========================================================================
4039 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4040 {
4041   // No Copy/Paste support
4042   return false;
4043 };
4044
4045 //===========================================================================
4046 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4047                                            CORBA::Long& theObjectID)
4048 {
4049   // No Copy/Paste support
4050   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4051   return aStreamFile._retn();
4052 };
4053
4054 //===========================================================================
4055 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4056                                         CORBA::Long theObjectID)
4057 {
4058   // No Copy/Paste support
4059   return false;
4060 };
4061
4062 //===========================================================================
4063 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4064                                                CORBA::Long theObjectID,
4065                                                SALOMEDS::SObject_ptr theSObject)
4066 {
4067   // No Copy/Paste support
4068   SALOMEDS::SObject_var aResultSO;
4069   return aResultSO._retn();
4070 };
4071
4072 //===========================================================================
4073 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4074 {
4075   PortableServer::Servant aServant = 0;
4076   if (!CORBA::is_nil(theObject)) {
4077     try {
4078       aServant = _poa->reference_to_servant(theObject);
4079     }
4080     catch (...) {
4081     }
4082   }
4083   return aServant;
4084 }
4085
4086 //==========================================================================
4087 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4088                                        CORBA::Boolean isPublished,
4089                                        CORBA::Boolean isMultiFile,
4090                                        CORBA::Boolean& isValidScript)
4091 {
4092    MESSAGE ("Entree dans DumpPython");
4093    isValidScript=1;
4094    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4095    if(CORBA::is_nil(aStudy))
4096      return new Engines::TMPFile(0);
4097
4098    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4099    if(CORBA::is_nil(aSO))
4100       return new Engines::TMPFile(0);
4101
4102    std::string aScript = "\"\"\"\n";
4103    aScript += "Python script for HOMARD\n";
4104    aScript += "Copyright EDF-R&D 2013\n";
4105    aScript += "\"\"\"\n";
4106    aScript += "__revision__ = \"V1.2\"\n";
4107    aScript += "import HOMARD\n";
4108    if( isMultiFile )
4109       aScript += "import salome\n";
4110    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4111    if( isMultiFile ) {
4112       aScript += "def RebuildData(theStudy):\n";
4113       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4114    }
4115    else
4116       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4117    MESSAGE (". Au depart \n"<<aScript);
4118
4119
4120    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4121    {
4122     MESSAGE (". Ecritures des frontieres");
4123     aScript += "#\n# Creation of the boundaries";
4124     aScript +=  "\n# ==========================";
4125    }
4126    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4127    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4128         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4129    {
4130     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4131     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4132     std::string dumpBoundary = dumpCorbaBoundary.in();
4133     MESSAGE (dumpBoundary<<"\n");
4134     aScript += dumpBoundary;
4135    }
4136
4137
4138    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4139    {
4140     MESSAGE (". Ecritures des zones");
4141     aScript += "#\n# Creation of the zones";
4142     aScript +=  "\n# =====================";
4143    }
4144    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4145    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4146          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4147    {
4148     HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
4149     CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
4150     std::string dumpZone = dumpCorbaZone.in();
4151     MESSAGE (dumpZone<<"\n");
4152     aScript += dumpZone;
4153    }
4154
4155
4156    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4157    {
4158     MESSAGE (". Ecritures des hypotheses");
4159     aScript += "#\n# Creation of the hypotheses";
4160     aScript +=  "\n# ==========================";
4161    }
4162    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4163    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4164          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4165    {
4166     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4167     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4168     std::string dumpHypo = dumpCorbaHypo.in();
4169     MESSAGE (dumpHypo<<"\n");
4170     aScript += dumpHypo;
4171    }
4172
4173
4174    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4175    {
4176     MESSAGE (". Ecritures des cas");
4177     aScript += "#\n# Creation of the cases";
4178     aScript += "\n# =====================";
4179    }
4180    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4181    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4182         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4183         {
4184            std::string nomCas = (*it_cas).first;
4185            std::string dumpCas = std::string("\n# Creation of the case ") ;
4186            dumpCas +=  nomCas + std::string("\n");
4187            dumpCas += std::string("\t") + nomCas;
4188            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4189
4190            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4191            CORBA::String_var cIter0= myCase->GetIter0Name();
4192            std::string iter0 = cIter0.in();
4193
4194            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4195            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4196            std::string mesh0 = cMesh0.in();
4197            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4198            std::string meshName0 = cMeshName0.in();
4199            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4200            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4201            std::string dumpCas2= dumpCorbaCase.in();
4202
4203            MESSAGE (dumpCas<<dumpCas2<<"\n");
4204            aScript += dumpCas + dumpCas2;
4205         };
4206
4207
4208    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4209    {
4210     MESSAGE (". Ecritures des iterations");
4211     aScript += "#\n# Creation of the iterations" ;
4212     aScript += "\n# ==========================";
4213    }
4214    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4215    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4216         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4217    {
4218     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4219     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4220     std::string dumpIter = dumpCorbaIter.in();
4221     MESSAGE (dumpIter<<"\n");
4222     aScript += dumpIter;
4223    }
4224
4225   MESSAGE (". Ecritures finales");
4226   if( isMultiFile )
4227     aScript += "\n\tpass";
4228   aScript += "\n";
4229
4230   if( !isMultiFile ) // remove unnecessary tabulation
4231     aScript = RemoveTabulation( aScript );
4232
4233 //   MESSAGE ("A ecrire \n"<<aScript);
4234   const size_t aLen = strlen(aScript.c_str());
4235   char* aBuffer = new char[aLen+1];
4236   strcpy(aBuffer, aScript.c_str());
4237
4238   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4239   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4240
4241   MESSAGE ("Sortie de DumpPython");
4242   return aStreamFile._retn();
4243 }
4244
4245
4246 //=============================================================================
4247 //=============================================================================
4248 // Utilitaires
4249 //=============================================================================
4250 //=============================================================================
4251 void HOMARD_Gen_i::IsValidStudy( )
4252 {
4253 //   MESSAGE( "IsValidStudy" );
4254   if (CORBA::is_nil(myCurrentStudy))
4255   {
4256     SALOME::ExceptionStruct es;
4257     es.type = SALOME::BAD_PARAM;
4258     es.text = "Invalid study context";
4259     throw SALOME::SALOME_Exception(es);
4260   };
4261   return ;
4262 }
4263
4264 //=============================================================================
4265 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
4266 {
4267   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4268   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4269   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4270   {
4271    if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
4272   }
4273   return true;
4274 }
4275 /*//=============================================================================
4276 void SALOMEException( std::string message )
4277 {
4278   SALOME::ExceptionStruct es;
4279   es.type = SALOME::BAD_PARAM;
4280   es.text = message;
4281   throw SALOME::SALOME_Exception(es);
4282   return ;
4283 }*/
4284 //=============================================================================
4285 char* HOMARD_Gen_i::getVersion()
4286 {
4287 #if HOMARD_DEVELOPMENT
4288   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4289 #else
4290   return CORBA::string_dup(HOMARD_VERSION_STR);
4291 #endif
4292 }
4293 //===============================================================================
4294 // Recuperation de la chaine de caracteres par rapport l'apparition d'un texte
4295 // ligne : la ligne a manipuler
4296 // texte : le texte a reperer
4297 // option : 0 : la chaine avant le texte
4298 //          1 : la chaine apres le texte
4299 // Si le texte est absent, on retourne la chaine totale
4300 //===============================================================================
4301 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4302 {
4303 //   MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4304 //
4305   std::string chaine = ligne ;
4306   int position = ligne.find_first_of( texte ) ;
4307   if ( position > 0 )
4308   {
4309     if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4310     else               { chaine = ligne.substr( position+1 ) ; }
4311   }
4312 // Conversion de type
4313   return chaine ;
4314 //
4315 }
4316
4317 //=============================================================================
4318 extern "C"
4319 {
4320   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4321                                                   PortableServer::POA_ptr poa,
4322                                                   PortableServer::ObjectId* contId,
4323                                                   const char* instanceName,
4324                                                   const char* interfaceName)
4325   {
4326     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4327     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4328     return myHOMARD_Gen->getId();
4329   }
4330 }