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