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