Salome HOME
Gestion des préférences entre HOMARD_GEN et le GUI
[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_Boundary_ptr HOMARD_Gen_i::CreateBoundaryTorus(const char* BoundaryName,
2045                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2046                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2047                                       CORBA::Double RayonRev, CORBA::Double RayonPri)
2048 {
2049   INFOS ("CreateBoundaryTorus : BoundaryName  = " << BoundaryName ) ;
2050 //
2051   SALOME::ExceptionStruct es;
2052   int error = 0 ;
2053   if ( ( RayonRev <= 0.0 ) || ( RayonPri <= 0.0 ) )
2054   { es.text = "The radius must be positive." ;
2055     error = 1 ; }
2056   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2057   if ( daux < 0.0000001 )
2058   { es.text = "The axis must be a non 0 vector." ;
2059     error = 2 ; }
2060   if ( error != 0 )
2061   {
2062     es.type = SALOME::BAD_PARAM;
2063     throw SALOME::SALOME_Exception(es);
2064     return 0;
2065   };
2066 //
2067   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 5) ;
2068   myBoundary->SetTorus( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, RayonRev, RayonPri ) ;
2069
2070   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2071 }
2072 //=============================================================================
2073 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2074 {
2075   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
2076   IsValidStudy () ;
2077
2078   // Controle du nom :
2079   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2080   {
2081     SALOME::ExceptionStruct es;
2082     es.type = SALOME::BAD_PARAM;
2083     es.text = "This zone has already been defined";
2084     throw SALOME::SALOME_Exception(es);
2085     return 0;
2086   };
2087
2088   HOMARD::HOMARD_Zone_var myZone = newZone();
2089   myZone->SetName(ZoneName);
2090   myZone->SetType(ZoneType);
2091
2092   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2093
2094   SALOMEDS::SObject_var aSO;
2095   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2096
2097   return HOMARD::HOMARD_Zone::_duplicate(myZone);
2098 }
2099 //=============================================================================
2100 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2101                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
2102                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
2103                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
2104 {
2105   INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
2106 //
2107   SALOME::ExceptionStruct es;
2108   int error = 0 ;
2109   if ( Xmini > Xmaxi )
2110   { es.text = "The X coordinates are not coherent." ;
2111     error = 1 ; }
2112   if ( Ymini > Ymaxi )
2113   { es.text = "The Y coordinates are not coherent." ;
2114     error = 2 ; }
2115   if ( Zmini > Zmaxi )
2116   { es.text = "The Z coordinates are not coherent." ;
2117     error = 3 ; }
2118   if ( error != 0 )
2119   {
2120     es.type = SALOME::BAD_PARAM;
2121     throw SALOME::SALOME_Exception(es);
2122     return 0;
2123   };
2124 //
2125   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2126   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2127
2128   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2129 }
2130 //=============================================================================
2131 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2132                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2133 {
2134   INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
2135 //
2136   SALOME::ExceptionStruct es;
2137   int error = 0 ;
2138   if ( Rayon <= 0.0 )
2139   { es.text = "The radius must be positive." ;
2140     error = 1 ; }
2141   if ( error != 0 )
2142   {
2143     es.type = SALOME::BAD_PARAM;
2144     throw SALOME::SALOME_Exception(es);
2145     return 0;
2146   };
2147 //
2148   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2149   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2150
2151   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2152 }
2153 //=============================================================================
2154 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2155                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2156                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2157                                       CORBA::Double Rayon, CORBA::Double Haut)
2158 {
2159   INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
2160 //
2161   SALOME::ExceptionStruct es;
2162   int error = 0 ;
2163   if ( Rayon <= 0.0 )
2164   { es.text = "The radius must be positive." ;
2165     error = 1 ; }
2166   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2167   if ( daux < 0.0000001 )
2168   { es.text = "The axis must be a non 0 vector." ;
2169     error = 2 ; }
2170   if ( Haut <= 0.0 )
2171   { es.text = "The height must be positive." ;
2172     error = 3 ; }
2173   if ( error != 0 )
2174   {
2175     es.type = SALOME::BAD_PARAM;
2176     throw SALOME::SALOME_Exception(es);
2177     return 0;
2178   };
2179 //
2180   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2181   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2182
2183   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2184 }
2185 //=============================================================================
2186 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2187                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2188                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2189                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2190 {
2191   INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
2192 //
2193   SALOME::ExceptionStruct es;
2194   int error = 0 ;
2195   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2196   { es.text = "The radius must be positive." ;
2197     error = 1 ; }
2198   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2199   if ( daux < 0.0000001 )
2200   { es.text = "The axis must be a non 0 vector." ;
2201     error = 2 ; }
2202   if ( Haut <= 0.0 )
2203   { es.text = "The height must be positive." ;
2204     error = 3 ; }
2205   if ( Rayon <= Rayonint )
2206   { es.text = "The external radius must be higher than the internal radius." ;
2207     error = 4 ; }
2208   if ( error != 0 )
2209   {
2210     es.type = SALOME::BAD_PARAM;
2211     throw SALOME::SALOME_Exception(es);
2212     return 0;
2213   };
2214 //
2215   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2216   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2217
2218   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2219 }
2220 //=============================================================================
2221 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2222                                       CORBA::Double Umini, CORBA::Double Umaxi,
2223                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
2224                                       CORBA::Long Orient)
2225 {
2226   INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
2227 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2228 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2229 //   MESSAGE ("Orient = " << Orient ) ;
2230 //
2231   SALOME::ExceptionStruct es;
2232   int error = 0 ;
2233   if ( Umini > Umaxi )
2234   { es.text = "The first coordinates are not coherent." ;
2235     error = 1 ; }
2236   if ( Vmini > Vmaxi )
2237   { es.text = "The second coordinates are not coherent." ;
2238     error = 2 ; }
2239   if ( Orient < 1 || Orient > 3 )
2240   { es.text = "The orientation must be 1, 2 or 3." ;
2241     error = 3 ; }
2242   if ( error != 0 )
2243   {
2244     es.type = SALOME::BAD_PARAM;
2245     throw SALOME::SALOME_Exception(es);
2246     return 0;
2247   };
2248 //
2249   double Xmini, Xmaxi ;
2250   double Ymini, Ymaxi ;
2251   double Zmini, Zmaxi ;
2252   if ( Orient == 1 )
2253   { Xmini = Umini ;
2254     Xmaxi = Umaxi ;
2255     Ymini = Vmini ;
2256     Ymaxi = Vmaxi ;
2257     Zmini = 0. ;
2258     Zmaxi = 0. ; }
2259   else if ( Orient == 2 )
2260   { Xmini = 0. ;
2261     Xmaxi = 0. ;
2262     Ymini = Umini ;
2263     Ymaxi = Umaxi ;
2264     Zmini = Vmini ;
2265     Zmaxi = Vmaxi ; }
2266   else if ( Orient == 3 )
2267   { Xmini = Vmini ;
2268     Xmaxi = Vmaxi ;
2269     Ymini = 0. ;
2270     Ymaxi = 0. ;
2271     Zmini = Umini ;
2272     Zmaxi = Umaxi ; }
2273   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2274
2275   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2276   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2277
2278   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2279 }
2280 //=============================================================================
2281 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2282                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2283                                       CORBA::Double Rayon,
2284                                       CORBA::Long Orient)
2285 {
2286   INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
2287 //
2288   SALOME::ExceptionStruct es;
2289   int error = 0 ;
2290   if ( Rayon <= 0.0 )
2291   { es.text = "The radius must be positive." ;
2292     error = 1 ; }
2293   if ( Orient < 1 || Orient > 3 )
2294   { es.text = "The orientation must be 1, 2 or 3." ;
2295     error = 3 ; }
2296   if ( error != 0 )
2297   {
2298     es.type = SALOME::BAD_PARAM;
2299     throw SALOME::SALOME_Exception(es);
2300     return 0;
2301   };
2302 //
2303   double Xcentre ;
2304   double Ycentre ;
2305   double Zcentre ;
2306   if ( Orient == 1 )
2307   { Xcentre = Ucentre ;
2308     Ycentre = Vcentre ;
2309     Zcentre = 0. ; }
2310   else if ( Orient == 2 )
2311   { Xcentre = 0. ;
2312     Ycentre = Ucentre ;
2313     Zcentre = Vcentre ; }
2314   else if ( Orient == 3 )
2315   { Xcentre = Vcentre ;
2316     Ycentre = 0. ;
2317     Zcentre = Ucentre ; }
2318   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2319
2320   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2321   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2322
2323   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2324 }
2325 //=============================================================================
2326 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2327                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2328                                       CORBA::Double Rayon, CORBA::Double Rayonint,
2329                                       CORBA::Long Orient)
2330 {
2331   INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
2332 //
2333   SALOME::ExceptionStruct es;
2334   int error = 0 ;
2335   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2336   { es.text = "The radius must be positive." ;
2337     error = 1 ; }
2338   if ( Orient < 1 || Orient > 3 )
2339   { es.text = "The orientation must be 1, 2 or 3." ;
2340     error = 3 ; }
2341   if ( Rayon <= Rayonint )
2342   { es.text = "The external radius must be higher than the internal radius." ;
2343     error = 4 ; }
2344   if ( error != 0 )
2345   {
2346     es.type = SALOME::BAD_PARAM;
2347     throw SALOME::SALOME_Exception(es);
2348     return 0;
2349   };
2350 //
2351   double Xcentre ;
2352   double Ycentre ;
2353   double Zcentre ;
2354   if ( Orient == 1 )
2355   { Xcentre = Ucentre ;
2356     Ycentre = Vcentre ;
2357     Zcentre = 0. ; }
2358   else if ( Orient == 2 )
2359   { Xcentre = 0. ;
2360     Ycentre = Ucentre ;
2361     Zcentre = Vcentre ; }
2362   else if ( Orient == 3 )
2363   { Xcentre = Vcentre ;
2364     Ycentre = 0. ;
2365     Zcentre = Ucentre ; }
2366   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2367
2368   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2369   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2370
2371   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2372 }
2373 //=============================================================================
2374 //=============================================================================
2375
2376
2377
2378
2379 //=============================================================================
2380 //=============================================================================
2381 // Traitement d'une iteration
2382 // etatMenage = 1 : destruction du repertoire d'execution
2383 // modeHOMARD  = 1 : adaptation
2384 //            != 1 : information avec les options modeHOMARD
2385 // Option1 >0 : appel depuis python
2386 //         <0 : appel depuis GUI
2387 // Option2 : multiple de nombres premiers
2388 //         1 : aucune option
2389 //        x2 : publication du maillage dans SMESH
2390 //=============================================================================
2391 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2392 {
2393   INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2394
2395   // A. Prealable
2396   int codret = 0;
2397
2398   // A.1. L'objet iteration
2399   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2400   ASSERT(!CORBA::is_nil(myIteration));
2401
2402   // A.2. Controle de la possibilite d'agir
2403   // A.2.1. Etat de l'iteration
2404   int etat = myIteration->GetState();
2405   MESSAGE ( "etat = "<<etat );
2406   // A.2.2. On ne calcule pas l'iteration initiale, ni une iteration deja calculee
2407   if ( modeHOMARD == 1 )
2408   {
2409     if ( etat <= 0 )
2410     {
2411       SALOME::ExceptionStruct es;
2412       es.type = SALOME::BAD_PARAM;
2413       es.text = "This iteration is the first of the case and cannot be computed.";
2414       throw SALOME::SALOME_Exception(es);
2415       return 1 ;
2416     }
2417     else if ( ( etat == 2 ) & ( modeHOMARD == 1 ) )
2418     {
2419       SALOME::ExceptionStruct es;
2420       es.type = SALOME::BAD_PARAM;
2421       es.text = "This iteration is already computed.";
2422       throw SALOME::SALOME_Exception(es);
2423       return 1 ;
2424     }
2425   }
2426   // A.2.3. On n'analyse pas une iteration non calculee
2427   else
2428   {
2429     if ( etat == 1 )
2430     {
2431       SALOME::ExceptionStruct es;
2432       es.type = SALOME::BAD_PARAM;
2433       es.text = "This iteration is not computed.";
2434       throw SALOME::SALOME_Exception(es);
2435       return 1 ;
2436     }
2437   }
2438
2439   // A.3. Numero de l'iteration
2440   //     siterp1 : numero de l'iteration a traiter
2441   //     Si adaptation :
2442   //        siter   : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2443   //     Ou si information :
2444   //        siter = siterp1
2445   int NumeIter = myIteration->GetNumber();
2446   std::string siterp1 ;
2447   std::stringstream saux1 ;
2448   saux1 << NumeIter ;
2449   siterp1 = saux1.str() ;
2450   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2451
2452   std::string siter ;
2453   if ( modeHOMARD==1 )
2454   {
2455     std::stringstream saux0 ;
2456     int iaux = max(0, NumeIter-1) ;
2457     saux0 << iaux ;
2458     siter = saux0.str() ;
2459     if (NumeIter < 11) { siter = "0" + siter ; }
2460   }
2461   else
2462   { siter = siterp1 ; }
2463
2464   // A.4. Le cas
2465   const char* nomCas = myIteration->GetCaseName();
2466   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2467   ASSERT(!CORBA::is_nil(myCase));
2468
2469   // B. Les repertoires
2470   // B.1. Le repertoire courant
2471   std::string nomDirWork = getenv("PWD") ;
2472   // B.2. Le sous-repertoire de l'iteration a traiter
2473   char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2474   MESSAGE( ". DirCompute = " << DirCompute );
2475
2476   // C. Le fichier des messages
2477   // C.1. Le deroulement de l'execution de HOMARD
2478   std::string LogFile = DirCompute ;
2479   LogFile += "/Liste" ;
2480   if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2481   LogFile += ".log" ;
2482   MESSAGE (". LogFile = " << LogFile);
2483   if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2484   // C.2. Le bilan de l'analyse du maillage
2485   std::string FileInfo = DirCompute ;
2486   FileInfo += "/" ;
2487   if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2488   else
2489   { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2490     else                 { FileInfo += "info_ap" ; }
2491   }
2492   FileInfo += "." + siterp1 + ".bilan" ;
2493   myIteration->SetFileInfo(FileInfo.c_str());
2494
2495    // D. On passe dans le repertoire de l'iteration a calculer
2496   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2497 #ifndef WIN32
2498   chdir(DirCompute);
2499 #else
2500   _chdir(DirCompute);
2501 #endif
2502
2503   // E. Les donnees de l'execution HOMARD
2504   // E.1. L'objet du texte du fichier de configuration
2505   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2506   myDriver->TexteInit(DirCompute, LogFile, _Langue);
2507
2508   // E.2. Le maillage associe a l'iteration
2509   const char* NomMesh = myIteration->GetMeshName();
2510   MESSAGE ( ". NomMesh = " << NomMesh );
2511   const char* MeshFile = myIteration->GetMeshFile();
2512   MESSAGE ( ". MeshFile = " << MeshFile );
2513
2514   // E.3. Les donnees du traitement HOMARD
2515   int iaux ;
2516   if ( modeHOMARD == 1 )
2517   {
2518     iaux = 1 ;
2519     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2520     myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2521     codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2522   }
2523   else
2524   {
2525     InvalideIterInfo(NomIteration);
2526     myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2527     iaux = 0 ;
2528     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2529     myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2530     myDriver->CreeFichierDonn();
2531   }
2532
2533   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2534   DriverTexteBoundary(myCase, myDriver) ;
2535
2536   // E.5. Ecriture du texte dans le fichier
2537   MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2538   if (codret == 0)
2539   { myDriver->CreeFichier(); }
2540
2541 // G. Execution
2542 //
2543   int codretexec = 12 ;
2544   if (codret == 0)
2545   {
2546     codretexec = myDriver->ExecuteHomard(Option1);
2547 //
2548     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2549     // En mode adaptation, on ajuste l'etat de l'iteration
2550     if ( modeHOMARD == 1 )
2551     {
2552       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2553       else                 { SetEtatIter(NomIteration,1); }
2554       // GERALD -- QMESSAGE BOX
2555     }
2556   }
2557
2558   // H. Gestion des resultats
2559   if (codret == 0)
2560   {
2561     std::string Commentaire ;
2562     // H.1. Le fichier des messages, dans tous les cas
2563     Commentaire = "log" ;
2564     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2565     else                   { Commentaire += "Info" ; }
2566     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2567
2568     // H.2. Si tout s'est bien passe :
2569     if (codretexec == 0)
2570     {
2571     // H.2.1. Le fichier de bilan
2572       Commentaire = "Summary" ;
2573       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2574       else                   { Commentaire += "Info" ; }
2575       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2576     // H.2.2. Le fichier de  maillage obtenu
2577       if ( modeHOMARD == 1 )
2578       {
2579         std::stringstream saux0 ;
2580         Commentaire = "Mesh" ;
2581         Commentaire += " " + siterp1 ;
2582         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2583         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2584       }
2585     }
2586   // H.3 Message d'erreur
2587     if (codretexec != 0)
2588     {
2589       std::string text ;
2590       // Message d'erreur en cas de probleme en adaptation
2591       if ( modeHOMARD == 1 )
2592       {
2593         text = "Error during the adaptation.\n" ;
2594         bool stopvu = false ;
2595         std::ifstream fichier( LogFile.c_str() );
2596         if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2597         {
2598           std::string ligne; // variable contenant chaque ligne lue
2599           while ( std::getline( fichier, ligne ) )
2600           {
2601 //             INFOS(ligne);
2602             if ( stopvu )
2603             { text += ligne+ "\n"; }
2604             else
2605             {
2606               int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2607               if ( position > 0 ) { stopvu = true ; }
2608             }
2609           }
2610         }
2611       }
2612       else
2613       {
2614         text = "Voir le fichier Liste.log.\n" ;
2615       }
2616       INFOS ( text ) ;
2617       SALOME::ExceptionStruct es;
2618       es.type = SALOME::BAD_PARAM;
2619       es.text = CORBA::string_dup(text.c_str());
2620       throw SALOME::SALOME_Exception(es);
2621 //
2622       // En mode information, on force le succes pour pouvoir consulter le fichier log
2623       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2624     }
2625   }
2626
2627   // I. Menage et retour dans le repertoire du cas
2628   if (codret == 0)
2629   {
2630     delete myDriver;
2631     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2632
2633 #ifndef WIN32
2634     chdir(nomDirWork.c_str());
2635 #else
2636     _chdir(nomDirWork.c_str());
2637 #endif
2638   }
2639
2640   return codretexec ;
2641 }
2642 //=============================================================================
2643 // Calcul d'une iteration : partie specifique a l'adaptation
2644 //=============================================================================
2645 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)
2646 {
2647   MESSAGE ( "ComputeAdap" );
2648
2649   // A. Prealable
2650   // A.1. Bases
2651   int codret = 0;
2652   // Numero de l'iteration
2653   int NumeIter = myIteration->GetNumber();
2654   std::stringstream saux0 ;
2655   saux0 << NumeIter-1 ;
2656   std::string siter = saux0.str() ;
2657   if (NumeIter < 11) { siter = "0" + siter ; }
2658
2659   // A.2. On verifie qu il y a une hypothese (erreur improbable);
2660   const char* nomHypo = myIteration->GetHypoName();
2661   if (std::string(nomHypo) == std::string(""))
2662   {
2663       SALOME::ExceptionStruct es;
2664       es.type = SALOME::BAD_PARAM;
2665       es.text = "This iteration does not have any associated hypothesis.";
2666       throw SALOME::SALOME_Exception(es);
2667       return 2;
2668   };
2669   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2670   ASSERT(!CORBA::is_nil(myHypo));
2671
2672   // B. L'iteration parent
2673   const char* nomIterationParent = myIteration->GetIterParentName();
2674   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2675   ASSERT(!CORBA::is_nil(myIterationParent));
2676   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2677   if ( myIterationParent->GetState() == 1 )
2678   {
2679     int iaux = 1 ;
2680     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2681     if (codret != 0)
2682     {
2683       // GERALD -- QMESSAGE BOX
2684       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2685     }
2686   };
2687
2688   // C. Le sous-repertoire de l'iteration precedente
2689   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2690   MESSAGE( ". DirComputePa = " << DirComputePa );
2691
2692   // D. Les donnees de l'adaptation HOMARD
2693   // D.1. Le type de conformite
2694   int ConfType = myCase->GetConfType();
2695   MESSAGE ( ". ConfType = " << ConfType );
2696
2697   // D.2. Le maillage de depart
2698   const char* NomMeshParent = myIterationParent->GetMeshName();
2699   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2700   const char* MeshFileParent = myIterationParent->GetMeshFile();
2701   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2702
2703   // D.3. Le maillage associe a l'iteration
2704   const char* MeshFile = myIteration->GetMeshFile();
2705   MESSAGE ( ". MeshFile = " << MeshFile );
2706   FILE *file = fopen(MeshFile,"r");
2707   if (file != NULL)
2708   {
2709     fclose(file);
2710     if (etatMenage == 0)
2711     {
2712       SALOME::ExceptionStruct es;
2713       es.type = SALOME::BAD_PARAM;
2714       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2715       es.text = CORBA::string_dup(text.c_str());
2716       throw SALOME::SALOME_Exception(es);
2717       return 4;
2718     }
2719     else
2720     {
2721       std::string commande = "rm -f " + std::string(MeshFile);
2722       codret = system(commande.c_str());
2723       if (codret != 0)
2724       {
2725         SALOME::ExceptionStruct es;
2726         es.type = SALOME::BAD_PARAM;
2727         es.text = "The mesh file cannot be deleted.";
2728         throw SALOME::SALOME_Exception(es);
2729         return 5;
2730       }
2731     }
2732   }
2733
2734   // D.4. Les types de raffinement et de deraffinement
2735   // Les appels corba sont lourds, il vaut mieux les grouper
2736   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2737   ASSERT(ListTypes->length() == 3);
2738   int TypeAdap = (*ListTypes)[0];
2739   int TypeRaff = (*ListTypes)[1];
2740   int TypeDera = (*ListTypes)[2];
2741
2742   // E. Texte du fichier de configuration
2743   // E.1. Incontournables du texte
2744   myDriver->TexteAdap();
2745   int iaux = 0 ;
2746   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2747   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2748   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2749
2750   // E.2. Ajout des informations liees aux zones eventuelles
2751   if ( TypeAdap == 0 )
2752   { DriverTexteZone(myHypo, myDriver) ; }
2753
2754   // E.3. Ajout des informations liees aux champs eventuels
2755   if ( TypeAdap == 1 )
2756   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2757
2758   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2759   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2760   int numberOfGroups = listeGroupes->length();
2761   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2762   if (numberOfGroups > 0)
2763   {
2764     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2765     {
2766       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2767       MESSAGE( "... GroupName = " << GroupName );
2768       myDriver->TexteGroup(GroupName);
2769     }
2770   }
2771
2772   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2773   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2774
2775   // E.6. Ajout des options avancees
2776   int Pyram = myCase->GetPyram();
2777   MESSAGE ( ". Pyram = " << Pyram );
2778   int NivMax = myHypo->GetNivMax();
2779   MESSAGE ( ". NivMax = " << NivMax );
2780   double DiamMin = myHypo->GetDiamMin() ;
2781   MESSAGE ( ". DiamMin = " << DiamMin );
2782   int AdapInit = myHypo->GetAdapInit();
2783   MESSAGE ( ". AdapInit = " << AdapInit );
2784   int LevelOutput = myHypo->GetLevelOutput();
2785   MESSAGE ( ". LevelOutput = " << LevelOutput );
2786   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2787
2788   // E.7. Ajout des informations sur le deroulement de l'execution
2789   int MessInfo = myIteration->GetInfoCompute();
2790   MESSAGE ( ". MessInfo = " << MessInfo );
2791   myDriver->TexteInfoCompute(MessInfo);
2792
2793   return codret ;
2794 }
2795 //=============================================================================
2796 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2797 //  nomrep : nom du repertoire parent
2798 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2799 //=============================================================================
2800 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2801 {
2802   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2803   // On verifie que le repertoire parent existe
2804 #ifndef WIN32
2805   int codret = chdir(nomrep) ;
2806 #else
2807   int codret = _chdir(nomrep) ;
2808 #endif
2809   if ( codret != 0 )
2810   {
2811     SALOME::ExceptionStruct es;
2812     es.type = SALOME::BAD_PARAM;
2813     es.text = "The directory of the case does not exist.";
2814     throw SALOME::SALOME_Exception(es);
2815     return 0;
2816   };
2817   std::string nomDirActuel = getenv("PWD") ;
2818   std::string DirName ;
2819   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2820   bool a_chercher = true ;
2821   while ( a_chercher )
2822   {
2823     // On passe dans le repertoire parent
2824
2825 #ifndef WIN32
2826   chdir(nomrep);
2827 #else
2828   _chdir(nomrep);
2829 #endif
2830     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2831     int jaux ;
2832     if      ( num <    100 ) { jaux = 2 ; }
2833     else if ( num <   1000 ) { jaux = 3 ; }
2834     else if ( num <  10000 ) { jaux = 4 ; }
2835     else if ( num < 100000 ) { jaux = 5 ; }
2836     else                     { jaux = 9 ; }
2837     std::ostringstream iaux ;
2838     iaux << std::setw(jaux) << std::setfill('0') << num ;
2839     std::ostringstream DirNameA ;
2840     DirNameA << "I" << iaux.str();
2841     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2842     // que c'est bien un probleme d'absence
2843 #ifndef WIN32
2844     if ( chdir(DirNameA.str().c_str()) != 0 )
2845     {
2846 #else
2847     if ( _chdir(DirNameA.str().c_str()) != 0 )
2848     {
2849 #endif
2850       bool existe = false ;
2851 #ifndef WIN32
2852       DIR *dp;
2853       struct dirent *dirp;
2854       dp  = opendir(nomrep);
2855       while ( (dirp = readdir(dp)) != NULL )
2856       {
2857         std::string file_name(dirp->d_name);
2858 #else
2859       HANDLE hFind = INVALID_HANDLE_VALUE;
2860       WIN32_FIND_DATA ffd;
2861       hFind = FindFirstFile(nomrep, &ffd);
2862       if (INVALID_HANDLE_VALUE != hFind) {
2863         while (FindNextFile(hFind, &ffd) != 0) {
2864          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2865          std::string file_name(ffd.cFileName);
2866 #endif
2867         if ( file_name == DirNameA.str() ) { existe = true ; }
2868       }
2869 #ifndef WIN32
2870       closedir(dp);
2871 #else
2872       }
2873       FindClose(hFind);
2874 #endif
2875       if ( !existe )
2876       {
2877         DirName = DirNameA.str() ;
2878         a_chercher = false ;
2879         break ;
2880       }
2881     }
2882     num += 1;
2883   }
2884
2885   MESSAGE ( "==> DirName = " << DirName);
2886   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2887 #ifndef WIN32
2888   chdir(nomDirActuel.c_str());
2889 #else
2890   _chdir(nomDirActuel.c_str());
2891 #endif
2892   return CORBA::string_dup( DirName.c_str() );
2893 }
2894 //=============================================================================
2895 // Calcul d'une iteration : gestion du repertoire de calcul
2896 //        Si le sous-repertoire existe :
2897 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2898 //         etatMenage =  1 : on fait le menage du repertoire
2899 //         etatMenage = -1 : on ne fait rien
2900 //=============================================================================
2901 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2902 {
2903   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2904   // B.2. Le repertoire du cas
2905   const char* nomDirCase = myCase->GetDirName();
2906   MESSAGE ( ". nomDirCase = " << nomDirCase );
2907
2908   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2909   // B.3.1. Le nom du sous-repertoire
2910   const char* nomDirIt = myIteration->GetDirNameLoc();
2911
2912   // B.3.2. Le nom complet du sous-repertoire
2913   std::stringstream DirCompute ;
2914   DirCompute << nomDirCase << "/" << nomDirIt;
2915   MESSAGE (". DirCompute = " << DirCompute.str() );
2916
2917   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2918 #ifndef WIN32
2919   if (chdir(DirCompute.str().c_str()) != 0)
2920   {
2921 //  Creation du repertoire car il n'existe pas :
2922     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2923     {
2924 #else
2925   if (_chdir(DirCompute.str().c_str()) != 0)
2926   {
2927 //  Creation du repertoire car il n'existe pas :
2928     if (_mkdir(DirCompute.str().c_str()) != 0)
2929     {
2930 #endif
2931        // GERALD -- QMESSAGE BOX
2932        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2933        VERIFICATION("Pb a la creation du repertoire" == 0);
2934     }
2935   }
2936   else
2937   {
2938 //  Le repertoire existe
2939 //  On demande de faire le menage de son contenu :
2940     if (etatMenage == 1)
2941     {
2942       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2943       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2944       int codret = system(commande.c_str());
2945       if (codret != 0)
2946       {
2947         // GERALD -- QMESSAGE BOX
2948         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2949         VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2950       }
2951     }
2952 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2953     else
2954     {
2955       if (etatMenage == 0)
2956       {
2957 #ifndef WIN32
2958         DIR *dp;
2959         struct dirent *dirp;
2960         dp  = opendir(DirCompute.str().c_str());
2961         bool result = true;
2962         while ((dirp = readdir(dp)) != NULL && result )
2963         {
2964           std::string file_name(dirp->d_name);
2965           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2966         }
2967         closedir(dp);
2968 #else
2969        HANDLE hFind = INVALID_HANDLE_VALUE;
2970        WIN32_FIND_DATA ffd;
2971        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2972        bool result = true;
2973        if (INVALID_HANDLE_VALUE != hFind) {
2974          while (FindNextFile(hFind, &ffd) != 0) {
2975           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2976           std::string file_name(ffd.cFileName);
2977           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2978          }
2979        }
2980        FindClose(hFind);
2981 #endif
2982         if ( result == false)
2983         {
2984           SALOME::ExceptionStruct es;
2985           es.type = SALOME::BAD_PARAM;
2986           std::string text = "Directory : " + DirCompute.str() + " is not empty";
2987           es.text = CORBA::string_dup(text.c_str());
2988           throw SALOME::SALOME_Exception(es);
2989           VERIFICATION("Directory is not empty" == 0);
2990         }
2991       }
2992     }
2993   }
2994
2995   return CORBA::string_dup( DirCompute.str().c_str() );
2996 }
2997 //=============================================================================
2998 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2999 //=============================================================================
3000 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
3001 {
3002   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
3003   // Le repertoire du cas
3004   const char* nomDirCase = myCase->GetDirName();
3005   MESSAGE ( ". nomDirCase = " << nomDirCase );
3006
3007   // Le sous-repertoire de l'iteration precedente
3008
3009   const char* nomIterationParent = myIteration->GetIterParentName();
3010   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
3011   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
3012   std::stringstream DirComputePa ;
3013   DirComputePa << nomDirCase << "/" << nomDirItPa;
3014   MESSAGE( ". nomDirItPa = " << nomDirItPa);
3015   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
3016
3017   return CORBA::string_dup( DirComputePa.str().c_str() );
3018 }
3019 //=============================================================================
3020 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
3021 //=============================================================================
3022 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3023 {
3024   MESSAGE ( "... DriverTexteZone" );
3025   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3026   int numberOfZonesx2 = ListZone->length();
3027   int NumZone ;
3028
3029   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3030   {
3031     std::string ZoneName = std::string((*ListZone)[iaux]);
3032     MESSAGE ( "... ZoneName = " << ZoneName);
3033     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3034     ASSERT(!CORBA::is_nil(myZone));
3035
3036     int ZoneType = myZone->GetType();
3037     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
3038     int TypeUse = atoi( TypeUsestr.c_str() );
3039     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
3040     NumZone = iaux/2 + 1 ;
3041     HOMARD::double_array* zone = myZone->GetCoords();
3042     if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
3043     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
3044     else if ( ZoneType == 4 ) // Cas d une sphere
3045     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
3046     else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
3047     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
3048     else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
3049     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
3050     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
3051     iaux += 1 ;
3052   }
3053   return ;
3054 }
3055 //=============================================================================
3056 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
3057 //=============================================================================
3058 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3059 {
3060   MESSAGE ( "... DriverTexteField" );
3061 //  Le fichier du champ
3062   char* FieldFile = myIteration->GetFieldFile();
3063   MESSAGE ( ". FieldFile = " << FieldFile );
3064   if (strlen(FieldFile) == 0)
3065   {
3066     // GERALD -- QMESSAGE BOX
3067     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3068     VERIFICATION("The file for the field is not given." == 0);
3069   }
3070 //  Les caracteristiques d'instants du champ de pilotage
3071   int TimeStep = myIteration->GetTimeStep();
3072   MESSAGE( ". TimeStep = " << TimeStep );
3073   int Rank = myIteration->GetRank();
3074   MESSAGE( ". Rank = " << Rank );
3075 //  Les informations sur les champs
3076   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3077 //  Le nom
3078   const char* FieldName = aInfosHypo->FieldName;
3079 //  Les seuils
3080   int TypeThR = aInfosHypo->TypeThR;
3081   double ThreshR = aInfosHypo->ThreshR;
3082   int TypeThC = aInfosHypo->TypeThC;
3083   double ThreshC = aInfosHypo->ThreshC;
3084 //  Saut entre mailles ou non ?
3085   int UsField = aInfosHypo->UsField;
3086   MESSAGE( ". UsField = " << UsField );
3087 //  L'usage des composantes
3088   int UsCmpI = aInfosHypo->UsCmpI;
3089   MESSAGE( ". UsCmpI = " << UsCmpI );
3090 //
3091   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3092 //
3093 //  Les composantes
3094   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3095   int numberOfCompos = mescompo->length();
3096   MESSAGE( ". numberOfCompos = " << numberOfCompos );
3097   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3098   {
3099     std::string nomCompo = std::string((*mescompo)[NumeComp]);
3100     MESSAGE( "... nomCompo = " << nomCompo );
3101     myDriver->TexteCompo(NumeComp, nomCompo);
3102   }
3103   return ;
3104 }
3105 //=============================================================================
3106 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3107 // On ecrit dans l'ordre :
3108 //    1. la definition des frontieres
3109 //    2. les liens avec les groupes
3110 //    3. un entier resumant le type de comportement pour les frontieres
3111 //=============================================================================
3112 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3113 {
3114   MESSAGE ( "... DriverTexteBoundary" );
3115   // 1. Recuperation des frontieres
3116   std::list<std::string>  ListeBoundaryTraitees ;
3117   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3118   int numberOfitems = ListBoundaryGroupType->length();
3119   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3120   int BoundaryOption = 1 ;
3121   // 2. Parcours des frontieres pour ecrire leur description
3122   int NumBoundaryAnalytical = 0 ;
3123   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3124   {
3125     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3126     MESSAGE ( "... BoundaryName = " << BoundaryName);
3127     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3128     //      Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3129     int A_faire = 1 ;
3130     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3131     while (it != ListeBoundaryTraitees.end())
3132     {
3133       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3134       if ( BoundaryName == *it ) { A_faire = 0 ; }
3135       it++;
3136     }
3137     // 2.2. Ecriture de la frontiere
3138     if ( A_faire == 1 )
3139     {
3140       // 2.2.1. Caracteristiques de la frontiere
3141       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3142       ASSERT(!CORBA::is_nil(myBoundary));
3143       int BoundaryType = myBoundary->GetType();
3144       MESSAGE ( "... BoundaryType = " << BoundaryType );
3145       // 2.2.2. Ecriture selon le type
3146       // 2.2.2.1. Cas d une frontiere discrete
3147       if (BoundaryType == 0)
3148       {
3149         const char* MeshName = myBoundary->GetMeshName() ;
3150         const char* MeshFile = myBoundary->GetMeshFile() ;
3151         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3152         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3153       }
3154       // 2.2.2.1. Cas d une frontiere analytique
3155       else
3156       {
3157         NumBoundaryAnalytical++ ;
3158         HOMARD::double_array* coor = myBoundary->GetCoords();
3159         if (BoundaryType == 1) // Cas d un cylindre
3160         {
3161           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3162           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3163         }
3164         else if (BoundaryType == 2) // Cas d une sphere
3165         {
3166           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3167           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3168         }
3169         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3170         {
3171           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3172           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3173         }
3174         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3175         {
3176           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3177           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3178         }
3179         else if (BoundaryType == 5) // Cas d un tore
3180         {
3181           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3182           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3183         }
3184       }
3185       // 2.2.3. Memorisation du traitement
3186       ListeBoundaryTraitees.push_back( BoundaryName );
3187     }
3188   }
3189   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3190   NumBoundaryAnalytical = 0 ;
3191   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3192   {
3193     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3194     MESSAGE ( "... BoundaryName = " << BoundaryName);
3195     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3196     ASSERT(!CORBA::is_nil(myBoundary));
3197     int BoundaryType = myBoundary->GetType();
3198     MESSAGE ( "... BoundaryType = " << BoundaryType );
3199     // 3.1. Recuperation du nom du groupe
3200     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3201     MESSAGE ( "... GroupName = " << GroupName);
3202     // 3.2. Cas d une frontiere discrete
3203     if ( BoundaryType == 0 )
3204     {
3205       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3206     }
3207     // 3.3. Cas d une frontiere analytique
3208     else
3209     {
3210       NumBoundaryAnalytical++ ;
3211       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3212     }
3213   }
3214   // 4. Ecriture de l'option finale
3215   myDriver->TexteBoundaryOption(BoundaryOption);
3216 //
3217   return ;
3218 }
3219 //=============================================================================
3220 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3221 //=============================================================================
3222 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3223 {
3224   MESSAGE ( "... DriverTexteFieldInterp" );
3225   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3226   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3227   if (TypeFieldInterp != 0)
3228   {
3229 //  Le fichier des champs
3230     char* FieldFile = myIteration->GetFieldFile();
3231     MESSAGE ( ". FieldFile = " << FieldFile );
3232     if (strlen(FieldFile) == 0)
3233     {
3234       // GERALD -- QMESSAGE BOX
3235       VERIFICATION("The file for the field is not given." == 0);
3236     }
3237   //
3238     const char* MeshFile = myIteration->GetMeshFile();
3239     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3240
3241   // Les champs
3242   // Interpolation de tous les champs
3243     if ( TypeFieldInterp == 1 )
3244     {
3245       myDriver->TexteFieldInterpAll();
3246     }
3247   // Interpolation de certains champs
3248     else if (TypeFieldInterp == 2)
3249     {
3250       // Les champs et leurs instants pour l'iteration
3251       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3252       int numberOfFieldsx3 = ListFieldTSR->length();
3253       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3254       // Les champs pour l'hypothese
3255       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3256       int numberOfFieldsx2 = ListField->length();
3257       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3258       // On parcourt tous les champs de  l'hypothese
3259       int NumField = 0 ;
3260       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3261       {
3262         // Le nom du champ
3263         std::string FieldName = std::string((*ListField)[iaux]) ;
3264         // Le type d'interpolation
3265         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3266         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3267         // On cherche à savoir si des instants ont été précisés pour cette itération
3268         int tsrvu = 0;
3269         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3270         {
3271         // Le nom du champ
3272           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3273           MESSAGE( "..... FieldName2 = " << FieldName2 );
3274         // Quand c'est le bon champ, on ecrit le pas de temps
3275           if ( FieldName == FieldName2 )
3276           {
3277             tsrvu = 1 ;
3278             // Le pas de temps
3279             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3280             // Le numero d'ordre
3281             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3282             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3283             NumField += 1 ;
3284             int TimeStep = atoi( TimeStepstr.c_str() );
3285             int Rank = atoi( Rankstr.c_str() );
3286             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3287           }
3288           jaux += 2 ;
3289         }
3290         // Si aucun instant n'a été défini
3291         if ( tsrvu == 0 )
3292         {
3293           NumField += 1 ;
3294           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3295         }
3296         iaux++ ;
3297       }
3298     }
3299   }
3300   return ;
3301 }
3302 //===========================================================================
3303 //===========================================================================
3304
3305
3306 //===========================================================================
3307 //===========================================================================
3308 // Publications
3309 //===========================================================================
3310 //===========================================================================
3311 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3312                                                    SALOMEDS::SObject_ptr theSObject,
3313                                                    CORBA::Object_ptr theObject,
3314                                                    const char* theName)
3315 {
3316   MESSAGE("PublishInStudy pour " << theName);
3317   SALOMEDS::SObject_var aResultSO;
3318   if (CORBA::is_nil(theStudy))
3319   {
3320     SALOME::ExceptionStruct es;
3321     es.type = SALOME::BAD_PARAM;
3322     es.text = "Invalid study context";
3323     throw SALOME::SALOME_Exception(es);
3324     return 0;
3325   };
3326
3327 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3328 // Rq : Iteration est publiee ailleurs
3329   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3330   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3331   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3332   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3333   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3334
3335    addInStudy(theStudy);
3336
3337 // Controle de la non publication d'un objet de meme nom
3338    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3339   {
3340     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3341     if (listSO->length() >= 1)
3342     {
3343       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3344       aResultSO = listSO[0];
3345       return aResultSO._retn();
3346     }
3347   }
3348
3349   // Caracteristiques de l'etude
3350   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3351   aStudyBuilder->NewCommand();
3352   if(!aBoundary->_is_nil())
3353     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3354   else if(!aCase->_is_nil())
3355     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3356   else if(!aHypo->_is_nil())
3357     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3358   else if(!aYACS->_is_nil())
3359     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3360   else if(!aZone->_is_nil())
3361     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3362
3363   aStudyBuilder->CommitCommand();
3364
3365   return aResultSO._retn();
3366 };
3367 //=============================================================================
3368 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3369                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3370                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3371 {
3372   MESSAGE("PublishBoundaryStudy pour "<<theName);
3373   SALOMEDS::SObject_var aResultSO;
3374
3375   // Caracteristique de la Boundary
3376   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3377
3378   // On recupere le module pere dans l etude
3379   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3380   if (theFatherHomard->_is_nil())
3381   {
3382     MESSAGE("theFatherHomard->_is_nil()");
3383     return aResultSO._retn();
3384   }
3385
3386   // On ajoute la categorie des boundarys dans l etude si necessaire
3387   if ( _tag_boun == 0 )
3388   {
3389     _tag_gene += 1 ;
3390     _tag_boun = _tag_gene ;
3391   }
3392   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3393   SALOMEDS::SObject_var aSObject;
3394   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3395   {
3396     MESSAGE("Ajout de la categorie des boundarys");
3397     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3398     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3399   }
3400   else { MESSAGE("La categorie des boundarys existe deja."); }
3401
3402   CORBA::Long BoundaryType = myBoundary->GetType();
3403 //   MESSAGE("BoundaryType : "<<BoundaryType);
3404   std::string icone ;
3405   std::string value ;
3406   switch (BoundaryType)
3407   {
3408     case 0 :
3409     { value = "BoundaryDiHomard" ;
3410       icone = "mesh_tree_mesh.png" ;
3411       break;
3412     }
3413     case 1 :
3414     { value = "BoundaryAnHomard" ;
3415       icone = "cylinderpointvector_2.png" ;
3416       break;
3417     }
3418     case 2 :
3419     { value = "BoundaryAnHomard" ;
3420       icone = "spherepoint_2.png" ;
3421       break;
3422     }
3423     case 3 :
3424     { value = "BoundaryAnHomard" ;
3425       icone = "conepointvector.png" ;
3426       break;
3427     }
3428     case 4 :
3429     { value = "BoundaryAnHomard" ;
3430       icone = "conedxyz.png" ;
3431       break;
3432     }
3433     case 5 :
3434     { value = "BoundaryAnHomard" ;
3435       icone = "toruspointvector.png" ;
3436       break;
3437     }
3438   }
3439   aResultSO = aStudyBuilder->NewObject(aSObject);
3440   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3441   return aResultSO._retn();
3442 }
3443 //=============================================================================
3444 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3445                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3446                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3447 {
3448   MESSAGE("PublishCaseInStudy pour "<<theName);
3449   SALOMEDS::SObject_var aResultSO;
3450
3451   if (CORBA::is_nil(theObject)) {
3452     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3453     return aResultSO._retn();
3454   }
3455   if (theStudy->_is_nil()) {
3456     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3457     return aResultSO._retn();
3458   }
3459
3460   // On recupere le module pere dans l etude
3461   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3462   if (theFatherHomard->_is_nil())
3463   {
3464     MESSAGE("theFatherHomard->_is_nil()");
3465     return aResultSO._retn();
3466   }
3467
3468   _tag_gene += 1 ;
3469   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3470   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3471   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3472                      _orb->object_to_string(theObject) ) ;
3473
3474   return aResultSO._retn();
3475 }
3476 //=============================================================================
3477 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3478                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3479                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3480 {
3481   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3482   SALOMEDS::SObject_var aResultSO;
3483
3484   // On recupere le module pere dans l etude
3485   // On ajoute la categorie des hypotheses 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
3493   // On ajoute la categorie des hypotheses dans l etude si necessaire
3494   SALOMEDS::SObject_var aSObject;
3495   if ( _tag_hypo == 0 )
3496   {
3497     _tag_gene += 1 ;
3498     _tag_hypo = _tag_gene ;
3499   }
3500   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3501   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3502   {
3503     MESSAGE("Ajout de la categorie des hypotheses");
3504     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3505     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3506   }
3507   else { MESSAGE("La categorie des hypotheses existe deja."); }
3508
3509 // Creation du resultat dans l'etude
3510   aResultSO = aStudyBuilder->NewObject(aSObject);
3511   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3512
3513   return aResultSO._retn();
3514 }
3515 //=============================================================================
3516 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3517                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3518                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3519 {
3520   MESSAGE("PublishYACSInStudy pour "<<theName);
3521   SALOMEDS::SObject_var aResultSO;
3522
3523   // On recupere le module pere dans l etude
3524   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3525   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3526   if (theFatherHomard->_is_nil())
3527   {
3528     MESSAGE("theFatherHomard->_is_nil()");
3529     return aResultSO._retn();
3530   }
3531   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3532   if ( _tag_yacs == 0 )
3533   {
3534     _tag_gene += 1 ;
3535     _tag_yacs = _tag_gene ;
3536   }
3537   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3538   SALOMEDS::SObject_var aSObject;
3539   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3540   {
3541     MESSAGE("Ajout de la categorie des schemas YACS");
3542     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3543     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3544   }
3545   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3546
3547 // Creation du resultat dans l'etude
3548   aResultSO = aStudyBuilder->NewObject(aSObject);
3549   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3550
3551   return aResultSO._retn();
3552 }
3553
3554 //=============================================================================
3555 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3556                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3557                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3558 {
3559   MESSAGE("PublishZoneStudy pour "<<theName);
3560   SALOMEDS::SObject_var aResultSO;
3561   if (CORBA::is_nil(theObject))
3562   {
3563     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3564     return aResultSO._retn();
3565   }
3566   if (theStudy->_is_nil())
3567   {
3568     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3569     return aResultSO._retn();
3570   }
3571   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3572   if (theFatherHomard->_is_nil())
3573   {
3574     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3575     return aResultSO._retn();
3576   }
3577
3578   // Caracteristique de la zone
3579   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3580   CORBA::Long ZoneType = myZone->GetType();
3581
3582   // On ajoute la categorie des zones dans l etude si necessaire
3583   if ( _tag_zone == 0 )
3584   {
3585     _tag_gene += 1 ;
3586     _tag_zone = _tag_gene ;
3587   }
3588   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3589   SALOMEDS::SObject_var aSObject;
3590   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3591   {
3592     MESSAGE("Ajout de la categorie des zones");
3593     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3594     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3595   }
3596   else { MESSAGE("La categorie des zones existe deja."); }
3597
3598   aResultSO = aStudyBuilder->NewObject(aSObject);
3599   std::string icone ;
3600   switch (ZoneType)
3601   {
3602     case 11 :
3603     { }
3604     case 12 :
3605     { }
3606     case 13 :
3607     { icone = "boxdxy_2.png" ;
3608       break ;
3609     }
3610     case 2 :
3611     { icone = "boxdxyz_2.png" ;
3612       break ;
3613     }
3614     case 31 :
3615     { }
3616     case 32 :
3617     { }
3618     case 33 :
3619     { icone = "disk_2.png" ;
3620       break ;
3621      }
3622     case 4 :
3623     { icone = "spherepoint_2.png" ;
3624       break ;
3625     }
3626     case 5 :
3627     { icone = "cylinderpointvector_2.png" ;
3628       break ;
3629     }
3630     case 61 :
3631     { }
3632     case 62 :
3633     { }
3634     case 63 :
3635     { icone = "diskwithhole_2.png" ;
3636       break ;
3637      }
3638     case 7 :
3639     { icone = "pipe_2.png" ;
3640       break ;
3641     }
3642   }
3643   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3644
3645   return aResultSO._retn();
3646 }
3647 //===========================================================================
3648 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3649                                       SALOMEDS::SObject_var aResultSO,
3650                                       const char* name, const char* comment, const char* icone, const char* ior)
3651 {
3652   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3653 //   MESSAGE("icone = "<<icone);
3654 //   MESSAGE("ior   = "<<ior);
3655   SALOMEDS::GenericAttribute_var anAttr ;
3656 //  Ajout du nom
3657   if ( name != NULL )
3658   {
3659     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3660     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3661     aNameAttrib->SetValue(name);
3662   }
3663
3664 //  Ajout du commentaire
3665   if ( comment != NULL )
3666   {
3667     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3668     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3669     aCommentAttrib->SetValue(comment);
3670   }
3671
3672 //  Ajout de l'icone
3673   if ( icone != NULL  )
3674   {
3675     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3676     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3677     aPixmap->SetPixMap(icone);
3678   }
3679
3680 //  Ajout de l ior
3681   if ( ior != NULL  )
3682   {
3683     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3684     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3685     anIOR->SetValue(ior);
3686   }
3687 };
3688
3689 //=====================================================================================
3690 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3691 {
3692   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3693
3694   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3695   ASSERT(!CORBA::is_nil(myCase));
3696   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3697   ASSERT(!CORBA::is_nil(aCaseSO));
3698
3699   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3700   ASSERT(!CORBA::is_nil(myBoundary));
3701   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3702   ASSERT(!CORBA::is_nil(aBoundarySO));
3703
3704   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3705
3706   aStudyBuilder->NewCommand();
3707
3708   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3709   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3710 //   aStudyBuilder->RemoveReference(aSubSO);
3711
3712   aStudyBuilder->CommitCommand();
3713
3714 };
3715 //=====================================================================================
3716 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3717 {
3718   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3719
3720   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3721   ASSERT(!CORBA::is_nil(myYACS));
3722   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3723   ASSERT(!CORBA::is_nil(aYACSSO));
3724
3725   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3726   ASSERT(!CORBA::is_nil(myCase));
3727   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3728   ASSERT(!CORBA::is_nil(aCaseSO));
3729
3730   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3731
3732   aStudyBuilder->NewCommand();
3733
3734   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3735   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3736
3737   aStudyBuilder->CommitCommand();
3738
3739 };
3740 //=============================================================================
3741 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3742 //  Option = 0 : fichier issu d'une importation
3743 //  Option = 1 : fichier issu d'une execution HOMARD
3744 {
3745   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3746   if (CORBA::is_nil(myCurrentStudy))
3747   {
3748     SALOME::ExceptionStruct es;
3749     es.type = SALOME::BAD_PARAM;
3750     es.text = "Invalid study context";
3751     throw SALOME::SALOME_Exception(es);
3752     return ;
3753   };
3754
3755 // Le module SMESH est-il actif ?
3756   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3757 //
3758   if (!CORBA::is_nil(aSmeshSO))
3759   {
3760 // On verifie que le fichier n est pas deja publie
3761     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3762     for (; aIter->More(); aIter->Next())
3763     {
3764       SALOMEDS::SObject_var  aSO = aIter->Value();
3765       SALOMEDS::GenericAttribute_var aGAttr;
3766       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3767       {
3768         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3769         CORBA::String_var value=anAttr->Value();
3770         if (strcmp((const char*)value,NomFich) == 0)
3771         {
3772           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3773           // Pour un fichier importe, on ne republie pas
3774           if ( Option == 0 ) { return; }
3775           // Pour un fichier calcule, on commence par faire la depublication
3776           else
3777           {
3778             MESSAGE ( "PublishResultInSmesh : depublication" );
3779             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3780             CORBA::String_var value2=anAttr2->Value();
3781             std::string MeshName = string(value2) ;
3782             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3783             DeleteResultInSmesh(NomFich, MeshName) ;
3784           }
3785         }
3786       }
3787     }
3788   }
3789
3790 // On enregistre le fichier
3791   MESSAGE( "Enregistrement du fichier");
3792   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3793   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3794   ASSERT(!CORBA::is_nil(aSmeshEngine));
3795   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3796   SMESH::DriverMED_ReadStatus theStatus;
3797   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3798
3799 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3800   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3801   for (int i = 0; i < mesMaillages->length();  i++)
3802   {
3803     MESSAGE( ". Mise a jour des attributs du maillage");
3804     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3805     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3806     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3807     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3808     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3809     anAttr->SetValue(NomFich);
3810     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3811     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3812     const char* icone ;
3813     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3814     else               { icone = "mesh_tree_mesh.png" ; }
3815     anAttr2->SetPixMap( icone );
3816   }
3817
3818 }
3819 //=============================================================================
3820 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3821 {
3822   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3823   if (CORBA::is_nil(myCurrentStudy))
3824   {
3825       SALOME::ExceptionStruct es;
3826       es.type = SALOME::BAD_PARAM;
3827       es.text = "Invalid study context";
3828       throw SALOME::SALOME_Exception(es);
3829       return ;
3830   };
3831
3832 // Le module SMESH est-il actif ?
3833   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3834 //
3835   if (CORBA::is_nil(aSmeshSO))
3836   {
3837       return ;
3838   };
3839 // On verifie que le fichier est deja publie
3840   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3841   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3842   for (; aIter->More(); aIter->Next())
3843   {
3844      SALOMEDS::SObject_var  aSO = aIter->Value();
3845      SALOMEDS::GenericAttribute_var aGAttr;
3846      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3847      {
3848        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3849        CORBA::String_var value=anAttr->Value();
3850        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3851        {
3852          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3853          {
3854            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3855            CORBA::String_var value2=anAttr2->Value();
3856            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3857            {
3858              myBuilder->RemoveObjectWithChildren( aSO ) ;
3859            }
3860          }
3861        }
3862      }
3863   }
3864   return ;
3865 }
3866 //=============================================================================
3867 void HOMARD_Gen_i::PublishMeshIterInSmesh(const char* NomIter)
3868 {
3869   MESSAGE( "PublishMeshIterInSmesh " << NomIter);
3870   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3871
3872   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3873   if (CORBA::is_nil(myIteration))
3874   {
3875       SALOME::ExceptionStruct es;
3876       es.type = SALOME::BAD_PARAM;
3877       es.text = "Invalid iterationStudy Object";
3878       throw SALOME::SALOME_Exception(es);
3879       return ;
3880   };
3881   const char* MeshFile = myIteration->GetMeshFile() ;
3882   const char* MeshName = myIteration->GetMeshName() ;
3883   CORBA::Long Option = -1 ;
3884   int etat = myIteration->GetState();
3885 // Iteration initiale
3886   if ( etat <= 0 )      { Option = 0 ; }
3887 // ou iteration calculee
3888   else if ( etat == 2 ) { Option = 1 ; }
3889 // Publication effective apres menage eventuel
3890   if ( Option >= 0 )
3891   {
3892     DeleteResultInSmesh(MeshFile, MeshName) ;
3893     PublishResultInSmesh(MeshFile, Option) ;
3894   }
3895
3896 }
3897 //=============================================================================
3898 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3899 {
3900 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3901   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3902
3903   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3904   if (CORBA::is_nil(myIteration))
3905   {
3906       SALOME::ExceptionStruct es;
3907       es.type = SALOME::BAD_PARAM;
3908       es.text = "Invalid iterationStudy Object";
3909       throw SALOME::SALOME_Exception(es);
3910       return ;
3911   };
3912
3913   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3914
3915   aStudyBuilder->NewCommand();
3916
3917   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3918 // Pour les fichiers med, on affiche une icone de maillage
3919 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3920 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3921   std::string icone ;
3922   std::string ior = " " ;
3923   if ( Commentaire[0] == 'I' )
3924   { icone = "med.png" ; }
3925   else
3926   { icone = "texte_2.png" ; }
3927   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3928
3929   aStudyBuilder->CommitCommand();
3930 }
3931 //
3932 //=============================================================================
3933 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3934 {
3935 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3936   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3937
3938   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3939   if (CORBA::is_nil(myYACS))
3940   {
3941       SALOME::ExceptionStruct es;
3942       es.type = SALOME::BAD_PARAM;
3943       es.text = "Invalid YACSStudy Object";
3944       throw SALOME::SALOME_Exception(es);
3945       return ;
3946   };
3947
3948   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3949
3950   aStudyBuilder->NewCommand();
3951
3952   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3953   std::string icone = "texte_2.png" ;
3954   std::string ior = " " ;
3955   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3956
3957   aStudyBuilder->CommitCommand();
3958 }
3959 //
3960 //=============================================================================
3961 //=============================================================================
3962 // YACS
3963 //=============================================================================
3964 //=============================================================================
3965 //=============================================================================
3966 // Creation d'un schema YACS
3967 // nomCas : nom du cas a traiter
3968 // FileName : nom du fichier contenant le script de lancement du calcul
3969 // DirName : le repertoire de lancement des calculs du schéma
3970 //=============================================================================
3971 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3972 {
3973   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3974   INFOS ( ". nomCas     : " << nomCas);
3975   INFOS ( ". ScriptFile : " << ScriptFile);
3976   INFOS ( ". DirName    : " << DirName);
3977   INFOS ( ". MeshFile   : " << MeshFile);
3978
3979   // A. Controle du nom :
3980   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3981   {
3982     SALOME::ExceptionStruct es;
3983     es.type = SALOME::BAD_PARAM;
3984     es.text = "This schema YACS has already been defined.";
3985     throw SALOME::SALOME_Exception(es);
3986     return 0;
3987   }
3988
3989   // B. Creation de l'objet
3990   HOMARD::HOMARD_YACS_var myYACS = newYACS();
3991   if (CORBA::is_nil(myYACS))
3992   {
3993     SALOME::ExceptionStruct es;
3994     es.type = SALOME::BAD_PARAM;
3995     es.text = "Unable to create the schema YACS";
3996     throw SALOME::SALOME_Exception(es);
3997     return 0;
3998   };
3999   myYACS->SetName( nomYACS ) ;
4000
4001   // C. Enregistrement
4002   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
4003
4004   SALOMEDS::SObject_var aSO;
4005   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
4006
4007   PublishCaseUnderYACS(nomYACS, nomCas);
4008
4009   // D. Caracterisation
4010   // D.1. Options
4011   myYACS->SetDirName( DirName ) ;
4012   myYACS->SetMeshFile( MeshFile ) ;
4013   myYACS->SetScriptFile( ScriptFile ) ;
4014   myYACS->SetCaseName( nomCas ) ;
4015   // D.2. Defaut
4016   // D.2.1. Type constant
4017   myYACS->SetType( 1 ) ;
4018   // D.2.2. Fichier de sauvegarde dans le repertoire du cas
4019   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
4020   std::string dirnamecase = caseyacs->GetDirName() ;
4021   std::string XMLFile ;
4022   XMLFile = dirnamecase + "/schema.xml" ;
4023   myYACS->SetXMLFile( XMLFile.c_str() ) ;
4024
4025   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
4026 }
4027 //=============================================================================
4028 // Ecriture d'un schema YACS
4029 //=============================================================================
4030 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
4031 {
4032   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
4033 // Le repertoire du cas
4034   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4035   ASSERT(!CORBA::is_nil(myYACS));
4036 // Le nom du fichier du schema
4037   std::string XMLFile ;
4038   XMLFile = myYACS->GetXMLFile() ;
4039
4040   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
4041
4042   return codret ;
4043 }
4044 //=============================================================================
4045 // Ecriture d'un schema YACS sur un fichier donne
4046 //=============================================================================
4047 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
4048 {
4049   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
4050
4051   // A. Prealable
4052   int codret = 0;
4053
4054   // B. L'objet YACS
4055   // B.1. L'objet
4056   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
4057   ASSERT(!CORBA::is_nil(myYACS));
4058   // B.2. Les caracteristiques
4059   std::string DirName = myYACS->GetDirName() ;
4060   std::string MeshFile = myYACS->GetMeshFile() ;
4061   std::string ScriptFile = myYACS->GetScriptFile() ;
4062
4063   // C. Le cas
4064   // C.1. L'objet cas
4065   const char* nomCas = myYACS->GetCaseName();
4066   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
4067   ASSERT(!CORBA::is_nil(myCase));
4068   // C.2. Les instructions python associees au cas
4069   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4070   std::string pythonCas = dumpCorbaCase.in();
4071   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
4072
4073   // D. Les iterations
4074   // D.1. L'iteration initiale
4075   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
4076   std::string Iter0Name = myCase->GetIter0Name() ;
4077   MESSAGE (". Iter0Name = " << Iter0Name);
4078   std::string MeshName = Iter0->GetMeshName();
4079   MESSAGE (". MeshName = " << MeshName);
4080   // D.2. L'iteration numero 1
4081   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
4082   int numberOfIter = maListe->length();
4083   if ( numberOfIter > 1 )
4084   {
4085     MESSAGE (". numberOfIter = " << numberOfIter);
4086     SALOME::ExceptionStruct es ;
4087     es.type = SALOME::BAD_PARAM;
4088     std::string text = "Une seule iteration est permise." ;
4089     es.text = CORBA::string_dup(text.c_str());
4090     throw SALOME::SALOME_Exception(es);
4091     return 0;
4092   }
4093   std::string Iter1Name = std::string((*maListe)[0]);
4094   MESSAGE ("... Iter1Name = " << Iter1Name);
4095   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
4096   // D.3. Les instructions python associees a l'iteration
4097   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
4098   std::string pythonIter = dumpCorbaIter.in();
4099   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
4100
4101   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4102   // E.1. La structure
4103   std::string nomHypo = Iter1->GetHypoName();
4104   MESSAGE (". nomHypo = " << nomHypo);
4105   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4106   ASSERT(!CORBA::is_nil(myHypo));
4107   // E.2. Les caracteristiques de l'adaptation
4108   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4109   ASSERT(ListTypes->length() == 3);
4110   int TypeAdap = (*ListTypes)[0];
4111 //   int TypeRaff = (*ListTypes)[1];
4112 //   int TypeDera = (*ListTypes)[2];
4113   // E.3. Les instructions python associees a l'hypothese
4114   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4115   std::string pythonHypo = dumpCorbaHypo.in();
4116   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4117
4118   // F. Le fichier du schema de reference
4119   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4120   std::string XMLFile_base ;
4121   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4122   else
4123   {
4124     SALOME::ExceptionStruct es ;
4125     es.type = SALOME::BAD_PARAM;
4126     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4127     es.text = CORBA::string_dup(text.c_str());
4128     throw SALOME::SALOME_Exception(es);
4129     return 0;
4130   }
4131   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4132 //   if ( _Langue ==
4133   MESSAGE("XMLFile_base ="<<XMLFile_base);
4134
4135   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4136   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4137   std::ifstream fichier( XMLFile_base.c_str() );
4138   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4139   {
4140     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4141     std::string ligne; // variable contenant chaque ligne lue
4142     std::string mot_cle;
4143     while ( std::getline( fichier, ligne ) )
4144     {
4145       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4146       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4147       ligne_bis >> mot_cle ;
4148       // G.1.2. Le maillage initial
4149       if ( mot_cle == "DataInit_MeshFile" )
4150       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4151       // G.1.3. Le script de lancement
4152       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4153       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4154       // G.1.4. Les options du cas
4155       else if ( mot_cle == "Iter_1_Case_Options" )
4156       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4157       // G.1.5. Execution de HOMARD : le repertoire du cas
4158       else if ( mot_cle == "HOMARD_Exec_DirName" )
4159       { myDriver->Texte_HOMARD_Exec_DirName(); }
4160       // G.1.6. Execution de HOMARD : le nom du maillage
4161       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4162       {
4163         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4164         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4165         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4166       }
4167       // G.1.7. Execution de HOMARD : les options de l'hypothese
4168       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4169       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4170       // G.1.8. Execution de HOMARD : les options de l'iteration
4171       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4172       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4173       // G.1.9. Zones et frontieres : les creations
4174       else if ( mot_cle == "Iter_1" )
4175       {
4176         std::string texte_control = myDriver->Texte_Iter_1_control() ;
4177         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4178         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4179         myDriver->TexteAdd(texte_control);
4180       }
4181       // G.1.10. Les parametres
4182       else if ( mot_cle == "PARAMETRES" )
4183       { myDriver->TexteAddParametres(); }
4184       // G.1.n. La ligne est recopiee telle quelle
4185       else { myDriver->TexteAdd(ligne);  }
4186     }
4187     // G.2. Ecriture du texte dans le fichier
4188     if ( codret == 0 )
4189     { myDriver->CreeFichier(); }
4190   }
4191   else
4192   {
4193     SALOME::ExceptionStruct es;
4194     es.type = SALOME::BAD_PARAM;
4195     std::string text = "The reference file for the YACS schema cannot be read." ;
4196     es.text = CORBA::string_dup(text.c_str());
4197     throw SALOME::SALOME_Exception(es);
4198   }
4199
4200   delete myDriver;
4201
4202   // H. Publication du fichier dans l'arbre
4203
4204     std::string Commentaire = "xml" ;
4205     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4206
4207   return codret ;
4208 }
4209 //=============================================================================
4210 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4211 //=============================================================================
4212 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4213 {
4214   MESSAGE ( "YACSDriverTexteZone" );
4215   // A. Les zones associees a cette hypothese
4216   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4217   int numberOfZonesx2 = ListZone->length();
4218
4219   // B. Parcours des zones
4220   std::string texte_control ;
4221   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4222   {
4223     // 1. Reperage de la zone
4224     std::string ZoneName = std::string((*ListZone)[iaux]);
4225     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4226     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4227     ASSERT(!CORBA::is_nil(myZone));
4228     // 2. Les instructions python associees a la zone
4229     //    La premiere ligne est un commentaire a eliminer
4230     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4231     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4232     std::string pythonStructure_0 = dumpCorbaZone.in();
4233     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4234     std::istringstream tout (pythonStructure_0) ;
4235     std::string ligne ;
4236     std::string pythonStructure ;
4237     while ( std::getline( tout, ligne ) )
4238     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4239     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4240     // 3. Decodage du nom du service
4241     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4242     MESSAGE ( "... methode = " << methode);
4243     // 4. Mise en place des instructions
4244     int ZoneType = myZone->GetType();
4245     MESSAGE ( "... ZoneType = " << ZoneType);
4246     std::string texte_control_0 ;
4247     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4248     texte_control += texte_control_0 ;
4249     // 5. Decalage
4250     iaux ++ ;
4251   }
4252
4253   return texte_control ;
4254 }
4255 //=============================================================================
4256 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4257 //=============================================================================
4258 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4259 {
4260   MESSAGE ( "YACSDriverTexteBoundary" );
4261   // A. Les frontieres associees au cas
4262   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4263   int numberOfitems = ListBoundaryGroupType->length();
4264
4265   // B. Parcours des frontieres
4266   std::string texte_control ;
4267   std::list<std::string>  ListeBoundaryTraitees ;
4268   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4269   {
4270     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4271     MESSAGE ( "... BoundaryName = " << BoundaryName);
4272     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4273     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4274     int A_faire = 1 ;
4275     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4276     while (it != ListeBoundaryTraitees.end())
4277     {
4278       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4279       if ( BoundaryName == *it ) { A_faire = 0 ; }
4280       it++;
4281     }
4282     if ( A_faire == 1 )
4283     {
4284     // 1. Caracteristiques de la frontiere
4285       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4286       ASSERT(!CORBA::is_nil(myBoundary));
4287       // 2. Les instructions python associees a la frontiere
4288       //    La premiere ligne est un commentaire a eliminer
4289       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4290       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4291       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4292       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4293       std::istringstream tout (pythonStructure_0) ;
4294       std::string ligne ;
4295       std::string pythonStructure ;
4296       while ( std::getline( tout, ligne ) )
4297       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4298       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4299       // 3. Decodage du nom du service
4300       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4301       MESSAGE ( "... methode = " << methode);
4302       // 4. Mise en place des instructions
4303       int BoundaryType = myBoundary->GetType();
4304       MESSAGE ( "... BoundaryType = " << BoundaryType);
4305       std::string texte_control_0 ;
4306       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4307       texte_control += texte_control_0 ;
4308       // 5. Memorisation du traitement
4309       ListeBoundaryTraitees.push_back( BoundaryName );
4310     }
4311   }
4312
4313   return texte_control ;
4314 }
4315 //
4316 //=============================================================================
4317 //=============================================================================
4318 // Next functions are inherited from SALOMEDS::Driver interface
4319 //=============================================================================
4320 //=============================================================================
4321 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4322                                       const char* theURL,
4323                                       CORBA::Boolean isMultiFile)
4324 {
4325   MESSAGE ("Save for theURL = "<< theURL);
4326   SALOMEDS::TMPFile_var aStreamFile;
4327
4328   // get temporary directory name
4329   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4330
4331   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4332   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4333
4334   // HOMARD data file name
4335   std::string aFileName = "";
4336   if (isMultiFile)
4337     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4338   aFileName += "_HOMARD.dat";
4339
4340   // initialize sequence of file names
4341   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4342   aFileSeq->length(1);
4343   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4344
4345   // get full path to the data file
4346   aFileName = tmpDir + aFileName;
4347
4348   // save data
4349   // -> create file
4350   std::ofstream f(aFileName.c_str());
4351
4352   // clear temporary id map
4353   context._idmap.clear();
4354
4355   int id = 1;
4356
4357   // -> save cases
4358   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4359   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4360     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4361     PortableServer::ServantBase_var aServant = GetServant(aCas);
4362     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4363     if (aCasServant) {
4364       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4365       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4366     }
4367   }
4368   // -> save zones
4369   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4370   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4371     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4372     PortableServer::ServantBase_var aServant = GetServant(aZone);
4373     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4374     if (aZoneServant) {
4375       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4376       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4377     }
4378   }
4379   // -> save hypotheses
4380   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4381   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4382     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4383     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4384     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4385     if (aHypoServant) {
4386       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4387       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4388     }
4389   }
4390   // -> save iterations
4391   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4392   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4393     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4394     PortableServer::ServantBase_var aServant = GetServant(aIter);
4395     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4396     if (aIterServant) {
4397       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4398       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4399     }
4400   }
4401   // -> save boundaries
4402   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4403   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4404     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4405     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4406     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4407     if (aBoundaryServant) {
4408       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4409       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4410     }
4411   }
4412   // -> close file
4413   MESSAGE ("close file");
4414   f.close();
4415
4416   // put temporary files to the stream
4417   MESSAGE ("put temporary files to the stream");
4418   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4419
4420   // remove temporary files
4421   MESSAGE ("remove temporary files");
4422   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4423
4424   // return data stream
4425   MESSAGE ("return data stream");
4426   return aStreamFile._retn();
4427 };
4428
4429 //===========================================================================
4430 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4431                                            const char* theURL,
4432                                            CORBA::Boolean isMultiFile)
4433 {
4434   // No specific ASCII persistence
4435   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4436   return aStreamFile._retn();
4437 };
4438
4439 //===========================================================================
4440 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4441                                    const SALOMEDS::TMPFile& theStream,
4442                                    const char* theURL,
4443                                    CORBA::Boolean isMultiFile)
4444 {
4445   MESSAGE ("Load pour theURL = "<< theURL);
4446   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4447
4448   // set current study
4449   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4450     SetCurrentStudy(aStudy);
4451
4452   // get temporary directory name
4453   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4454
4455   // Convert the stream into sequence of files to process
4456   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4457                                                                             tmpDir.c_str(),
4458                                                                             isMultiFile);
4459   // HOMARD data file name
4460   std::string aFileName = "";
4461   if (isMultiFile)
4462     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4463   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4464
4465   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4466
4467   // save data
4468   // -> create file
4469   std::ifstream f(aFileName.c_str());
4470
4471   // clear context
4472   context._mesCas.clear();
4473   context._mesHypotheses.clear();
4474   context._mesIterations.clear();
4475   context._mesZones.clear();
4476   context._mesBoundarys.clear();
4477   context._idmap.clear();
4478
4479   int id = 1;
4480   std::string line;
4481
4482   while (f) {
4483     std::getline(f, line);
4484     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4485     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4486     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4487     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4488     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4489     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4490     if (line.substr(0, bounSignature.size()) == bounSignature) {
4491       // re-create boundary
4492       MESSAGE ("Recreation de la frontiere" );
4493       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4494       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4495       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4496       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4497         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4498         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4499       }
4500     }
4501     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4502       // re-create case
4503       MESSAGE ("Recreation du cas" );
4504       HOMARD::HOMARD_Cas_var aCase = newCase();
4505       PortableServer::ServantBase_var aServant = GetServant(aCase);
4506       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4507       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4508         context._mesCas[aCase->GetName()] = aCase;
4509         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4510       }
4511     }
4512     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4513       // re-create hypothesis
4514       MESSAGE ("Recreation de l hypothese" );
4515       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4516       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4517       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4518       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4519         context._mesHypotheses[aHypo->GetName()] = aHypo;
4520         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4521       }
4522     }
4523     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4524       // re-create iteration
4525       MESSAGE ("Recreation de l'iteration" );
4526       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4527       PortableServer::ServantBase_var aServant = GetServant(aIter);
4528       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4529       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4530         context._mesIterations[aIter->GetName()] = aIter;
4531         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4532       }
4533     }
4534     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4535       MESSAGE ("Recreation de la zone" );
4536       // re-create zone
4537       HOMARD::HOMARD_Zone_var aZone = newZone();
4538       PortableServer::ServantBase_var aServant = GetServant(aZone);
4539       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4540       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4541         context._mesZones[aZone->GetName()] = aZone;
4542         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4543       }
4544     }
4545     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4546       MESSAGE ("Recreation du schema YACS" );
4547       // re-create YACS
4548       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4549       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4550       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4551       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4552         context._mesYACSs[aYACS->GetName()] = aYACS;
4553         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4554       }
4555     }
4556     id++;
4557   }
4558
4559   // -> close file
4560   f.close();
4561
4562   // Remove temporary files created from the stream
4563   if (!isMultiFile)
4564     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4565
4566   return true;
4567 };
4568
4569 //===========================================================================
4570 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4571                                         const SALOMEDS::TMPFile& theStream,
4572                                         const char* theURL,
4573                                         CORBA::Boolean isMultiFile)
4574 {
4575   // No specific ASCII persistence
4576   return Load(theComponent, theStream, theURL, isMultiFile);
4577 };
4578
4579 //===========================================================================
4580 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4581 {
4582   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4583     // clearing study context should be done here:
4584     // - destroy all servants and related CORBA objects
4585     // ... (TODO)
4586     // - remove context from myContextMap
4587     myContextMap.erase(theComponent->GetStudy()->StudyId());
4588     // - nullify myCurrentStudy
4589     myCurrentStudy = SALOMEDS::Study::_nil();
4590   }
4591 };
4592
4593 //===========================================================================
4594 char* HOMARD_Gen_i::ComponentDataType()
4595 {
4596   return CORBA::string_dup("HOMARD");
4597 };
4598
4599 //===========================================================================
4600 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4601                                             const char* IORString,
4602                                             CORBA::Boolean isMultiFile,
4603                                             CORBA::Boolean isASCII)
4604 {
4605   CORBA::String_var aString("");
4606   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4607     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4608     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4609     if (!CORBA::is_nil(anObj)) {
4610       PortableServer::ServantBase_var aServant = GetServant(anObj);
4611       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4612       if (aStorable) {
4613         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4614         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4615           if (it->second == aStorable) {
4616             std::stringstream os;
4617             os << it->first;
4618             aString = CORBA::string_dup(os.str().c_str());
4619           }
4620         }
4621       }
4622     }
4623   }
4624   return aString._retn();
4625 };
4626
4627 //===========================================================================
4628 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4629                                             const char* aLocalPersistentID,
4630                                             CORBA::Boolean isMultiFile,
4631                                             CORBA::Boolean isASCII)
4632 {
4633   CORBA::String_var aString("");
4634   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4635     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4636     int id = atoi(aLocalPersistentID);
4637     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4638       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4639       if (!CORBA::is_nil(object)) {
4640         aString = _orb->object_to_string(object);
4641       }
4642     }
4643   }
4644   return aString._retn();
4645 };
4646
4647 //===========================================================================
4648 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4649 {
4650   if(CORBA::is_nil(myCurrentStudy))
4651     return false;
4652
4653   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4654   if(!aCas->_is_nil())
4655     return true;
4656
4657   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4658   if(!aHypo->_is_nil())
4659     return true;
4660
4661   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4662   if(!aZone->_is_nil())
4663     return true;
4664
4665   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4666   if(!aBoundary->_is_nil())
4667     return true;
4668
4669   /* Iteration is not published directly
4670   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4671   if(!aIter->_is_nil())
4672     return true;
4673   */
4674   return false;
4675 };
4676
4677 //===========================================================================
4678 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4679 {
4680   // No Copy/Paste support
4681   return false;
4682 };
4683
4684 //===========================================================================
4685 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4686                                            CORBA::Long& theObjectID)
4687 {
4688   // No Copy/Paste support
4689   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4690   return aStreamFile._retn();
4691 };
4692
4693 //===========================================================================
4694 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4695                                         CORBA::Long theObjectID)
4696 {
4697   // No Copy/Paste support
4698   return false;
4699 };
4700
4701 //===========================================================================
4702 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4703                                                CORBA::Long theObjectID,
4704                                                SALOMEDS::SObject_ptr theSObject)
4705 {
4706   // No Copy/Paste support
4707   SALOMEDS::SObject_var aResultSO;
4708   return aResultSO._retn();
4709 };
4710
4711 //===========================================================================
4712 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4713 {
4714   PortableServer::Servant aServant = 0;
4715   if (!CORBA::is_nil(theObject)) {
4716     try {
4717       aServant = _poa->reference_to_servant(theObject);
4718     }
4719     catch (...) {
4720     }
4721   }
4722   return aServant;
4723 }
4724
4725 //==========================================================================
4726 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4727                                        CORBA::Boolean isPublished,
4728                                        CORBA::Boolean isMultiFile,
4729                                        CORBA::Boolean& isValidScript)
4730 {
4731    MESSAGE ("Entree dans DumpPython");
4732    isValidScript=1;
4733    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4734    if(CORBA::is_nil(aStudy))
4735      return new Engines::TMPFile(0);
4736
4737    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4738    if(CORBA::is_nil(aSO))
4739       return new Engines::TMPFile(0);
4740
4741    std::string aScript = "\"\"\"\n";
4742    aScript += "Python script for HOMARD\n";
4743    aScript += "Copyright EDF-R&D 1996, 2011, 2014\n";
4744    aScript += "\"\"\"\n";
4745    aScript += "__revision__ = \"V1.2\"\n";
4746    aScript += "import HOMARD\n";
4747    if( isMultiFile )
4748       aScript += "import salome\n";
4749    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4750    if( isMultiFile ) {
4751       aScript += "def RebuildData(theStudy):\n";
4752       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4753    }
4754    else
4755       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4756    MESSAGE (". Au depart \n"<<aScript);
4757
4758
4759    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4760    {
4761     MESSAGE (". Ecritures des frontieres");
4762     aScript += "#\n# Creation of the boundaries";
4763     aScript +=  "\n# ==========================";
4764    }
4765    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4766    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4767         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4768    {
4769     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4770     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4771     std::string dumpBoundary = dumpCorbaBoundary.in();
4772     MESSAGE (dumpBoundary<<"\n");
4773     aScript += dumpBoundary;
4774    }
4775
4776
4777    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4778    {
4779     MESSAGE (". Ecritures des zones");
4780     aScript += "#\n# Creation of the zones";
4781     aScript +=  "\n# =====================";
4782    }
4783    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4784    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4785          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4786    {
4787     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4788     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4789     std::string dumpZone = dumpCorbaZone.in();
4790     MESSAGE (dumpZone<<"\n");
4791     aScript += dumpZone;
4792    }
4793
4794
4795    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4796    {
4797     MESSAGE (". Ecritures des hypotheses");
4798     aScript += "#\n# Creation of the hypotheses";
4799     aScript +=  "\n# ==========================";
4800    }
4801    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4802    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4803          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4804    {
4805     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4806     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4807     std::string dumpHypo = dumpCorbaHypo.in();
4808     MESSAGE (dumpHypo<<"\n");
4809     aScript += dumpHypo;
4810    }
4811
4812
4813    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4814    {
4815     MESSAGE (". Ecritures des cas");
4816     aScript += "#\n# Creation of the cases";
4817     aScript += "\n# =====================";
4818    }
4819    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4820    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4821         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4822         {
4823            std::string nomCas = (*it_cas).first;
4824            std::string dumpCas = std::string("\n# Creation of the case ") ;
4825            dumpCas +=  nomCas + std::string("\n");
4826            dumpCas += std::string("\t") + nomCas;
4827            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4828
4829            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4830            CORBA::String_var cIter0= myCase->GetIter0Name();
4831            std::string iter0 = cIter0.in();
4832
4833            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4834            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4835            std::string mesh0 = cMesh0.in();
4836            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4837            std::string meshName0 = cMeshName0.in();
4838            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4839            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4840            std::string dumpCas2= dumpCorbaCase.in();
4841
4842            MESSAGE (dumpCas<<dumpCas2<<"\n");
4843            aScript += dumpCas + dumpCas2;
4844         };
4845
4846
4847    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4848    {
4849     MESSAGE (". Ecritures des iterations");
4850     aScript += "#\n# Creation of the iterations" ;
4851     aScript += "\n# ==========================";
4852    }
4853    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4854    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4855         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4856    {
4857     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4858     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4859     std::string dumpIter = dumpCorbaIter.in();
4860     MESSAGE (dumpIter<<"\n");
4861     aScript += dumpIter;
4862    }
4863
4864
4865    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4866    {
4867     MESSAGE (". Ecritures des schemas YACS");
4868     aScript += "#\n# Creation of the schemas YACS";
4869     aScript +=  "\n# ============================";
4870    }
4871    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4872    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4873          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4874    {
4875     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4876     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4877     std::string dumpYACS = dumpCorbaYACS.in();
4878     MESSAGE (dumpYACS<<"\n");
4879     aScript += dumpYACS;
4880    }
4881
4882   MESSAGE (". Ecritures finales");
4883   if( isMultiFile )
4884     aScript += "\n\tpass";
4885   aScript += "\n";
4886
4887   if( !isMultiFile ) // remove unnecessary tabulation
4888     aScript = RemoveTabulation( aScript );
4889
4890 //   MESSAGE ("A ecrire \n"<<aScript);
4891   const size_t aLen = strlen(aScript.c_str());
4892   char* aBuffer = new char[aLen+1];
4893   strcpy(aBuffer, aScript.c_str());
4894
4895   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4896   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4897
4898   MESSAGE ("Sortie de DumpPython");
4899   return aStreamFile._retn();
4900 }
4901
4902
4903 //=============================================================================
4904 //=============================================================================
4905 // Utilitaires
4906 //=============================================================================
4907 //=============================================================================
4908 void HOMARD_Gen_i::IsValidStudy( )
4909 {
4910 //   MESSAGE( "IsValidStudy" );
4911   if (CORBA::is_nil(myCurrentStudy))
4912   {
4913     SALOME::ExceptionStruct es;
4914     es.type = SALOME::BAD_PARAM;
4915     es.text = "Invalid study context";
4916     throw SALOME::SALOME_Exception(es);
4917   };
4918   return ;
4919 }
4920
4921 //=============================================================================
4922 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4923 {
4924   std::string casename = std::string("") ;
4925   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4926   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4927   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4928   {
4929    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4930    {
4931      casename = std::string(it->second->GetName()) ;
4932      break ;
4933    }
4934   }
4935   return CORBA::string_dup( casename.c_str() );
4936 }
4937 /*//=============================================================================
4938 void SALOMEException( std::string message )
4939 {
4940   SALOME::ExceptionStruct es;
4941   es.type = SALOME::BAD_PARAM;
4942   es.text = message;
4943   throw SALOME::SALOME_Exception(es);
4944   return ;
4945 }*/
4946 //=============================================================================
4947 char* HOMARD_Gen_i::getVersion()
4948 {
4949 #if HOMARD_DEVELOPMENT
4950   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4951 #else
4952   return CORBA::string_dup(HOMARD_VERSION_STR);
4953 #endif
4954 }
4955 //===============================================================================
4956 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un caractere
4957 // ligne : la ligne a manipuler
4958 // caractere : le caractere a reperer
4959 // option : 0 : la chaine avant la premiere apparition du caractere
4960 //          1 : la chaine apres la premiere apparition du caractere
4961 //          2 : la chaine avant la derniere apparition du caractere
4962 //          3 : la chaine apres la derniere apparition du caractere
4963 // Si le caractere est absent, on retourne la chaine totale
4964 //===============================================================================
4965 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string caractere, int option )
4966 {
4967 //   MESSAGE("GetStringInTexte, recherche de '"<<caractere<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4968 //
4969   std::string chaine = ligne ;
4970   int position ;
4971   if ( option < 2 ) { position = ligne.find_first_of( caractere ) ; }
4972   else              { position = ligne.find_last_of( caractere ) ; }
4973 //   MESSAGE("position = "<<position);
4974 //   MESSAGE("a = "<<ligne.substr( 0, position ).c_str());
4975 //   MESSAGE("b = "<<ligne.substr( position+1 ).c_str());
4976 //
4977   if ( position != std::string::npos )
4978   {
4979     if ( ( option == 0 ) || ( option == 2 ) ) { chaine = ligne.substr( 0, position ) ; }
4980     else                                      { chaine = ligne.substr( position+1 ) ; }
4981   }
4982   return chaine ;
4983 //
4984 }
4985 //=============================================================================
4986 //=============================================================================
4987 // Gestion des preferences
4988 //=============================================================================
4989 //=============================================================================
4990 // Decodage du fichier d'arcihvage des preferences
4991 //
4992 void HOMARD_Gen_i::SetPreferences( )
4993 {
4994   MESSAGE ( "SetPreferences" );
4995
4996   std::string ligne, mot_cle, salome_version ;
4997   bool ok = true ;
4998
4999   // A. Les valeurs par defaut ; elles doivent etre coherentes
5000   std::string LanguageShort = "en" ;
5001   int PublisMeshIN = 0 ;
5002   int PublisMeshOUT = 0 ;
5003   int YACSMaxIter = 0 ;
5004   int YACSMaxNode = 0 ;
5005   int YACSMaxElem = 0 ;
5006
5007   // B. La version de salome
5008   // Cela se presente sous la forme :
5009   // [SALOME KERNEL] : 7.3.0
5010   std::string File ;
5011   File  = getenv("KERNEL_ROOT_DIR") ;
5012   File += "/bin/salome/VERSION" ;
5013   MESSAGE ( "File = "<<File ) ;
5014   std::ifstream fichier0( File.c_str() ) ;
5015   if ( fichier0 ) // ce test échoue si le fichier n'est pas ouvert
5016   {
5017     std::string ligne; // variable contenant chaque ligne lue
5018     while ( std::getline( fichier0, ligne ) )
5019     {
5020       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5021       ligne_bis >> mot_cle ;
5022       if ( mot_cle == "[SALOME" )
5023       {
5024         salome_version = GetStringInTexte ( ligne, " ", 3 ) ;
5025 //         MESSAGE ( "salome_version = "<<salome_version<<"|||");
5026         break ;
5027       }
5028     }
5029   }
5030   else { ok = false ; }
5031
5032   // B. Decodage du fichier de preferences
5033   if ( ok )
5034   {
5035     std::string PrefFile ;
5036     PrefFile  = getenv("HOME") ;
5037     PrefFile += "/.config/salome/SalomeApprc." + salome_version ;
5038     MESSAGE ( "PrefFile = "<<PrefFile ) ;
5039
5040     std::ifstream fichier( PrefFile.c_str() );
5041     if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
5042     {
5043       bool section_langue = false ;
5044       bool section_homard = false ;
5045       while ( std::getline( fichier, ligne ) )
5046       {
5047         std::string chaine ;
5048         // 1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
5049         std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
5050         ligne_bis >> mot_cle ;
5051
5052         // 2. Les sections
5053         // 2.1. Debut d'une section
5054   //       MESSAGE(mot_cle);
5055         if ( mot_cle == "<section" )
5056         { /*MESSAGE ( "Debut de la section : "<< ligne);*/
5057           ligne_bis >> mot_cle ;
5058           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5059           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5060           if ( chaine == "language" ) { section_langue = true ; }
5061           if ( chaine == "HOMARD" )   { section_homard = true ; }
5062   //         MESSAGE ( "section_langue = "<<section_langue<<", section_homard = "<<section_homard);
5063         }
5064         // 2.2. Fin d'une section
5065         else if ( mot_cle == "</section>" )
5066         { /*MESSAGE ( "Fin de la section : "<< ligne<<", section_langue = "<<section_langue<<", section_homard = "<<section_homard);*/
5067           section_langue = false ;
5068           section_homard = false ; }
5069
5070         // 3. Parametres
5071         // 3.1. La langue
5072         else if ( section_langue || section_homard )
5073         { /*MESSAGE ( "a decoder : "<< ligne);*/
5074           ligne_bis >> mot_cle ;
5075           chaine = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5076           chaine = GetStringInTexte ( chaine,  "\"", 0 ) ;
5077 //           MESSAGE("chaine = "<<chaine<<"|");
5078           ligne_bis >> mot_cle ;
5079           std::string chaine2 = GetStringInTexte ( mot_cle, "\"", 1 ) ;
5080           chaine2 = GetStringInTexte ( chaine2,  "\"", 0 ) ;
5081           MESSAGE("chaine2 = "<<chaine2<<"|");
5082           // 3.1. La langue
5083           if ( section_langue )
5084           { if ( chaine2 == "language" ) { LanguageShort = chaine ; } }
5085           // 3.2. HOMARD
5086           if ( section_homard )
5087           {
5088             std::istringstream chainebis( chaine ) ;
5089             // 3.2.1. Les publications
5090             if ( chaine2 == "publish_mesh_in" )  { chainebis >> PublisMeshIN ; }
5091             if ( chaine2 == "publish_mesh_out" ) { chainebis >> PublisMeshOUT ; }
5092             // 3.2.2. Les maximum pour YACS
5093             if ( chaine2 == "yacs_max_iter" ) { chainebis >> YACSMaxIter ; }
5094             if ( chaine2 == "yacs_max_node" ) { chainebis >> YACSMaxNode ; }
5095             if ( chaine2 == "yacs_max_elem" ) { chainebis >> YACSMaxElem ; }
5096           }
5097         }
5098       }
5099     }
5100   }
5101
5102   // C. Enregistrement
5103   MESSAGE ("Enregistrement de LanguageShort = " << LanguageShort );
5104   MESSAGE ("Enregistrement de PublisMeshIN = " << PublisMeshIN<<", PublisMeshOUT = "<< PublisMeshOUT);
5105   MESSAGE ("Enregistrement de YACSMaxIter = " << YACSMaxIter<<", YACSMaxNode = "<< YACSMaxNode<<", YACSMaxElem = "<< YACSMaxElem);
5106   SetLanguageShort( LanguageShort.c_str() ) ;
5107   SetPublisMesh(PublisMeshIN, PublisMeshOUT) ;
5108   SetYACSMaximum(YACSMaxIter, YACSMaxNode, YACSMaxElem) ;
5109
5110   return ;
5111 }
5112 //===============================================================================
5113 // Langue de SALOME
5114 //===============================================================================
5115 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
5116 {
5117 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
5118   _LangueShort = LanguageShort ;
5119   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
5120   else                        { _Langue = "English" ; }
5121   return ;
5122 }
5123 char* HOMARD_Gen_i::GetLanguageShort()
5124 {
5125 //   MESSAGE ("GetLanguageShort");
5126   return CORBA::string_dup( _LangueShort.c_str() );
5127 }
5128 //===============================================================================
5129 // Options de publications
5130 //===============================================================================
5131 void HOMARD_Gen_i::SetPublisMesh(CORBA::Long PublisMeshIN, CORBA::Long PublisMeshOUT)
5132 {
5133   _PublisMeshIN  = PublisMeshIN  ;
5134   _PublisMeshOUT = PublisMeshOUT ;
5135   return ;
5136 }
5137 CORBA::Long HOMARD_Gen_i::GetPublisMeshIN()
5138 {
5139   return _PublisMeshIN ;
5140 }
5141 CORBA::Long HOMARD_Gen_i::GetPublisMeshOUT()
5142 {
5143   return _PublisMeshOUT ;
5144 }
5145 //===============================================================================
5146 // YACS - maximum
5147 //===============================================================================
5148 void HOMARD_Gen_i::SetYACSMaximum(CORBA::Long YACSMaxIter, CORBA::Long YACSMaxNode, CORBA::Long YACSMaxElem)
5149 {
5150   _YACSMaxIter = YACSMaxIter ;
5151   _YACSMaxNode = YACSMaxNode ;
5152   _YACSMaxElem = YACSMaxElem ;
5153   return ;
5154 }
5155 CORBA::Long HOMARD_Gen_i::GetYACSMaxIter()
5156 {
5157   return _YACSMaxIter ;
5158 }
5159 CORBA::Long HOMARD_Gen_i::GetYACSMaxNode()
5160 {
5161   return _YACSMaxNode ;
5162 }
5163 CORBA::Long HOMARD_Gen_i::GetYACSMaxElem()
5164 {
5165   return _YACSMaxElem ;
5166 }
5167
5168 //=============================================================================
5169 extern "C"
5170 {
5171   HOMARDENGINE_EXPORT
5172   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
5173                                                   PortableServer::POA_ptr poa,
5174                                                   PortableServer::ObjectId* contId,
5175                                                   const char* instanceName,
5176                                                   const char* interfaceName)
5177   {
5178     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
5179     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
5180     return myHOMARD_Gen->getId();
5181   }
5182 }