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