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