Salome HOME
Merge branch 'gn/evol'
[modules/homard.git] / src / HOMARD_I / HOMARD_Gen_i.cxx
1 // Copyright (C) 2011-2015  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 TypeConf = 0 ;
1320   int Pyram = 0 ;
1321   char* MeshName ;
1322   char* MeshFile ;
1323   // le constructeur de ifstream permet d'ouvrir un fichier en lecture
1324   std::ifstream fichier( file_configuration.c_str() );
1325   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1326   {
1327     std::string ligne; // variable contenant chaque ligne lue
1328     std::string mot_cle;
1329     std::string argument;
1330     int decalage;
1331     // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1332     while ( std::getline( fichier, ligne ) )
1333     {
1334       // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1335       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1336       ligne_bis >> mot_cle ;
1337       // B.2. Des valeurs entieres : le second bloc de la ligne
1338       if ( mot_cle == "NumeIter" )
1339       {
1340         ligne_bis >> NumeIter ;
1341         NumeIter += 1 ;
1342       }
1343       // B.3. Des valeurs caracteres brutes : le second bloc de la ligne est la valeur
1344       else if ( ( mot_cle == "TypeConf" ) || ( mot_cle == "TypeElem" ) )
1345       {
1346         ligne_bis >> argument ;
1347
1348         if ( mot_cle == "TypeConf" )
1349         {
1350           if      ( argument == "conforme" )                { TypeConf = 1 ; }
1351           else if ( argument == "non_conforme_1_noeud" )    { TypeConf = 2 ; }
1352           else if ( argument == "non_conforme_1_arete" )    { TypeConf = 3 ; }
1353           else if ( argument == "non_conforme_indicateur" ) { TypeConf = 4 ; }
1354         }
1355         else if ( mot_cle == "TypeElem" )
1356         {
1357           if ( argument == "ignore_pyra" ) { Pyram = 1 ; }
1358           else if ( argument == "HOMARD" ) { Pyram = 0 ; }
1359         }
1360       }
1361       // B.4. Des valeurs caracteres : le deuxieme bloc de la ligne peut etre encadre par des quotes :
1362       //                               il faut les supprimer
1363       else if ( ( mot_cle == "CCNoMNP1" ) || ( mot_cle == "CCMaiNP1" ) )
1364       {
1365         ligne_bis >> argument ;
1366         if ( argument[0] == '"' ) { decalage = 1 ; }
1367         else                      { decalage = 0 ; }
1368         size_t size = argument.size() + 1 - 2*decalage ;
1369
1370         if ( mot_cle == "CCNoMNP1" )
1371         {
1372           MeshName = new char[ size ];
1373           strncpy( MeshName, argument.c_str()+decalage, size );
1374           MeshName[size-1] = '\0' ;
1375         }
1376         else if ( mot_cle == "CCMaiNP1" )
1377         {
1378           MeshFile = new char[ size ];
1379           strncpy( MeshFile, argument.c_str()+decalage, size );
1380           MeshFile[size-1] = '\0' ;
1381         }
1382       }
1383     }
1384     MESSAGE ( "==> TypeConf   : " << TypeConf ) ;
1385     MESSAGE ( "==> MeshName   : " << MeshName ) ;
1386     MESSAGE ( "==> MeshFile   : " << MeshFile ) ;
1387     MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1388     MESSAGE ( "==> Pyram      : " << Pyram ) ;
1389   }
1390   else
1391   {
1392     SALOME::ExceptionStruct es;
1393     es.type = SALOME::BAD_PARAM;
1394     std::string text = "The configuration file cannot be read." ;
1395     es.text = CORBA::string_dup(text.c_str());
1396     throw SALOME::SALOME_Exception(es);
1397   }
1398
1399   // C. Creation effective du cas
1400
1401   int option = 1 ;
1402   if ( _PublisMeshIN != 0 ) option = 2 ;
1403   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, option) ;
1404
1405   // D. Parametrages lus dans le fichier de configuration
1406
1407   myCase->SetConfType (TypeConf) ;
1408   myCase->SetPyram (Pyram) ;
1409
1410   // E. Copie du fichier de maillage homard
1411   // E.1. Repertoire associe au cas
1412   char* nomDirCase = myCase->GetDirName() ;
1413   // E.2. Repertoire associe a l'iteration de ce cas
1414   char* IterName ;
1415   IterName = myCase->GetIter0Name() ;
1416   HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1417   char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1418   Iter->SetDirNameLoc(nomDirIter);
1419   std::string nomDirIterTotal ;
1420   nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1421 #ifndef WIN32
1422   if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1423 #else
1424   if (_mkdir(nomDirIterTotal.c_str()) != 0)
1425 #endif
1426   {
1427     MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1428     SALOME::ExceptionStruct es;
1429     es.type = SALOME::BAD_PARAM;
1430     std::string text = "The directory for the computation cannot be created." ;
1431     es.text = CORBA::string_dup(text.c_str());
1432     throw SALOME::SALOME_Exception(es);
1433   }
1434   // E.3. Copie du maillage HOMARD au format MED
1435   codret = CHDIR(DirNameStart) ;
1436   std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1437   MESSAGE ( "commande : " << commande ) ;
1438   codret = system(commande.c_str()) ;
1439   MESSAGE ( "codret : " << codret ) ;
1440   if ( codret != 0 )
1441   {
1442     SALOME::ExceptionStruct es;
1443     es.type = SALOME::BAD_PARAM;
1444     es.text = "The starting point for the case cannot be copied into the working directory.";
1445     throw SALOME::SALOME_Exception(es);
1446     return 0;
1447   };
1448
1449   // F. Menage
1450
1451   delete[] MeshName ;
1452   delete[] MeshFile ;
1453
1454   CHDIR(nomDirWork.c_str());
1455   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1456 }
1457 //=============================================================================
1458 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1459 //
1460 // nomCas : nom du cas a creer
1461 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1462 //
1463 {
1464   INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1465
1466   std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1467
1468   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1469   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1470
1471   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1472 }
1473 //=============================================================================
1474 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1475 //
1476 // nomCas : nom du cas a creer
1477 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1478 // Number : numero de l'iteration de depart
1479 //
1480 {
1481   INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1482   if ( Number < 0 )
1483   {
1484     SALOME::ExceptionStruct es;
1485     es.type = SALOME::BAD_PARAM;
1486     es.text = "The number of iteration must be positive.";
1487     throw SALOME::SALOME_Exception(es);
1488     return 0;
1489   };
1490
1491   std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1492
1493   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1494   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1495
1496   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1497 }
1498 //=============================================================================
1499 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1500 //
1501 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1502 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1503 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1504 //
1505 {
1506   MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1507   std::string nomDirWork = getenv("PWD") ;
1508   std::string DirNameStartIter ;
1509   int codret ;
1510   int NumeIterMax = -1 ;
1511
1512   // A.1. Controle du repertoire de depart du cas
1513   codret = CHDIR(DirNameStart) ;
1514   if ( codret != 0 )
1515   {
1516     SALOME::ExceptionStruct es;
1517     es.type = SALOME::BAD_PARAM;
1518     es.text = "The directory of the case for the pursuit does not exist.";
1519     throw SALOME::SALOME_Exception(es);
1520     return 0;
1521   };
1522   // A.2. Reperage des sous-repertoire du repertoire de reprise
1523   bool existe = false ;
1524 #ifndef WIN32
1525   DIR *dp;
1526   struct dirent *dirp;
1527   dp  = opendir(DirNameStart);
1528   while ( (dirp = readdir(dp)) != NULL ) {
1529     std::string DirName_1(dirp->d_name);
1530 #else
1531   HANDLE hFind = INVALID_HANDLE_VALUE;
1532   WIN32_FIND_DATA ffd;
1533   hFind = FindFirstFile(DirNameStart, &ffd);
1534   if (INVALID_HANDLE_VALUE != hFind) {
1535     while (FindNextFile(hFind, &ffd) != 0) {
1536       std::string DirName_1 = "";
1537       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1538         DirName_1 = std::string(ffd.cFileName);
1539       }
1540 #endif
1541     if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1542     {
1543       if ( CHDIR(DirName_1.c_str()) == 0 )
1544       {
1545 //      On cherche le fichier de configuration dans ce sous-repertoire
1546         codret = CHDIR(DirNameStart);
1547 #ifndef WIN32
1548         DIR *dp_1;
1549         struct dirent *dirp_1;
1550         dp_1  = opendir(DirName_1.c_str()) ;
1551         while ( (dirp_1 = readdir(dp_1)) != NULL )
1552         {
1553           std::string file_name_1(dirp_1->d_name);
1554 #else
1555         HANDLE hFind1 = INVALID_HANDLE_VALUE;
1556         WIN32_FIND_DATA ffd1;
1557         hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1558         while (FindNextFile(hFind1, &ffd1) != 0)
1559         {
1560           if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
1561           std::string file_name_1(ffd1.cFileName);
1562 #endif
1563           int bilan = file_name_1.find("HOMARD.Configuration.") ;
1564           if ( bilan != string::npos )
1565           {
1566   // Decodage du fichier pour trouver le numero d'iteration
1567             CHDIR(DirName_1.c_str()) ;
1568
1569             std::ifstream fichier( file_name_1.c_str() );
1570             if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1571             {
1572               int NumeIter ;
1573               std::string ligne; // variable contenant chaque ligne lue
1574               std::string mot_cle;
1575               // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1576               while ( std::getline( fichier, ligne ) )
1577               {
1578                 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1579                 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1580                 ligne_bis >> mot_cle ;
1581                 if ( mot_cle == "NumeIter" )
1582                 {
1583                   ligne_bis >> NumeIter ;
1584                   NumeIter += 1 ;
1585 //                   MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1586                   if ( Number == - 1 )
1587                   {
1588                     if ( NumeIter >= NumeIterMax )
1589                     {
1590                       NumeIterMax = NumeIter ;
1591                       DirNameStartIter = DirName_1 ;
1592                     }
1593                   }
1594                   else
1595                   {
1596                     if ( NumeIter == Number )
1597                     {
1598                       DirNameStartIter = DirName_1 ;
1599                       existe = true ;
1600                       break ;
1601                     }
1602                   }
1603                 }
1604               }
1605             }
1606             else
1607             {
1608               SALOME::ExceptionStruct es;
1609               es.type = SALOME::BAD_PARAM;
1610               std::string text = "The configuration file cannot be read." ;
1611               es.text = CORBA::string_dup(text.c_str());
1612               throw SALOME::SALOME_Exception(es);
1613             }
1614             CHDIR(DirNameStart) ;
1615           }
1616           if ( existe ) { break ; }
1617         }
1618 #ifndef WIN32
1619         closedir(dp_1);
1620 #else
1621         FindClose(hFind1);
1622 #endif
1623         if ( existe ) { break ; }
1624      }
1625     }
1626   }
1627 #ifndef WIN32
1628   closedir(dp);
1629 #else
1630   FindClose(hFind);
1631 #endif
1632   CHDIR(nomDirWork.c_str());
1633
1634   if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1635   {
1636     SALOME::ExceptionStruct es;
1637     es.type = SALOME::BAD_PARAM;
1638     es.text = "The directory of the iteration does not exist.";
1639     throw SALOME::SALOME_Exception(es);
1640     return 0;
1641   };
1642
1643   return DirNameStartIter ;
1644 }
1645 //=============================================================================
1646 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)
1647 //
1648 // nomCas : nom du cas a creer
1649 // MeshName, MeshFile : nom et fichier du maillage correspondant
1650 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1651 //              1 : le maillage fourni peut ne pas exister ==> on continue si absent
1652 //             -1 : le maillage n'est pas fourni
1653 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1654 // Option : multiple de nombres premiers
1655 //         1 : aucune option
1656 //        x2 : publication du maillage dans SMESH
1657 {
1658   MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1659   MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1660   MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1661 //
1662   // A. Controles
1663   // A.1. L'etude
1664   IsValidStudy () ;
1665
1666   // A.2. Controle du nom :
1667   if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1668   {
1669     SALOME::ExceptionStruct es;
1670     es.type = SALOME::BAD_PARAM;
1671     es.text = "This case has already been defined.";
1672     throw SALOME::SALOME_Exception(es);
1673     return 0;
1674   };
1675
1676   // A.3. Controle du fichier du maillage
1677   int existeMeshFile ;
1678   if ( MeshOption >= 0 )
1679   {
1680     existeMeshFile = MEDFileExist ( MeshFile ) ;
1681     MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1682     if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1683     {
1684       SALOME::ExceptionStruct es;
1685       es.type = SALOME::BAD_PARAM;
1686       es.text = "The mesh file does not exist.";
1687       throw SALOME::SALOME_Exception(es);
1688       return 0;
1689     }
1690   }
1691   else { existeMeshFile = 0 ; }
1692
1693   // B. Creation de l'objet cas et publication
1694 //   MESSAGE ( "CreateCase0 : Creation de l'objet" );
1695   HOMARD::HOMARD_Cas_var myCase = newCase();
1696   myCase->SetName(nomCas);
1697   SALOMEDS::SObject_var aSO;
1698   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1699   myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1700
1701   // C. Caracteristiques du maillage
1702   if ( existeMeshFile != 0 )
1703   {
1704   // Les valeurs extremes des coordonnees
1705 //     MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1706     std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1707     HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1708     if (LesExtremes.size()!=10) { return false; }
1709     aSeq->length(10) ;
1710     for (int i =0 ; i< LesExtremes.size() ; i++)
1711         aSeq[i]=LesExtremes[i] ;
1712     myCase->SetBoundingBox(aSeq) ;
1713   // Les groupes
1714 //     MESSAGE ( "CreateCase0 : Les groupes" );
1715     std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile) ;
1716     HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1717     aSeqGroupe->length(LesGroupes.size());
1718     std::set<std::string>::const_iterator it ;
1719     int i = 0 ;
1720     for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1721       aSeqGroupe[i++]=(*it).c_str() ;
1722     myCase->SetGroups(aSeqGroupe) ;
1723   }
1724
1725   // D. L'iteration initiale du cas
1726   MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1727   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1728   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1729   int monNum = 0;
1730   std::string NomIteration = std::string(MeshName) ;
1731   while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1732   {
1733     std::ostringstream nom;
1734     nom << MeshName << monNum;
1735     NomIteration = nom.str();
1736     monNum += 1;
1737   }
1738   MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1739
1740   // D.2. Creation de l'iteration
1741   HOMARD::HOMARD_Iteration_var anIter = newIteration();
1742   myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1743   anIter->SetName(NomIteration.c_str());
1744   AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1745
1746   // D.4. Maillage correspondant
1747   if ( existeMeshFile != 0 )
1748   {
1749     anIter->SetMeshFile(MeshFile);
1750     if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1751   }
1752   anIter->SetMeshName(MeshName);
1753
1754   // D.5. Numero d'iteration
1755   anIter->SetNumber(NumeIter);
1756
1757   // D.6. Etat
1758   SetEtatIter(NomIteration.c_str(), -NumeIter);
1759 //
1760
1761   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1762 }
1763 //=============================================================================
1764 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1765 {
1766   INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1767   IsValidStudy () ;
1768
1769   // A. Controle du nom :
1770   if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1771   {
1772     SALOME::ExceptionStruct es;
1773     es.type = SALOME::BAD_PARAM;
1774     es.text = "This hypothesis has already been defined.";
1775     throw SALOME::SALOME_Exception(es);
1776     return 0;
1777   }
1778
1779   // B. Creation de l'objet
1780   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1781   if (CORBA::is_nil(myHypothesis))
1782   {
1783     SALOME::ExceptionStruct es;
1784     es.type = SALOME::BAD_PARAM;
1785     es.text = "Unable to create the hypothesis";
1786     throw SALOME::SALOME_Exception(es);
1787     return 0;
1788   };
1789   myHypothesis->SetName(nomHypothesis);
1790
1791   // C. Enregistrement
1792   myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1793
1794   SALOMEDS::SObject_var aSO;
1795   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1796
1797   // D. Valeurs par defaut des options avancees
1798   myHypothesis->SetNivMax(-1);
1799   myHypothesis->SetDiamMin(-1.0);
1800   myHypothesis->SetAdapInit(0);
1801   myHypothesis->SetExtraOutput(1);
1802
1803   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1804 }
1805
1806 //=============================================================================
1807 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1808 //=============================================================================
1809 {
1810   INFOS ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
1811   IsValidStudy () ;
1812
1813   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1814   if (CORBA::is_nil(myIterationParent))
1815   {
1816     SALOME::ExceptionStruct es;
1817     es.type = SALOME::BAD_PARAM;
1818     es.text = "The parent iteration is not defined.";
1819     throw SALOME::SALOME_Exception(es);
1820     return 0;
1821   };
1822
1823   const char* nomCas = myIterationParent->GetCaseName();
1824   MESSAGE ("CreateIteration : nomCas = " << nomCas);
1825   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1826   if (CORBA::is_nil(myCase))
1827   {
1828     SALOME::ExceptionStruct es;
1829     es.type = SALOME::BAD_PARAM;
1830     es.text = "Invalid case context";
1831     throw SALOME::SALOME_Exception(es);
1832     return 0;
1833   };
1834   const char* nomDirCase = myCase->GetDirName();
1835
1836   // Controle du nom :
1837   if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1838   {
1839     SALOME::ExceptionStruct es;
1840     es.type = SALOME::BAD_PARAM;
1841     es.text = "This iteration has already been defined.";
1842     throw SALOME::SALOME_Exception(es);
1843     return 0;
1844   };
1845
1846    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1847    if (CORBA::is_nil(myIteration))
1848   {
1849     SALOME::ExceptionStruct es;
1850     es.type = SALOME::BAD_PARAM;
1851     es.text = "Unable to create the iteration";
1852     throw SALOME::SALOME_Exception(es);
1853     return 0;
1854   };
1855   myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1856 // Nom de l'iteration et du maillage
1857   myIteration->SetName(NomIteration);
1858   myIteration->SetMeshName(NomIteration);
1859   myIteration->SetState(1);
1860
1861   int numero = myIterationParent->GetNumber() + 1;
1862   myIteration->SetNumber(numero);
1863
1864 // Nombre d'iterations deja connues pour le cas, permettant
1865 // la creation d'un sous-repertoire unique
1866   int nbitercase = myCase->GetNumberofIter();
1867   char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1868   myIteration->SetDirNameLoc(nomDirIter);
1869
1870 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1871 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1872 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1873 // situation la plus frequente.
1874 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1875 // le nombre d'iterations du cas permet d'eviter les collisions.
1876   int jaux ;
1877   if      ( nbitercase <    100 ) { jaux = 2 ; }
1878   else if ( nbitercase <   1000 ) { jaux = 3 ; }
1879   else if ( nbitercase <  10000 ) { jaux = 4 ; }
1880   else if ( nbitercase < 100000 ) { jaux = 5 ; }
1881   else                            { jaux = 9 ; }
1882   std::ostringstream iaux ;
1883   iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1884   std::stringstream MeshFile;
1885   MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1886   myIteration->SetMeshFile(MeshFile.str().c_str());
1887
1888 // Association avec le cas
1889   std::string label = "IterationHomard_" + std::string(nomIterParent);
1890   AssociateCaseIter(nomCas, NomIteration, label.c_str());
1891 // Lien avec l'iteration precedente
1892   myIterationParent->LinkNextIteration(NomIteration);
1893   myIteration->SetIterParentName(nomIterParent);
1894   // Gestion de l'arbre d'etudes
1895   SALOMEDS::SObject_var aIterSOParent = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIterationParent)));
1896   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
1897   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1898   aStudyBuilder->NewCommand();
1899   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
1900   aStudyBuilder->Addreference(aSubSO, aIterSOParent);
1901   aStudyBuilder->CommitCommand();
1902
1903   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1904 }
1905 //=============================================================================
1906 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1907 {
1908   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1909   IsValidStudy () ;
1910
1911   // Controle du nom :
1912   if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1913   {
1914     MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1915     SALOME::ExceptionStruct es;
1916     es.type = SALOME::BAD_PARAM;
1917     es.text = "This boundary has already been defined";
1918     throw SALOME::SALOME_Exception(es);
1919     return 0;
1920   };
1921
1922   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1923   myBoundary->SetName(BoundaryName);
1924   myBoundary->SetType(BoundaryType);
1925
1926   myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1927
1928   SALOMEDS::SObject_var aSO;
1929   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1930
1931   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1932 }
1933 //=============================================================================
1934 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1935 {
1936   INFOS ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << ", MeshName = " << MeshName );
1937   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1938   myBoundary->SetMeshFile( MeshFile ) ;
1939   myBoundary->SetMeshName( MeshName ) ;
1940
1941   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1942 }
1943 //=============================================================================
1944 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1945                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1946                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1947                                       CORBA::Double Rayon)
1948 {
1949   INFOS ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
1950 //
1951   SALOME::ExceptionStruct es;
1952   int error = 0 ;
1953   if ( Rayon <= 0.0 )
1954   { es.text = "The radius must be positive." ;
1955     error = 1 ; }
1956   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1957   if ( daux < 0.0000001 )
1958   { es.text = "The axis must be a non 0 vector." ;
1959     error = 2 ; }
1960   if ( error != 0 )
1961   {
1962     es.type = SALOME::BAD_PARAM;
1963     throw SALOME::SALOME_Exception(es);
1964     return 0;
1965   };
1966 //
1967   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1968   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1969
1970   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1971 }
1972 //=============================================================================
1973 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1974                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1975                                       CORBA::Double Rayon)
1976 {
1977   INFOS ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
1978 //
1979   SALOME::ExceptionStruct es;
1980   int error = 0 ;
1981   if ( Rayon <= 0.0 )
1982   { es.text = "The radius must be positive." ;
1983     error = 1 ; }
1984   if ( error != 0 )
1985   {
1986     es.type = SALOME::BAD_PARAM;
1987     throw SALOME::SALOME_Exception(es);
1988     return 0;
1989   };
1990 //
1991   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1992   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1993
1994   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1995 }
1996 //=============================================================================
1997 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1998                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1999                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
2000 {
2001   INFOS ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
2002 //
2003   SALOME::ExceptionStruct es;
2004   int error = 0 ;
2005   if ( Angle <= 0.0 || Angle >= 90.0 )
2006   { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
2007     error = 1 ; }
2008   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2009   if ( daux < 0.0000001 )
2010   { es.text = "The axis must be a non 0 vector." ;
2011     error = 2 ; }
2012   if ( error != 0 )
2013   {
2014     es.type = SALOME::BAD_PARAM;
2015     throw SALOME::SALOME_Exception(es);
2016     return 0;
2017   };
2018 //
2019   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
2020   myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
2021
2022   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2023 }
2024 //=============================================================================
2025 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2026                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2027                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2028 {
2029   INFOS ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
2030 //
2031   SALOME::ExceptionStruct es;
2032   int error = 0 ;
2033   if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2034   { es.text = "The radius must be positive." ;
2035     error = 1 ; }
2036   double daux = fabs(Rayon2-Rayon1) ;
2037   if ( daux < 0.0000001 )
2038   { es.text = "The radius must be different." ;
2039     error = 2 ; }
2040   daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2041   if ( daux < 0.0000001 )
2042   { es.text = "The centers must be different." ;
2043     error = 3 ; }
2044   if ( error != 0 )
2045   {
2046     es.type = SALOME::BAD_PARAM;
2047     throw SALOME::SALOME_Exception(es);
2048     return 0;
2049   };
2050 //
2051   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2052   myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2053
2054   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2055 }
2056 //=============================================================================
2057 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2058                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2059                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2060                                       CORBA::Double RayonRev, CORBA::Double RayonPri)
2061 {
2062   INFOS ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName ) ;
2063 //
2064   SALOME::ExceptionStruct es;
2065   int error = 0 ;
2066   if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2067   { es.text = "The radius must be positive." ;
2068     error = 1 ; }
2069   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2070   if ( daux < 0.0000001 )
2071   { es.text = "The axis must be a non 0 vector." ;
2072     error = 2 ; }
2073   if ( error != 0 )
2074   {
2075     es.type = SALOME::BAD_PARAM;
2076     throw SALOME::SALOME_Exception(es);
2077     return 0;
2078   };
2079 //
2080   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2081   myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2082
2083   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2084 }
2085 //=============================================================================
2086 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2087 {
2088   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
2089   IsValidStudy () ;
2090
2091   // Controle du nom :
2092   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2093   {
2094     SALOME::ExceptionStruct es;
2095     es.type = SALOME::BAD_PARAM;
2096     es.text = "This zone has already been defined";
2097     throw SALOME::SALOME_Exception(es);
2098     return 0;
2099   };
2100
2101   HOMARD::HOMARD_Zone_var myZone = newZone();
2102   myZone->SetName(ZoneName);
2103   myZone->SetType(ZoneType);
2104
2105   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2106
2107   SALOMEDS::SObject_var aSO;
2108   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2109
2110   return HOMARD::HOMARD_Zone::_duplicate(myZone);
2111 }
2112 //=============================================================================
2113 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2114                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
2115                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
2116                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
2117 {
2118   INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
2119 //
2120   SALOME::ExceptionStruct es;
2121   int error = 0 ;
2122   if ( Xmini > Xmaxi )
2123   { es.text = "The X coordinates are not coherent." ;
2124     error = 1 ; }
2125   if ( Ymini > Ymaxi )
2126   { es.text = "The Y coordinates are not coherent." ;
2127     error = 2 ; }
2128   if ( Zmini > Zmaxi )
2129   { es.text = "The Z coordinates are not coherent." ;
2130     error = 3 ; }
2131   if ( error != 0 )
2132   {
2133     es.type = SALOME::BAD_PARAM;
2134     throw SALOME::SALOME_Exception(es);
2135     return 0;
2136   };
2137 //
2138   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2139   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2140
2141   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2142 }
2143 //=============================================================================
2144 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2145                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2146 {
2147   INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
2148 //
2149   SALOME::ExceptionStruct es;
2150   int error = 0 ;
2151   if ( Rayon <= 0.0 )
2152   { es.text = "The radius must be positive." ;
2153     error = 1 ; }
2154   if ( error != 0 )
2155   {
2156     es.type = SALOME::BAD_PARAM;
2157     throw SALOME::SALOME_Exception(es);
2158     return 0;
2159   };
2160 //
2161   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2162   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2163
2164   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2165 }
2166 //=============================================================================
2167 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2168                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2169                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2170                                       CORBA::Double Rayon, CORBA::Double Haut)
2171 {
2172   INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
2173 //
2174   SALOME::ExceptionStruct es;
2175   int error = 0 ;
2176   if ( Rayon <= 0.0 )
2177   { es.text = "The radius must be positive." ;
2178     error = 1 ; }
2179   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2180   if ( daux < 0.0000001 )
2181   { es.text = "The axis must be a non 0 vector." ;
2182     error = 2 ; }
2183   if ( Haut <= 0.0 )
2184   { es.text = "The height must be positive." ;
2185     error = 3 ; }
2186   if ( error != 0 )
2187   {
2188     es.type = SALOME::BAD_PARAM;
2189     throw SALOME::SALOME_Exception(es);
2190     return 0;
2191   };
2192 //
2193   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2194   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2195
2196   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2197 }
2198 //=============================================================================
2199 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2200                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2201                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2202                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2203 {
2204   INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
2205 //
2206   SALOME::ExceptionStruct es;
2207   int error = 0 ;
2208   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2209   { es.text = "The radius must be positive." ;
2210     error = 1 ; }
2211   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2212   if ( daux < 0.0000001 )
2213   { es.text = "The axis must be a non 0 vector." ;
2214     error = 2 ; }
2215   if ( Haut <= 0.0 )
2216   { es.text = "The height must be positive." ;
2217     error = 3 ; }
2218   if ( Rayon <= Rayonint )
2219   { es.text = "The external radius must be higher than the internal radius." ;
2220     error = 4 ; }
2221   if ( error != 0 )
2222   {
2223     es.type = SALOME::BAD_PARAM;
2224     throw SALOME::SALOME_Exception(es);
2225     return 0;
2226   };
2227 //
2228   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2229   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2230
2231   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2232 }
2233 //=============================================================================
2234 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2235                                       CORBA::Double Umini, CORBA::Double Umaxi,
2236                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
2237                                       CORBA::Long Orient)
2238 {
2239   INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
2240 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2241 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2242 //   MESSAGE ("Orient = " << Orient ) ;
2243 //
2244   SALOME::ExceptionStruct es;
2245   int error = 0 ;
2246   if ( Umini > Umaxi )
2247   { es.text = "The first coordinates are not coherent." ;
2248     error = 1 ; }
2249   if ( Vmini > Vmaxi )
2250   { es.text = "The second coordinates are not coherent." ;
2251     error = 2 ; }
2252   if ( Orient < 1 || Orient > 3 )
2253   { es.text = "The orientation must be 1, 2 or 3." ;
2254     error = 3 ; }
2255   if ( error != 0 )
2256   {
2257     es.type = SALOME::BAD_PARAM;
2258     throw SALOME::SALOME_Exception(es);
2259     return 0;
2260   };
2261 //
2262   double Xmini, Xmaxi ;
2263   double Ymini, Ymaxi ;
2264   double Zmini, Zmaxi ;
2265   if ( Orient == 1 )
2266   { Xmini = Umini ;
2267     Xmaxi = Umaxi ;
2268     Ymini = Vmini ;
2269     Ymaxi = Vmaxi ;
2270     Zmini = 0. ;
2271     Zmaxi = 0. ; }
2272   else if ( Orient == 2 )
2273   { Xmini = 0. ;
2274     Xmaxi = 0. ;
2275     Ymini = Umini ;
2276     Ymaxi = Umaxi ;
2277     Zmini = Vmini ;
2278     Zmaxi = Vmaxi ; }
2279   else if ( Orient == 3 )
2280   { Xmini = Vmini ;
2281     Xmaxi = Vmaxi ;
2282     Ymini = 0. ;
2283     Ymaxi = 0. ;
2284     Zmini = Umini ;
2285     Zmaxi = Umaxi ; }
2286   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2287
2288   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2289   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2290
2291   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2292 }
2293 //=============================================================================
2294 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2295                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2296                                       CORBA::Double Rayon,
2297                                       CORBA::Long Orient)
2298 {
2299   INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
2300 //
2301   SALOME::ExceptionStruct es;
2302   int error = 0 ;
2303   if ( Rayon <= 0.0 )
2304   { es.text = "The radius must be positive." ;
2305     error = 1 ; }
2306   if ( Orient < 1 || Orient > 3 )
2307   { es.text = "The orientation must be 1, 2 or 3." ;
2308     error = 3 ; }
2309   if ( error != 0 )
2310   {
2311     es.type = SALOME::BAD_PARAM;
2312     throw SALOME::SALOME_Exception(es);
2313     return 0;
2314   };
2315 //
2316   double Xcentre ;
2317   double Ycentre ;
2318   double Zcentre ;
2319   if ( Orient == 1 )
2320   { Xcentre = Ucentre ;
2321     Ycentre = Vcentre ;
2322     Zcentre = 0. ; }
2323   else if ( Orient == 2 )
2324   { Xcentre = 0. ;
2325     Ycentre = Ucentre ;
2326     Zcentre = Vcentre ; }
2327   else if ( Orient == 3 )
2328   { Xcentre = Vcentre ;
2329     Ycentre = 0. ;
2330     Zcentre = Ucentre ; }
2331   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2332
2333   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2334   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2335
2336   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2337 }
2338 //=============================================================================
2339 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2340                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2341                                       CORBA::Double Rayon, CORBA::Double Rayonint,
2342                                       CORBA::Long Orient)
2343 {
2344   INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
2345 //
2346   SALOME::ExceptionStruct es;
2347   int error = 0 ;
2348   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2349   { es.text = "The radius must be positive." ;
2350     error = 1 ; }
2351   if ( Orient < 1 || Orient > 3 )
2352   { es.text = "The orientation must be 1, 2 or 3." ;
2353     error = 3 ; }
2354   if ( Rayon <= Rayonint )
2355   { es.text = "The external radius must be higher than the internal radius." ;
2356     error = 4 ; }
2357   if ( error != 0 )
2358   {
2359     es.type = SALOME::BAD_PARAM;
2360     throw SALOME::SALOME_Exception(es);
2361     return 0;
2362   };
2363 //
2364   double Xcentre ;
2365   double Ycentre ;
2366   double Zcentre ;
2367   if ( Orient == 1 )
2368   { Xcentre = Ucentre ;
2369     Ycentre = Vcentre ;
2370     Zcentre = 0. ; }
2371   else if ( Orient == 2 )
2372   { Xcentre = 0. ;
2373     Ycentre = Ucentre ;
2374     Zcentre = Vcentre ; }
2375   else if ( Orient == 3 )
2376   { Xcentre = Vcentre ;
2377     Ycentre = 0. ;
2378     Zcentre = Ucentre ; }
2379   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2380
2381   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2382   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2383
2384   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2385 }
2386 //=============================================================================
2387 //=============================================================================
2388
2389
2390
2391
2392 //=============================================================================
2393 //=============================================================================
2394 // Traitement d'une iteration
2395 // etatMenage = 1 : destruction du repertoire d'execution
2396 // modeHOMARD  = 1 : adaptation
2397 //            != 1 : information avec les options modeHOMARD
2398 // Option1 >0 : appel depuis python
2399 //         <0 : appel depuis GUI
2400 // Option2 : multiple de nombres premiers
2401 //         1 : aucune option
2402 //        x2 : publication du maillage dans SMESH
2403 //=============================================================================
2404 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2405 {
2406   INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2407
2408   // A. Prealable
2409   int codret = 0;
2410
2411   // A.1. L'objet iteration
2412   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2413   ASSERT(!CORBA::is_nil(myIteration));
2414
2415   // A.2. Controle de la possibilite d'agir
2416   // A.2.1. Etat de l'iteration
2417   int etat = myIteration->GetState();
2418   MESSAGE ( "etat = "<<etat );
2419   // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2420   if ( modeHOMARD == 1 )
2421   {
2422     if ( etat <= 0 )
2423     {
2424       SALOME::ExceptionStruct es;
2425       es.type = SALOME::BAD_PARAM;
2426       es.text = "This iteration is the first of the case and cannot be computed.";
2427       throw SALOME::SALOME_Exception(es);
2428       return 1 ;
2429     }
2430     else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2431     {
2432       SALOME::ExceptionStruct es;
2433       es.type = SALOME::BAD_PARAM;
2434       es.text = "This iteration is already computed.";
2435       throw SALOME::SALOME_Exception(es);
2436       return 1 ;
2437     }
2438   }
2439   // A.2.3. On n'analyse pas une iteration non calculee
2440   else
2441   {
2442     if ( etat == 1 )
2443     {
2444       SALOME::ExceptionStruct es;
2445       es.type = SALOME::BAD_PARAM;
2446       es.text = "This iteration is not computed.";
2447       throw SALOME::SALOME_Exception(es);
2448       return 1 ;
2449     }
2450   }
2451
2452   // A.3. Numero de l'iteration
2453   //     siterp1 : numero de l'iteration a traiter
2454   //     Si adaptation :
2455   //        siter   : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2456   //     Ou si information :
2457   //        siter = siterp1
2458   int NumeIter = myIteration->GetNumber();
2459   std::string siterp1 ;
2460   std::stringstream saux1 ;
2461   saux1 << NumeIter ;
2462   siterp1 = saux1.str() ;
2463   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2464
2465   std::string siter ;
2466   if ( modeHOMARD==1 )
2467   {
2468     std::stringstream saux0 ;
2469     int iaux = max(0, NumeIter-1) ;
2470     saux0 << iaux ;
2471     siter = saux0.str() ;
2472     if (NumeIter < 11) { siter = "0" + siter ; }
2473   }
2474   else
2475   { siter = siterp1 ; }
2476
2477   // A.4. Le cas
2478   const char* nomCas = myIteration->GetCaseName();
2479   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2480   ASSERT(!CORBA::is_nil(myCase));
2481
2482   // B. Les repertoires
2483   // B.1. Le repertoire courant
2484   std::string nomDirWork = getenv("PWD") ;
2485   // B.2. Le sous-repertoire de l'iteration a traiter
2486   char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2487   MESSAGE( ". DirCompute = " << DirCompute );
2488
2489   // C. Le fichier des messages
2490   // C.1. Le deroulement de l'execution de HOMARD
2491   std::string LogFile = DirCompute ;
2492   LogFile += "/Liste" ;
2493   if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2494   LogFile += ".log" ;
2495   MESSAGE (". LogFile = " << LogFile);
2496   if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2497   // C.2. Le bilan de l'analyse du maillage
2498   std::string FileInfo = DirCompute ;
2499   FileInfo += "/" ;
2500   if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2501   else
2502   { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2503     else                 { FileInfo += "info_ap" ; }
2504   }
2505   FileInfo += "." + siterp1 + ".bilan" ;
2506   myIteration->SetFileInfo(FileInfo.c_str());
2507
2508    // D. On passe dans le repertoire de l'iteration a calculer
2509   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2510   CHDIR(DirCompute);
2511
2512   // E. Les donnees de l'execution HOMARD
2513   // E.1. L'objet du texte du fichier de configuration
2514   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2515   myDriver->TexteInit(DirCompute, LogFile, _Langue);
2516
2517   // E.2. Le maillage associe a l'iteration
2518   const char* NomMesh = myIteration->GetMeshName();
2519   MESSAGE ( ". NomMesh = " << NomMesh );
2520   const char* MeshFile = myIteration->GetMeshFile();
2521   MESSAGE ( ". MeshFile = " << MeshFile );
2522
2523   // E.3. Les donnees du traitement HOMARD
2524   int iaux ;
2525   if ( modeHOMARD == 1 )
2526   {
2527     iaux = 1 ;
2528     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2529     myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2530     codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2531   }
2532   else
2533   {
2534     InvalideIterInfo(NomIteration);
2535     myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2536     iaux = 0 ;
2537     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2538     myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2539     myDriver->CreeFichierDonn();
2540   }
2541
2542   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2543   DriverTexteBoundary(myCase, myDriver) ;
2544
2545   // E.5. Ecriture du texte dans le fichier
2546   MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2547   if (codret == 0)
2548   { myDriver->CreeFichier(); }
2549
2550 // G. Execution
2551 //
2552   int codretexec = 12 ;
2553   if (codret == 0)
2554   {
2555     codretexec = myDriver->ExecuteHomard(Option1);
2556 //
2557     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2558     // En mode adaptation, on ajuste l'etat de l'iteration
2559     if ( modeHOMARD == 1 )
2560     {
2561       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2562       else                 { SetEtatIter(NomIteration,1); }
2563       // GERALD -- QMESSAGE BOX
2564     }
2565   }
2566
2567   // H. Gestion des resultats
2568   if (codret == 0)
2569   {
2570     std::string Commentaire ;
2571     // H.1. Le fichier des messages, dans tous les cas
2572     Commentaire = "log" ;
2573     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2574     else                   { Commentaire += "Info" ; }
2575     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2576
2577     // H.2. Si tout s'est bien passe :
2578     if (codretexec == 0)
2579     {
2580     // H.2.1. Le fichier de bilan
2581       Commentaire = "Summary" ;
2582       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2583       else                   { Commentaire += "Info" ; }
2584       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2585     // H.2.2. Le fichier de  maillage obtenu
2586       if ( modeHOMARD == 1 )
2587       {
2588         std::stringstream saux0 ;
2589         Commentaire = "Mesh" ;
2590         Commentaire += " " + siterp1 ;
2591         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2592         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2593       }
2594     }
2595   // H.3 Message d'erreur
2596     if (codretexec != 0)
2597     {
2598       std::string text = "" ;
2599       // Message d'erreur en cas de probleme en adaptation
2600       if ( modeHOMARD == 1 )
2601       {
2602         text = "Error during the adaptation.\n" ;
2603         bool stopvu = false ;
2604         std::ifstream fichier( LogFile.c_str() );
2605         if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2606         {
2607           std::string ligne; // variable contenant chaque ligne lue
2608           while ( std::getline( fichier, ligne ) )
2609           {
2610 //             INFOS(ligne);
2611             if ( stopvu )
2612             { text += ligne+ "\n"; }
2613             else
2614             {
2615               int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2616               if ( position > 0 ) { stopvu = true ; }
2617             }
2618           }
2619         }
2620       }
2621       text += "\n\nSee the file " + LogFile + "\n" ;
2622       INFOS ( text ) ;
2623       SALOME::ExceptionStruct es;
2624       es.type = SALOME::BAD_PARAM;
2625       es.text = CORBA::string_dup(text.c_str());
2626       throw SALOME::SALOME_Exception(es);
2627 //
2628       // En mode information, on force le succes pour pouvoir consulter le fichier log
2629       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2630     }
2631   }
2632
2633   // I. Menage et retour dans le repertoire du cas
2634   if (codret == 0)
2635   {
2636     delete myDriver;
2637     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2638
2639     CHDIR(nomDirWork.c_str());
2640   }
2641
2642   return codretexec ;
2643 }
2644 //=============================================================================
2645 // Calcul d'une iteration : partie specifique a l'adaptation
2646 //=============================================================================
2647 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)
2648 {
2649   MESSAGE ( "ComputeAdap" );
2650
2651   // A. Prealable
2652   // A.1. Bases
2653   int codret = 0;
2654   // Numero de l'iteration
2655   int NumeIter = myIteration->GetNumber();
2656   std::stringstream saux0 ;
2657   saux0 << NumeIter-1 ;
2658   std::string siter = saux0.str() ;
2659   if (NumeIter < 11) { siter = "0" + siter ; }
2660
2661   // A.2. On verifie qu il y a une hypothese (erreur improbable);
2662   const char* nomHypo = myIteration->GetHypoName();
2663   if (std::string(nomHypo) == std::string(""))
2664   {
2665       SALOME::ExceptionStruct es;
2666       es.type = SALOME::BAD_PARAM;
2667       es.text = "This iteration does not have any associated hypothesis.";
2668       throw SALOME::SALOME_Exception(es);
2669       return 2;
2670   };
2671   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2672   ASSERT(!CORBA::is_nil(myHypo));
2673
2674   // B. L'iteration parent
2675   const char* nomIterationParent = myIteration->GetIterParentName();
2676   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2677   ASSERT(!CORBA::is_nil(myIterationParent));
2678   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2679   if ( myIterationParent->GetState() == 1 )
2680   {
2681     int iaux = 1 ;
2682     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2683     if (codret != 0)
2684     {
2685       // GERALD -- QMESSAGE BOX
2686       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2687     }
2688   };
2689
2690   // C. Le sous-repertoire de l'iteration precedente
2691   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2692   MESSAGE( ". DirComputePa = " << DirComputePa );
2693
2694   // D. Les donnees de l'adaptation HOMARD
2695   // D.1. Le type de conformite
2696   int ConfType = myCase->GetConfType();
2697   MESSAGE ( ". ConfType = " << ConfType );
2698
2699   // D.2. Le maillage de depart
2700   const char* NomMeshParent = myIterationParent->GetMeshName();
2701   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2702   const char* MeshFileParent = myIterationParent->GetMeshFile();
2703   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2704
2705   // D.3. Le maillage associe a l'iteration
2706   const char* MeshFile = myIteration->GetMeshFile();
2707   MESSAGE ( ". MeshFile = " << MeshFile );
2708   FILE *file = fopen(MeshFile,"r");
2709   if (file != NULL)
2710   {
2711     fclose(file);
2712     if (etatMenage == 0)
2713     {
2714       SALOME::ExceptionStruct es;
2715       es.type = SALOME::BAD_PARAM;
2716       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2717       es.text = CORBA::string_dup(text.c_str());
2718       throw SALOME::SALOME_Exception(es);
2719       return 4;
2720     }
2721     else
2722     {
2723       std::string commande = "rm -f " + std::string(MeshFile);
2724       codret = system(commande.c_str());
2725       if (codret != 0)
2726       {
2727         SALOME::ExceptionStruct es;
2728         es.type = SALOME::BAD_PARAM;
2729         es.text = "The mesh file cannot be deleted.";
2730         throw SALOME::SALOME_Exception(es);
2731         return 5;
2732       }
2733     }
2734   }
2735
2736   // D.4. Les types de raffinement et de deraffinement
2737   // Les appels corba sont lourds, il vaut mieux les grouper
2738   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2739   ASSERT(ListTypes->length() == 3);
2740   int TypeAdap = (*ListTypes)[0];
2741   int TypeRaff = (*ListTypes)[1];
2742   int TypeDera = (*ListTypes)[2];
2743 //   MESSAGE ( ". TypeAdap = " << TypeAdap << ", TypeRaff = " << TypeRaff << ", TypeDera = " << TypeDera  );
2744
2745   // E. Texte du fichier de configuration
2746   // E.1. Incontournables du texte
2747   myDriver->TexteAdap();
2748   int iaux = 0 ;
2749   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2750   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2751   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2752
2753   // E.2. Ajout des informations liees aux zones eventuelles
2754   if ( TypeAdap == 0 )
2755   { DriverTexteZone(myHypo, myDriver) ; }
2756
2757   // E.3. Ajout des informations liees aux champs eventuels
2758   if ( TypeAdap == 1 )
2759   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2760
2761   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2762   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2763   int numberOfGroups = listeGroupes->length();
2764   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2765   if (numberOfGroups > 0)
2766   {
2767     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2768     {
2769       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2770       MESSAGE( "... GroupName = " << GroupName );
2771       myDriver->TexteGroup(GroupName);
2772     }
2773   }
2774
2775   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2776   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2777
2778   // E.6. Ajout des options avancees
2779   int Pyram = myCase->GetPyram();
2780   MESSAGE ( ". Pyram = " << Pyram );
2781   int NivMax = myHypo->GetNivMax();
2782   MESSAGE ( ". NivMax = " << NivMax );
2783   double DiamMin = myHypo->GetDiamMin() ;
2784   MESSAGE ( ". DiamMin = " << DiamMin );
2785   int AdapInit = myHypo->GetAdapInit();
2786   MESSAGE ( ". AdapInit = " << AdapInit );
2787   int ExtraOutput = myHypo->GetExtraOutput();
2788   MESSAGE ( ". ExtraOutput = " << ExtraOutput );
2789   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, ExtraOutput);
2790
2791   // E.7. Ajout des informations sur le deroulement de l'execution
2792   int MessInfo = myIteration->GetInfoCompute();
2793   MESSAGE ( ". MessInfo = " << MessInfo );
2794   myDriver->TexteInfoCompute(MessInfo);
2795
2796   return codret ;
2797 }
2798 //=============================================================================
2799 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2800 //  nomrep : nom du repertoire parent
2801 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2802 //=============================================================================
2803 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2804 {
2805   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2806   // On verifie que le repertoire parent existe
2807   int codret = CHDIR(nomrep) ;
2808   if ( codret != 0 )
2809   {
2810     SALOME::ExceptionStruct es;
2811     es.type = SALOME::BAD_PARAM;
2812     es.text = "The directory of the case does not exist.";
2813     throw SALOME::SALOME_Exception(es);
2814     return 0;
2815   };
2816   std::string nomDirActuel = getenv("PWD") ;
2817   std::string DirName ;
2818   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2819   bool a_chercher = true ;
2820   while ( a_chercher )
2821   {
2822     // On passe dans le repertoire parent
2823
2824     CHDIR(nomrep);
2825     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2826     int jaux ;
2827     if      ( num <    100 ) { jaux = 2 ; }
2828     else if ( num <   1000 ) { jaux = 3 ; }
2829     else if ( num <  10000 ) { jaux = 4 ; }
2830     else if ( num < 100000 ) { jaux = 5 ; }
2831     else                     { jaux = 9 ; }
2832     std::ostringstream iaux ;
2833     iaux << std::setw(jaux) << std::setfill('0') << num ;
2834     std::ostringstream DirNameA ;
2835     DirNameA << "I" << iaux.str();
2836     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2837     // que c'est bien un probleme d'absence
2838     if ( CHDIR(DirNameA.str().c_str()) != 0 )
2839     {
2840       bool existe = false ;
2841 #ifndef WIN32
2842       DIR *dp;
2843       struct dirent *dirp;
2844       dp  = opendir(nomrep);
2845       while ( (dirp = readdir(dp)) != NULL )
2846       {
2847         std::string file_name(dirp->d_name);
2848 #else
2849       HANDLE hFind = INVALID_HANDLE_VALUE;
2850       WIN32_FIND_DATA ffd;
2851       hFind = FindFirstFile(nomrep, &ffd);
2852       if (INVALID_HANDLE_VALUE != hFind) {
2853         while (FindNextFile(hFind, &ffd) != 0) {
2854          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2855          std::string file_name(ffd.cFileName);
2856 #endif
2857         if ( file_name == DirNameA.str() ) { existe = true ; }
2858       }
2859 #ifndef WIN32
2860       closedir(dp);
2861 #else
2862       FindClose(hFind);
2863 #endif
2864       if ( !existe )
2865       {
2866         DirName = DirNameA.str() ;
2867         a_chercher = false ;
2868         break ;
2869       }
2870     }
2871     num += 1;
2872   }
2873
2874   MESSAGE ( "==> DirName = " << DirName);
2875   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2876   CHDIR(nomDirActuel.c_str());
2877   return CORBA::string_dup( DirName.c_str() );
2878 }
2879 //=============================================================================
2880 // Calcul d'une iteration : gestion du repertoire de calcul
2881 //        Si le sous-repertoire existe :
2882 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2883 //         etatMenage =  1 : on fait le menage du repertoire
2884 //         etatMenage = -1 : on ne fait rien
2885 //=============================================================================
2886 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2887 {
2888   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2889   // B.2. Le repertoire du cas
2890   const char* nomDirCase = myCase->GetDirName();
2891   MESSAGE ( ". nomDirCase = " << nomDirCase );
2892
2893   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2894   // B.3.1. Le nom du sous-repertoire
2895   const char* nomDirIt = myIteration->GetDirNameLoc();
2896
2897   // B.3.2. Le nom complet du sous-repertoire
2898   std::stringstream DirCompute ;
2899   DirCompute << nomDirCase << "/" << nomDirIt;
2900   MESSAGE (". DirCompute = " << DirCompute.str() );
2901
2902   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2903   if (CHDIR(DirCompute.str().c_str()) != 0)
2904   {
2905 #ifndef WIN32
2906     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2907 #else
2908     if (_mkdir(DirCompute.str().c_str()) != 0)
2909 #endif
2910     {
2911        // GERALD -- QMESSAGE BOX
2912        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2913        VERIFICATION("Pb a la creation du repertoire" == 0);
2914     }
2915   }
2916   else
2917   {
2918 //  Le repertoire existe
2919 //  On demande de faire le menage de son contenu :
2920     if (etatMenage == 1)
2921     {
2922       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2923       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2924       int codret = system(commande.c_str());
2925       if (codret != 0)
2926       {
2927         // GERALD -- QMESSAGE BOX
2928         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2929         VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2930       }
2931     }
2932 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2933     else
2934     {
2935       if (etatMenage == 0)
2936       {
2937 #ifndef WIN32
2938         DIR *dp;
2939         struct dirent *dirp;
2940         dp  = opendir(DirCompute.str().c_str());
2941         bool result = true;
2942         while ((dirp = readdir(dp)) != NULL && result )
2943         {
2944           std::string file_name(dirp->d_name);
2945           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2946         }
2947         closedir(dp);
2948 #else
2949        HANDLE hFind = INVALID_HANDLE_VALUE;
2950        WIN32_FIND_DATA ffd;
2951        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2952        bool result = true;
2953        if (INVALID_HANDLE_VALUE != hFind) {
2954          while (FindNextFile(hFind, &ffd) != 0) {
2955           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2956           std::string file_name(ffd.cFileName);
2957           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2958          }
2959        }
2960        FindClose(hFind);
2961 #endif
2962         if ( result == false)
2963         {
2964           SALOME::ExceptionStruct es;
2965           es.type = SALOME::BAD_PARAM;
2966           std::string text = "Directory : " + DirCompute.str() + " is not empty";
2967           es.text = CORBA::string_dup(text.c_str());
2968           throw SALOME::SALOME_Exception(es);
2969           VERIFICATION("Directory is not empty" == 0);
2970         }
2971       }
2972     }
2973   }
2974
2975   return CORBA::string_dup( DirCompute.str().c_str() );
2976 }
2977 //=============================================================================
2978 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2979 //=============================================================================
2980 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2981 {
2982   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2983   // Le repertoire du cas
2984   const char* nomDirCase = myCase->GetDirName();
2985   MESSAGE ( ". nomDirCase = " << nomDirCase );
2986
2987   // Le sous-repertoire de l'iteration precedente
2988
2989   const char* nomIterationParent = myIteration->GetIterParentName();
2990   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2991   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2992   std::stringstream DirComputePa ;
2993   DirComputePa << nomDirCase << "/" << nomDirItPa;
2994   MESSAGE( ". nomDirItPa = " << nomDirItPa);
2995   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2996
2997   return CORBA::string_dup( DirComputePa.str().c_str() );
2998 }
2999 //=============================================================================
3000 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3001 //=============================================================================
3002 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3003 {
3004   MESSAGE ( "... DriverTexteZone" );
3005   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3006   int numberOfZonesx2 = ListZone->length();
3007   int NumZone ;
3008
3009   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3010   {
3011     std::string ZoneName = std::string((*ListZone)[iaux]);
3012     MESSAGE ( "... ZoneName = " << ZoneName);
3013     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3014     ASSERT(!CORBA::is_nil(myZone));
3015
3016     int ZoneType = myZone->GetType();
3017     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3018     int TypeUse = atoi( TypeUsestr.c_str() );
3019     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3020     NumZone = iaux/2 + 1 ;
3021     HOMARD::double_array* zone = myZone->GetCoords();
3022     if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3023     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3024     else if ( ZoneType == 4 ) // Cas d une sphere
3025     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3026     else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3027     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3028     else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3029     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3030     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3031     iaux += 1 ;
3032   }
3033   return ;
3034 }
3035 //=============================================================================
3036 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3037 //=============================================================================
3038 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3039 {
3040   MESSAGE ( "... DriverTexteField" );
3041 //  Le fichier du champ
3042   char* FieldFile = myIteration->GetFieldFile();
3043   MESSAGE ( ". FieldFile = " << FieldFile );
3044   if (strlen(FieldFile) == 0)
3045   {
3046     // GERALD -- QMESSAGE BOX
3047     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3048     VERIFICATION("The file for the field is not given." == 0);
3049   }
3050 //  Les caracteristiques d'instants du champ de pilotage
3051   int TimeStep = myIteration->GetTimeStep();
3052   MESSAGE( ". TimeStep = " << TimeStep );
3053   int Rank = myIteration->GetRank();
3054   MESSAGE( ". Rank = " << Rank );
3055 //  Les informations sur les champs
3056   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3057 //  Le nom
3058   const char* FieldName = aInfosHypo->FieldName;
3059 //  Les seuils
3060   int TypeThR = aInfosHypo->TypeThR;
3061   double ThreshR = aInfosHypo->ThreshR;
3062   int TypeThC = aInfosHypo->TypeThC;
3063   double ThreshC = aInfosHypo->ThreshC;
3064 //  Saut entre mailles ou non ?
3065   int UsField = aInfosHypo->UsField;
3066   MESSAGE( ". UsField = " << UsField );
3067 //  L'usage des composantes
3068   int UsCmpI = aInfosHypo->UsCmpI;
3069   MESSAGE( ". UsCmpI = " << UsCmpI );
3070 //
3071   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3072 //
3073 //  Les composantes
3074   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3075   int numberOfCompos = mescompo->length();
3076   MESSAGE( ". numberOfCompos = " << numberOfCompos );
3077   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3078   {
3079     std::string nomCompo = std::string((*mescompo)[NumeComp]);
3080     MESSAGE( "... nomCompo = " << nomCompo );
3081     myDriver->TexteCompo(NumeComp, nomCompo);
3082   }
3083   return ;
3084 }
3085 //=============================================================================
3086 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3087 // On ecrit dans l'ordre :
3088 //    1. la definition des frontieres
3089 //    2. les liens avec les groupes
3090 //    3. un entier resumant le type de comportement pour les frontieres
3091 //=============================================================================
3092 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3093 {
3094   MESSAGE ( "... DriverTexteBoundary" );
3095   // 1. Recuperation des frontieres
3096   std::list<std::string>  ListeBoundaryTraitees ;
3097   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3098   int numberOfitems = ListBoundaryGroupType->length();
3099   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3100   int BoundaryOption = 1 ;
3101   // 2. Parcours des frontieres pour ecrire leur description
3102   int NumBoundaryAnalytical = 0 ;
3103   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3104   {
3105     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3106     MESSAGE ( "... BoundaryName = " << BoundaryName);
3107     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3108     //      Cela arrive quand elle est liee a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3109     int A_faire = 1 ;
3110     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3111     while (it != ListeBoundaryTraitees.end())
3112     {
3113       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3114       if ( BoundaryName == *it ) { A_faire = 0 ; }
3115       it++;
3116     }
3117     // 2.2. Ecriture de la frontiere
3118     if ( A_faire == 1 )
3119     {
3120       // 2.2.1. Caracteristiques de la frontiere
3121       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3122       ASSERT(!CORBA::is_nil(myBoundary));
3123       int BoundaryType = myBoundary->GetType();
3124       MESSAGE ( "... BoundaryType = " << BoundaryType );
3125       // 2.2.2. Ecriture selon le type
3126       // 2.2.2.1. Cas d une frontiere discrete
3127       if (BoundaryType == 0)
3128       {
3129         const char* MeshName = myBoundary->GetMeshName() ;
3130         MESSAGE ( ". MeshName = " << MeshName );
3131         const char* MeshFile = myBoundary->GetMeshFile() ;
3132         MESSAGE ( ". MeshFile = " << MeshFile );
3133         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3134         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3135       }
3136       // 2.2.2.1. Cas d une frontiere analytique
3137       else
3138       {
3139         NumBoundaryAnalytical++ ;
3140         HOMARD::double_array* coor = myBoundary->GetCoords();
3141         if (BoundaryType == 1) // Cas d un cylindre
3142         {
3143           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3144           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3145         }
3146         else if (BoundaryType == 2) // Cas d une sphere
3147         {
3148           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3149           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3150         }
3151         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3152         {
3153           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3154           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3155         }
3156         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3157         {
3158           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3159           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3160         }
3161         else if (BoundaryType == 5) // Cas d un tore
3162         {
3163           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3164           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3165         }
3166       }
3167       // 2.2.3. Memorisation du traitement
3168       ListeBoundaryTraitees.push_back( BoundaryName );
3169     }
3170   }
3171   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3172   NumBoundaryAnalytical = 0 ;
3173   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3174   {
3175     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3176     MESSAGE ( "... BoundaryName = " << BoundaryName);
3177     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3178     ASSERT(!CORBA::is_nil(myBoundary));
3179     int BoundaryType = myBoundary->GetType();
3180     MESSAGE ( "... BoundaryType = " << BoundaryType );
3181     // 3.1. Recuperation du nom du groupe
3182     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3183     MESSAGE ( "... GroupName = " << GroupName);
3184     // 3.2. Cas d une frontiere discrete
3185     if ( BoundaryType == 0 )
3186     {
3187       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3188     }
3189     // 3.3. Cas d une frontiere analytique
3190     else
3191     {
3192       NumBoundaryAnalytical++ ;
3193       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3194     }
3195   }
3196   // 4. Ecriture de l'option finale
3197   myDriver->TexteBoundaryOption(BoundaryOption);
3198 //
3199   return ;
3200 }
3201 //=============================================================================
3202 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3203 //=============================================================================
3204 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3205 {
3206   MESSAGE ( "... DriverTexteFieldInterp" );
3207   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3208   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3209   if (TypeFieldInterp != 0)
3210   {
3211 //  Le fichier des champs
3212     char* FieldFile = myIteration->GetFieldFile();
3213     MESSAGE ( ". FieldFile = " << FieldFile );
3214     if (strlen(FieldFile) == 0)
3215     {
3216       // GERALD -- QMESSAGE BOX
3217       VERIFICATION("The file for the field is not given." == 0);
3218     }
3219   //
3220     const char* MeshFile = myIteration->GetMeshFile();
3221     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3222
3223   // Les champs
3224   // Interpolation de tous les champs
3225     if ( TypeFieldInterp == 1 )
3226     {
3227       myDriver->TexteFieldInterpAll();
3228     }
3229   // Interpolation de certains champs
3230     else if (TypeFieldInterp == 2)
3231     {
3232       // Les champs et leurs instants pour l'iteration
3233       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3234       int numberOfFieldsx3 = ListFieldTSR->length();
3235       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3236       // Les champs pour l'hypothese
3237       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3238       int numberOfFieldsx2 = ListField->length();
3239       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3240       // On parcourt tous les champs de  l'hypothese
3241       int NumField = 0 ;
3242       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3243       {
3244         // Le nom du champ
3245         std::string FieldName = std::string((*ListField)[iaux]) ;
3246         // Le type d'interpolation
3247         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3248         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3249         // On cherche à savoir si des instants ont été précisés pour cette itération
3250         int tsrvu = 0;
3251         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3252         {
3253         // Le nom du champ
3254           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3255           MESSAGE( "..... FieldName2 = " << FieldName2 );
3256         // Quand c'est le bon champ, on ecrit le pas de temps
3257           if ( FieldName == FieldName2 )
3258           {
3259             tsrvu = 1 ;
3260             // Le pas de temps
3261             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3262             // Le numero d'ordre
3263             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3264             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3265             NumField += 1 ;
3266             int TimeStep = atoi( TimeStepstr.c_str() );
3267             int Rank = atoi( Rankstr.c_str() );
3268             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3269           }
3270           jaux += 2 ;
3271         }
3272         // Si aucun instant n'a été défini
3273         if ( tsrvu == 0 )
3274         {
3275           NumField += 1 ;
3276           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3277         }
3278         iaux++ ;
3279       }
3280     }
3281   }
3282   return ;
3283 }
3284 //===========================================================================
3285 //===========================================================================
3286
3287
3288 //===========================================================================
3289 //===========================================================================
3290 // Publications
3291 //===========================================================================
3292 //===========================================================================
3293 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3294                                                    SALOMEDS::SObject_ptr theSObject,
3295                                                    CORBA::Object_ptr theObject,
3296                                                    const char* theName)
3297 {
3298   MESSAGE("PublishInStudy pour " << theName);
3299   SALOMEDS::SObject_var aResultSO;
3300   if (CORBA::is_nil(theStudy))
3301   {
3302     SALOME::ExceptionStruct es;
3303     es.type = SALOME::BAD_PARAM;
3304     es.text = "Invalid study context";
3305     throw SALOME::SALOME_Exception(es);
3306     return 0;
3307   };
3308
3309 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3310 // Rq : Iteration est publiee ailleurs
3311   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3312   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3313   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3314   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3315   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3316
3317    addInStudy(theStudy);
3318
3319 // Controle de la non publication d'un objet de meme nom
3320    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3321   {
3322     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3323     if (listSO->length() >= 1)
3324     {
3325       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3326       aResultSO = listSO[0];
3327       return aResultSO._retn();
3328     }
3329   }
3330
3331   // Caracteristiques de l'etude
3332   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3333   aStudyBuilder->NewCommand();
3334   if(!aBoundary->_is_nil())
3335     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3336   else if(!aCase->_is_nil())
3337     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3338   else if(!aHypo->_is_nil())
3339     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3340   else if(!aYACS->_is_nil())
3341     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3342   else if(!aZone->_is_nil())
3343     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3344
3345   aStudyBuilder->CommitCommand();
3346
3347   return aResultSO._retn();
3348 };
3349 //=============================================================================
3350 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3351                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3352                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3353 {
3354   MESSAGE("PublishBoundaryStudy pour "<<theName);
3355   SALOMEDS::SObject_var aResultSO;
3356
3357   // Caracteristique de la Boundary
3358   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3359
3360   // On recupere le module pere dans l etude
3361   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3362   if (theFatherHomard->_is_nil())
3363   {
3364     MESSAGE("theFatherHomard->_is_nil()");
3365     return aResultSO._retn();
3366   }
3367
3368   // On ajoute la categorie des boundarys dans l etude si necessaire
3369   if ( _tag_boun == 0 )
3370   {
3371     _tag_gene += 1 ;
3372     _tag_boun = _tag_gene ;
3373   }
3374   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3375   SALOMEDS::SObject_var aSObject;
3376   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3377   {
3378     MESSAGE("Ajout de la categorie des boundarys");
3379     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3380     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3381   }
3382   else { MESSAGE("La categorie des boundarys existe deja."); }
3383
3384   CORBA::Long BoundaryType = myBoundary->GetType();
3385 //   MESSAGE("BoundaryType : "<<BoundaryType);
3386   std::string icone ;
3387   std::string value ;
3388   switch (BoundaryType)
3389   {
3390     case 0 :
3391     { value = "BoundaryDiHomard" ;
3392       icone = "mesh_tree_mesh.png" ;
3393       break;
3394     }
3395     case 1 :
3396     { value = "BoundaryAnHomard" ;
3397       icone = "cylinderpointvector_2.png" ;
3398       break;
3399     }
3400     case 2 :
3401     { value = "BoundaryAnHomard" ;
3402       icone = "spherepoint_2.png" ;
3403       break;
3404     }
3405     case 3 :
3406     { value = "BoundaryAnHomard" ;
3407       icone = "conepointvector.png" ;
3408       break;
3409     }
3410     case 4 :
3411     { value = "BoundaryAnHomard" ;
3412       icone = "conedxyz.png" ;
3413       break;
3414     }
3415     case 5 :
3416     { value = "BoundaryAnHomard" ;
3417       icone = "toruspointvector.png" ;
3418       break;
3419     }
3420   }
3421   aResultSO = aStudyBuilder->NewObject(aSObject);
3422   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3423   return aResultSO._retn();
3424 }
3425 //=============================================================================
3426 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3427                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3428                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3429 {
3430   MESSAGE("PublishCaseInStudy pour "<<theName);
3431   SALOMEDS::SObject_var aResultSO;
3432
3433   if (CORBA::is_nil(theObject)) {
3434     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3435     return aResultSO._retn();
3436   }
3437   if (theStudy->_is_nil()) {
3438     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3439     return aResultSO._retn();
3440   }
3441
3442   // On recupere le module pere dans l etude
3443   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3444   if (theFatherHomard->_is_nil())
3445   {
3446     MESSAGE("theFatherHomard->_is_nil()");
3447     return aResultSO._retn();
3448   }
3449
3450   _tag_gene += 1 ;
3451   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3452   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3453   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3454                      _orb->object_to_string(theObject) ) ;
3455
3456   return aResultSO._retn();
3457 }
3458 //=============================================================================
3459 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3460                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3461                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3462 {
3463   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3464   SALOMEDS::SObject_var aResultSO;
3465
3466   // On recupere le module pere dans l etude
3467   // On ajoute la categorie des hypotheses dans l etude si necessaire
3468   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3469   if (theFatherHomard->_is_nil())
3470   {
3471     MESSAGE("theFatherHomard->_is_nil()");
3472     return aResultSO._retn();
3473   }
3474
3475   // On ajoute la categorie des hypotheses dans l etude si necessaire
3476   SALOMEDS::SObject_var aSObject;
3477   if ( _tag_hypo == 0 )
3478   {
3479     _tag_gene += 1 ;
3480     _tag_hypo = _tag_gene ;
3481   }
3482   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3483   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3484   {
3485     MESSAGE("Ajout de la categorie des hypotheses");
3486     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3487     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3488   }
3489   else { MESSAGE("La categorie des hypotheses existe deja."); }
3490
3491 // Creation du resultat dans l'etude
3492   aResultSO = aStudyBuilder->NewObject(aSObject);
3493   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3494
3495   return aResultSO._retn();
3496 }
3497 //=============================================================================
3498 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3499                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3500                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3501 {
3502   MESSAGE("PublishYACSInStudy pour "<<theName);
3503   SALOMEDS::SObject_var aResultSO;
3504
3505   // On recupere le module pere dans l etude
3506   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3507   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3508   if (theFatherHomard->_is_nil())
3509   {
3510     MESSAGE("theFatherHomard->_is_nil()");
3511     return aResultSO._retn();
3512   }
3513   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3514   if ( _tag_yacs == 0 )
3515   {
3516     _tag_gene += 1 ;
3517     _tag_yacs = _tag_gene ;
3518   }
3519   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3520   SALOMEDS::SObject_var aSObject;
3521   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3522   {
3523     MESSAGE("Ajout de la categorie des schemas YACS");
3524     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3525     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3526   }
3527   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3528
3529 // Creation du resultat dans l'etude
3530   aResultSO = aStudyBuilder->NewObject(aSObject);
3531   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3532
3533   return aResultSO._retn();
3534 }
3535
3536 //=============================================================================
3537 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3538                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3539                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3540 {
3541   MESSAGE("PublishZoneStudy pour "<<theName);
3542   SALOMEDS::SObject_var aResultSO;
3543   if (CORBA::is_nil(theObject))
3544   {
3545     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3546     return aResultSO._retn();
3547   }
3548   if (theStudy->_is_nil())
3549   {
3550     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3551     return aResultSO._retn();
3552   }
3553   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3554   if (theFatherHomard->_is_nil())
3555   {
3556     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3557     return aResultSO._retn();
3558   }
3559
3560   // Caracteristique de la zone
3561   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3562   CORBA::Long ZoneType = myZone->GetType();
3563
3564   // On ajoute la categorie des zones dans l etude si necessaire
3565   if ( _tag_zone == 0 )
3566   {
3567     _tag_gene += 1 ;
3568     _tag_zone = _tag_gene ;
3569   }
3570   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3571   SALOMEDS::SObject_var aSObject;
3572   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3573   {
3574     MESSAGE("Ajout de la categorie des zones");
3575     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3576     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3577   }
3578   else { MESSAGE("La categorie des zones existe deja."); }
3579
3580   aResultSO = aStudyBuilder->NewObject(aSObject);
3581   std::string icone ;
3582   switch (ZoneType)
3583   {
3584     case 11 :
3585     { }
3586     case 12 :
3587     { }
3588     case 13 :
3589     { icone = "boxdxy_2.png" ;
3590       break ;
3591     }
3592     case 2 :
3593     { icone = "boxdxyz_2.png" ;
3594       break ;
3595     }
3596     case 31 :
3597     { }
3598     case 32 :
3599     { }
3600     case 33 :
3601     { icone = "disk_2.png" ;
3602       break ;
3603      }
3604     case 4 :
3605     { icone = "spherepoint_2.png" ;
3606       break ;
3607     }
3608     case 5 :
3609     { icone = "cylinderpointvector_2.png" ;
3610       break ;
3611     }
3612     case 61 :
3613     { }
3614     case 62 :
3615     { }
3616     case 63 :
3617     { icone = "diskwithhole_2.png" ;
3618       break ;
3619      }
3620     case 7 :
3621     { icone = "pipe_2.png" ;
3622       break ;
3623     }
3624   }
3625   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3626
3627   return aResultSO._retn();
3628 }
3629 //===========================================================================
3630 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3631                                       SALOMEDS::SObject_var aResultSO,
3632                                       const char* name, const char* comment, const char* icone, const char* ior)
3633 {
3634   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3635 //   MESSAGE("icone = "<<icone);
3636 //   MESSAGE("ior   = "<<ior);
3637   SALOMEDS::GenericAttribute_var anAttr ;
3638 //  Ajout du nom
3639   if ( name != NULL )
3640   {
3641     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3642     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3643     aNameAttrib->SetValue(name);
3644   }
3645
3646 //  Ajout du commentaire
3647   if ( comment != NULL )
3648   {
3649     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3650     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3651     aCommentAttrib->SetValue(comment);
3652   }
3653
3654 //  Ajout de l'icone
3655   if ( icone != NULL  )
3656   {
3657     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3658     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3659     aPixmap->SetPixMap(icone);
3660   }
3661
3662 //  Ajout de l ior
3663   if ( ior != NULL  )
3664   {
3665     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3666     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3667     anIOR->SetValue(ior);
3668   }
3669 };
3670
3671 //=====================================================================================
3672 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3673 {
3674   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3675
3676   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3677   ASSERT(!CORBA::is_nil(myCase));
3678   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3679   ASSERT(!CORBA::is_nil(aCaseSO));
3680
3681   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3682   ASSERT(!CORBA::is_nil(myBoundary));
3683   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3684   ASSERT(!CORBA::is_nil(aBoundarySO));
3685
3686   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3687
3688   aStudyBuilder->NewCommand();
3689
3690   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3691   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3692 //   aStudyBuilder->RemoveReference(aSubSO);
3693
3694   aStudyBuilder->CommitCommand();
3695
3696 };
3697 //=====================================================================================
3698 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3699 {
3700   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3701
3702   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3703   ASSERT(!CORBA::is_nil(myYACS));
3704   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3705   ASSERT(!CORBA::is_nil(aYACSSO));
3706
3707   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3708   ASSERT(!CORBA::is_nil(myCase));
3709   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3710   ASSERT(!CORBA::is_nil(aCaseSO));
3711
3712   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3713
3714   aStudyBuilder->NewCommand();
3715
3716   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3717   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3718
3719   aStudyBuilder->CommitCommand();
3720
3721 };
3722 //=============================================================================
3723 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3724 //  Option = 0 : fichier issu d'une importation
3725 //  Option = 1 : fichier issu d'une execution HOMARD
3726 {
3727   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3728   if (CORBA::is_nil(myCurrentStudy))
3729   {
3730     SALOME::ExceptionStruct es;
3731     es.type = SALOME::BAD_PARAM;
3732     es.text = "Invalid study context";
3733     throw SALOME::SALOME_Exception(es);
3734     return ;
3735   };
3736
3737 // Le module SMESH est-il actif ?
3738   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3739 //
3740   if (!CORBA::is_nil(aSmeshSO))
3741   {
3742 // On verifie que le fichier n est pas deja publie
3743     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3744     for (; aIter->More(); aIter->Next())
3745     {
3746       SALOMEDS::SObject_var  aSO = aIter->Value();
3747       SALOMEDS::GenericAttribute_var aGAttr;
3748       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3749       {
3750         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3751         CORBA::String_var value=anAttr->Value();
3752         if (strcmp((const char*)value,NomFich) == 0)
3753         {
3754           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3755           // Pour un fichier importe, on ne republie pas
3756           if ( Option == 0 ) { return; }
3757           // Pour un fichier calcule, on commence par faire la depublication
3758           else
3759           {
3760             MESSAGE ( "PublishResultInSmesh : depublication" );
3761             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3762             CORBA::String_var value2=anAttr2->Value();
3763             std::string MeshName = string(value2) ;
3764             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3765             DeleteResultInSmesh(NomFich, MeshName) ;
3766           }
3767         }
3768       }
3769     }
3770   }
3771
3772 // On enregistre le fichier
3773   MESSAGE( "Enregistrement du fichier");
3774   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3775   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3776   ASSERT(!CORBA::is_nil(aSmeshEngine));
3777   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3778   SMESH::DriverMED_ReadStatus theStatus;
3779   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3780
3781 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3782   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3783   for (int i = 0; i < mesMaillages->length();  i++)
3784   {
3785     MESSAGE( ". Mise a jour des attributs du maillage");
3786     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3787     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3788     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3789     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3790     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3791     anAttr->SetValue(NomFich);
3792     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3793     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3794     const char* icone ;
3795     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3796     else               { icone = "mesh_tree_mesh.png" ; }
3797     anAttr2->SetPixMap( icone );
3798   }
3799
3800 }
3801 //=============================================================================
3802 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3803 {
3804   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3805   if (CORBA::is_nil(myCurrentStudy))
3806   {
3807       SALOME::ExceptionStruct es;
3808       es.type = SALOME::BAD_PARAM;
3809       es.text = "Invalid study context";
3810       throw SALOME::SALOME_Exception(es);
3811       return ;
3812   };
3813
3814 // Le module SMESH est-il actif ?
3815   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3816 //
3817   if (CORBA::is_nil(aSmeshSO))
3818   {
3819       return ;
3820   };
3821 // On verifie que le fichier est deja publie
3822   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3823   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3824   for (; aIter->More(); aIter->Next())
3825   {
3826      SALOMEDS::SObject_var  aSO = aIter->Value();
3827      SALOMEDS::GenericAttribute_var aGAttr;
3828      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3829      {
3830        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3831        CORBA::String_var value=anAttr->Value();
3832        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3833        {
3834          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3835          {
3836            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3837            CORBA::String_var value2=anAttr2->Value();
3838            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3839            {
3840              myBuilder->RemoveObjectWithChildren( aSO ) ;
3841            }
3842          }
3843        }
3844      }
3845   }
3846   return ;
3847 }
3848 //=============================================================================
3849 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3850 {
3851   MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3852   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3853
3854   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3855   if (CORBA::is_nil(myIteration))
3856   {
3857       SALOME::ExceptionStruct es;
3858       es.type = SALOME::BAD_PARAM;
3859       es.text = "Invalid iterationStudy Object";
3860       throw SALOME::SALOME_Exception(es);
3861       return ;
3862   };
3863   const char* MeshFile = myIteration->GetMeshFile() ;
3864   const char* MeshName = myIteration->GetMeshName() ;
3865   CORBA::Long Option = -1 ;
3866   int etat = myIteration->GetState();
3867 // Iteration initiale
3868   if ( etat <= 0 )      { Option = 0 ; }
3869 // ou iteration calculee
3870   else if ( etat == 2 ) { Option = 1 ; }
3871 // Publication effective apres menage eventuel
3872   if ( Option >= 0 )
3873   {
3874     DeleteResultInSmesh(MeshFile, MeshName) ;
3875     PublishResultInSmesh(MeshFile, Option) ;
3876   }
3877
3878 }
3879 //=============================================================================
3880 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3881 {
3882 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3883   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3884
3885   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3886   if (CORBA::is_nil(myIteration))
3887   {
3888       SALOME::ExceptionStruct es;
3889       es.type = SALOME::BAD_PARAM;
3890       es.text = "Invalid iterationStudy Object";
3891       throw SALOME::SALOME_Exception(es);
3892       return ;
3893   };
3894
3895   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3896
3897   aStudyBuilder->NewCommand();
3898
3899   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3900 // Pour les fichiers med, on affiche une icone de maillage
3901 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3902 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3903   std::string icone ;
3904   std::string ior = " " ;
3905   if ( Commentaire[0] == 'M' )
3906   { icone = "med.png" ; }
3907   else
3908   { icone = "texte_2.png" ; }
3909   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3910
3911   aStudyBuilder->CommitCommand();
3912 }
3913 //
3914 //=============================================================================
3915 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3916 {
3917 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3918   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3919
3920   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3921   if (CORBA::is_nil(myYACS))
3922   {
3923       SALOME::ExceptionStruct es;
3924       es.type = SALOME::BAD_PARAM;
3925       es.text = "Invalid YACSStudy Object";
3926       throw SALOME::SALOME_Exception(es);
3927       return ;
3928   };
3929
3930   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3931
3932   aStudyBuilder->NewCommand();
3933
3934   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3935   std::string icone = "texte_2.png" ;
3936   std::string ior = " " ;
3937   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3938
3939   aStudyBuilder->CommitCommand();
3940 }
3941 //
3942 //=============================================================================
3943 //=============================================================================
3944 // YACS
3945 //=============================================================================
3946 //=============================================================================
3947 //=============================================================================
3948 // Creation d'un schema YACS
3949 // nomCas : nom du cas a traiter
3950 // FileName : nom du fichier contenant le script de lancement du calcul
3951 // DirName : le repertoire de lancement des calculs du schéma
3952 //=============================================================================
3953 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3954 {
3955   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3956   INFOS ( ". nomCas     : " << nomCas);
3957   INFOS ( ". ScriptFile : " << ScriptFile);
3958   INFOS ( ". DirName    : " << DirName);
3959   INFOS ( ". MeshFile   : " << MeshFile);
3960
3961   // A. Controle du nom :
3962   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3963   {
3964     SALOME::ExceptionStruct es;
3965     es.type = SALOME::BAD_PARAM;
3966     es.text = "This schema YACS has already been defined.";
3967     throw SALOME::SALOME_Exception(es);
3968     return 0;
3969   }
3970
3971   // B. Creation de l'objet
3972   HOMARD::HOMARD_YACS_var myYACS = newYACS();
3973   if (CORBA::is_nil(myYACS))
3974   {
3975     SALOME::ExceptionStruct es;
3976     es.type = SALOME::BAD_PARAM;
3977     es.text = "Unable to create the schema YACS";
3978     throw SALOME::SALOME_Exception(es);
3979     return 0;
3980   };
3981   myYACS->SetName( nomYACS ) ;
3982
3983   // C. Enregistrement
3984   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3985
3986   SALOMEDS::SObject_var aSO;
3987   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3988
3989   PublishCaseUnderYACS(nomYACS, nomCas);
3990
3991   // D. Caracterisation
3992   // D.1. Options
3993   myYACS->SetDirName( DirName ) ;
3994   myYACS->SetMeshFile( MeshFile ) ;
3995   myYACS->SetScriptFile( ScriptFile ) ;
3996   myYACS->SetCaseName( nomCas ) ;
3997   // D.2. Defaut
3998   int defaut_i ;
3999   // D.2.1. Type constant
4000   myYACS->SetType( 1 ) ;
4001   // D.2.2. Convergence
4002   defaut_i = GetYACSMaxIter() ;
4003   myYACS->SetMaxIter( defaut_i ) ;
4004   defaut_i = GetYACSMaxNode() ;
4005   myYACS->SetMaxNode( defaut_i ) ;
4006   defaut_i = GetYACSMaxElem() ;
4007   myYACS->SetMaxElem( defaut_i ) ;
4008   // D.3. Fichier de sauvegarde dans le repertoire du cas
4009   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4010   std::string dirnamecase = caseyacs->GetDirName() ;
4011   std::string XMLFile ;
4012   XMLFile = dirnamecase + "/schema.xml" ;
4013   myYACS->SetXMLFile( XMLFile.c_str() ) ;
4014
4015   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4016 }
4017 //=============================================================================
4018 // Ecriture d'un schema YACS
4019 //=============================================================================
4020 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4021 {
4022   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4023 // Le repertoire du cas
4024   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4025   ASSERT(!CORBA::is_nil(myYACS));
4026 // Le nom du fichier du schema
4027   std::string XMLFile ;
4028   XMLFile = myYACS->GetXMLFile() ;
4029
4030   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4031
4032   return codret ;
4033 }
4034 //=============================================================================
4035 // Ecriture d'un schema YACS sur un fichier donne
4036 //=============================================================================
4037 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4038 {
4039   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4040
4041   // A. Prealable
4042   int codret = 0;
4043
4044   // B. L'objet YACS
4045   // B.1. L'objet
4046   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4047   ASSERT(!CORBA::is_nil(myYACS));
4048   // B.2. Les caracteristiques
4049   std::string DirName = myYACS->GetDirName() ;
4050   std::string MeshFile = myYACS->GetMeshFile() ;
4051   std::string ScriptFile = myYACS->GetScriptFile() ;
4052   // B.3. Les caracteristiques de convergence
4053   int MaxIter = myYACS->GetMaxIter() ;
4054   int MaxNode = myYACS->GetMaxNode() ;
4055   int MaxElem = myYACS->GetMaxElem() ;
4056
4057   // C. Le cas
4058   // C.1. L'objet cas
4059   const char* nomCas = myYACS->GetCaseName();
4060   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4061   ASSERT(!CORBA::is_nil(myCase));
4062   // C.2. Les instructions python associees au cas
4063   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4064   std::string pythonCas = dumpCorbaCase.in();
4065   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4066
4067   // D. Les iterations
4068   // D.1. L'iteration initiale
4069   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4070   std::string Iter0Name = myCase->GetIter0Name() ;
4071   MESSAGE (". Iter0Name = " << Iter0Name);
4072   std::string MeshName = Iter0->GetMeshName();
4073   MESSAGE (". MeshName = " << MeshName);
4074   // D.2. L'iteration numero 1
4075   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4076   int numberOfIter = maListe->length();
4077   if ( numberOfIter > 1 )
4078   {
4079     MESSAGE (". numberOfIter = " << numberOfIter);
4080     SALOME::ExceptionStruct es ;
4081     es.type = SALOME::BAD_PARAM;
4082     std::string text = "Une seule iteration est permise." ;
4083     es.text = CORBA::string_dup(text.c_str());
4084     throw SALOME::SALOME_Exception(es);
4085     return 0;
4086   }
4087   std::string Iter1Name = std::string((*maListe)[0]);
4088   MESSAGE ("... Iter1Name = " << Iter1Name);
4089   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4090   // D.3. Les instructions python associees a l'iteration
4091   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4092   std::string pythonIter = dumpCorbaIter.in();
4093   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4094
4095   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4096   // E.1. La structure
4097   std::string nomHypo = Iter1->GetHypoName();
4098   MESSAGE (". nomHypo = " << nomHypo);
4099   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4100   ASSERT(!CORBA::is_nil(myHypo));
4101   // E.2. Les caracteristiques de l'adaptation
4102   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4103   ASSERT(ListTypes->length() == 3);
4104   int TypeAdap = (*ListTypes)[0];
4105 //   int TypeRaff = (*ListTypes)[1];
4106 //   int TypeDera = (*ListTypes)[2];
4107   // E.3. Les instructions python associees a l'hypothese
4108   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4109   std::string pythonHypo = dumpCorbaHypo.in();
4110   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4111
4112   // F. Le fichier du schema de reference
4113   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4114   std::string XMLFile_base ;
4115   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4116   else
4117   {
4118     SALOME::ExceptionStruct es ;
4119     es.type = SALOME::BAD_PARAM;
4120     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4121     es.text = CORBA::string_dup(text.c_str());
4122     throw SALOME::SALOME_Exception(es);
4123     return 0;
4124   }
4125   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4126 //   if ( _Langue ==
4127   MESSAGE("XMLFile_base ="<<XMLFile_base);
4128
4129   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4130   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4131   std::ifstream fichier( XMLFile_base.c_str() );
4132   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4133   {
4134     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4135     std::string ligne; // variable contenant chaque ligne lue
4136     std::string mot_cle;
4137     while ( std::getline( fichier, ligne ) )
4138     {
4139       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4140       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4141       ligne_bis >> mot_cle ;
4142       // G.1.2. Le maillage initial
4143       if ( mot_cle == "DataInit_MeshFile" )
4144       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4145       // G.1.3. Le script de lancement
4146       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4147       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4148       // G.1.4. Les options du cas
4149       else if ( mot_cle == "Iter_1_Case_Options" )
4150       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4151       // G.1.5. Execution de HOMARD : le repertoire du cas
4152       else if ( mot_cle == "HOMARD_Exec_DirName" )
4153       { myDriver->Texte_HOMARD_Exec_DirName(); }
4154       // G.1.6. Execution de HOMARD : le nom du maillage
4155       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4156       {
4157         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4158         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4159         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4160       }
4161       // G.1.7. Execution de HOMARD : les options de l'hypothese
4162       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4163       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4164       // G.1.8. Execution de HOMARD : les options de l'iteration
4165       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4166       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4167       // G.1.9. a. Creation eventuelles des zones et frontieres
4168       //        b. Enchainement
4169       else if ( mot_cle == "Iter_1" )
4170       {
4171         std::string texte_control = "" ;
4172         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4173         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4174         texte_control += myDriver->Texte_Iter_1_control() ;
4175         myDriver->TexteAdd(texte_control);
4176       }
4177       // G.1.10. Les tests de convergence
4178       else if ( mot_cle == "Analyse_Test_Convergence" )
4179       { myDriver->TexteAnalyse_Test_Convergence(MaxIter, MaxNode, MaxElem); }
4180       // G.1.11. Les parametres
4181       else if ( mot_cle == "PARAMETRES" )
4182       { myDriver->TexteAddParametres(); }
4183       // G.1.n. La ligne est recopiee telle quelle
4184       else { myDriver->TexteAdd(ligne);  }
4185     }
4186     // G.2. Ecriture du texte dans le fichier
4187     if ( codret == 0 )
4188     { myDriver->CreeFichier(); }
4189   }
4190   else
4191   {
4192     SALOME::ExceptionStruct es;
4193     es.type = SALOME::BAD_PARAM;
4194     std::string text = "The reference file for the YACS schema cannot be read." ;
4195     es.text = CORBA::string_dup(text.c_str());
4196     throw SALOME::SALOME_Exception(es);
4197   }
4198
4199   delete myDriver;
4200
4201   // H. Publication du fichier dans l'arbre
4202
4203     std::string Commentaire = "xml" ;
4204     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4205
4206   return codret ;
4207 }
4208 //=============================================================================
4209 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4210 //=============================================================================
4211 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4212 {
4213   MESSAGE ( "YACSDriverTexteZone" );
4214   // A. Les zones associees a cette hypothese
4215   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4216   int numberOfZonesx2 = ListZone->length();
4217
4218   // B. Parcours des zones
4219   std::string texte_control ;
4220   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4221   {
4222     // 1. Reperage de la zone
4223     std::string ZoneName = std::string((*ListZone)[iaux]);
4224     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4225     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4226     ASSERT(!CORBA::is_nil(myZone));
4227     // 2. Les instructions python associees a la zone
4228     //    La premiere ligne est un commentaire a eliminer
4229     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4230     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4231     std::string pythonStructure_0 = dumpCorbaZone.in();
4232     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4233     std::istringstream tout (pythonStructure_0) ;
4234     std::string ligne ;
4235     std::string pythonStructure ;
4236     while ( std::getline( tout, ligne ) )
4237     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4238     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4239     // 3. Decodage du nom du service
4240     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4241     MESSAGE ( "... methode = " << methode);
4242     // 4. Mise en place des instructions
4243     int ZoneType = myZone->GetType();
4244     MESSAGE ( "... ZoneType = " << ZoneType);
4245     std::string texte_control_0 ;
4246     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4247     texte_control += texte_control_0 ;
4248     // 5. Decalage
4249     iaux ++ ;
4250   }
4251
4252   return texte_control ;
4253 }
4254 //=============================================================================
4255 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4256 //=============================================================================
4257 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4258 {
4259   MESSAGE ( "YACSDriverTexteBoundary" );
4260   // A. Les frontieres associees au cas
4261   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4262   int numberOfitems = ListBoundaryGroupType->length();
4263
4264   // B. Parcours des frontieres
4265   std::string texte_control ;
4266   std::list<std::string>  ListeBoundaryTraitees ;
4267   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4268   {
4269     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4270     MESSAGE ( "... BoundaryName = " << BoundaryName);
4271     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4272     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4273     int A_faire = 1 ;
4274     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4275     while (it != ListeBoundaryTraitees.end())
4276     {
4277       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4278       if ( BoundaryName == *it ) { A_faire = 0 ; }
4279       it++;
4280     }
4281     if ( A_faire == 1 )
4282     {
4283     // 1. Caracteristiques de la frontiere
4284       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4285       ASSERT(!CORBA::is_nil(myBoundary));
4286       // 2. Les instructions python associees a la frontiere
4287       //    La premiere ligne est un commentaire a eliminer
4288       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4289       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4290       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4291       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4292       std::istringstream tout (pythonStructure_0) ;
4293       std::string ligne ;
4294       std::string pythonStructure ;
4295       while ( std::getline( tout, ligne ) )
4296       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4297       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4298       // 3. Decodage du nom du service
4299       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4300       MESSAGE ( "... methode = " << methode);
4301       // 4. Mise en place des instructions
4302       int BoundaryType = myBoundary->GetType();
4303       MESSAGE ( "... BoundaryType = " << BoundaryType);
4304       const char* MeshName ;
4305       const char* MeshFile ;
4306       if (BoundaryType == 0)
4307       {
4308         MeshName = myBoundary->GetMeshName() ;
4309         MESSAGE ( ". MeshName = " << MeshName );
4310         MeshFile = myBoundary->GetMeshFile() ;
4311         MESSAGE ( ". MeshFile = " << MeshFile );
4312       }
4313       std::string texte_control_0 ;
4314       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName, MeshName, MeshFile );
4315       texte_control += texte_control_0 ;
4316       // 5. Memorisation du traitement
4317       ListeBoundaryTraitees.push_back( BoundaryName );
4318     }
4319   }
4320
4321   return texte_control ;
4322 }
4323 //
4324 //=============================================================================
4325 //=============================================================================
4326 // Next functions are inherited from SALOMEDS::Driver interface
4327 //=============================================================================
4328 //=============================================================================
4329 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4330                                       const char* theURL,
4331                                       CORBA::Boolean isMultiFile)
4332 {
4333   MESSAGE ("Save for theURL = "<< theURL);
4334   SALOMEDS::TMPFile_var aStreamFile;
4335
4336   // get temporary directory name
4337   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4338
4339   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4340   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4341
4342   // HOMARD data file name
4343   std::string aFileName = "";
4344   if (isMultiFile)
4345     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4346   aFileName += "_HOMARD.dat";
4347
4348   // initialize sequence of file names
4349   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4350   aFileSeq->length(1);
4351   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4352
4353   // get full path to the data file
4354   aFileName = tmpDir + aFileName;
4355
4356   // save data
4357   // -> create file
4358   std::ofstream f(aFileName.c_str());
4359
4360   // clear temporary id map
4361   context._idmap.clear();
4362
4363   int id = 1;
4364
4365   // -> save cases
4366   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4367   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4368     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4369     PortableServer::ServantBase_var aServant = GetServant(aCas);
4370     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4371     if (aCasServant) {
4372       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4373       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4374     }
4375   }
4376   // -> save zones
4377   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4378   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4379     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4380     PortableServer::ServantBase_var aServant = GetServant(aZone);
4381     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4382     if (aZoneServant) {
4383       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4384       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4385     }
4386   }
4387   // -> save hypotheses
4388   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4389   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4390     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4391     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4392     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4393     if (aHypoServant) {
4394       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4395       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4396     }
4397   }
4398   // -> save iterations
4399   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4400   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4401     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4402     PortableServer::ServantBase_var aServant = GetServant(aIter);
4403     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4404     if (aIterServant) {
4405       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4406       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4407     }
4408   }
4409   // -> save boundaries
4410   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4411   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4412     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4413     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4414     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4415     if (aBoundaryServant) {
4416       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4417       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4418     }
4419   }
4420   // -> close file
4421   MESSAGE ("close file");
4422   f.close();
4423
4424   // put temporary files to the stream
4425   MESSAGE ("put temporary files to the stream");
4426   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4427
4428   // remove temporary files
4429   MESSAGE ("remove temporary files");
4430   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4431
4432   // return data stream
4433   MESSAGE ("return data stream");
4434   return aStreamFile._retn();
4435 };
4436
4437 //===========================================================================
4438 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4439                                            const char* theURL,
4440                                            CORBA::Boolean isMultiFile)
4441 {
4442   // No specific ASCII persistence
4443   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4444   return aStreamFile._retn();
4445 };
4446
4447 //===========================================================================
4448 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4449                                    const SALOMEDS::TMPFile& theStream,
4450                                    const char* theURL,
4451                                    CORBA::Boolean isMultiFile)
4452 {
4453   MESSAGE ("Load pour theURL = "<< theURL);
4454   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4455
4456   // set current study
4457   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4458     SetCurrentStudy(aStudy);
4459
4460   // get temporary directory name
4461   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4462
4463   // Convert the stream into sequence of files to process
4464   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4465                                                                             tmpDir.c_str(),
4466                                                                             isMultiFile);
4467   // HOMARD data file name
4468   std::string aFileName = "";
4469   if (isMultiFile)
4470     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4471   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4472
4473   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4474
4475   // save data
4476   // -> create file
4477   std::ifstream f(aFileName.c_str());
4478
4479   // clear context
4480   context._mesCas.clear();
4481   context._mesHypotheses.clear();
4482   context._mesIterations.clear();
4483   context._mesZones.clear();
4484   context._mesBoundarys.clear();
4485   context._idmap.clear();
4486
4487   int id = 1;
4488   std::string line;
4489
4490   while (f) {
4491     std::getline(f, line);
4492     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4493     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4494     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4495     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4496     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4497     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4498     if (line.substr(0, bounSignature.size()) == bounSignature) {
4499       // re-create boundary
4500       MESSAGE ("Recreation de la frontiere" );
4501       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4502       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4503       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4504       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4505         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4506         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4507       }
4508     }
4509     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4510       // re-create case
4511       MESSAGE ("Recreation du cas" );
4512       HOMARD::HOMARD_Cas_var aCase = newCase();
4513       PortableServer::ServantBase_var aServant = GetServant(aCase);
4514       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4515       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4516         context._mesCas[aCase->GetName()] = aCase;
4517         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4518       }
4519     }
4520     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4521       // re-create hypothesis
4522       MESSAGE ("Recreation de l hypothese" );
4523       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4524       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4525       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4526       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4527         context._mesHypotheses[aHypo->GetName()] = aHypo;
4528         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4529       }
4530     }
4531     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4532       // re-create iteration
4533       MESSAGE ("Recreation de l'iteration" );
4534       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4535       PortableServer::ServantBase_var aServant = GetServant(aIter);
4536       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4537       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4538         context._mesIterations[aIter->GetName()] = aIter;
4539         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4540       }
4541     }
4542     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4543       MESSAGE ("Recreation de la zone" );
4544       // re-create zone
4545       HOMARD::HOMARD_Zone_var aZone = newZone();
4546       PortableServer::ServantBase_var aServant = GetServant(aZone);
4547       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4548       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4549         context._mesZones[aZone->GetName()] = aZone;
4550         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4551       }
4552     }
4553     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4554       MESSAGE ("Recreation du schema YACS" );
4555       // re-create YACS
4556       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4557       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4558       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4559       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4560         context._mesYACSs[aYACS->GetName()] = aYACS;
4561         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4562       }
4563     }
4564     id++;
4565   }
4566
4567   // -> close file
4568   f.close();
4569
4570   // Remove temporary files created from the stream
4571   if (!isMultiFile)
4572     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4573
4574   return true;
4575 };
4576
4577 //===========================================================================
4578 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4579                                         const SALOMEDS::TMPFile& theStream,
4580                                         const char* theURL,
4581                                         CORBA::Boolean isMultiFile)
4582 {
4583   // No specific ASCII persistence
4584   return Load(theComponent, theStream, theURL, isMultiFile);
4585 };
4586
4587 //===========================================================================
4588 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4589 {
4590   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4591     // clearing study context should be done here:
4592     // - destroy all servants and related CORBA objects
4593     // ... (TODO)
4594     // - remove context from myContextMap
4595     myContextMap.erase(theComponent->GetStudy()->StudyId());
4596     // - nullify myCurrentStudy
4597     myCurrentStudy = SALOMEDS::Study::_nil();
4598   }
4599 };
4600
4601 //===========================================================================
4602 char* HOMARD_Gen_i::ComponentDataType()
4603 {
4604   return CORBA::string_dup("HOMARD");
4605 };
4606
4607 //===========================================================================
4608 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4609                                             const char* IORString,
4610                                             CORBA::Boolean isMultiFile,
4611                                             CORBA::Boolean isASCII)
4612 {
4613   CORBA::String_var aString("");
4614   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4615     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4616     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4617     if (!CORBA::is_nil(anObj)) {
4618       PortableServer::ServantBase_var aServant = GetServant(anObj);
4619       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4620       if (aStorable) {
4621         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4622         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4623           if (it->second == aStorable) {
4624             std::stringstream os;
4625             os << it->first;
4626             aString = CORBA::string_dup(os.str().c_str());
4627           }
4628         }
4629       }
4630     }
4631   }
4632   return aString._retn();
4633 };
4634
4635 //===========================================================================
4636 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4637                                             const char* aLocalPersistentID,
4638                                             CORBA::Boolean isMultiFile,
4639                                             CORBA::Boolean isASCII)
4640 {
4641   CORBA::String_var aString("");
4642   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4643     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4644     int id = atoi(aLocalPersistentID);
4645     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4646       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4647       if (!CORBA::is_nil(object)) {
4648         aString = _orb->object_to_string(object);
4649       }
4650     }
4651   }
4652   return aString._retn();
4653 };
4654
4655 //===========================================================================
4656 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4657 {
4658   if(CORBA::is_nil(myCurrentStudy))
4659     return false;
4660
4661   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4662   if(!aCas->_is_nil())
4663     return true;
4664
4665   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4666   if(!aHypo->_is_nil())
4667     return true;
4668
4669   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4670   if(!aZone->_is_nil())
4671     return true;
4672
4673   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4674   if(!aBoundary->_is_nil())
4675     return true;
4676
4677   /* Iteration is not published directly
4678   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4679   if(!aIter->_is_nil())
4680     return true;
4681   */
4682   return false;
4683 };
4684
4685 //===========================================================================
4686 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4687 {
4688   // No Copy/Paste support
4689   return false;
4690 };
4691
4692 //===========================================================================
4693 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4694                                            CORBA::Long& theObjectID)
4695 {
4696   // No Copy/Paste support
4697   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4698   return aStreamFile._retn();
4699 };
4700
4701 //===========================================================================
4702 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4703                                         CORBA::Long theObjectID)
4704 {
4705   // No Copy/Paste support
4706   return false;
4707 };
4708
4709 //===========================================================================
4710 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4711                                                CORBA::Long theObjectID,
4712                                                SALOMEDS::SObject_ptr theSObject)
4713 {
4714   // No Copy/Paste support
4715   SALOMEDS::SObject_var aResultSO;
4716   return aResultSO._retn();
4717 };
4718
4719 //===========================================================================
4720 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4721 {
4722   PortableServer::Servant aServant = 0;
4723   if (!CORBA::is_nil(theObject)) {
4724     try {
4725       aServant = _poa->reference_to_servant(theObject);
4726     }
4727     catch (...) {
4728     }
4729   }
4730   return aServant;
4731 }
4732
4733 //==========================================================================
4734 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4735                                        CORBA::Boolean isPublished,
4736                                        CORBA::Boolean isMultiFile,
4737                                        CORBA::Boolean& isValidScript)
4738 {
4739    MESSAGE ("Entree dans DumpPython");
4740    isValidScript=1;
4741    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4742    if(CORBA::is_nil(aStudy))
4743      return new Engines::TMPFile(0);
4744
4745    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4746    if(CORBA::is_nil(aSO))
4747       return new Engines::TMPFile(0);
4748
4749    std::string aScript = "\"\"\"\n";
4750    aScript += "Python script for HOMARD\n";
4751    aScript += "Copyright 1996, 2011, 1015 EDF\n";
4752    aScript += "\"\"\"\n";
4753    aScript += "__revision__ = \"V1.2\"\n";
4754    aScript += "import HOMARD\n";
4755    if( isMultiFile )
4756       aScript += "import salome\n";
4757    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4758    if( isMultiFile ) {
4759       aScript += "def RebuildData(theStudy):\n";
4760       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4761    }
4762    else
4763       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4764    MESSAGE (". Au depart \n"<<aScript);
4765
4766
4767    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4768    {
4769     MESSAGE (". Ecritures des frontieres");
4770     aScript += "#\n# Creation of the boundaries";
4771     aScript +=  "\n# ==========================";
4772    }
4773    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4774    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4775         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4776    {
4777     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4778     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4779     std::string dumpBoundary = dumpCorbaBoundary.in();
4780     MESSAGE (dumpBoundary<<"\n");
4781     aScript += dumpBoundary;
4782    }
4783
4784
4785    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4786    {
4787     MESSAGE (". Ecritures des zones");
4788     aScript += "#\n# Creation of the zones";
4789     aScript +=  "\n# =====================";
4790    }
4791    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4792    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4793          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4794    {
4795     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4796     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4797     std::string dumpZone = dumpCorbaZone.in();
4798     MESSAGE (dumpZone<<"\n");
4799     aScript += dumpZone;
4800    }
4801
4802
4803    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4804    {
4805     MESSAGE (". Ecritures des hypotheses");
4806     aScript += "#\n# Creation of the hypotheses";
4807     aScript +=  "\n# ==========================";
4808    }
4809    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4810    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4811          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4812    {
4813     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4814     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4815     std::string dumpHypo = dumpCorbaHypo.in();
4816     MESSAGE (dumpHypo<<"\n");
4817     aScript += dumpHypo;
4818    }
4819
4820
4821    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4822    {
4823     MESSAGE (". Ecritures des cas");
4824     aScript += "#\n# Creation of the cases";
4825     aScript += "\n# =====================";
4826    }
4827    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4828    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4829         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4830         {
4831            std::string nomCas = (*it_cas).first;
4832            std::string dumpCas = std::string("\n# Creation of the case ") ;
4833            dumpCas +=  nomCas + std::string("\n");
4834            dumpCas += std::string("\t") + nomCas;
4835            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4836
4837            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4838            CORBA::String_var cIter0= myCase->GetIter0Name();
4839            std::string iter0 = cIter0.in();
4840
4841            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4842            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4843            std::string mesh0 = cMesh0.in();
4844            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4845            std::string meshName0 = cMeshName0.in();
4846            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4847            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4848            std::string dumpCas2= dumpCorbaCase.in();
4849
4850            MESSAGE (dumpCas<<dumpCas2<<"\n");
4851            aScript += dumpCas + dumpCas2;
4852         };
4853
4854
4855    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4856    {
4857     MESSAGE (". Ecritures des iterations");
4858     aScript += "#\n# Creation of the iterations" ;
4859     aScript += "\n# ==========================";
4860    }
4861    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4862    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4863         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4864    {
4865     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4866     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4867     std::string dumpIter = dumpCorbaIter.in();
4868     MESSAGE (dumpIter<<"\n");
4869     aScript += dumpIter;
4870    }
4871
4872
4873    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4874    {
4875     MESSAGE (". Ecritures des schemas YACS");
4876     aScript += "#\n# Creation of the schemas YACS";
4877     aScript +=  "\n# ============================";
4878    }
4879    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4880    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4881          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4882    {
4883     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4884     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4885     std::string dumpYACS = dumpCorbaYACS.in();
4886     MESSAGE (dumpYACS<<"\n");
4887     aScript += dumpYACS;
4888    }
4889
4890   MESSAGE (". Ecritures finales");
4891   if( isMultiFile )
4892     aScript += "\n\tpass";
4893   aScript += "\n";
4894
4895   if( !isMultiFile ) // remove unnecessary tabulation
4896     aScript = RemoveTabulation( aScript );
4897
4898 //   MESSAGE ("A ecrire \n"<<aScript);
4899   const size_t aLen = strlen(aScript.c_str());
4900   char* aBuffer = new char[aLen+1];
4901   strcpy(aBuffer, aScript.c_str());
4902
4903   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4904   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4905
4906   MESSAGE ("Sortie de DumpPython");
4907   return aStreamFile._retn();
4908 }
4909
4910
4911 //=============================================================================
4912 //=============================================================================
4913 // Utilitaires
4914 //=============================================================================
4915 //=============================================================================
4916 void HOMARD_Gen_i::IsValidStudy( )
4917 {
4918 //   MESSAGE( "IsValidStudy" );
4919   if (CORBA::is_nil(myCurrentStudy))
4920   {
4921     SALOME::ExceptionStruct es;
4922     es.type = SALOME::BAD_PARAM;
4923     es.text = "Invalid study context";
4924     throw SALOME::SALOME_Exception(es);
4925   };
4926   return ;
4927 }
4928
4929 //=============================================================================
4930 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4931 {
4932   std::string casename = std::string("") ;
4933   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4934   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4935   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4936   {
4937    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4938    {
4939      casename = std::string(it->second->GetName()) ;
4940      break ;
4941    }
4942   }
4943   return CORBA::string_dup( casename.c_str() );
4944 }
4945 /*//=============================================================================
4946 void SALOMEException( std::string message )
4947 {
4948   SALOME::ExceptionStruct es;
4949   es.type = SALOME::BAD_PARAM;
4950   es.text = message;
4951   throw SALOME::SALOME_Exception(es);
4952   return ;
4953 }*/
4954 //=============================================================================
4955 char* HOMARD_Gen_i::getVersion()
4956 {
4957 #if HOMARD_DEVELOPMENT
4958   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4959 #else
4960   return CORBA::string_dup(HOMARD_VERSION_STR);
4961 #endif
4962 }
4963 //===============================================================================
4964 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
4965 // ligne : la ligne a manipuler
4966 // caractere : le caractere a reperer
4967 // option : 0 : la chaine avant la premiere apparition du caractere
4968 //          1 : la chaine apres la premiere apparition du caractere
4969 //          2 : la chaine avant la derniere apparition du caractere
4970 //          3 : la chaine apres la derniere apparition du caractere
4971 // Si le caractere est absent, on retourne la chaine totale
4972 //===============================================================================
4973 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
4974 {
4975 //   MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4976 //
4977   std::string chaine = ligne ;
4978   int position ;
4979   if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
4980   else              { position = ligne.find_last_of( caractere ) ; }
4981 //   MESSAGE("position = "<<position);
4982 //   MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
4983 //   MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
4984 //
4985   if ( position != std::string::npos )
4986   {
4987     if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
4988     else                                      { chaine = ligne.substr( position+1 ) ; }
4989   }
4990   return chaine ;
4991 //
4992 }
4993 //=============================================================================
4994 //=============================================================================
4995 // Gestion des preferences
4996 //=============================================================================
4997 //=============================================================================
4998 // Decodage du fichier d'arcihvage des preferences
4999 //
5000 void HOMARD_Gen_i::SetPreferences( )
5001 {
5002   MESSAGE ( "SetPreferences" );
5003
5004   std::string ligne, mot_cle, salome_version ;
5005   bool ok = true ;
5006
5007   // A. Les valeurs par defaut ; elles doivent etre coherentes
5008   std::string LanguageShort = "en" ;
5009   int PublisMeshIN = 0 ;
5010   int PublisMeshOUT = 0 ;
5011   int YACSMaxIter = 0 ;
5012   int YACSMaxNode = 0 ;
5013   int YACSMaxElem = 0 ;
5014   std::string YACSTypeTestchaine = "None" ;
5015
5016   // B. La version de salome
5017   // Cela se presente sous la forme :
5018   // [SALOME KERNEL] : 7.3.0
5019   std::string File ;
5020   File  = getenv("KERNEL_ROOT_DIR") ;
5021   File += "/bin/salome/VERSION" ;
5022   MESSAGE ( "File = "<<File ) ;
5023   std::ifstream fichier0( File.c_str() ) ;
5024   if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5025   {
5026     std::string ligne; // variable contenant chaque ligne lue
5027     while ( std::getline( fichier0, ligne ) )
5028     {
5029       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5030       ligne_bis >> mot_cle ;
5031       if ( mot_cle == "[SALOME" )
5032       {
5033         salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5034 //         MESSAGE ( "salome_version = "<<salome_version<<"|||");
5035         break ;
5036       }
5037     }
5038   }
5039   else { ok = false ; }
5040
5041   // B. Decodage du fichier de preferences
5042   if ( ok )
5043   {
5044     std::string PrefFile ;
5045     PrefFile  = getenv("HOME") ;
5046     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5047     MESSAGE ( "PrefFile = "<<PrefFile ) ;
5048
5049     std::ifstream fichier( PrefFile.c_str() );
5050     if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5051     {
5052       bool section_langue = false ;
5053       bool section_homard = false ;
5054       while ( std::getline( fichier, ligne ) )
5055       {
5056         std::string chaine ;
5057         // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5058         std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5059         ligne_bis >> mot_cle ;
5060
5061         // 2. Les sections
5062         // 2.1. Debut d'une section
5063   //       MESSAGE(mot_cle);
5064         if ( mot_cle == "<section" )
5065         { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5066           ligne_bis >> mot_cle ;
5067           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5068           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5069           if ( chaine == "language" ) { section_langue = true ; }
5070           if ( chaine == "HOMARD" )   { section_homard = true ; }
5071   //         MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5072         }
5073         // 2.2. Fin d'une section
5074         else if ( mot_cle == "</section>" )
5075         { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5076           section_langue = false ;
5077           section_homard = false ; }
5078
5079         // 3. Parametres
5080         // 3.1. La langue
5081         else if ( section_langue || section_homard )
5082         { MESSAGE ( "a decoder : "<< ligne);
5083 //        La valeur : entre les deux premieres quotes
5084           chaine = GetStringInTexte ( ligne, "\"", 1 ) ;
5085 //           MESSAGE("chaine 1 = |"<<chaine<<"|");
5086           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5087 //           MESSAGE("chaine = |"<<chaine<<"|");
5088 //        Le mot_cle : entre les deux dernieres quotes
5089           std::string chaine2 = GetStringInTexte ( ligne, "\"", 2 ) ;
5090 //           MESSAGE("chaine2 1 = |"<<chaine2<<"|");
5091           chaine2 = GetStringInTexte ( chaine2,  "\"", 3 ) ;
5092 //           MESSAGE("chaine2 = |"<<chaine2<<"|");
5093           // 3.1. La langue
5094           if ( section_langue )
5095           { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5096           // 3.2. HOMARD
5097           if ( section_homard )
5098           {
5099             std::istringstream chainebis( chaine ) ;
5100             // 3.2.1. Les publications
5101             if ( chaine2 == "publish_mesh_in" )  { chainebis >> PublisMeshIN ; }
5102             if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5103             // 3.2.2. Les maximum pour YACS
5104             if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5105             if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5106             if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5107             if ( chaine2 == "yacs_type_test" ) { YACSTypeTestchaine = chaine ; }
5108           }
5109         }
5110       }
5111     }
5112   }
5113
5114   // C. Enregistrements
5115   MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5116   SetLanguageShort( LanguageShort.c_str() ) ;
5117
5118   MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5119   SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5120
5121   MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5122   SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5123
5124   MESSAGE ("Enregistrement de TypeTest = " << YACSTypeTestchaine.c_str() );
5125   int YACSTypeTest ;
5126   if ( ( YACSTypeTestchaine == "VTest > VRef" ) || ( YACSTypeTestchaine == "VTest &gt; VRef" ) )      { YACSTypeTest = 1 ; }
5127   else if ( ( YACSTypeTestchaine == "VTest < VRef" ) || ( YACSTypeTestchaine == "VTest &lt; VRef" ) ) { YACSTypeTest = 2 ; }
5128   else                                                                                                { YACSTypeTest = 0 ; }
5129   MESSAGE ("==> TypeTest = " << YACSTypeTest );
5130   SetYACSConvergenceType( YACSTypeTest ) ;
5131
5132   return ;
5133 }
5134 //===============================================================================
5135 // Langue de SALOME
5136 //===============================================================================
5137 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5138 {
5139 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5140   _LangueShort = LanguageShort ;
5141   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5142   else                        { _Langue = "English" ; }
5143   return ;
5144 }
5145 char* HOMARD_Gen_i::GetLanguageShort()
5146 {
5147 //   MESSAGE ("GetLanguageShort");
5148   return CORBA::string_dup( _LangueShort.c_str() );
5149 }
5150 //===============================================================================
5151 // Options de publications
5152 //===============================================================================
5153 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5154 {
5155   _PublisMeshIN  = PublisMeshIN  ;
5156   _PublisMeshOUT = PublisMeshOUT ;
5157   return ;
5158 }
5159 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5160 {
5161   return _PublisMeshIN ;
5162 }
5163 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5164 {
5165   return _PublisMeshOUT ;
5166 }
5167 //===============================================================================
5168 // YACS - test de convergence
5169 //===============================================================================
5170 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5171 {
5172   _YACSMaxIter = YACSMaxIter ;
5173   _YACSMaxNode = YACSMaxNode ;
5174   _YACSMaxElem = YACSMaxElem ;
5175   return ;
5176 }
5177 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5178 {
5179   return _YACSMaxIter ;
5180 }
5181 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5182 {
5183   return _YACSMaxNode ;
5184 }
5185 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5186 {
5187   return _YACSMaxElem ;
5188 }
5189 void HOMARD_Gen_i::SetYACSConvergenceType(CORBA::Long YACSTypeTest)
5190 {
5191   _YACSTypeTest = YACSTypeTest ;
5192   return ;
5193 }
5194 CORBA::Long HOMARD_Gen_i::GetYACSConvergenceType()
5195 {
5196   return _YACSTypeTest ;
5197 }
5198
5199 //=============================================================================
5200 extern "C"
5201 {
5202   HOMARDENGINE_EXPORT
5203   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5204                                                   PortableServer::POA_ptr poa,
5205                                                   PortableServer::ObjectId* contId,
5206                                                   const char* instanceName,
5207                                                   const char* interfaceName)
5208   {
5209     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5210     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5211     return myHOMARD_Gen->getId();
5212   }
5213 }