Salome HOME
Pilotage de l'adaptation pour Code_Saturne
[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     if ((system(nomCompo.c_str())) != 0)
3087     {
3088       MESSAGE( "... nomCompo = " << nomCompo );
3089       myDriver->TexteCompo(NumeComp, nomCompo);
3090     }
3091   }
3092   return ;
3093 }
3094 //=============================================================================
3095 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3096 // On ecrit dans l'ordre :
3097 //    1. la definition des frontieres
3098 //    2. les liens avec les groupes
3099 //    3. un entier resumant le type de comportement pour les frontieres
3100 //=============================================================================
3101 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3102 {
3103   MESSAGE ( "... DriverTexteBoundary" );
3104   // 1. Recuperation des frontieres
3105   std::list<std::string>  ListeBoundaryTraitees ;
3106   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3107   int numberOfitems = ListBoundaryGroupType->length();
3108   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3109   int BoundaryOption = 1 ;
3110   // 2. Parcours des frontieres pour ecrire leur description
3111   int NumBoundaryAnalytical = 0 ;
3112   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3113   {
3114     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3115     MESSAGE ( "... BoundaryName = " << BoundaryName);
3116     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3117     //      Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3118     int A_faire = 1 ;
3119     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3120     while (it != ListeBoundaryTraitees.end())
3121     {
3122       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3123       if ( BoundaryName == *it ) { A_faire = 0 ; }
3124       it++;
3125     }
3126     // 2.2. Ecriture de la frontiere
3127     if ( A_faire == 1 )
3128     {
3129       // 2.2.1. Caracteristiques de la frontiere
3130       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3131       ASSERT(!CORBA::is_nil(myBoundary));
3132       int BoundaryType = myBoundary->GetType();
3133       MESSAGE ( "... BoundaryType = " << BoundaryType );
3134       // 2.2.2. Ecriture selon le type
3135       // 2.2.2.1. Cas d une frontiere discrete
3136       if (BoundaryType == 0)
3137       {
3138         const char* MeshName = myBoundary->GetMeshName() ;
3139         MESSAGE ( ". MeshName = " << MeshName );
3140         const char* MeshFile = myBoundary->GetMeshFile() ;
3141         MESSAGE ( ". MeshFile = " << MeshFile );
3142         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3143         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3144       }
3145       // 2.2.2.1. Cas d une frontiere analytique
3146       else
3147       {
3148         NumBoundaryAnalytical++ ;
3149         HOMARD::double_array* coor = myBoundary->GetCoords();
3150         if (BoundaryType == 1) // Cas d un cylindre
3151         {
3152           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3153           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3154         }
3155         else if (BoundaryType == 2) // Cas d une sphere
3156         {
3157           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3158           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3159         }
3160         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3161         {
3162           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3163           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3164         }
3165         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3166         {
3167           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3168           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3169         }
3170         else if (BoundaryType == 5) // Cas d un tore
3171         {
3172           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3173           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3174         }
3175       }
3176       // 2.2.3. Memorisation du traitement
3177       ListeBoundaryTraitees.push_back( BoundaryName );
3178     }
3179   }
3180   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3181   NumBoundaryAnalytical = 0 ;
3182   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3183   {
3184     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3185     MESSAGE ( "... BoundaryName = " << BoundaryName);
3186     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3187     ASSERT(!CORBA::is_nil(myBoundary));
3188     int BoundaryType = myBoundary->GetType();
3189     MESSAGE ( "... BoundaryType = " << BoundaryType );
3190     // 3.1. Recuperation du nom du groupe
3191     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3192     MESSAGE ( "... GroupName = " << GroupName);
3193     // 3.2. Cas d une frontiere discrete
3194     if ( BoundaryType == 0 )
3195     {
3196       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3197     }
3198     // 3.3. Cas d une frontiere analytique
3199     else
3200     {
3201       NumBoundaryAnalytical++ ;
3202       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3203     }
3204   }
3205   // 4. Ecriture de l'option finale
3206   myDriver->TexteBoundaryOption(BoundaryOption);
3207 //
3208   return ;
3209 }
3210 //=============================================================================
3211 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3212 //=============================================================================
3213 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3214 {
3215   MESSAGE ( "... DriverTexteFieldInterp" );
3216   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3217   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3218   if (TypeFieldInterp != 0)
3219   {
3220 //  Le fichier des champs
3221     char* FieldFile = myIteration->GetFieldFile();
3222     MESSAGE ( ". FieldFile = " << FieldFile );
3223     if (strlen(FieldFile) == 0)
3224     {
3225       // GERALD -- QMESSAGE BOX
3226       VERIFICATION("The file for the field is not given." == 0);
3227     }
3228   //
3229     const char* MeshFile = myIteration->GetMeshFile();
3230     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3231
3232   // Les champs
3233   // Interpolation de tous les champs
3234     if ( TypeFieldInterp == 1 )
3235     {
3236       myDriver->TexteFieldInterpAll();
3237     }
3238   // Interpolation de certains champs
3239     else if (TypeFieldInterp == 2)
3240     {
3241       // Les champs et leurs instants pour l'iteration
3242       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3243       int numberOfFieldsx3 = ListFieldTSR->length();
3244       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3245       // Les champs pour l'hypothese
3246       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3247       int numberOfFieldsx2 = ListField->length();
3248       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3249       // On parcourt tous les champs de  l'hypothese
3250       int NumField = 0 ;
3251       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3252       {
3253         // Le nom du champ
3254         std::string FieldName = std::string((*ListField)[iaux]) ;
3255         // Le type d'interpolation
3256         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3257         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3258         // On cherche à savoir si des instants ont été précisés pour cette itération
3259         int tsrvu = 0;
3260         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3261         {
3262         // Le nom du champ
3263           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3264           MESSAGE( "..... FieldName2 = " << FieldName2 );
3265         // Quand c'est le bon champ, on ecrit le pas de temps
3266           if ( FieldName == FieldName2 )
3267           {
3268             tsrvu = 1 ;
3269             // Le pas de temps
3270             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3271             // Le numero d'ordre
3272             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3273             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3274             NumField += 1 ;
3275             int TimeStep = atoi( TimeStepstr.c_str() );
3276             int Rank = atoi( Rankstr.c_str() );
3277             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3278           }
3279           jaux += 2 ;
3280         }
3281         // Si aucun instant n'a été défini
3282         if ( tsrvu == 0 )
3283         {
3284           NumField += 1 ;
3285           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3286         }
3287         iaux++ ;
3288       }
3289     }
3290   }
3291   return ;
3292 }
3293 //===========================================================================
3294 //===========================================================================
3295
3296
3297 //===========================================================================
3298 //===========================================================================
3299 // Publications
3300 //===========================================================================
3301 //===========================================================================
3302 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3303                                                    SALOMEDS::SObject_ptr theSObject,
3304                                                    CORBA::Object_ptr theObject,
3305                                                    const char* theName)
3306 {
3307   MESSAGE("PublishInStudy pour " << theName);
3308   SALOMEDS::SObject_var aResultSO;
3309   if (CORBA::is_nil(theStudy))
3310   {
3311     SALOME::ExceptionStruct es;
3312     es.type = SALOME::BAD_PARAM;
3313     es.text = "Invalid study context";
3314     throw SALOME::SALOME_Exception(es);
3315     return 0;
3316   };
3317
3318 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3319 // Rq : Iteration est publiee ailleurs
3320   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3321   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3322   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3323   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3324   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3325
3326    addInStudy(theStudy);
3327
3328 // Controle de la non publication d'un objet de meme nom
3329    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3330   {
3331     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3332     if (listSO->length() >= 1)
3333     {
3334       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3335       aResultSO = listSO[0];
3336       return aResultSO._retn();
3337     }
3338   }
3339
3340   // Caracteristiques de l'etude
3341   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3342   aStudyBuilder->NewCommand();
3343   if(!aBoundary->_is_nil())
3344     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3345   else if(!aCase->_is_nil())
3346     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3347   else if(!aHypo->_is_nil())
3348     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3349   else if(!aYACS->_is_nil())
3350     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3351   else if(!aZone->_is_nil())
3352     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3353
3354   aStudyBuilder->CommitCommand();
3355
3356   return aResultSO._retn();
3357 };
3358 //=============================================================================
3359 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3360                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3361                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3362 {
3363   MESSAGE("PublishBoundaryStudy pour "<<theName);
3364   SALOMEDS::SObject_var aResultSO;
3365
3366   // Caracteristique de la Boundary
3367   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3368
3369   // On recupere le module pere dans l etude
3370   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3371   if (theFatherHomard->_is_nil())
3372   {
3373     MESSAGE("theFatherHomard->_is_nil()");
3374     return aResultSO._retn();
3375   }
3376
3377   // On ajoute la categorie des boundarys dans l etude si necessaire
3378   if ( _tag_boun == 0 )
3379   {
3380     _tag_gene += 1 ;
3381     _tag_boun = _tag_gene ;
3382   }
3383   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3384   SALOMEDS::SObject_var aSObject;
3385   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3386   {
3387     MESSAGE("Ajout de la categorie des boundarys");
3388     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3389     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3390   }
3391   else { MESSAGE("La categorie des boundarys existe deja."); }
3392
3393   CORBA::Long BoundaryType = myBoundary->GetType();
3394 //   MESSAGE("BoundaryType : "<<BoundaryType);
3395   std::string icone ;
3396   std::string value ;
3397   switch (BoundaryType)
3398   {
3399     case 0 :
3400     { value = "BoundaryDiHomard" ;
3401       icone = "mesh_tree_mesh.png" ;
3402       break;
3403     }
3404     case 1 :
3405     { value = "BoundaryAnHomard" ;
3406       icone = "cylinderpointvector_2.png" ;
3407       break;
3408     }
3409     case 2 :
3410     { value = "BoundaryAnHomard" ;
3411       icone = "spherepoint_2.png" ;
3412       break;
3413     }
3414     case 3 :
3415     { value = "BoundaryAnHomard" ;
3416       icone = "conepointvector.png" ;
3417       break;
3418     }
3419     case 4 :
3420     { value = "BoundaryAnHomard" ;
3421       icone = "conedxyz.png" ;
3422       break;
3423     }
3424     case 5 :
3425     { value = "BoundaryAnHomard" ;
3426       icone = "toruspointvector.png" ;
3427       break;
3428     }
3429   }
3430   aResultSO = aStudyBuilder->NewObject(aSObject);
3431   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3432   return aResultSO._retn();
3433 }
3434 //=============================================================================
3435 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3436                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3437                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3438 {
3439   MESSAGE("PublishCaseInStudy pour "<<theName);
3440   SALOMEDS::SObject_var aResultSO;
3441
3442   if (CORBA::is_nil(theObject)) {
3443     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3444     return aResultSO._retn();
3445   }
3446   if (theStudy->_is_nil()) {
3447     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3448     return aResultSO._retn();
3449   }
3450
3451   // On recupere le module pere dans l etude
3452   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3453   if (theFatherHomard->_is_nil())
3454   {
3455     MESSAGE("theFatherHomard->_is_nil()");
3456     return aResultSO._retn();
3457   }
3458
3459   _tag_gene += 1 ;
3460   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3461   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3462   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3463                      _orb->object_to_string(theObject) ) ;
3464
3465   return aResultSO._retn();
3466 }
3467 //=============================================================================
3468 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3469                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3470                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3471 {
3472   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3473   SALOMEDS::SObject_var aResultSO;
3474
3475   // On recupere le module pere dans l etude
3476   // On ajoute la categorie des hypotheses dans l etude si necessaire
3477   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3478   if (theFatherHomard->_is_nil())
3479   {
3480     MESSAGE("theFatherHomard->_is_nil()");
3481     return aResultSO._retn();
3482   }
3483
3484   // On ajoute la categorie des hypotheses dans l etude si necessaire
3485   SALOMEDS::SObject_var aSObject;
3486   if ( _tag_hypo == 0 )
3487   {
3488     _tag_gene += 1 ;
3489     _tag_hypo = _tag_gene ;
3490   }
3491   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3492   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3493   {
3494     MESSAGE("Ajout de la categorie des hypotheses");
3495     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3496     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3497   }
3498   else { MESSAGE("La categorie des hypotheses existe deja."); }
3499
3500 // Creation du resultat dans l'etude
3501   aResultSO = aStudyBuilder->NewObject(aSObject);
3502   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3503
3504   return aResultSO._retn();
3505 }
3506 //=============================================================================
3507 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3508                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3509                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3510 {
3511   MESSAGE("PublishYACSInStudy pour "<<theName);
3512   SALOMEDS::SObject_var aResultSO;
3513
3514   // On recupere le module pere dans l etude
3515   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3516   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3517   if (theFatherHomard->_is_nil())
3518   {
3519     MESSAGE("theFatherHomard->_is_nil()");
3520     return aResultSO._retn();
3521   }
3522   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3523   if ( _tag_yacs == 0 )
3524   {
3525     _tag_gene += 1 ;
3526     _tag_yacs = _tag_gene ;
3527   }
3528   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3529   SALOMEDS::SObject_var aSObject;
3530   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3531   {
3532     MESSAGE("Ajout de la categorie des schemas YACS");
3533     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3534     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3535   }
3536   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3537
3538 // Creation du resultat dans l'etude
3539   aResultSO = aStudyBuilder->NewObject(aSObject);
3540   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3541
3542   return aResultSO._retn();
3543 }
3544
3545 //=============================================================================
3546 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3547                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3548                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3549 {
3550   MESSAGE("PublishZoneStudy pour "<<theName);
3551   SALOMEDS::SObject_var aResultSO;
3552   if (CORBA::is_nil(theObject))
3553   {
3554     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3555     return aResultSO._retn();
3556   }
3557   if (theStudy->_is_nil())
3558   {
3559     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3560     return aResultSO._retn();
3561   }
3562   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3563   if (theFatherHomard->_is_nil())
3564   {
3565     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3566     return aResultSO._retn();
3567   }
3568
3569   // Caracteristique de la zone
3570   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3571   CORBA::Long ZoneType = myZone->GetType();
3572
3573   // On ajoute la categorie des zones dans l etude si necessaire
3574   if ( _tag_zone == 0 )
3575   {
3576     _tag_gene += 1 ;
3577     _tag_zone = _tag_gene ;
3578   }
3579   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3580   SALOMEDS::SObject_var aSObject;
3581   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3582   {
3583     MESSAGE("Ajout de la categorie des zones");
3584     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3585     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3586   }
3587   else { MESSAGE("La categorie des zones existe deja."); }
3588
3589   aResultSO = aStudyBuilder->NewObject(aSObject);
3590   std::string icone ;
3591   switch (ZoneType)
3592   {
3593     case 11 :
3594     { }
3595     case 12 :
3596     { }
3597     case 13 :
3598     { icone = "boxdxy_2.png" ;
3599       break ;
3600     }
3601     case 2 :
3602     { icone = "boxdxyz_2.png" ;
3603       break ;
3604     }
3605     case 31 :
3606     { }
3607     case 32 :
3608     { }
3609     case 33 :
3610     { icone = "disk_2.png" ;
3611       break ;
3612      }
3613     case 4 :
3614     { icone = "spherepoint_2.png" ;
3615       break ;
3616     }
3617     case 5 :
3618     { icone = "cylinderpointvector_2.png" ;
3619       break ;
3620     }
3621     case 61 :
3622     { }
3623     case 62 :
3624     { }
3625     case 63 :
3626     { icone = "diskwithhole_2.png" ;
3627       break ;
3628      }
3629     case 7 :
3630     { icone = "pipe_2.png" ;
3631       break ;
3632     }
3633   }
3634   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3635
3636   return aResultSO._retn();
3637 }
3638 //===========================================================================
3639 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3640                                       SALOMEDS::SObject_var aResultSO,
3641                                       const char* name, const char* comment, const char* icone, const char* ior)
3642 {
3643   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3644 //   MESSAGE("icone = "<<icone);
3645 //   MESSAGE("ior   = "<<ior);
3646   SALOMEDS::GenericAttribute_var anAttr ;
3647 //  Ajout du nom
3648   if ( name != NULL )
3649   {
3650     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3651     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3652     aNameAttrib->SetValue(name);
3653   }
3654
3655 //  Ajout du commentaire
3656   if ( comment != NULL )
3657   {
3658     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3659     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3660     aCommentAttrib->SetValue(comment);
3661   }
3662
3663 //  Ajout de l'icone
3664   if ( icone != NULL  )
3665   {
3666     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3667     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3668     aPixmap->SetPixMap(icone);
3669   }
3670
3671 //  Ajout de l ior
3672   if ( ior != NULL  )
3673   {
3674     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3675     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3676     anIOR->SetValue(ior);
3677   }
3678 };
3679
3680 //=====================================================================================
3681 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3682 {
3683   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3684
3685   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3686   ASSERT(!CORBA::is_nil(myCase));
3687   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3688   ASSERT(!CORBA::is_nil(aCaseSO));
3689
3690   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3691   ASSERT(!CORBA::is_nil(myBoundary));
3692   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3693   ASSERT(!CORBA::is_nil(aBoundarySO));
3694
3695   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3696
3697   aStudyBuilder->NewCommand();
3698
3699   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3700   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3701 //   aStudyBuilder->RemoveReference(aSubSO);
3702
3703   aStudyBuilder->CommitCommand();
3704
3705 };
3706 //=====================================================================================
3707 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3708 {
3709   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3710
3711   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3712   ASSERT(!CORBA::is_nil(myYACS));
3713   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3714   ASSERT(!CORBA::is_nil(aYACSSO));
3715
3716   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3717   ASSERT(!CORBA::is_nil(myCase));
3718   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3719   ASSERT(!CORBA::is_nil(aCaseSO));
3720
3721   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3722
3723   aStudyBuilder->NewCommand();
3724
3725   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3726   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3727
3728   aStudyBuilder->CommitCommand();
3729
3730 };
3731 //=============================================================================
3732 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3733 //  Option = 0 : fichier issu d'une importation
3734 //  Option = 1 : fichier issu d'une execution HOMARD
3735 {
3736   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3737   if (CORBA::is_nil(myCurrentStudy))
3738   {
3739     SALOME::ExceptionStruct es;
3740     es.type = SALOME::BAD_PARAM;
3741     es.text = "Invalid study context";
3742     throw SALOME::SALOME_Exception(es);
3743     return ;
3744   };
3745
3746 // Le module SMESH est-il actif ?
3747   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3748 //
3749   if (!CORBA::is_nil(aSmeshSO))
3750   {
3751 // On verifie que le fichier n est pas deja publie
3752     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3753     for (; aIter->More(); aIter->Next())
3754     {
3755       SALOMEDS::SObject_var  aSO = aIter->Value();
3756       SALOMEDS::GenericAttribute_var aGAttr;
3757       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3758       {
3759         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3760         CORBA::String_var value=anAttr->Value();
3761         if (strcmp((const char*)value,NomFich) == 0)
3762         {
3763           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3764           // Pour un fichier importe, on ne republie pas
3765           if ( Option == 0 ) { return; }
3766           // Pour un fichier calcule, on commence par faire la depublication
3767           else
3768           {
3769             MESSAGE ( "PublishResultInSmesh : depublication" );
3770             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3771             CORBA::String_var value2=anAttr2->Value();
3772             std::string MeshName = string(value2) ;
3773             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3774             DeleteResultInSmesh(NomFich, MeshName) ;
3775           }
3776         }
3777       }
3778     }
3779   }
3780
3781 // On enregistre le fichier
3782   MESSAGE( "Enregistrement du fichier");
3783   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3784   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3785   ASSERT(!CORBA::is_nil(aSmeshEngine));
3786   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3787   SMESH::DriverMED_ReadStatus theStatus;
3788   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3789
3790 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3791   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3792   for (int i = 0; i < mesMaillages->length();  i++)
3793   {
3794     MESSAGE( ". Mise a jour des attributs du maillage");
3795     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3796     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3797     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3798     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3799     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3800     anAttr->SetValue(NomFich);
3801     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3802     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3803     const char* icone ;
3804     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3805     else               { icone = "mesh_tree_mesh.png" ; }
3806     anAttr2->SetPixMap( icone );
3807   }
3808
3809 }
3810 //=============================================================================
3811 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3812 {
3813   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3814   if (CORBA::is_nil(myCurrentStudy))
3815   {
3816       SALOME::ExceptionStruct es;
3817       es.type = SALOME::BAD_PARAM;
3818       es.text = "Invalid study context";
3819       throw SALOME::SALOME_Exception(es);
3820       return ;
3821   };
3822
3823 // Le module SMESH est-il actif ?
3824   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3825 //
3826   if (CORBA::is_nil(aSmeshSO))
3827   {
3828       return ;
3829   };
3830 // On verifie que le fichier est deja publie
3831   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3832   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3833   for (; aIter->More(); aIter->Next())
3834   {
3835      SALOMEDS::SObject_var  aSO = aIter->Value();
3836      SALOMEDS::GenericAttribute_var aGAttr;
3837      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3838      {
3839        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3840        CORBA::String_var value=anAttr->Value();
3841        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3842        {
3843          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3844          {
3845            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3846            CORBA::String_var value2=anAttr2->Value();
3847            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3848            {
3849              myBuilder->RemoveObjectWithChildren( aSO ) ;
3850            }
3851          }
3852        }
3853      }
3854   }
3855   return ;
3856 }
3857 //=============================================================================
3858 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3859 {
3860   MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3861   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3862
3863   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3864   if (CORBA::is_nil(myIteration))
3865   {
3866       SALOME::ExceptionStruct es;
3867       es.type = SALOME::BAD_PARAM;
3868       es.text = "Invalid iterationStudy Object";
3869       throw SALOME::SALOME_Exception(es);
3870       return ;
3871   };
3872   const char* MeshFile = myIteration->GetMeshFile() ;
3873   const char* MeshName = myIteration->GetMeshName() ;
3874   CORBA::Long Option = -1 ;
3875   int etat = myIteration->GetState();
3876 // Iteration initiale
3877   if ( etat <= 0 )      { Option = 0 ; }
3878 // ou iteration calculee
3879   else if ( etat == 2 ) { Option = 1 ; }
3880 // Publication effective apres menage eventuel
3881   if ( Option >= 0 )
3882   {
3883     DeleteResultInSmesh(MeshFile, MeshName) ;
3884     PublishResultInSmesh(MeshFile, Option) ;
3885   }
3886
3887 }
3888 //=============================================================================
3889 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3890 {
3891 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3892   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3893
3894   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3895   if (CORBA::is_nil(myIteration))
3896   {
3897       SALOME::ExceptionStruct es;
3898       es.type = SALOME::BAD_PARAM;
3899       es.text = "Invalid iterationStudy Object";
3900       throw SALOME::SALOME_Exception(es);
3901       return ;
3902   };
3903
3904   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3905
3906   aStudyBuilder->NewCommand();
3907
3908   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3909 // Pour les fichiers med, on affiche une icone de maillage
3910 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3911 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3912   std::string icone ;
3913   std::string ior = " " ;
3914   if ( Commentaire[0] == 'M' )
3915   { icone = "med.png" ; }
3916   else
3917   { icone = "texte_2.png" ; }
3918   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3919
3920   aStudyBuilder->CommitCommand();
3921 }
3922 //
3923 //=============================================================================
3924 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3925 {
3926 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3927   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3928
3929   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3930   if (CORBA::is_nil(myYACS))
3931   {
3932       SALOME::ExceptionStruct es;
3933       es.type = SALOME::BAD_PARAM;
3934       es.text = "Invalid YACSStudy Object";
3935       throw SALOME::SALOME_Exception(es);
3936       return ;
3937   };
3938
3939   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3940
3941   aStudyBuilder->NewCommand();
3942
3943   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3944   std::string icone = "texte_2.png" ;
3945   std::string ior = " " ;
3946   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3947
3948   aStudyBuilder->CommitCommand();
3949 }
3950 //
3951 //=============================================================================
3952 //=============================================================================
3953 // YACS
3954 //=============================================================================
3955 //=============================================================================
3956 //=============================================================================
3957 // Creation d'un schema YACS
3958 // nomCas : nom du cas a traiter
3959 // FileName : nom du fichier contenant le script de lancement du calcul
3960 // DirName : le repertoire de lancement des calculs du schéma
3961 //=============================================================================
3962 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3963 {
3964   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3965   INFOS ( ". nomCas     : " << nomCas);
3966   INFOS ( ". ScriptFile : " << ScriptFile);
3967   INFOS ( ". DirName    : " << DirName);
3968   INFOS ( ". MeshFile   : " << MeshFile);
3969
3970   // A. Controle du nom :
3971   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3972   {
3973     SALOME::ExceptionStruct es;
3974     es.type = SALOME::BAD_PARAM;
3975     es.text = "This schema YACS has already been defined.";
3976     throw SALOME::SALOME_Exception(es);
3977     return 0;
3978   }
3979
3980   // B. Creation de l'objet
3981   HOMARD::HOMARD_YACS_var myYACS = newYACS();
3982   if (CORBA::is_nil(myYACS))
3983   {
3984     SALOME::ExceptionStruct es;
3985     es.type = SALOME::BAD_PARAM;
3986     es.text = "Unable to create the schema YACS";
3987     throw SALOME::SALOME_Exception(es);
3988     return 0;
3989   };
3990   myYACS->SetName( nomYACS ) ;
3991
3992   // C. Enregistrement
3993   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3994
3995   SALOMEDS::SObject_var aSO;
3996   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3997
3998   PublishCaseUnderYACS(nomYACS, nomCas);
3999
4000   // D. Caracterisation
4001   // D.1. Options
4002   myYACS->SetDirName( DirName ) ;
4003   myYACS->SetMeshFile( MeshFile ) ;
4004   myYACS->SetScriptFile( ScriptFile ) ;
4005   myYACS->SetCaseName( nomCas ) ;
4006   // D.2. Defaut
4007   int defaut_i ;
4008   // D.2.1. Type constant
4009   myYACS->SetType( 1 ) ;
4010   // D.2.2. Convergence
4011   defaut_i = GetYACSMaxIter() ;
4012   myYACS->SetMaxIter( defaut_i ) ;
4013   defaut_i = GetYACSMaxNode() ;
4014   myYACS->SetMaxNode( defaut_i ) ;
4015   defaut_i = GetYACSMaxElem() ;
4016   myYACS->SetMaxElem( defaut_i ) ;
4017   // D.3. Fichier de sauvegarde dans le repertoire du cas
4018   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4019   std::string dirnamecase = caseyacs->GetDirName() ;
4020   std::string XMLFile ;
4021   XMLFile = dirnamecase + "/schema.xml" ;
4022   myYACS->SetXMLFile( XMLFile.c_str() ) ;
4023
4024   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4025 }
4026 //=============================================================================
4027 // Ecriture d'un schema YACS
4028 //=============================================================================
4029 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4030 {
4031   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4032 // Le repertoire du cas
4033   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4034   ASSERT(!CORBA::is_nil(myYACS));
4035 // Le nom du fichier du schema
4036   std::string XMLFile ;
4037   XMLFile = myYACS->GetXMLFile() ;
4038
4039   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4040
4041   return codret ;
4042 }
4043 //=============================================================================
4044 // Ecriture d'un schema YACS sur un fichier donne
4045 //=============================================================================
4046 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4047 {
4048   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4049
4050   // A. Prealable
4051   int codret = 0;
4052
4053   // B. L'objet YACS
4054   // B.1. L'objet
4055   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4056   ASSERT(!CORBA::is_nil(myYACS));
4057   // B.2. Les caracteristiques
4058   std::string DirName = myYACS->GetDirName() ;
4059   std::string MeshFile = myYACS->GetMeshFile() ;
4060   std::string ScriptFile = myYACS->GetScriptFile() ;
4061   // B.3. Les caracteristiques de convergence
4062   int MaxIter = myYACS->GetMaxIter() ;
4063   int MaxNode = myYACS->GetMaxNode() ;
4064   int MaxElem = myYACS->GetMaxElem() ;
4065
4066   // C. Le cas
4067   // C.1. L'objet cas
4068   const char* nomCas = myYACS->GetCaseName();
4069   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4070   ASSERT(!CORBA::is_nil(myCase));
4071   // C.2. Les instructions python associees au cas
4072   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4073   std::string pythonCas = dumpCorbaCase.in();
4074   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4075
4076   // D. Les iterations
4077   // D.1. L'iteration initiale
4078   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4079   std::string Iter0Name = myCase->GetIter0Name() ;
4080   MESSAGE (". Iter0Name = " << Iter0Name);
4081   std::string MeshName = Iter0->GetMeshName();
4082   MESSAGE (". MeshName = " << MeshName);
4083   // D.2. L'iteration numero 1
4084   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4085   int numberOfIter = maListe->length();
4086   if ( numberOfIter > 1 )
4087   {
4088     MESSAGE (". numberOfIter = " << numberOfIter);
4089     SALOME::ExceptionStruct es ;
4090     es.type = SALOME::BAD_PARAM;
4091     std::string text = "Une seule iteration est permise." ;
4092     es.text = CORBA::string_dup(text.c_str());
4093     throw SALOME::SALOME_Exception(es);
4094     return 0;
4095   }
4096   std::string Iter1Name = std::string((*maListe)[0]);
4097   MESSAGE ("... Iter1Name = " << Iter1Name);
4098   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4099   // D.3. Les instructions python associees a l'iteration
4100   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4101   std::string pythonIter = dumpCorbaIter.in();
4102   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4103
4104   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4105   // E.1. La structure
4106   std::string nomHypo = Iter1->GetHypoName();
4107   MESSAGE (". nomHypo = " << nomHypo);
4108   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4109   ASSERT(!CORBA::is_nil(myHypo));
4110   // E.2. Les caracteristiques de l'adaptation
4111   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4112   ASSERT(ListTypes->length() == 3);
4113   int TypeAdap = (*ListTypes)[0];
4114 //   int TypeRaff = (*ListTypes)[1];
4115 //   int TypeDera = (*ListTypes)[2];
4116   // E.3. Les instructions python associees a l'hypothese
4117   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4118   std::string pythonHypo = dumpCorbaHypo.in();
4119   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4120
4121   // F. Le fichier du schema de reference
4122   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4123   std::string XMLFile_base ;
4124   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4125   else
4126   {
4127     SALOME::ExceptionStruct es ;
4128     es.type = SALOME::BAD_PARAM;
4129     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4130     es.text = CORBA::string_dup(text.c_str());
4131     throw SALOME::SALOME_Exception(es);
4132     return 0;
4133   }
4134   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4135 //   if ( _Langue ==
4136   MESSAGE("XMLFile_base ="<<XMLFile_base);
4137
4138   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4139   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4140   std::ifstream fichier( XMLFile_base.c_str() );
4141   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4142   {
4143     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4144     std::string ligne; // variable contenant chaque ligne lue
4145     std::string mot_cle;
4146     while ( std::getline( fichier, ligne ) )
4147     {
4148       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4149       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4150       ligne_bis >> mot_cle ;
4151       // G.1.2. Le maillage initial
4152       if ( mot_cle == "DataInit_MeshFile" )
4153       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4154       // G.1.3. Le script de lancement
4155       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4156       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4157       // G.1.4. Les options du cas
4158       else if ( mot_cle == "Iter_1_Case_Options" )
4159       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4160       // G.1.5. Execution de HOMARD : le repertoire du cas
4161       else if ( mot_cle == "HOMARD_Exec_DirName" )
4162       { myDriver->Texte_HOMARD_Exec_DirName(); }
4163       // G.1.6. Execution de HOMARD : le nom du maillage
4164       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4165       {
4166         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4167         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4168         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4169       }
4170       // G.1.7. Execution de HOMARD : les options de l'hypothese
4171       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4172       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4173       // G.1.8. Execution de HOMARD : les options de l'iteration
4174       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4175       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4176       // G.1.9. a. Creation eventuelles des zones et frontieres
4177       //        b. Enchainement
4178       else if ( mot_cle == "Iter_1" )
4179       {
4180         std::string texte_control = "" ;
4181         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4182         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4183         texte_control += myDriver->Texte_Iter_1_control() ;
4184         myDriver->TexteAdd(texte_control);
4185       }
4186       // G.1.10. Les tests de convergence
4187       else if ( mot_cle == "Analyse_Test_Convergence" )
4188       { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4189       // G.1.11. Les parametres
4190       else if ( mot_cle == "PARAMETRES" )
4191       { myDriver->TexteAddParametres(); }
4192       // G.1.n. La ligne est recopiee telle quelle
4193       else { myDriver->TexteAdd(ligne);  }
4194     }
4195     // G.2. Ecriture du texte dans le fichier
4196     if ( codret == 0 )
4197     { myDriver->CreeFichier(); }
4198   }
4199   else
4200   {
4201     SALOME::ExceptionStruct es;
4202     es.type = SALOME::BAD_PARAM;
4203     std::string text = "The reference file for the YACS schema cannot be read." ;
4204     es.text = CORBA::string_dup(text.c_str());
4205     throw SALOME::SALOME_Exception(es);
4206   }
4207
4208   delete myDriver;
4209
4210   // H. Publication du fichier dans l'arbre
4211
4212     std::string Commentaire = "xml" ;
4213     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4214
4215   return codret ;
4216 }
4217 //=============================================================================
4218 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4219 //=============================================================================
4220 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4221 {
4222   MESSAGE ( "YACSDriverTexteZone" );
4223   // A. Les zones associees a cette hypothese
4224   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4225   int numberOfZonesx2 = ListZone->length();
4226
4227   // B. Parcours des zones
4228   std::string texte_control ;
4229   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4230   {
4231     // 1. Reperage de la zone
4232     std::string ZoneName = std::string((*ListZone)[iaux]);
4233     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4234     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4235     ASSERT(!CORBA::is_nil(myZone));
4236     // 2. Les instructions python associees a la zone
4237     //    La premiere ligne est un commentaire a eliminer
4238     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4239     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4240     std::string pythonStructure_0 = dumpCorbaZone.in();
4241     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4242     std::istringstream tout (pythonStructure_0) ;
4243     std::string ligne ;
4244     std::string pythonStructure ;
4245     while ( std::getline( tout, ligne ) )
4246     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4247     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4248     // 3. Decodage du nom du service
4249     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4250     MESSAGE ( "... methode = " << methode);
4251     // 4. Mise en place des instructions
4252     int ZoneType = myZone->GetType();
4253     MESSAGE ( "... ZoneType = " << ZoneType);
4254     std::string texte_control_0 ;
4255     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4256     texte_control += texte_control_0 ;
4257     // 5. Decalage
4258     iaux ++ ;
4259   }
4260
4261   return texte_control ;
4262 }
4263 //=============================================================================
4264 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4265 //=============================================================================
4266 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4267 {
4268   MESSAGE ( "YACSDriverTexteBoundary" );
4269   // A. Les frontieres associees au cas
4270   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4271   int numberOfitems = ListBoundaryGroupType->length();
4272
4273   // B. Parcours des frontieres
4274   std::string texte_control ;
4275   std::list<std::string>  ListeBoundaryTraitees ;
4276   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4277   {
4278     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4279     MESSAGE ( "... BoundaryName = " << BoundaryName);
4280     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4281     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4282     int A_faire = 1 ;
4283     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4284     while (it != ListeBoundaryTraitees.end())
4285     {
4286       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4287       if ( BoundaryName == *it ) { A_faire = 0 ; }
4288       it++;
4289     }
4290     if ( A_faire == 1 )
4291     {
4292     // 1. Caracteristiques de la frontiere
4293       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4294       ASSERT(!CORBA::is_nil(myBoundary));
4295       // 2. Les instructions python associees a la frontiere
4296       //    La premiere ligne est un commentaire a eliminer
4297       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4298       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4299       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4300       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4301       std::istringstream tout (pythonStructure_0) ;
4302       std::string ligne ;
4303       std::string pythonStructure ;
4304       while ( std::getline( tout, ligne ) )
4305       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4306       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4307       // 3. Decodage du nom du service
4308       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4309       MESSAGE ( "... methode = " << methode);
4310       // 4. Mise en place des instructions
4311       int BoundaryType = myBoundary->GetType();
4312       MESSAGE ( "... BoundaryType = " << BoundaryType);
4313       const char* MeshName ;
4314       const char* MeshFile ;
4315       if (BoundaryType == 0)
4316       {
4317         MeshName = myBoundary->GetMeshName() ;
4318         MESSAGE ( ". MeshName = " << MeshName );
4319         MeshFile = myBoundary->GetMeshFile() ;
4320         MESSAGE ( ". MeshFile = " << MeshFile );
4321       }
4322       std::string texte_control_0 ;
4323       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, MeshFile );
4324       texte_control += texte_control_0 ;
4325       // 5. Memorisation du traitement
4326       ListeBoundaryTraitees.push_back( BoundaryName );
4327     }
4328   }
4329
4330   return texte_control ;
4331 }
4332 //
4333 //=============================================================================
4334 //=============================================================================
4335 // Next functions are inherited from SALOMEDS::Driver interface
4336 //=============================================================================
4337 //=============================================================================
4338 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4339                                       const char* theURL,
4340                                       CORBA::Boolean isMultiFile)
4341 {
4342   MESSAGE ("Save for theURL = "<< theURL);
4343   SALOMEDS::TMPFile_var aStreamFile;
4344
4345   // get temporary directory name
4346   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4347
4348   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4349   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4350
4351   // HOMARD data file name
4352   std::string aFileName = "";
4353   if (isMultiFile)
4354     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4355   aFileName += "_HOMARD.dat";
4356
4357   // initialize sequence of file names
4358   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4359   aFileSeq->length(1);
4360   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4361
4362   // get full path to the data file
4363   aFileName = tmpDir + aFileName;
4364
4365   // save data
4366   // -> create file
4367   std::ofstream f(aFileName.c_str());
4368
4369   // clear temporary id map
4370   context._idmap.clear();
4371
4372   int id = 1;
4373
4374   // -> save cases
4375   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4376   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4377     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4378     PortableServer::ServantBase_var aServant = GetServant(aCas);
4379     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4380     if (aCasServant) {
4381       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4382       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4383     }
4384   }
4385   // -> save zones
4386   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4387   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4388     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4389     PortableServer::ServantBase_var aServant = GetServant(aZone);
4390     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4391     if (aZoneServant) {
4392       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4393       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4394     }
4395   }
4396   // -> save hypotheses
4397   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4398   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4399     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4400     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4401     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4402     if (aHypoServant) {
4403       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4404       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4405     }
4406   }
4407   // -> save iterations
4408   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4409   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4410     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4411     PortableServer::ServantBase_var aServant = GetServant(aIter);
4412     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4413     if (aIterServant) {
4414       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4415       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4416     }
4417   }
4418   // -> save boundaries
4419   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4420   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4421     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4422     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4423     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4424     if (aBoundaryServant) {
4425       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4426       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4427     }
4428   }
4429   // -> close file
4430   MESSAGE ("close file");
4431   f.close();
4432
4433   // put temporary files to the stream
4434   MESSAGE ("put temporary files to the stream");
4435   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4436
4437   // remove temporary files
4438   MESSAGE ("remove temporary files");
4439   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4440
4441   // return data stream
4442   MESSAGE ("return data stream");
4443   return aStreamFile._retn();
4444 };
4445
4446 //===========================================================================
4447 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4448                                            const char* theURL,
4449                                            CORBA::Boolean isMultiFile)
4450 {
4451   // No specific ASCII persistence
4452   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4453   return aStreamFile._retn();
4454 };
4455
4456 //===========================================================================
4457 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4458                                    const SALOMEDS::TMPFile& theStream,
4459                                    const char* theURL,
4460                                    CORBA::Boolean isMultiFile)
4461 {
4462   MESSAGE ("Load pour theURL = "<< theURL);
4463   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4464
4465   // set current study
4466   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4467     SetCurrentStudy(aStudy);
4468
4469   // get temporary directory name
4470   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4471
4472   // Convert the stream into sequence of files to process
4473   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4474                                                                             tmpDir.c_str(),
4475                                                                             isMultiFile);
4476   // HOMARD data file name
4477   std::string aFileName = "";
4478   if (isMultiFile)
4479     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4480   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4481
4482   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4483
4484   // save data
4485   // -> create file
4486   std::ifstream f(aFileName.c_str());
4487
4488   // clear context
4489   context._mesCas.clear();
4490   context._mesHypotheses.clear();
4491   context._mesIterations.clear();
4492   context._mesZones.clear();
4493   context._mesBoundarys.clear();
4494   context._idmap.clear();
4495
4496   int id = 1;
4497   std::string line;
4498
4499   while (f) {
4500     std::getline(f, line);
4501     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4502     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4503     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4504     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4505     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4506     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4507     if (line.substr(0, bounSignature.size()) == bounSignature) {
4508       // re-create boundary
4509       MESSAGE ("Recreation de la frontiere" );
4510       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4511       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4512       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4513       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4514         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4515         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4516       }
4517     }
4518     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4519       // re-create case
4520       MESSAGE ("Recreation du cas" );
4521       HOMARD::HOMARD_Cas_var aCase = newCase();
4522       PortableServer::ServantBase_var aServant = GetServant(aCase);
4523       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4524       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4525         context._mesCas[aCase->GetName()] = aCase;
4526         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4527       }
4528     }
4529     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4530       // re-create hypothesis
4531       MESSAGE ("Recreation de l hypothese" );
4532       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4533       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4534       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4535       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4536         context._mesHypotheses[aHypo->GetName()] = aHypo;
4537         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4538       }
4539     }
4540     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4541       // re-create iteration
4542       MESSAGE ("Recreation de l'iteration" );
4543       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4544       PortableServer::ServantBase_var aServant = GetServant(aIter);
4545       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4546       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4547         context._mesIterations[aIter->GetName()] = aIter;
4548         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4549       }
4550     }
4551     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4552       MESSAGE ("Recreation de la zone" );
4553       // re-create zone
4554       HOMARD::HOMARD_Zone_var aZone = newZone();
4555       PortableServer::ServantBase_var aServant = GetServant(aZone);
4556       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4557       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4558         context._mesZones[aZone->GetName()] = aZone;
4559         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4560       }
4561     }
4562     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4563       MESSAGE ("Recreation du schema YACS" );
4564       // re-create YACS
4565       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4566       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4567       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4568       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4569         context._mesYACSs[aYACS->GetName()] = aYACS;
4570         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4571       }
4572     }
4573     id++;
4574   }
4575
4576   // -> close file
4577   f.close();
4578
4579   // Remove temporary files created from the stream
4580   if (!isMultiFile)
4581     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4582
4583   return true;
4584 };
4585
4586 //===========================================================================
4587 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4588                                         const SALOMEDS::TMPFile& theStream,
4589                                         const char* theURL,
4590                                         CORBA::Boolean isMultiFile)
4591 {
4592   // No specific ASCII persistence
4593   return Load(theComponent, theStream, theURL, isMultiFile);
4594 };
4595
4596 //===========================================================================
4597 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4598 {
4599   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4600     // clearing study context should be done here:
4601     // - destroy all servants and related CORBA objects
4602     // ... (TODO)
4603     // - remove context from myContextMap
4604     myContextMap.erase(theComponent->GetStudy()->StudyId());
4605     // - nullify myCurrentStudy
4606     myCurrentStudy = SALOMEDS::Study::_nil();
4607   }
4608 };
4609
4610 //===========================================================================
4611 char* HOMARD_Gen_i::ComponentDataType()
4612 {
4613   return CORBA::string_dup("HOMARD");
4614 };
4615
4616 //===========================================================================
4617 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4618                                             const char* IORString,
4619                                             CORBA::Boolean isMultiFile,
4620                                             CORBA::Boolean isASCII)
4621 {
4622   CORBA::String_var aString("");
4623   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4624     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4625     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4626     if (!CORBA::is_nil(anObj)) {
4627       PortableServer::ServantBase_var aServant = GetServant(anObj);
4628       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4629       if (aStorable) {
4630         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4631         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4632           if (it->second == aStorable) {
4633             std::stringstream os;
4634             os << it->first;
4635             aString = CORBA::string_dup(os.str().c_str());
4636           }
4637         }
4638       }
4639     }
4640   }
4641   return aString._retn();
4642 };
4643
4644 //===========================================================================
4645 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4646                                             const char* aLocalPersistentID,
4647                                             CORBA::Boolean isMultiFile,
4648                                             CORBA::Boolean isASCII)
4649 {
4650   CORBA::String_var aString("");
4651   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4652     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4653     int id = atoi(aLocalPersistentID);
4654     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4655       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4656       if (!CORBA::is_nil(object)) {
4657         aString = _orb->object_to_string(object);
4658       }
4659     }
4660   }
4661   return aString._retn();
4662 };
4663
4664 //===========================================================================
4665 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4666 {
4667   if(CORBA::is_nil(myCurrentStudy))
4668     return false;
4669
4670   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4671   if(!aCas->_is_nil())
4672     return true;
4673
4674   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4675   if(!aHypo->_is_nil())
4676     return true;
4677
4678   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4679   if(!aZone->_is_nil())
4680     return true;
4681
4682   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4683   if(!aBoundary->_is_nil())
4684     return true;
4685
4686   /* Iteration is not published directly
4687   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4688   if(!aIter->_is_nil())
4689     return true;
4690   */
4691   return false;
4692 };
4693
4694 //===========================================================================
4695 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4696 {
4697   // No Copy/Paste support
4698   return false;
4699 };
4700
4701 //===========================================================================
4702 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4703                                            CORBA::Long& theObjectID)
4704 {
4705   // No Copy/Paste support
4706   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4707   return aStreamFile._retn();
4708 };
4709
4710 //===========================================================================
4711 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4712                                         CORBA::Long theObjectID)
4713 {
4714   // No Copy/Paste support
4715   return false;
4716 };
4717
4718 //===========================================================================
4719 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4720                                                CORBA::Long theObjectID,
4721                                                SALOMEDS::SObject_ptr theSObject)
4722 {
4723   // No Copy/Paste support
4724   SALOMEDS::SObject_var aResultSO;
4725   return aResultSO._retn();
4726 };
4727
4728 //===========================================================================
4729 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4730 {
4731   PortableServer::Servant aServant = 0;
4732   if (!CORBA::is_nil(theObject)) {
4733     try {
4734       aServant = _poa->reference_to_servant(theObject);
4735     }
4736     catch (...) {
4737     }
4738   }
4739   return aServant;
4740 }
4741
4742 //==========================================================================
4743 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4744                                        CORBA::Boolean isPublished,
4745                                        CORBA::Boolean isMultiFile,
4746                                        CORBA::Boolean& isValidScript)
4747 {
4748    MESSAGE ("Entree dans DumpPython");
4749    isValidScript=1;
4750    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4751    if(CORBA::is_nil(aStudy))
4752      return new Engines::TMPFile(0);
4753
4754    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4755    if(CORBA::is_nil(aSO))
4756       return new Engines::TMPFile(0);
4757
4758    std::string aScript = "\"\"\"\n";
4759    aScript += "Python script for HOMARD\n";
4760    aScript += "Copyright 1996, 2011, 2015 EDF\n";
4761    aScript += "\"\"\"\n";
4762    aScript += "__revision__ = \"V1.2\"\n";
4763    aScript += "import HOMARD\n";
4764    if( isMultiFile )
4765       aScript += "import salome\n";
4766    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4767    if( isMultiFile ) {
4768       aScript += "def RebuildData(theStudy):\n";
4769       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4770    }
4771    else
4772       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4773    MESSAGE (". Au depart \n"<<aScript);
4774
4775
4776    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4777    {
4778     MESSAGE (". Ecritures des frontieres");
4779     aScript += "#\n# Creation of the boundaries";
4780     aScript +=  "\n# ==========================";
4781    }
4782    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4783    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4784         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4785    {
4786     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4787     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4788     std::string dumpBoundary = dumpCorbaBoundary.in();
4789     MESSAGE (dumpBoundary<<"\n");
4790     aScript += dumpBoundary;
4791    }
4792
4793
4794    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4795    {
4796     MESSAGE (". Ecritures des zones");
4797     aScript += "#\n# Creation of the zones";
4798     aScript +=  "\n# =====================";
4799    }
4800    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4801    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4802          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4803    {
4804     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4805     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4806     std::string dumpZone = dumpCorbaZone.in();
4807     MESSAGE (dumpZone<<"\n");
4808     aScript += dumpZone;
4809    }
4810
4811
4812    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4813    {
4814     MESSAGE (". Ecritures des hypotheses");
4815     aScript += "#\n# Creation of the hypotheses";
4816     aScript +=  "\n# ==========================";
4817    }
4818    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4819    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4820          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4821    {
4822     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4823     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4824     std::string dumpHypo = dumpCorbaHypo.in();
4825     MESSAGE (dumpHypo<<"\n");
4826     aScript += dumpHypo;
4827    }
4828
4829
4830    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4831    {
4832     MESSAGE (". Ecritures des cas");
4833     aScript += "#\n# Creation of the cases";
4834     aScript += "\n# =====================";
4835    }
4836    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4837    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4838         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4839         {
4840            std::string nomCas = (*it_cas).first;
4841            std::string dumpCas = std::string("\n# Creation of the case ") ;
4842            dumpCas +=  nomCas + std::string("\n");
4843            dumpCas += std::string("\t") + nomCas;
4844            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4845
4846            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4847            CORBA::String_var cIter0= myCase->GetIter0Name();
4848            std::string iter0 = cIter0.in();
4849
4850            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4851            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4852            std::string mesh0 = cMesh0.in();
4853            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4854            std::string meshName0 = cMeshName0.in();
4855            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4856            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4857            std::string dumpCas2= dumpCorbaCase.in();
4858
4859            MESSAGE (dumpCas<<dumpCas2<<"\n");
4860            aScript += dumpCas + dumpCas2;
4861         };
4862
4863
4864    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4865    {
4866     MESSAGE (". Ecritures des iterations");
4867     aScript += "#\n# Creation of the iterations" ;
4868     aScript += "\n# ==========================";
4869    }
4870    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4871    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4872         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4873    {
4874     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4875     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4876     std::string dumpIter = dumpCorbaIter.in();
4877     MESSAGE (dumpIter<<"\n");
4878     aScript += dumpIter;
4879    }
4880
4881
4882    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4883    {
4884     MESSAGE (". Ecritures des schemas YACS");
4885     aScript += "#\n# Creation of the schemas YACS";
4886     aScript +=  "\n# ============================";
4887    }
4888    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4889    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4890          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4891    {
4892     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4893     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4894     std::string dumpYACS = dumpCorbaYACS.in();
4895     MESSAGE (dumpYACS<<"\n");
4896     aScript += dumpYACS;
4897    }
4898
4899   MESSAGE (". Ecritures finales");
4900   if( isMultiFile )
4901     aScript += "\n\tpass";
4902   aScript += "\n";
4903
4904   if( !isMultiFile ) // remove unnecessary tabulation
4905     aScript = RemoveTabulation( aScript );
4906
4907 //   MESSAGE ("A ecrire \n"<<aScript);
4908   const size_t aLen = strlen(aScript.c_str());
4909   char* aBuffer = new char[aLen+1];
4910   strcpy(aBuffer, aScript.c_str());
4911
4912   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4913   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4914
4915   MESSAGE ("Sortie de DumpPython");
4916   return aStreamFile._retn();
4917 }
4918
4919
4920 //=============================================================================
4921 //=============================================================================
4922 // Utilitaires
4923 //=============================================================================
4924 //=============================================================================
4925 void HOMARD_Gen_i::IsValidStudy( )
4926 {
4927 //   MESSAGE( "IsValidStudy" );
4928   if (CORBA::is_nil(myCurrentStudy))
4929   {
4930     SALOME::ExceptionStruct es;
4931     es.type = SALOME::BAD_PARAM;
4932     es.text = "Invalid study context";
4933     throw SALOME::SALOME_Exception(es);
4934   };
4935   return ;
4936 }
4937
4938 //=============================================================================
4939 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4940 {
4941   std::string casename = std::string("") ;
4942   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4943   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4944   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4945   {
4946    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4947    {
4948      casename = std::string(it->second->GetName()) ;
4949      break ;
4950    }
4951   }
4952   return CORBA::string_dup( casename.c_str() );
4953 }
4954 /*//=============================================================================
4955 void SALOMEException( std::string message )
4956 {
4957   SALOME::ExceptionStruct es;
4958   es.type = SALOME::BAD_PARAM;
4959   es.text = message;
4960   throw SALOME::SALOME_Exception(es);
4961   return ;
4962 }*/
4963 //=============================================================================
4964 char* HOMARD_Gen_i::getVersion()
4965 {
4966 #if HOMARD_DEVELOPMENT
4967   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4968 #else
4969   return CORBA::string_dup(HOMARD_VERSION_STR);
4970 #endif
4971 }
4972 //===============================================================================
4973 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
4974 // ligne : la ligne a manipuler
4975 // caractere : le caractere a reperer
4976 // option : 0 : la chaine avant la premiere apparition du caractere
4977 //          1 : la chaine apres la premiere apparition du caractere
4978 //          2 : la chaine avant la derniere apparition du caractere
4979 //          3 : la chaine apres la derniere apparition du caractere
4980 // Si le caractere est absent, on retourne la chaine totale
4981 //===============================================================================
4982 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
4983 {
4984 //   MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4985 //
4986   std::string chaine = ligne ;
4987   int position ;
4988   if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
4989   else              { position = ligne.find_last_of( caractere ) ; }
4990 //   MESSAGE("position = "<<position);
4991 //   MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
4992 //   MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
4993 //
4994   if ( position != std::string::npos )
4995   {
4996     if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
4997     else                                      { chaine = ligne.substr( position+1 ) ; }
4998   }
4999   return chaine ;
5000 //
5001 }
5002 //=============================================================================
5003 //=============================================================================
5004 // Gestion des preferences
5005 //=============================================================================
5006 //=============================================================================
5007 // Decodage du fichier d'arcihvage des preferences
5008 //
5009 void HOMARD_Gen_i::SetPreferences( )
5010 {
5011   MESSAGE ( "SetPreferences" );
5012
5013   std::string ligne, mot_cle, salome_version ;
5014   bool ok = true ;
5015
5016   // A. Les valeurs par defaut ; elles doivent etre coherentes
5017   std::string LanguageShort = "en" ;
5018   int PublisMeshIN = 0 ;
5019   int PublisMeshOUT = 0 ;
5020   int YACSMaxIter = 0 ;
5021   int YACSMaxNode = 0 ;
5022   int YACSMaxElem = 0 ;
5023   std::string YACSTypeTestchaine = "None" ;
5024
5025   // B. La version de salome
5026   // Cela se presente sous la forme :
5027   // [SALOME KERNEL] : 7.3.0
5028   std::string File ;
5029   File  = getenv("KERNEL_ROOT_DIR") ;
5030   File += "/bin/salome/VERSION" ;
5031   MESSAGE ( "File = "<<File ) ;
5032   std::ifstream fichier0( File.c_str() ) ;
5033   if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5034   {
5035     std::string ligne; // variable contenant chaque ligne lue
5036     while ( std::getline( fichier0, ligne ) )
5037     {
5038       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5039       ligne_bis >> mot_cle ;
5040       if ( mot_cle == "[SALOME" )
5041       {
5042         salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5043 //         MESSAGE ( "salome_version = "<<salome_version<<"|||");
5044         break ;
5045       }
5046     }
5047   }
5048   else { ok = false ; }
5049
5050   // B. Decodage du fichier de preferences
5051   if ( ok )
5052   {
5053     std::string PrefFile ;
5054     PrefFile  = getenv("HOME") ;
5055     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5056     MESSAGE ( "PrefFile = "<<PrefFile ) ;
5057
5058     std::ifstream fichier( PrefFile.c_str() );
5059     if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5060     {
5061       bool section_langue = false ;
5062       bool section_homard = false ;
5063       while ( std::getline( fichier, ligne ) )
5064       {
5065         std::string chaine ;
5066         // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5067         std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5068         ligne_bis >> mot_cle ;
5069
5070         // 2. Les sections
5071         // 2.1. Debut d'une section
5072   //       MESSAGE(mot_cle);
5073         if ( mot_cle == "<section" )
5074         { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5075           ligne_bis >> mot_cle ;
5076           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5077           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5078           if ( chaine == "language" ) { section_langue = true ; }
5079           if ( chaine == "HOMARD" )   { section_homard = true ; }
5080   //         MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5081         }
5082         // 2.2. Fin d'une section
5083         else if ( mot_cle == "</section>" )
5084         { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5085           section_langue = false ;
5086           section_homard = false ; }
5087
5088         // 3. Parametres
5089         // 3.1. La langue
5090         else if ( section_langue || section_homard )
5091         { MESSAGE ( "a decoder : "<< ligne);
5092 //        La valeur : entre les deux premieres quotes
5093           chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5094 //           MESSAGE("chaine 1 = |"<<chaine<<"|");
5095           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5096 //           MESSAGE("chaine = |"<<chaine<<"|");
5097 //        Le mot_cle : entre les deux dernieres quotes
5098           std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5099 //           MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5100           chaine2 = GetStringInTexte ( chaine2,  "\"", 3 ) ;
5101 //           MESSAGE("chaine2 = |"<<chaine2<<"|");
5102           // 3.1. La langue
5103           if ( section_langue )
5104           { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5105           // 3.2. HOMARD
5106           if ( section_homard )
5107           {
5108             std::istringstream chainebis( chaine ) ;
5109             // 3.2.1. Les publications
5110             if ( chaine2 == "publish_mesh_in" )  { chainebis >> PublisMeshIN ; }
5111             if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5112             // 3.2.2. Les maximum pour YACS
5113             if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5114             if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5115             if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5116             if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5117           }
5118         }
5119       }
5120     }
5121   }
5122
5123   // C. Enregistrements
5124   MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5125   SetLanguageShort( LanguageShort.c_str() ) ;
5126
5127   MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5128   SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5129
5130   MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5131   SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5132
5133   MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5134   int YACSTypeTest ;
5135   if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest &gt; VRef" ) )      { YACSTypeTest = 1 ; }
5136   else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest &lt; VRef" ) ) { YACSTypeTest = 2 ; }
5137   else                                                                                                { YACSTypeTest = 0 ; }
5138   MESSAGE ("==> TypeTest = " << YACSTypeTest );
5139   SetYACSConvergenceType( YACSTypeTest ) ;
5140
5141   return ;
5142 }
5143 //===============================================================================
5144 // Langue de SALOME
5145 //===============================================================================
5146 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5147 {
5148 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5149   _LangueShort = LanguageShort ;
5150   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5151   else                        { _Langue = "English" ; }
5152   return ;
5153 }
5154 char* HOMARD_Gen_i::GetLanguageShort()
5155 {
5156 //   MESSAGE ("GetLanguageShort");
5157   return CORBA::string_dup( _LangueShort.c_str() );
5158 }
5159 //===============================================================================
5160 // Options de publications
5161 //===============================================================================
5162 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5163 {
5164   _PublisMeshIN  = PublisMeshIN  ;
5165   _PublisMeshOUT = PublisMeshOUT ;
5166   return ;
5167 }
5168 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5169 {
5170   return _PublisMeshIN ;
5171 }
5172 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5173 {
5174   return _PublisMeshOUT ;
5175 }
5176 //===============================================================================
5177 // YACS - test de convergence
5178 //===============================================================================
5179 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5180 {
5181   _YACSMaxIter = YACSMaxIter ;
5182   _YACSMaxNode = YACSMaxNode ;
5183   _YACSMaxElem = YACSMaxElem ;
5184   return ;
5185 }
5186 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5187 {
5188   return _YACSMaxIter ;
5189 }
5190 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5191 {
5192   return _YACSMaxNode ;
5193 }
5194 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5195 {
5196   return _YACSMaxElem ;
5197 }
5198 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5199 {
5200   _YACSTypeTest = YACSTypeTest ;
5201   return ;
5202 }
5203 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5204 {
5205   return _YACSTypeTest ;
5206 }
5207
5208 //=============================================================================
5209 extern "C"
5210 {
5211   HOMARDENGINE_EXPORT
5212   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5213                                                   PortableServer::POA_ptr poa,
5214                                                   PortableServer::ObjectId* contId,
5215                                                   const char* instanceName,
5216                                                   const char* interfaceName)
5217   {
5218     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5219     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5220     return myHOMARD_Gen->getId();
5221   }
5222 }