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