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