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