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