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