Salome HOME
Porting HOMARD SALOME module on WIN32 platform.
[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   _Langue = "Francais" ;
108   _LangueShort = "fr" ;
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'etude
843   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
844
845   aStudyBuilder->NewCommand();
846
847   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
848   aStudyBuilder->Addreference(aSubSO, aHypoSO);
849
850   aStudyBuilder->CommitCommand();
851
852   // Liens reciproques
853   myIteration->SetHypoName(nomHypo);
854   myHypo->LinkIteration(nomIter);
855
856   // On stocke les noms des champ a interpoler pour le futur controle de la donnee des pas de temps
857   myIteration->SupprFieldInterps() ;
858   HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
859   int numberOfFieldsx2 = ListField->length();
860   for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
861   {
862     std::string FieldName = std::string((*ListField)[iaux]) ;
863     myIteration->SetFieldInterp(FieldName.c_str()) ;
864     iaux++ ;
865   }
866 };
867 //=============================================================================
868 //=============================================================================
869 //
870 //=============================================================================
871 //=============================================================================
872 // Dissociation de lien entre des structures identifiees par leurs noms
873 //=============================================================================
874 //=============================================================================
875 void HOMARD_Gen_i::DissociateHypoZone(const char* nomHypothesis, const char* ZoneName)
876 {
877   MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
878
879   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
880   ASSERT(!CORBA::is_nil(myHypo));
881   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
882   ASSERT(!CORBA::is_nil(aHypoSO));
883
884   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
885   ASSERT(!CORBA::is_nil(myZone));
886   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
887   ASSERT(!CORBA::is_nil(aZoneSO));
888
889   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
890
891   SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
892   for (; it->More(); it->Next())
893   {
894     SALOMEDS::SObject_var aHypObj = it->Value();
895     SALOMEDS::SObject_var ptrObj;
896     if (aHypObj->ReferencedObject(ptrObj))
897     {
898       if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
899       {
900         aStudyBuilder->NewCommand();
901         aStudyBuilder->RemoveObject(aHypObj);
902         aStudyBuilder->CommitCommand();
903         break;
904       }
905     }
906   }
907
908   myZone->SupprHypo(nomHypothesis);
909   myHypo->SupprZone(ZoneName);
910 };
911 //=============================================================================
912 //=============================================================================
913 //
914
915 //=============================================================================
916 //=============================================================================
917 // Recuperation des listes
918 //=============================================================================
919 //=============================================================================
920 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarysName()
921 {
922   MESSAGE("GetAllBoundarysName");
923   IsValidStudy () ;
924
925   HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
926   ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
927   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
928   int i = 0;
929   for (it = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
930   it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
931   {
932     ret[i++] = CORBA::string_dup((*it).first.c_str());
933   }
934
935   return ret._retn();
936 }
937 //=============================================================================
938 HOMARD::listeCases* HOMARD_Gen_i::GetAllCasesName()
939 {
940   MESSAGE("GetAllCasesName");
941   IsValidStudy () ;
942
943   HOMARD::listeCases_var ret = new HOMARD::listeCases;
944   ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
945   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
946   int i = 0;
947   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
948   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
949   {
950     ret[i++] = CORBA::string_dup((*it).first.c_str());
951   }
952
953   return ret._retn();
954 }
955 //=============================================================================
956 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypothesesName()
957 {
958   MESSAGE("GetAllHypothesesName");
959   IsValidStudy () ;
960
961   HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
962   ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
963   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
964   int i = 0;
965   for (it = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
966   it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
967   {
968     ret[i++] = CORBA::string_dup((*it).first.c_str());
969   }
970
971   return ret._retn();
972 }
973 //=============================================================================
974 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterationsName()
975 {
976   MESSAGE("GetAllIterationsName");
977   IsValidStudy () ;
978
979   HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
980   ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
981   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
982   int i = 0;
983   for (it = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
984   it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
985   {
986     ret[i++] = CORBA::string_dup((*it).first.c_str());
987   }
988
989   return ret._retn();
990 }
991 //=============================================================================
992 HOMARD::listeYACSs* HOMARD_Gen_i::GetAllYACSsName()
993 {
994   MESSAGE("GetAllYACSsName");
995   IsValidStudy () ;
996
997   HOMARD::listeYACSs_var ret = new HOMARD::listeYACSs;
998   ret->length(myContextMap[GetCurrentStudyID()]._mesYACSs.size());
999   std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it;
1000   int i = 0;
1001   for (it = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
1002   it != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); it++)
1003   {
1004     ret[i++] = CORBA::string_dup((*it).first.c_str());
1005   }
1006
1007   return ret._retn();
1008 }
1009 //=============================================================================
1010 HOMARD::listeZones* HOMARD_Gen_i::GetAllZonesName()
1011 {
1012   MESSAGE("GetAllZonesName");
1013   IsValidStudy () ;
1014
1015   HOMARD::listeZones_var ret = new HOMARD::listeZones;
1016   ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1017   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1018   int i = 0;
1019   for (it = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1020   it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1021   {
1022     ret[i++] = CORBA::string_dup((*it).first.c_str());
1023   }
1024
1025   return ret._retn();
1026 }
1027 //=============================================================================
1028 //=============================================================================
1029
1030 //=============================================================================
1031 //=============================================================================
1032 // Recuperation des structures identifiees par leurs noms
1033 //=============================================================================
1034 //=============================================================================
1035 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
1036 {
1037   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
1038   ASSERT(!CORBA::is_nil(myBoundary));
1039   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1040 }
1041 //=============================================================================
1042 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCase(const char* nomCas)
1043 {
1044   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1045   ASSERT(!CORBA::is_nil(myCase));
1046   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1047 }
1048 //=============================================================================
1049 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
1050 {
1051   HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
1052   ASSERT(!CORBA::is_nil(myHypothesis));
1053   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1054 }
1055 //=============================================================================
1056 HOMARD::HOMARD_Iteration_ptr  HOMARD_Gen_i::GetIteration(const char* NomIterationation)
1057 {
1058   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIterationation];
1059   ASSERT(!CORBA::is_nil(myIteration));
1060   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1061 }
1062 //=============================================================================
1063 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::GetYACS(const char* nomYACS)
1064 {
1065   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
1066   ASSERT(!CORBA::is_nil(myYACS));
1067   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
1068 }
1069 //=============================================================================
1070 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
1071 {
1072   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1073   ASSERT(!CORBA::is_nil(myZone));
1074   return HOMARD::HOMARD_Zone::_duplicate(myZone);
1075 }
1076 //=============================================================================
1077 //=============================================================================
1078
1079 //=============================================================================
1080 //=============================================================================
1081 // Informations
1082 //=============================================================================
1083 //=============================================================================
1084 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)
1085 {
1086   INFOS ( "MeshInfo : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile  );
1087   INFOS ( "Qual = " << Qual << ", Diam = " << Diam << ", Conn = " << Conn << ", Tail = " << Tail << ", Inte = " << Inte  );
1088   IsValidStudy () ;
1089
1090 // Creation du cas
1091   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, 0, 1) ;
1092   myCase->SetDirName(DirName) ;
1093 // Analyse
1094   myCase->MeshInfo(Qual, Diam, Conn, Tail, Inte) ;
1095
1096   return ;
1097 }
1098 //=============================================================================
1099 //=============================================================================
1100
1101 //=============================================================================
1102 //=============================================================================
1103 // Recuperation des structures par le contexte
1104 //=============================================================================
1105 //=============================================================================
1106 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::LastIteration(const char* nomCas)
1107 {
1108   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1109   ASSERT(!CORBA::is_nil(myCase));
1110 //
1111   HOMARD::HOMARD_Iteration_var myIteration = myCase->LastIteration();
1112   ASSERT(!CORBA::is_nil(myIteration));
1113 //
1114   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1115 }
1116 //=============================================================================
1117 //=============================================================================
1118
1119 //=============================================================================
1120 //=============================================================================
1121 // Nouvelles structures
1122 //=============================================================================
1123 //=============================================================================
1124 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
1125 {
1126   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1127   HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
1128   HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
1129   return aCase._retn();
1130 }
1131 //=============================================================================
1132 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
1133 {
1134   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1135   HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
1136   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
1137   return aHypo._retn();
1138 }
1139 //=============================================================================
1140 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
1141 {
1142   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1143   HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
1144   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
1145   return aIter._retn();
1146 }
1147 //=============================================================================
1148 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
1149 {
1150   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1151   HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
1152   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
1153   return aBoundary._retn();
1154 }
1155 //=============================================================================
1156 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
1157 {
1158   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1159   HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
1160   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
1161   return aZone._retn();
1162 }
1163 //=============================================================================
1164 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::newYACS()
1165 {
1166   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
1167   HOMARD_YACS_i* aServant = new HOMARD_YACS_i(_orb, engine);
1168   HOMARD::HOMARD_YACS_var aYACS = HOMARD::HOMARD_YACS::_narrow(aServant->_this());
1169   return aYACS._retn();
1170 }
1171 //=============================================================================
1172 //=============================================================================
1173
1174 //=============================================================================
1175 //=============================================================================
1176 // Creation des structures identifiees par leurs noms
1177 //=============================================================================
1178 //=============================================================================
1179 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
1180 //
1181 // Creation d'un cas initial
1182 // nomCas : nom du cas a creer
1183 // MeshName, MeshFile : nom et fichier du maillage correspondant
1184 //
1185 {
1186   INFOS ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
1187
1188   // Par defaut, on ne publie pas le maillage
1189   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 0, 0, 1) ;
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   // Par defaut, on ne publie pas le maillage
1364   HOMARD::HOMARD_Cas_ptr myCase = CreateCase0(nomCas, MeshName, MeshFile, 1, NumeIter, 1) ;
1365
1366   // D. Parametrages lus dans le fichier de configuration
1367
1368   myCase->SetConfType (TypeConf) ;
1369   myCase->SetPyram (Pyram) ;
1370
1371   // E. Copie du fichier de maillage homard
1372   // E.1. Repertoire associe au cas
1373   char* nomDirCase = myCase->GetDirName() ;
1374   // E.2. Repertoire associe a l'iteration de ce cas
1375   char* IterName ;
1376   IterName = myCase->GetIter0Name() ;
1377   HOMARD::HOMARD_Iteration_var Iter = GetIteration(IterName) ;
1378   char* nomDirIter = CreateDirNameIter(nomDirCase, 0 );
1379   Iter->SetDirNameLoc(nomDirIter);
1380   std::string nomDirIterTotal ;
1381   nomDirIterTotal = std::string(nomDirCase) + "/" + std::string(nomDirIter) ;
1382 #ifndef WIN32
1383   if (mkdir(nomDirIterTotal.c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1384 #else 
1385   if (_mkdir(nomDirIterTotal.c_str()) != 0)
1386 #endif
1387   {
1388     MESSAGE ( "nomDirIterTotal : " << nomDirIterTotal ) ;
1389     SALOME::ExceptionStruct es;
1390     es.type = SALOME::BAD_PARAM;
1391     std::string text = "The directory for the computation cannot be created." ;
1392     es.text = CORBA::string_dup(text.c_str());
1393     throw SALOME::SALOME_Exception(es);
1394   }
1395   // E.3. Copie du maillage HOMARD au format MED
1396 #ifndef WIN32
1397   codret = chdir(DirNameStart) ;
1398 #else
1399   codret = _chdir(DirNameStart) ;
1400 #endif
1401   std::string commande = "cp " + file_maillage_homard + " " + nomDirIterTotal ;
1402   MESSAGE ( "commande : " << commande ) ;
1403   codret = system(commande.c_str()) ;
1404   MESSAGE ( "codret : " << codret ) ;
1405   if ( codret != 0 )
1406   {
1407     SALOME::ExceptionStruct es;
1408     es.type = SALOME::BAD_PARAM;
1409     es.text = "The starting point for the case cannot be copied into the working directory.";
1410     throw SALOME::SALOME_Exception(es);
1411     return 0;
1412   };
1413
1414   // F. Menage
1415
1416   delete[] MeshName ;
1417   delete[] MeshFile ;
1418
1419 #ifndef WIN32
1420   chdir(nomDirWork.c_str());
1421 #else
1422   _chdir(nomDirWork.c_str());
1423 #endif
1424   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1425 }
1426 //=============================================================================
1427 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseLastIteration(const char* nomCas, const char* DirNameStart)
1428 //
1429 // nomCas : nom du cas a creer
1430 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1431 //
1432 {
1433   INFOS ( "CreateCaseFromCaseLastIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart );
1434
1435   std::string DirNameStartIter = CreateCase1(DirNameStart, -1) ;
1436
1437   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1438   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1439
1440   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1441 }
1442 //=============================================================================
1443 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCaseFromCaseIteration(const char* nomCas, const char* DirNameStart, CORBA::Long Number)
1444 //
1445 // nomCas : nom du cas a creer
1446 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1447 // Number : numero de l'iteration de depart
1448 //
1449 {
1450   INFOS ( "CreateCaseFromCaseIteration : nomCas = " << nomCas << ", DirNameStart = " << DirNameStart << ", Number = " << Number );
1451   if ( Number < 0 )
1452   {
1453     SALOME::ExceptionStruct es;
1454     es.type = SALOME::BAD_PARAM;
1455     es.text = "The number of iteration must be positive.";
1456     throw SALOME::SALOME_Exception(es);
1457     return 0;
1458   };
1459
1460   std::string DirNameStartIter = CreateCase1(DirNameStart, Number) ;
1461
1462   DirNameStartIter = string(DirNameStart) + "/" + DirNameStartIter ;
1463   HOMARD::HOMARD_Cas_ptr myCase = CreateCaseFromIteration(nomCas, DirNameStartIter.c_str()) ;
1464
1465   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1466 }
1467 //=============================================================================
1468 std::string HOMARD_Gen_i::CreateCase1(const char* DirNameStart, CORBA::Long Number)
1469 //
1470 // Retourne le nom du repertoire ou se trouve l'iteration voulue.
1471 // DirNameStart : nom du repertoire du cas contenant l'iteration de reprise
1472 // Number : numero de l'iteration de depart ou -1 si on cherche la derniere
1473 //
1474 {
1475   MESSAGE ( "CreateCase1 : DirNameStart = " << DirNameStart << ", Number = " << Number );
1476   std::string nomDirWork = getenv("PWD") ;
1477   std::string DirNameStartIter ;
1478   int codret ;
1479   int NumeIterMax = -1 ;
1480
1481   // A.1. Controle du repertoire de depart du cas
1482 #ifndef WIN32
1483   codret = chdir(DirNameStart) ;
1484 #else
1485   codret = _chdir(DirNameStart) ;
1486 #endif
1487   if ( codret != 0 )
1488   {
1489     SALOME::ExceptionStruct es;
1490     es.type = SALOME::BAD_PARAM;
1491     es.text = "The directory of the case for the pursuit does not exist.";
1492     throw SALOME::SALOME_Exception(es);
1493     return 0;
1494   };
1495   // A.2. Reperage des sous-repertoire du repertoire de reprise
1496   bool existe = false ;
1497 #ifndef WIN32
1498   DIR *dp;
1499   struct dirent *dirp;
1500   dp  = opendir(DirNameStart);
1501   while ( (dirp = readdir(dp)) != NULL ) {
1502     std::string DirName_1(dirp->d_name);
1503 #else
1504   HANDLE hFind = INVALID_HANDLE_VALUE;
1505   WIN32_FIND_DATA ffd;
1506   hFind = FindFirstFile(DirNameStart, &ffd);
1507   if (INVALID_HANDLE_VALUE != hFind) {
1508     while (FindNextFile(hFind, &ffd) != 0) {
1509       std::string DirName_1 = "";
1510       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1511         DirName_1 = std::string(ffd.cFileName);
1512       }
1513 #endif
1514     if ( ( DirName_1 != "." ) && ( DirName_1 != ".." ) )
1515     {
1516 #ifndef WIN32
1517       if ( chdir(DirName_1.c_str()) == 0 )
1518       {
1519 //      On cherche le fichier de configuration dans ce sous-repertoire
1520         codret = chdir(DirNameStart);
1521         DIR *dp_1;
1522         struct dirent *dirp_1;
1523         dp_1  = opendir(DirName_1.c_str()) ;
1524         while ( (dirp_1 = readdir(dp_1)) != NULL )
1525         {
1526           std::string file_name_1(dirp_1->d_name);
1527 #else
1528      if ( _chdir(DirName_1.c_str()) == 0 )
1529      {
1530         codret = _chdir(DirNameStart);
1531         HANDLE hFind1 = INVALID_HANDLE_VALUE;
1532         WIN32_FIND_DATA ffd1;
1533         hFind1 = FindFirstFile(DirName_1.c_str(), &ffd1);
1534         while (FindNextFile(hFind1, &ffd1) != 0) 
1535         {
1536           if (ffd1.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories          
1537           std::string file_name_1(ffd1.cFileName);
1538 #endif          
1539           int bilan = file_name_1.find("HOMARD.Configuration.") ;
1540           if ( bilan != string::npos )
1541           {
1542   // Decodage du fichier pour trouver le numero d'iteration
1543 #ifndef WIN32
1544             chdir(DirName_1.c_str()) ;
1545 #else
1546             _chdir(DirName_1.c_str()) ;
1547 #endif
1548
1549             std::ifstream fichier( file_name_1.c_str() );
1550             if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
1551             {
1552               int NumeIter ;
1553               std::string ligne; // variable contenant chaque ligne lue
1554               std::string mot_cle;
1555               // cette boucle sur les lignes s'arrête dès qu'une erreur de lecture survient
1556               while ( std::getline( fichier, ligne ) )
1557               {
1558                 // B.1. Pour la ligne courante, on identifie le premier mot : le mot-cle
1559                 std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
1560                 ligne_bis >> mot_cle ;
1561                 if ( mot_cle == "NumeIter" )
1562                 {
1563                   ligne_bis >> NumeIter ;
1564                   NumeIter += 1 ;
1565 //                   MESSAGE ( "==> NumeIter   : " << NumeIter ) ;
1566                   if ( Number == - 1 )
1567                   {
1568                     if ( NumeIter >= NumeIterMax )
1569                     {
1570                       NumeIterMax = NumeIter ;
1571                       DirNameStartIter = DirName_1 ;
1572                     }
1573                   }
1574                   else
1575                   {
1576                     if ( NumeIter == Number )
1577                     {
1578                       DirNameStartIter = DirName_1 ;
1579                       existe = true ;
1580                       break ;
1581                     }
1582                   }
1583                 }
1584               }
1585             }
1586             else
1587             {
1588               SALOME::ExceptionStruct es;
1589               es.type = SALOME::BAD_PARAM;
1590               std::string text = "The configuration file cannot be read." ;
1591               es.text = CORBA::string_dup(text.c_str());
1592               throw SALOME::SALOME_Exception(es);
1593             }
1594 #ifndef WIN32
1595             chdir(DirNameStart) ;
1596 #else
1597             _chdir(DirNameStart) ;
1598 #endif
1599           }
1600           if ( existe ) { break ; }
1601         }
1602 #ifndef WIN32
1603         closedir(dp_1);
1604 #else
1605         FindClose(hFind1);
1606 #endif
1607         if ( existe ) { break ; }
1608      }
1609     }
1610   }
1611 #ifndef WIN32
1612   closedir(dp);
1613   chdir(nomDirWork.c_str());  
1614 #else
1615     FindClose(hFind);
1616   }
1617   _chdir(nomDirWork.c_str());
1618 #endif
1619
1620   if ( ( Number >= 0 && ( !existe ) ) || ( Number < 0 && ( NumeIterMax == -1 ) ) )
1621   {
1622     SALOME::ExceptionStruct es;
1623     es.type = SALOME::BAD_PARAM;
1624     es.text = "The directory of the iteration does not exist.";
1625     throw SALOME::SALOME_Exception(es);
1626     return 0;
1627   };
1628
1629   return DirNameStartIter ;
1630 }
1631 //=============================================================================
1632 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)
1633 //
1634 // nomCas : nom du cas a creer
1635 // MeshName, MeshFile : nom et fichier du maillage correspondant
1636 // MeshOption : 0 : le maillage fourni est obligatoirement present ==> erreur si absent
1637 //              1 : le maillage fourni peut ne pas exister ==> on continue si absent
1638 //             -1 : le maillage n'est pas fourni
1639 // NumeIter : numero de l'iteration correspondante : 0, pour un depart, n>0 pour une poursuite
1640 // Option : multiple de nombres premiers
1641 //         1 : aucune option
1642 //        x2 : publication du maillage dans SMESH
1643 {
1644   MESSAGE ( "CreateCase0 : nomCas = " << nomCas );
1645   MESSAGE ( "CreateCase0 : MeshName = " << MeshName << ", MeshFile = " << MeshFile << ", MeshOption = " << MeshOption );
1646   MESSAGE ( "CreateCase0 : NumeIter = " << NumeIter << ", Option = " << Option );
1647 //
1648   // A. Controles
1649   // A.1. L'etude
1650   IsValidStudy () ;
1651
1652   // A.2. Controle du nom :
1653   if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
1654   {
1655     SALOME::ExceptionStruct es;
1656     es.type = SALOME::BAD_PARAM;
1657     es.text = "This case has already been defined.";
1658     throw SALOME::SALOME_Exception(es);
1659     return 0;
1660   };
1661
1662   // A.3. Controle du fichier du maillage
1663   int existeMeshFile ;
1664   if ( MeshOption >= 0 )
1665   {
1666     existeMeshFile = MEDFileExist ( MeshFile ) ;
1667     MESSAGE ( "CreateCase0 : existeMeshFile = " << existeMeshFile );
1668     if ( ( existeMeshFile == 0 ) && ( MeshOption == 0 ) )
1669     {
1670       SALOME::ExceptionStruct es;
1671       es.type = SALOME::BAD_PARAM;
1672       es.text = "The mesh file does not exist.";
1673       throw SALOME::SALOME_Exception(es);
1674       return 0;
1675     }
1676   }
1677   else { existeMeshFile = 0 ; }
1678
1679   // B. Creation de l'objet cas et publication
1680 //   MESSAGE ( "CreateCase0 : Creation de l'objet" );
1681   HOMARD::HOMARD_Cas_var myCase = newCase();
1682   myCase->SetName(nomCas);
1683   SALOMEDS::SObject_var aSO;
1684   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
1685   myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
1686
1687   // C. Caracteristiques du maillage
1688   if ( existeMeshFile != 0 )
1689   {
1690   // Les valeurs extremes des coordonnees
1691 //     MESSAGE ( "CreateCase0 : Les valeurs extremes des coordonnees" );
1692     std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile) ;
1693     HOMARD::extrema_var aSeq = new HOMARD::extrema() ;
1694     if (LesExtremes.size()!=10) { return false; }
1695     aSeq->length(10) ;
1696     for (int i =0 ; i< LesExtremes.size() ; i++)
1697         aSeq[i]=LesExtremes[i] ;
1698     myCase->SetBoundingBox(aSeq) ;
1699   // Les groupes
1700 //     MESSAGE ( "CreateCase0 : Les groupes" );
1701     std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile) ;
1702     HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType ;
1703     aSeqGroupe->length(LesGroupes.size());
1704     std::set<std::string>::const_iterator it ;
1705     int i = 0 ;
1706     for (it=LesGroupes.begin() ; it != LesGroupes.end() ; it++)
1707       aSeqGroupe[i++]=(*it).c_str() ;
1708     myCase->SetGroups(aSeqGroupe) ;
1709   }
1710
1711   // D. L'iteration initiale du cas
1712   MESSAGE ( "CreateCase0 : iteration initiale du cas" );
1713   // D.1. Recherche d'un nom : par defaut, on prend le nom du maillage correspondant.
1714   // Si ce nom d'iteration existe deja, on incremente avec 0, 1, 2, etc.
1715   int monNum = 0;
1716   std::string NomIteration = std::string(MeshName) ;
1717   while ( (myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()) )
1718   {
1719     std::ostringstream nom;
1720     nom << MeshName << monNum;
1721     NomIteration = nom.str();
1722     monNum += 1;
1723   }
1724   MESSAGE ( "CreateCas0 : ==> NomIteration = " << NomIteration );
1725
1726   // D.2. Creation de l'iteration
1727   HOMARD::HOMARD_Iteration_var anIter = newIteration();
1728   myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration] = anIter;
1729   anIter->SetName(NomIteration.c_str());
1730   AssociateCaseIter (nomCas, NomIteration.c_str(), "IterationHomard");
1731
1732   // D.4. Maillage correspondant
1733   if ( existeMeshFile != 0 )
1734   {
1735     anIter->SetMeshFile(MeshFile);
1736     if ( Option % 2 == 0 ) { PublishResultInSmesh(MeshFile, 0); }
1737   }
1738   anIter->SetMeshName(MeshName);
1739
1740   // D.5. Numero d'iteration
1741   anIter->SetNumber(NumeIter);
1742
1743   // D.6. Etat
1744   SetEtatIter(NomIteration.c_str(), -NumeIter);
1745 //
1746
1747   return HOMARD::HOMARD_Cas::_duplicate(myCase);
1748 }
1749 //=============================================================================
1750 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
1751 {
1752   INFOS ( "CreateHypothesis : nomHypothesis = " << nomHypothesis );
1753   IsValidStudy () ;
1754
1755   // A. Controle du nom :
1756   if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
1757   {
1758     SALOME::ExceptionStruct es;
1759     es.type = SALOME::BAD_PARAM;
1760     es.text = "This hypothesis has already been defined.";
1761     throw SALOME::SALOME_Exception(es);
1762     return 0;
1763   }
1764
1765   // B. Creation de l'objet
1766   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
1767   if (CORBA::is_nil(myHypothesis))
1768   {
1769     SALOME::ExceptionStruct es;
1770     es.type = SALOME::BAD_PARAM;
1771     es.text = "Unable to create the hypothesis";
1772     throw SALOME::SALOME_Exception(es);
1773     return 0;
1774   };
1775   myHypothesis->SetName(nomHypothesis);
1776
1777   // C. Enregistrement
1778   myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
1779
1780   SALOMEDS::SObject_var aSO;
1781   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
1782
1783   // D. Valeurs par defaut des options avancees
1784   myHypothesis->SetNivMax(-1);
1785   myHypothesis->SetDiamMin(-1.0);
1786   myHypothesis->SetAdapInit(0);
1787   myHypothesis->SetLevelOutput(0);
1788
1789   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
1790 }
1791
1792 //=============================================================================
1793 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* NomIteration, const char* nomIterParent)
1794 //=============================================================================
1795 {
1796   INFOS ("CreateIteration : NomIteration  = " << NomIteration << ", nomIterParent = " << nomIterParent);
1797   IsValidStudy () ;
1798
1799   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
1800   if (CORBA::is_nil(myIterationParent))
1801   {
1802     SALOME::ExceptionStruct es;
1803     es.type = SALOME::BAD_PARAM;
1804     es.text = "The parent iteration is not defined.";
1805     throw SALOME::SALOME_Exception(es);
1806     return 0;
1807   };
1808
1809   const char* nomCas = myIterationParent->GetCaseName();
1810   MESSAGE ("CreateIteration : nomCas = " << nomCas);
1811   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1812   if (CORBA::is_nil(myCase))
1813   {
1814     SALOME::ExceptionStruct es;
1815     es.type = SALOME::BAD_PARAM;
1816     es.text = "Invalid case context";
1817     throw SALOME::SALOME_Exception(es);
1818     return 0;
1819   };
1820   const char* nomDirCase = myCase->GetDirName();
1821
1822   // Controle du nom :
1823   if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(NomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
1824   {
1825     SALOME::ExceptionStruct es;
1826     es.type = SALOME::BAD_PARAM;
1827     es.text = "This iteration has already been defined.";
1828     throw SALOME::SALOME_Exception(es);
1829     return 0;
1830   };
1831
1832    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
1833    if (CORBA::is_nil(myIteration))
1834   {
1835     SALOME::ExceptionStruct es;
1836     es.type = SALOME::BAD_PARAM;
1837     es.text = "Unable to create the iteration";
1838     throw SALOME::SALOME_Exception(es);
1839     return 0;
1840   };
1841   myContextMap[GetCurrentStudyID()]._mesIterations[std::string(NomIteration)] = myIteration;
1842 // Nom de l'iteration et du maillage
1843   myIteration->SetName(NomIteration);
1844   myIteration->SetMeshName(NomIteration);
1845   myIteration->SetState(1);
1846
1847   int numero = myIterationParent->GetNumber() + 1;
1848   myIteration->SetNumber(numero);
1849
1850 // Nombre d'iterations deja connues pour le cas, permettant
1851 // la creation d'un sous-repertoire unique
1852   int nbitercase = myCase->GetNumberofIter();
1853   char* nomDirIter = CreateDirNameIter(nomDirCase, nbitercase );
1854   myIteration->SetDirNameLoc(nomDirIter);
1855
1856 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
1857 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
1858 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est la
1859 // situation la plus frequente.
1860 // Si on a plusieurs branches, donc des iterations du meme niveau d'adaptation, utiliser
1861 // le nombre d'iterations du cas permet d'eviter les collisions.
1862   int jaux ;
1863   if      ( nbitercase <    100 ) { jaux = 2 ; }
1864   else if ( nbitercase <   1000 ) { jaux = 3 ; }
1865   else if ( nbitercase <  10000 ) { jaux = 4 ; }
1866   else if ( nbitercase < 100000 ) { jaux = 5 ; }
1867   else                            { jaux = 9 ; }
1868   std::ostringstream iaux ;
1869   iaux << std::setw(jaux) << std::setfill('0') << nbitercase ;
1870   std::stringstream MeshFile;
1871   MeshFile << nomDirCase << "/maill." << iaux.str() << ".med";
1872   myIteration->SetMeshFile(MeshFile.str().c_str());
1873
1874 // Association avec le cas
1875   std::string label = "IterationHomard_" + std::string(nomIterParent);
1876   AssociateCaseIter(nomCas, NomIteration, label.c_str());
1877 // Lien avec l'iteration precedente
1878   myIterationParent->LinkNextIteration(NomIteration);
1879   myIteration->SetIterParentName(nomIterParent);
1880
1881   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
1882 }
1883 //=============================================================================
1884 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
1885 {
1886   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
1887   IsValidStudy () ;
1888
1889   // Controle du nom :
1890   if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
1891   {
1892     MESSAGE ("CreateBoundary : la frontiere " << BoundaryName << " existe deja");
1893     SALOME::ExceptionStruct es;
1894     es.type = SALOME::BAD_PARAM;
1895     es.text = "This boundary has already been defined";
1896     throw SALOME::SALOME_Exception(es);
1897     return 0;
1898   };
1899
1900   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
1901   myBoundary->SetName(BoundaryName);
1902   myBoundary->SetType(BoundaryType);
1903
1904   myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
1905
1906   SALOMEDS::SObject_var aSO;
1907   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
1908
1909   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1910 }
1911 //=============================================================================
1912 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
1913 {
1914   INFOS ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << "MeshName = " << MeshName );
1915   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
1916   myBoundary->SetMeshFile( MeshFile ) ;
1917   myBoundary->SetMeshName( MeshName ) ;
1918
1919   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
1920 }
1921 //=============================================================================
1922 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
1923                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1924                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
1925                                       CORBA::Double Rayon)
1926 {
1927   INFOS ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
1928 //
1929   SALOME::ExceptionStruct es;
1930   int error = 0 ;
1931   if ( Rayon <= 0.0 )
1932   { es.text = "The radius must be positive." ;
1933     error = 1 ; }
1934   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1935   if ( daux < 0.0000001 )
1936   { es.text = "The axis must be a non 0 vector." ;
1937     error = 2 ; }
1938   if ( error != 0 )
1939   {
1940     es.type = SALOME::BAD_PARAM;
1941     throw SALOME::SALOME_Exception(es);
1942     return 0;
1943   };
1944 //
1945   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
1946   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon ) ;
1947
1948   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1949 }
1950 //=============================================================================
1951 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
1952                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
1953                                       CORBA::Double Rayon)
1954 {
1955   INFOS ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
1956 //
1957   SALOME::ExceptionStruct es;
1958   int error = 0 ;
1959   if ( Rayon <= 0.0 )
1960   { es.text = "The radius must be positive." ;
1961     error = 1 ; }
1962   if ( error != 0 )
1963   {
1964     es.type = SALOME::BAD_PARAM;
1965     throw SALOME::SALOME_Exception(es);
1966     return 0;
1967   };
1968 //
1969   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
1970   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
1971
1972   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
1973 }
1974 //=============================================================================
1975 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeA(const char* BoundaryName,
1976                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe, CORBA::Double Angle,
1977                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre)
1978 {
1979   INFOS ("CreateBoundaryConeA : BoundaryName  = " << BoundaryName ) ;
1980 //
1981   SALOME::ExceptionStruct es;
1982   int error = 0 ;
1983   if ( Angle <= 0.0 || Angle >= 90.0 )
1984   { es.text = "The angle must be included higher than 0 degree and lower than 90 degrees." ;
1985     error = 1 ; }
1986   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
1987   if ( daux < 0.0000001 )
1988   { es.text = "The axis must be a non 0 vector." ;
1989     error = 2 ; }
1990   if ( error != 0 )
1991   {
1992     es.type = SALOME::BAD_PARAM;
1993     throw SALOME::SALOME_Exception(es);
1994     return 0;
1995   };
1996 //
1997   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 3) ;
1998   myBoundary->SetConeA( Xaxe, Yaxe, Zaxe, Angle, Xcentre, Ycentre, Zcentre ) ;
1999
2000   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2001 }
2002 //=============================================================================
2003 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryConeR(const char* BoundaryName,
2004                                       CORBA::Double Xcentre1, CORBA::Double Ycentre1, CORBA::Double Zcentre1, CORBA::Double Rayon1,
2005                                       CORBA::Double Xcentre2, CORBA::Double Ycentre2, CORBA::Double Zcentre2, CORBA::Double Rayon2)
2006 {
2007   INFOS ("CreateBoundaryConeR : BoundaryName  = " << BoundaryName ) ;
2008 //
2009   SALOME::ExceptionStruct es;
2010   int error = 0 ;
2011   if ( Rayon1 < 0.0 || Rayon2 < 0.0 )
2012   { es.text = "The radius must be positive." ;
2013     error = 1 ; }
2014   double daux = fabs(Rayon2-Rayon1) ;
2015   if ( daux < 0.0000001 )
2016   { es.text = "The radius must be different." ;
2017     error = 2 ; }
2018   daux = fabs(Xcentre2-Xcentre1) + fabs(Ycentre2-Ycentre1) + fabs(Zcentre2-Zcentre1) ;
2019   if ( daux < 0.0000001 )
2020   { es.text = "The centers must be different." ;
2021     error = 3 ; }
2022   if ( error != 0 )
2023   {
2024     es.type = SALOME::BAD_PARAM;
2025     throw SALOME::SALOME_Exception(es);
2026     return 0;
2027   };
2028 //
2029   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 4) ;
2030   myBoundary->SetConeR( Xcentre1, Ycentre1, Zcentre1, Rayon1, Xcentre2, Ycentre2, Zcentre2, Rayon2 ) ;
2031
2032   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
2033 }
2034 //=============================================================================
2035 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
2036 {
2037   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
2038   IsValidStudy () ;
2039
2040   // Controle du nom :
2041   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
2042   {
2043     SALOME::ExceptionStruct es;
2044     es.type = SALOME::BAD_PARAM;
2045     es.text = "This zone has already been defined";
2046     throw SALOME::SALOME_Exception(es);
2047     return 0;
2048   };
2049
2050   HOMARD::HOMARD_Zone_var myZone = newZone();
2051   myZone->SetName(ZoneName);
2052   myZone->SetType(ZoneType);
2053
2054   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
2055
2056   SALOMEDS::SObject_var aSO;
2057   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
2058
2059   return HOMARD::HOMARD_Zone::_duplicate(myZone);
2060 }
2061 //=============================================================================
2062 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
2063                                       CORBA::Double Xmini, CORBA::Double Xmaxi,
2064                                       CORBA::Double Ymini, CORBA::Double Ymaxi,
2065                                       CORBA::Double Zmini, CORBA::Double Zmaxi)
2066 {
2067   INFOS ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
2068 //
2069   SALOME::ExceptionStruct es;
2070   int error = 0 ;
2071   if ( Xmini > Xmaxi )
2072   { es.text = "The X coordinates are not coherent." ;
2073     error = 1 ; }
2074   if ( Ymini > Ymaxi )
2075   { es.text = "The Y coordinates are not coherent." ;
2076     error = 2 ; }
2077   if ( Zmini > Zmaxi )
2078   { es.text = "The Z coordinates are not coherent." ;
2079     error = 3 ; }
2080   if ( error != 0 )
2081   {
2082     es.type = SALOME::BAD_PARAM;
2083     throw SALOME::SALOME_Exception(es);
2084     return 0;
2085   };
2086 //
2087   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
2088   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2089
2090   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2091 }
2092 //=============================================================================
2093 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
2094                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre, CORBA::Double Rayon)
2095 {
2096   INFOS ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
2097 //
2098   SALOME::ExceptionStruct es;
2099   int error = 0 ;
2100   if ( Rayon <= 0.0 )
2101   { es.text = "The radius must be positive." ;
2102     error = 1 ; }
2103   if ( error != 0 )
2104   {
2105     es.type = SALOME::BAD_PARAM;
2106     throw SALOME::SALOME_Exception(es);
2107     return 0;
2108   };
2109 //
2110   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
2111   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
2112
2113   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2114 }
2115 //=============================================================================
2116 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
2117                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2118                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2119                                       CORBA::Double Rayon, CORBA::Double Haut)
2120 {
2121   INFOS ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
2122 //
2123   SALOME::ExceptionStruct es;
2124   int error = 0 ;
2125   if ( Rayon <= 0.0 )
2126   { es.text = "The radius must be positive." ;
2127     error = 1 ; }
2128   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2129   if ( daux < 0.0000001 )
2130   { es.text = "The axis must be a non 0 vector." ;
2131     error = 2 ; }
2132   if ( Haut <= 0.0 )
2133   { es.text = "The height must be positive." ;
2134     error = 3 ; }
2135   if ( error != 0 )
2136   {
2137     es.type = SALOME::BAD_PARAM;
2138     throw SALOME::SALOME_Exception(es);
2139     return 0;
2140   };
2141 //
2142   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
2143   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
2144
2145   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2146 }
2147 //=============================================================================
2148 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
2149                                       CORBA::Double Xcentre, CORBA::Double Ycentre, CORBA::Double Zcentre,
2150                                       CORBA::Double Xaxe, CORBA::Double Yaxe, CORBA::Double Zaxe,
2151                                       CORBA::Double Rayon, CORBA::Double Haut, CORBA::Double Rayonint)
2152 {
2153   INFOS ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
2154 //
2155   SALOME::ExceptionStruct es;
2156   int error = 0 ;
2157   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2158   { es.text = "The radius must be positive." ;
2159     error = 1 ; }
2160   double daux = fabs(Xaxe) + fabs(Yaxe) + fabs(Zaxe) ;
2161   if ( daux < 0.0000001 )
2162   { es.text = "The axis must be a non 0 vector." ;
2163     error = 2 ; }
2164   if ( Haut <= 0.0 )
2165   { es.text = "The height must be positive." ;
2166     error = 3 ; }
2167   if ( Rayon <= Rayonint )
2168   { es.text = "The external radius must be higher than the internal radius." ;
2169     error = 4 ; }
2170   if ( error != 0 )
2171   {
2172     es.type = SALOME::BAD_PARAM;
2173     throw SALOME::SALOME_Exception(es);
2174     return 0;
2175   };
2176 //
2177   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
2178   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
2179
2180   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2181 }
2182 //=============================================================================
2183 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
2184                                       CORBA::Double Umini, CORBA::Double Umaxi,
2185                                       CORBA::Double Vmini, CORBA::Double Vmaxi,
2186                                       CORBA::Long Orient)
2187 {
2188   INFOS ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
2189 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
2190 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
2191 //   MESSAGE ("Orient = " << Orient ) ;
2192 //
2193   SALOME::ExceptionStruct es;
2194   int error = 0 ;
2195   if ( Umini > Umaxi )
2196   { es.text = "The first coordinates are not coherent." ;
2197     error = 1 ; }
2198   if ( Vmini > Vmaxi )
2199   { es.text = "The second coordinates are not coherent." ;
2200     error = 2 ; }
2201   if ( Orient < 1 || Orient > 3 )
2202   { es.text = "The orientation must be 1, 2 or 3." ;
2203     error = 3 ; }
2204   if ( error != 0 )
2205   {
2206     es.type = SALOME::BAD_PARAM;
2207     throw SALOME::SALOME_Exception(es);
2208     return 0;
2209   };
2210 //
2211   double Xmini, Xmaxi ;
2212   double Ymini, Ymaxi ;
2213   double Zmini, Zmaxi ;
2214   if ( Orient == 1 )
2215   { Xmini = Umini ;
2216     Xmaxi = Umaxi ;
2217     Ymini = Vmini ;
2218     Ymaxi = Vmaxi ;
2219     Zmini = 0. ;
2220     Zmaxi = 0. ; }
2221   else if ( Orient == 2 )
2222   { Xmini = 0. ;
2223     Xmaxi = 0. ;
2224     Ymini = Umini ;
2225     Ymaxi = Umaxi ;
2226     Zmini = Vmini ;
2227     Zmaxi = Vmaxi ; }
2228   else if ( Orient == 3 )
2229   { Xmini = Vmini ;
2230     Xmaxi = Vmaxi ;
2231     Ymini = 0. ;
2232     Ymaxi = 0. ;
2233     Zmini = Umini ;
2234     Zmaxi = Umaxi ; }
2235   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2236
2237   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
2238   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
2239
2240   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2241 }
2242 //=============================================================================
2243 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
2244                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2245                                       CORBA::Double Rayon,
2246                                       CORBA::Long Orient)
2247 {
2248   INFOS ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
2249 //
2250   SALOME::ExceptionStruct es;
2251   int error = 0 ;
2252   if ( Rayon <= 0.0 )
2253   { es.text = "The radius must be positive." ;
2254     error = 1 ; }
2255   if ( Orient < 1 || Orient > 3 )
2256   { es.text = "The orientation must be 1, 2 or 3." ;
2257     error = 3 ; }
2258   if ( error != 0 )
2259   {
2260     es.type = SALOME::BAD_PARAM;
2261     throw SALOME::SALOME_Exception(es);
2262     return 0;
2263   };
2264 //
2265   double Xcentre ;
2266   double Ycentre ;
2267   double Zcentre ;
2268   if ( Orient == 1 )
2269   { Xcentre = Ucentre ;
2270     Ycentre = Vcentre ;
2271     Zcentre = 0. ; }
2272   else if ( Orient == 2 )
2273   { Xcentre = 0. ;
2274     Ycentre = Ucentre ;
2275     Zcentre = Vcentre ; }
2276   else if ( Orient == 3 )
2277   { Xcentre = Vcentre ;
2278     Ycentre = 0. ;
2279     Zcentre = Ucentre ; }
2280   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2281
2282   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
2283   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
2284
2285   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2286 }
2287 //=============================================================================
2288 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
2289                                       CORBA::Double Ucentre, CORBA::Double Vcentre,
2290                                       CORBA::Double Rayon, CORBA::Double Rayonint,
2291                                       CORBA::Long Orient)
2292 {
2293   INFOS ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
2294 //
2295   SALOME::ExceptionStruct es;
2296   int error = 0 ;
2297   if ( Rayon <= 0.0 || Rayonint <= 0.0 )
2298   { es.text = "The radius must be positive." ;
2299     error = 1 ; }
2300   if ( Orient < 1 || Orient > 3 )
2301   { es.text = "The orientation must be 1, 2 or 3." ;
2302     error = 3 ; }
2303   if ( Rayon <= Rayonint )
2304   { es.text = "The external radius must be higher than the internal radius." ;
2305     error = 4 ; }
2306   if ( error != 0 )
2307   {
2308     es.type = SALOME::BAD_PARAM;
2309     throw SALOME::SALOME_Exception(es);
2310     return 0;
2311   };
2312 //
2313   double Xcentre ;
2314   double Ycentre ;
2315   double Zcentre ;
2316   if ( Orient == 1 )
2317   { Xcentre = Ucentre ;
2318     Ycentre = Vcentre ;
2319     Zcentre = 0. ; }
2320   else if ( Orient == 2 )
2321   { Xcentre = 0. ;
2322     Ycentre = Ucentre ;
2323     Zcentre = Vcentre ; }
2324   else if ( Orient == 3 )
2325   { Xcentre = Vcentre ;
2326     Ycentre = 0. ;
2327     Zcentre = Ucentre ; }
2328   else { VERIFICATION( (Orient>=1) && (Orient<=3) ) ; }
2329
2330   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
2331   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
2332
2333   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
2334 }
2335 //=============================================================================
2336 //=============================================================================
2337
2338
2339
2340
2341 //=============================================================================
2342 //=============================================================================
2343 // Traitement d'une iteration
2344 // etatMenage = 1 : destruction du repertoire d'execution
2345 // modeHOMARD  = 1 : adaptation
2346 //            != 1 : information avec les options modeHOMARD
2347 // Option1 >0 : appel depuis python
2348 //         <0 : appel depuis GUI
2349 // Option2 : multiple de nombres premiers
2350 //         1 : aucune option
2351 //        x2 : publication du maillage dans SMESH
2352 //=============================================================================
2353 CORBA::Long HOMARD_Gen_i::Compute(const char* NomIteration, CORBA::Long etatMenage, CORBA::Long modeHOMARD, CORBA::Long Option1, CORBA::Long Option2)
2354 {
2355   INFOS ( "Compute : traitement de " << NomIteration << ", avec modeHOMARD = " << modeHOMARD << ", Option1 = " << Option1 << ", Option2 = " << Option2 );
2356
2357   // A. Prealable
2358   int codret = 0;
2359
2360   // A.1. L'objet iteration
2361   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIteration];
2362   ASSERT(!CORBA::is_nil(myIteration));
2363
2364   // A.2. Numero de l'iteration
2365   //     siterp1 : numero de l'iteration a traiter
2366   //     Si adaptation :
2367   //        siter   : numero de l'iteration parent, ou 0 si deja au debut mais cela ne servira pas !
2368   //     Ou si information :
2369   //        siter = siterp1
2370   int NumeIter = myIteration->GetNumber();
2371   std::string siterp1 ;
2372   std::stringstream saux1 ;
2373   saux1 << NumeIter ;
2374   siterp1 = saux1.str() ;
2375   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
2376
2377   std::string siter ;
2378   if ( modeHOMARD==1 )
2379   {
2380     std::stringstream saux0 ;
2381     int iaux = max(0, NumeIter-1) ;
2382     saux0 << iaux ;
2383     siter = saux0.str() ;
2384     if (NumeIter < 11) { siter = "0" + siter ; }
2385   }
2386   else
2387   { siter = siterp1 ; }
2388
2389   // A.3. Le cas
2390   const char* nomCas = myIteration->GetCaseName();
2391   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
2392   ASSERT(!CORBA::is_nil(myCase));
2393
2394   // B. Les repertoires
2395   // B.1. Le repertoire courant
2396   std::string nomDirWork = getenv("PWD") ;
2397   // B.2. Le sous-repertoire de l'iteration a traiter
2398   char* DirCompute = ComputeDirManagement(myCase, myIteration, etatMenage);
2399   MESSAGE( ". DirCompute = " << DirCompute );
2400
2401   // C. Le fichier des messages
2402   // C.1. Le deroulement de l'execution de HOMARD
2403   std::string LogFile = DirCompute ;
2404   LogFile += "/Liste" ;
2405   if ( modeHOMARD == 1 ) { LogFile += "." + siter + ".vers." + siterp1 ; }
2406   LogFile += ".log" ;
2407   MESSAGE (". LogFile = " << LogFile);
2408   if ( modeHOMARD == 1 ) { myIteration->SetLogFile(LogFile.c_str()); }
2409   // C.2. Le bilan de l'analyse du maillage
2410   std::string FileInfo = DirCompute ;
2411   FileInfo += "/" ;
2412   if ( modeHOMARD == 1 ) { FileInfo += "apad" ; }
2413   else
2414   { if ( NumeIter == 0 ) { FileInfo += "info_av" ; }
2415     else                 { FileInfo += "info_ap" ; }
2416   }
2417   FileInfo += "." + siterp1 + ".bilan" ;
2418   myIteration->SetFileInfo(FileInfo.c_str());
2419
2420    // D. On passe dans le repertoire de l'iteration a calculer
2421   MESSAGE ( ". On passe dans DirCompute = " << DirCompute );
2422 #ifndef WIN32
2423   chdir(DirCompute);
2424 #else
2425   _chdir(DirCompute);
2426 #endif
2427
2428   // E. Les donnees de l'execution HOMARD
2429   // E.1. L'objet du texte du fichier de configuration
2430   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
2431   myDriver->TexteInit(DirCompute, LogFile, _Langue);
2432
2433   // E.2. Le maillage associe a l'iteration
2434   const char* NomMesh = myIteration->GetMeshName();
2435   MESSAGE ( ". NomMesh = " << NomMesh );
2436   const char* MeshFile = myIteration->GetMeshFile();
2437   MESSAGE ( ". MeshFile = " << MeshFile );
2438
2439   // E.3. Les donnees du traitement HOMARD
2440   int iaux ;
2441   if ( modeHOMARD == 1 )
2442   {
2443     iaux = 1 ;
2444     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2445     myDriver->TexteMaillage(NomMesh, MeshFile, 1);
2446     codret = ComputeAdap(myCase, myIteration, etatMenage, myDriver, Option1, Option2) ;
2447   }
2448   else
2449   {
2450     InvalideIterInfo(NomIteration);
2451     myDriver->TexteInfo( modeHOMARD, NumeIter ) ;
2452     iaux = 0 ;
2453     myDriver->TexteMaillageHOMARD( DirCompute, siterp1, iaux ) ;
2454     myDriver->TexteMaillage(NomMesh, MeshFile, 0);
2455     myDriver->CreeFichierDonn();
2456   }
2457
2458   // E.4. Ajout des informations liees a l'eventuel suivi de frontiere
2459   DriverTexteBoundary(myCase, myDriver) ;
2460
2461   // E.5. Ecriture du texte dans le fichier
2462   MESSAGE ( ". Ecriture du texte dans le fichier de configuration ; codret = "<<codret );
2463   if (codret == 0)
2464   { myDriver->CreeFichier(); }
2465
2466 // G. Execution
2467 //
2468   int codretexec = 12 ;
2469   if (codret == 0)
2470   {
2471     codretexec = myDriver->ExecuteHomard(Option1);
2472 //
2473     MESSAGE ( "Erreur en executant HOMARD : " << codretexec );
2474     // En mode adaptation, on ajuste l'etat de l'iteration
2475     if ( modeHOMARD == 1 )
2476     {
2477       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2478       else                 { SetEtatIter(NomIteration,1); }
2479       // GERALD -- QMESSAGE BOX
2480     }
2481   }
2482
2483   // H. Gestion des resultats
2484   if (codret == 0)
2485   {
2486     std::string Commentaire ;
2487     // H.1. Le fichier des messages, dans tous les cas
2488     Commentaire = "log" ;
2489     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2490     else                   { Commentaire += "Info" ; }
2491     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2492
2493     // H.2. Si tout s'est bien passe :
2494     if (codretexec == 0)
2495     {
2496     // H.2.1. Le fichier de bilan
2497       Commentaire = "Summary" ;
2498       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2499       else                   { Commentaire += "Info" ; }
2500       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2501     // H.2.2. Le fichier de  maillage obtenu
2502       if ( modeHOMARD == 1 )
2503       {
2504         std::stringstream saux0 ;
2505         Commentaire = "Mesh" ;
2506         Commentaire += " " + siterp1 ;
2507         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2508         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2509       }
2510     }
2511   // H.3 Message d'erreur
2512     if (codretexec != 0)
2513     {
2514       std::string text ;
2515       // Message d'erreur en cas de probleme en adaptation
2516       if ( modeHOMARD == 1 )
2517       {
2518         text = "Error during the adaptation.\n" ;
2519         bool stopvu = false ;
2520         std::ifstream fichier( LogFile.c_str() );
2521         if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2522         {
2523           std::string ligne; // variable contenant chaque ligne lue
2524           while ( std::getline( fichier, ligne ) )
2525           {
2526 //             INFOS(ligne);
2527             if ( stopvu )
2528             { text += ligne+ "\n"; }
2529             else
2530             {
2531               int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2532               if ( position > 0 ) { stopvu = true ; }
2533             }
2534           }
2535         }
2536       }
2537       else
2538       {
2539         text = "Voir le fichier Liste.log.\n" ;
2540       }
2541       INFOS ( text ) ;
2542       SALOME::ExceptionStruct es;
2543       es.type = SALOME::BAD_PARAM;
2544       es.text = CORBA::string_dup(text.c_str());
2545       throw SALOME::SALOME_Exception(es);
2546 //
2547       // En mode information, on force le succes pour pouvoir consulter le fichier log
2548       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2549     }
2550   }
2551
2552   // I. Menage et retour dans le repertoire du cas
2553   if (codret == 0)
2554   {
2555     delete myDriver;
2556     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2557     
2558 #ifndef WIN32
2559     chdir(nomDirWork.c_str());
2560 #else
2561     _chdir(nomDirWork.c_str());
2562 #endif
2563   }
2564
2565   return codretexec ;
2566 }
2567 //=============================================================================
2568 // Calcul d'une iteration : partie specifique a l'adaptation
2569 //=============================================================================
2570 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)
2571 {
2572   MESSAGE ( "ComputeAdap" );
2573
2574   // A. Prealable
2575   // A.1. Bases
2576   int codret = 0;
2577   // Etat de l'iteration
2578   int etat = myIteration->GetState();
2579   // Numero de l'iteration
2580   int NumeIter = myIteration->GetNumber();
2581   std::stringstream saux0 ;
2582   saux0 << NumeIter-1 ;
2583   std::string siter = saux0.str() ;
2584   if (NumeIter < 11) { siter = "0" + siter ; }
2585
2586   // A.2. On ne calcule pas l iteration initiale
2587   if ( etat <= 0 )
2588   {
2589     MESSAGE ( "etat = "<<etat );
2590     SALOME::ExceptionStruct es;
2591     es.type = SALOME::BAD_PARAM;
2592     es.text = "This iteration is the first of the case and cannot be computed.";
2593     throw SALOME::SALOME_Exception(es);
2594     return 1;
2595   };
2596
2597   // A.3. On verifie qu il y a une hypothese (erreur improbable);
2598   const char* nomHypo = myIteration->GetHypoName();
2599   if (std::string(nomHypo) == std::string(""))
2600   {
2601       SALOME::ExceptionStruct es;
2602       es.type = SALOME::BAD_PARAM;
2603       es.text = "This iteration does not have any associated hypothesis.";
2604       throw SALOME::SALOME_Exception(es);
2605       return 2;
2606   };
2607   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2608   ASSERT(!CORBA::is_nil(myHypo));
2609
2610   // B. L'iteration parent
2611   const char* nomIterationParent = myIteration->GetIterParentName();
2612   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2613   ASSERT(!CORBA::is_nil(myIterationParent));
2614   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2615   if ( myIterationParent->GetState() == 1 )
2616   {
2617     int iaux = 1 ;
2618     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2619     if (codret != 0)
2620     {
2621       // GERALD -- QMESSAGE BOX
2622       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2623     }
2624   };
2625
2626   // C. Le sous-repertoire de l'iteration precedente
2627   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2628   MESSAGE( ". DirComputePa = " << DirComputePa );
2629
2630   // D. Les donnees de l'adaptation HOMARD
2631   // D.1. Le type de conformite
2632   int ConfType = myCase->GetConfType();
2633   MESSAGE ( ". ConfType = " << ConfType );
2634
2635   // D.2. Le maillage de depart
2636   const char* NomMeshParent = myIterationParent->GetMeshName();
2637   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2638   const char* MeshFileParent = myIterationParent->GetMeshFile();
2639   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2640
2641   // D.3. Le maillage associe a l'iteration
2642   const char* MeshFile = myIteration->GetMeshFile();
2643   MESSAGE ( ". MeshFile = " << MeshFile );
2644   FILE *file = fopen(MeshFile,"r");
2645   if (file != NULL)
2646   {
2647     fclose(file);
2648     if (etatMenage == 0)
2649     {
2650       SALOME::ExceptionStruct es;
2651       es.type = SALOME::BAD_PARAM;
2652       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2653       es.text = CORBA::string_dup(text.c_str());
2654       throw SALOME::SALOME_Exception(es);
2655       return 4;
2656     }
2657     else
2658     {
2659       std::string commande = "rm -f " + std::string(MeshFile);
2660       codret = system(commande.c_str());
2661       if (codret != 0)
2662       {
2663         SALOME::ExceptionStruct es;
2664         es.type = SALOME::BAD_PARAM;
2665         es.text = "The mesh file cannot be deleted.";
2666         throw SALOME::SALOME_Exception(es);
2667         return 5;
2668       }
2669     }
2670   }
2671
2672   // D.4. Les types de raffinement et de deraffinement
2673   // Les appels corba sont lourds, il vaut mieux les grouper
2674   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2675   ASSERT(ListTypes->length() == 3);
2676   int TypeAdap = (*ListTypes)[0];
2677   int TypeRaff = (*ListTypes)[1];
2678   int TypeDera = (*ListTypes)[2];
2679
2680   // E. Texte du fichier de configuration
2681   // E.1. Incontournables du texte
2682   myDriver->TexteAdap();
2683   int iaux = 0 ;
2684   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2685   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2686   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2687
2688   // E.2. Ajout des informations liees aux zones eventuelles
2689   if ( TypeAdap == 0 )
2690   { DriverTexteZone(myHypo, myDriver) ; }
2691
2692   // E.3. Ajout des informations liees aux champs eventuels
2693   if ( TypeAdap == 1 )
2694   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2695
2696   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2697   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2698   int numberOfGroups = listeGroupes->length();
2699   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2700   if (numberOfGroups > 0)
2701   {
2702     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2703     {
2704       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2705       MESSAGE( "... GroupName = " << GroupName );
2706       myDriver->TexteGroup(GroupName);
2707     }
2708   }
2709
2710   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2711   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2712
2713   // E.6. Ajout des options avancees
2714   int Pyram = myCase->GetPyram();
2715   MESSAGE ( ". Pyram = " << Pyram );
2716   int NivMax = myHypo->GetNivMax();
2717   MESSAGE ( ". NivMax = " << NivMax );
2718   double DiamMin = myHypo->GetDiamMin() ;
2719   MESSAGE ( ". DiamMin = " << DiamMin );
2720   int AdapInit = myHypo->GetAdapInit();
2721   MESSAGE ( ". AdapInit = " << AdapInit );
2722   int LevelOutput = myHypo->GetLevelOutput();
2723   MESSAGE ( ". LevelOutput = " << LevelOutput );
2724   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2725
2726   // E.7. Ajout des informations sur le deroulement de l'execution
2727   int MessInfo = myIteration->GetInfoCompute();
2728   MESSAGE ( ". MessInfo = " << MessInfo );
2729   myDriver->TexteInfoCompute(MessInfo);
2730
2731   return codret ;
2732 }
2733 //=============================================================================
2734 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2735 //  nomrep : nom du repertoire parent
2736 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2737 //=============================================================================
2738 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2739 {
2740   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2741   // On verifie que le repertoire parent existe  
2742 #ifndef WIN32
2743   int codret = chdir(nomrep) ;
2744 #else
2745   int codret = _chdir(nomrep) ;
2746 #endif
2747   if ( codret != 0 )
2748   {
2749     SALOME::ExceptionStruct es;
2750     es.type = SALOME::BAD_PARAM;
2751     es.text = "The directory of the case does not exist.";
2752     throw SALOME::SALOME_Exception(es);
2753     return 0;
2754   };
2755   std::string nomDirActuel = getenv("PWD") ;
2756   std::string DirName ;
2757   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2758   bool a_chercher = true ;
2759   while ( a_chercher )
2760   {
2761     // On passe dans le repertoire parent
2762     
2763 #ifndef WIN32
2764   chdir(nomrep);
2765 #else
2766   _chdir(nomrep);
2767 #endif
2768     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2769     int jaux ;
2770     if      ( num <    100 ) { jaux = 2 ; }
2771     else if ( num <   1000 ) { jaux = 3 ; }
2772     else if ( num <  10000 ) { jaux = 4 ; }
2773     else if ( num < 100000 ) { jaux = 5 ; }
2774     else                     { jaux = 9 ; }
2775     std::ostringstream iaux ;
2776     iaux << std::setw(jaux) << std::setfill('0') << num ;
2777     std::ostringstream DirNameA ;
2778     DirNameA << "I" << iaux.str();
2779     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2780     // que c'est bien un probleme d'absence
2781 #ifndef WIN32
2782     if ( chdir(DirNameA.str().c_str()) != 0 )
2783     {
2784 #else
2785     if ( _chdir(DirNameA.str().c_str()) != 0 )
2786     {
2787 #endif
2788       bool existe = false ;
2789 #ifndef WIN32
2790       DIR *dp;
2791       struct dirent *dirp;
2792       dp  = opendir(nomrep);
2793       while ( (dirp = readdir(dp)) != NULL )
2794       {
2795         std::string file_name(dirp->d_name);
2796 #else
2797       HANDLE hFind = INVALID_HANDLE_VALUE;
2798       WIN32_FIND_DATA ffd;
2799       hFind = FindFirstFile(nomrep, &ffd);
2800       if (INVALID_HANDLE_VALUE != hFind) {
2801         while (FindNextFile(hFind, &ffd) != 0) {
2802          if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2803          std::string file_name(ffd.cFileName);
2804 #endif        
2805         if ( file_name == DirNameA.str() ) { existe = true ; }
2806       }
2807 #ifndef WIN32
2808       closedir(dp);
2809 #else 
2810       }
2811       FindClose(hFind);
2812 #endif
2813       if ( !existe )
2814       {
2815         DirName = DirNameA.str() ;
2816         a_chercher = false ;
2817         break ;
2818       }
2819     }
2820     num += 1;
2821   }
2822
2823   MESSAGE ( "==> DirName = " << DirName);
2824   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2825 #ifndef WIN32
2826   chdir(nomDirActuel.c_str());
2827 #else
2828   _chdir(nomDirActuel.c_str());
2829 #endif
2830   return CORBA::string_dup( DirName.c_str() );
2831 }
2832 //=============================================================================
2833 // Calcul d'une iteration : gestion du repertoire de calcul
2834 //        Si le sous-repertoire existe :
2835 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2836 //         etatMenage =  1 : on fait le menage du repertoire
2837 //         etatMenage = -1 : on ne fait rien
2838 //=============================================================================
2839 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2840 {
2841   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2842   // B.2. Le repertoire du cas
2843   const char* nomDirCase = myCase->GetDirName();
2844   MESSAGE ( ". nomDirCase = " << nomDirCase );
2845
2846   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2847   // B.3.1. Le nom du sous-repertoire
2848   const char* nomDirIt = myIteration->GetDirNameLoc();
2849
2850   // B.3.2. Le nom complet du sous-repertoire
2851   std::stringstream DirCompute ;
2852   DirCompute << nomDirCase << "/" << nomDirIt;
2853   MESSAGE (". DirCompute = " << DirCompute.str() );
2854
2855   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2856 #ifndef WIN32
2857   if (chdir(DirCompute.str().c_str()) != 0)
2858   {
2859 //  Creation du repertoire car il n'existe pas :
2860     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2861     {
2862 #else
2863   if (_chdir(DirCompute.str().c_str()) != 0)
2864   {
2865 //  Creation du repertoire car il n'existe pas :
2866     if (_mkdir(DirCompute.str().c_str()) != 0)
2867     {
2868 #endif
2869        // GERALD -- QMESSAGE BOX
2870        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2871        VERIFICATION("Pb a la creation du repertoire" == 0);
2872     }
2873   }
2874   else
2875   {
2876 //  Le repertoire existe
2877 //  On demande de faire le menage de son contenu :
2878     if (etatMenage == 1)
2879     {
2880       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2881       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2882       int codret = system(commande.c_str());
2883       if (codret != 0)
2884       {
2885         // GERALD -- QMESSAGE BOX
2886         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2887         VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2888       }
2889     }
2890 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2891     else
2892     {
2893       if (etatMenage == 0)
2894       {
2895 #ifndef WIN32
2896         DIR *dp;
2897         struct dirent *dirp;
2898         dp  = opendir(DirCompute.str().c_str());
2899         bool result = true;
2900         while ((dirp = readdir(dp)) != NULL && result )
2901         {
2902           std::string file_name(dirp->d_name);
2903           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2904         }
2905         closedir(dp);
2906 #else
2907        HANDLE hFind = INVALID_HANDLE_VALUE;
2908        WIN32_FIND_DATA ffd;
2909        hFind = FindFirstFile(DirCompute.str().c_str(), &ffd);
2910        bool result = true;
2911        if (INVALID_HANDLE_VALUE != hFind) {
2912          while (FindNextFile(hFind, &ffd) != 0) {
2913           if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; //skip directories
2914           std::string file_name(ffd.cFileName);
2915           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2916          }
2917        }
2918        FindClose(hFind);
2919 #endif
2920         if ( result == false)
2921         {
2922           SALOME::ExceptionStruct es;
2923           es.type = SALOME::BAD_PARAM;
2924           std::string text = "Directory : " + DirCompute.str() + "is not empty";
2925           es.text = CORBA::string_dup(text.c_str());
2926           throw SALOME::SALOME_Exception(es);
2927           VERIFICATION("Directory is not empty" == 0);
2928         }
2929       }
2930     }
2931   }
2932
2933   return CORBA::string_dup( DirCompute.str().c_str() );
2934 }
2935 //=============================================================================
2936 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2937 //=============================================================================
2938 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2939 {
2940   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2941   // Le repertoire du cas
2942   const char* nomDirCase = myCase->GetDirName();
2943   MESSAGE ( ". nomDirCase = " << nomDirCase );
2944
2945   // Le sous-repertoire de l'iteration precedente
2946
2947   const char* nomIterationParent = myIteration->GetIterParentName();
2948   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2949   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2950   std::stringstream DirComputePa ;
2951   DirComputePa << nomDirCase << "/" << nomDirItPa;
2952   MESSAGE( ". nomDirItPa = " << nomDirItPa);
2953   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2954
2955   return CORBA::string_dup( DirComputePa.str().c_str() );
2956 }
2957 //=============================================================================
2958 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2959 //=============================================================================
2960 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2961 {
2962   MESSAGE ( "... DriverTexteZone" );
2963   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2964   int numberOfZonesx2 = ListZone->length();
2965   int NumZone ;
2966
2967   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2968   {
2969     std::string ZoneName = std::string((*ListZone)[iaux]);
2970     MESSAGE ( "... ZoneName = " << ZoneName);
2971     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2972     ASSERT(!CORBA::is_nil(myZone));
2973
2974     int ZoneType = myZone->GetType();
2975     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2976     int TypeUse = atoi( TypeUsestr.c_str() );
2977     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2978     NumZone = iaux/2 + 1 ;
2979     HOMARD::double_array* zone = myZone->GetCoords();
2980     if ( ZoneType == 2 || ( ZoneType>=11 && ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2981     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2982     else if ( ZoneType == 4 ) // Cas d une sphere
2983     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2984     else if ( ZoneType == 5 || ( ZoneType>=31 && ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2985     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2986     else if ( ZoneType == 7 || ( ZoneType>=61 && ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2987     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2988     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
2989     iaux += 1 ;
2990   }
2991   return ;
2992 }
2993 //=============================================================================
2994 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2995 //=============================================================================
2996 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2997 {
2998   MESSAGE ( "... DriverTexteField" );
2999 //  Le fichier du champ
3000   char* FieldFile = myIteration->GetFieldFile();
3001   MESSAGE ( ". FieldFile = " << FieldFile );
3002   if (strlen(FieldFile) == 0)
3003   {
3004     // GERALD -- QMESSAGE BOX
3005     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
3006     VERIFICATION("The file for the field is not given." == 0);
3007   }
3008 //  Les caracteristiques d'instants du champ de pilotage
3009   int TimeStep = myIteration->GetTimeStep();
3010   MESSAGE( ". TimeStep = " << TimeStep );
3011   int Rank = myIteration->GetRank();
3012   MESSAGE( ". Rank = " << Rank );
3013 //  Les informations sur les champs
3014   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
3015 //  Le nom
3016   const char* FieldName = aInfosHypo->FieldName;
3017 //  Les seuils
3018   int TypeThR = aInfosHypo->TypeThR;
3019   double ThreshR = aInfosHypo->ThreshR;
3020   int TypeThC = aInfosHypo->TypeThC;
3021   double ThreshC = aInfosHypo->ThreshC;
3022 //  Saut entre mailles ou non ?
3023   int UsField = aInfosHypo->UsField;
3024   MESSAGE( ". UsField = " << UsField );
3025 //  L'usage des composantes
3026   int UsCmpI = aInfosHypo->UsCmpI;
3027   MESSAGE( ". UsCmpI = " << UsCmpI );
3028 //
3029   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
3030 //
3031 //  Les composantes
3032   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
3033   int numberOfCompos = mescompo->length();
3034   MESSAGE( ". numberOfCompos = " << numberOfCompos );
3035   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
3036   {
3037     std::string nomCompo = std::string((*mescompo)[NumeComp]);
3038     MESSAGE( "... nomCompo = " << nomCompo );
3039     myDriver->TexteCompo(NumeComp, nomCompo);
3040   }
3041   return ;
3042 }
3043 //=============================================================================
3044 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
3045 // On ecrit dans l'ordre :
3046 //    1. la definition des frontieres
3047 //    2. les liens avec les groupes
3048 //    3. un entier resumant le type de comportement pour les frontieres
3049 //=============================================================================
3050 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
3051 {
3052   MESSAGE ( "... DriverTexteBoundary" );
3053   // 1. Recuperation des frontieres
3054   std::list<std::string>  ListeBoundaryTraitees ;
3055   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
3056   int numberOfitems = ListBoundaryGroupType->length();
3057   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
3058   int BoundaryOption = 1 ;
3059   // 2. Parcours des frontieres pour ecrire leur description
3060   int NumBoundaryAnalytical = 0 ;
3061   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3062   {
3063     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3064     MESSAGE ( "... BoundaryName = " << BoundaryName);
3065     // 2.1. La frontiere a-t-elle deja ete ecrite ?
3066     //      Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
3067     int A_faire = 1 ;
3068     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
3069     while (it != ListeBoundaryTraitees.end())
3070     {
3071       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
3072       if ( BoundaryName == *it ) { A_faire = 0 ; }
3073       it++;
3074     }
3075     // 2.2. Ecriture de la frontiere
3076     if ( A_faire == 1 )
3077     {
3078       // 2.2.1. Caracteristiques de la frontiere
3079       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3080       ASSERT(!CORBA::is_nil(myBoundary));
3081       int BoundaryType = myBoundary->GetType();
3082       MESSAGE ( "... BoundaryType = " << BoundaryType );
3083       // 2.2.2. Ecriture selon le type
3084       // 2.2.2.1. Cas d une frontiere discrete
3085       if (BoundaryType == 0)
3086       {
3087         const char* MeshName = myBoundary->GetMeshName() ;
3088         const char* MeshFile = myBoundary->GetMeshFile() ;
3089         myDriver->TexteBoundaryDi( MeshName, MeshFile);
3090         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
3091       }
3092       // 2.2.2.1. Cas d une frontiere analytique
3093       else
3094       {
3095         NumBoundaryAnalytical++ ;
3096         HOMARD::double_array* coor = myBoundary->GetCoords();
3097         if (BoundaryType == 1) // Cas d un cylindre
3098         {
3099           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3100           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3101         }
3102         else if (BoundaryType == 2) // Cas d une sphere
3103         {
3104           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
3105           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3106         }
3107         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
3108         {
3109           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
3110           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3111         }
3112         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
3113         {
3114           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
3115           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
3116         }
3117       }
3118       // 2.2.3. Memorisation du traitement
3119       ListeBoundaryTraitees.push_back( BoundaryName );
3120     }
3121   }
3122   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
3123   NumBoundaryAnalytical = 0 ;
3124   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
3125   {
3126     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
3127     MESSAGE ( "... BoundaryName = " << BoundaryName);
3128     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3129     ASSERT(!CORBA::is_nil(myBoundary));
3130     int BoundaryType = myBoundary->GetType();
3131     MESSAGE ( "... BoundaryType = " << BoundaryType );
3132     // 3.1. Recuperation du nom du groupe
3133     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
3134     MESSAGE ( "... GroupName = " << GroupName);
3135     // 3.2. Cas d une frontiere discrete
3136     if ( BoundaryType == 0 )
3137     {
3138       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
3139     }
3140     // 3.3. Cas d une frontiere analytique
3141     else
3142     {
3143       NumBoundaryAnalytical++ ;
3144       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
3145     }
3146   }
3147   // 4. Ecriture de l'option finale
3148   myDriver->TexteBoundaryOption(BoundaryOption);
3149 //
3150   return ;
3151 }
3152 //=============================================================================
3153 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3154 //=============================================================================
3155 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3156 {
3157   MESSAGE ( "... DriverTexteFieldInterp" );
3158   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3159   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3160   if (TypeFieldInterp != 0)
3161   {
3162 //  Le fichier des champs
3163     char* FieldFile = myIteration->GetFieldFile();
3164     MESSAGE ( ". FieldFile = " << FieldFile );
3165     if (strlen(FieldFile) == 0)
3166     {
3167       // GERALD -- QMESSAGE BOX
3168       VERIFICATION("The file for the field is not given." == 0);
3169     }
3170   //
3171     const char* MeshFile = myIteration->GetMeshFile();
3172     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3173
3174   // Les champs
3175   // Interpolation de tous les champs
3176     if ( TypeFieldInterp == 1 )
3177     {
3178       myDriver->TexteFieldInterpAll();
3179     }
3180   // Interpolation de certains champs
3181     else if (TypeFieldInterp == 2)
3182     {
3183       // Les champs et leurs instants pour l'iteration
3184       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3185       int numberOfFieldsx3 = ListFieldTSR->length();
3186       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3187       // Les champs pour l'hypothese
3188       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3189       int numberOfFieldsx2 = ListField->length();
3190       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3191       // On parcourt tous les champs de  l'hypothese
3192       int NumField = 0 ;
3193       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3194       {
3195         // Le nom du champ
3196         std::string FieldName = std::string((*ListField)[iaux]) ;
3197         // Le type d'interpolation
3198         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3199         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3200         // On cherche à savoir si des instants ont été précisés pour cette itération
3201         int tsrvu = 0;
3202         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3203         {
3204         // Le nom du champ
3205           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3206           MESSAGE( "..... FieldName2 = " << FieldName2 );
3207         // Quand c'est le bon champ, on ecrit le pas de temps
3208           if ( FieldName == FieldName2 )
3209           {
3210             tsrvu = 1 ;
3211             // Le pas de temps
3212             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3213             // Le numero d'ordre
3214             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3215             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3216             NumField += 1 ;
3217             int TimeStep = atoi( TimeStepstr.c_str() );
3218             int Rank = atoi( Rankstr.c_str() );
3219             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3220           }
3221           jaux += 2 ;
3222         }
3223         // Si aucun instant n'a été défini
3224         if ( tsrvu == 0 )
3225         {
3226           NumField += 1 ;
3227           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3228         }
3229         iaux++ ;
3230       }
3231     }
3232   }
3233   return ;
3234 }
3235 //===========================================================================
3236 //===========================================================================
3237
3238
3239 //===========================================================================
3240 //===========================================================================
3241 // Publications
3242 //===========================================================================
3243 //===========================================================================
3244 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3245                                                    SALOMEDS::SObject_ptr theSObject,
3246                                                    CORBA::Object_ptr theObject,
3247                                                    const char* theName)
3248 {
3249   MESSAGE("PublishInStudy pour " << theName);
3250   SALOMEDS::SObject_var aResultSO;
3251   if (CORBA::is_nil(theStudy))
3252   {
3253     SALOME::ExceptionStruct es;
3254     es.type = SALOME::BAD_PARAM;
3255     es.text = "Invalid study context";
3256     throw SALOME::SALOME_Exception(es);
3257     return 0;
3258   };
3259
3260 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3261 // Rq : Iteration est publiee ailleurs
3262   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3263   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3264   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3265   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3266   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3267
3268    addInStudy(theStudy);
3269
3270 // Controle de la non publication d'un objet de meme nom
3271    if ( (!aBoundary->_is_nil()) || (!aHypo->_is_nil()) || (!aYACS->_is_nil()) || (!aZone->_is_nil()) )
3272   {
3273     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3274     if (listSO->length() >= 1)
3275     {
3276       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3277       aResultSO = listSO[0];
3278       return aResultSO._retn();
3279     }
3280   }
3281
3282   // Caracteristiques de l'etude
3283   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3284   aStudyBuilder->NewCommand();
3285   if(!aBoundary->_is_nil())
3286     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3287   else if(!aCase->_is_nil())
3288     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3289   else if(!aHypo->_is_nil())
3290     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3291   else if(!aYACS->_is_nil())
3292     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3293   else if(!aZone->_is_nil())
3294     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3295
3296   aStudyBuilder->CommitCommand();
3297
3298   return aResultSO._retn();
3299 };
3300 //=============================================================================
3301 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3302                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3303                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3304 {
3305   MESSAGE("PublishBoundaryStudy pour "<<theName);
3306   SALOMEDS::SObject_var aResultSO;
3307
3308   // Caracteristique de la Boundary
3309   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3310
3311   // On recupere le module pere dans l etude
3312   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3313   if (theFatherHomard->_is_nil())
3314   {
3315     MESSAGE("theFatherHomard->_is_nil()");
3316     return aResultSO._retn();
3317   }
3318
3319   // On ajoute la categorie des boundarys dans l etude si necessaire
3320   if ( _tag_boun == 0 )
3321   {
3322     _tag_gene += 1 ;
3323     _tag_boun = _tag_gene ;
3324   }
3325   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3326   SALOMEDS::SObject_var aSObject;
3327   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3328   {
3329     MESSAGE("Ajout de la categorie des boundarys");
3330     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3331     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3332   }
3333   else { MESSAGE("La categorie des boundarys existe deja."); }
3334
3335   CORBA::Long BoundaryType = myBoundary->GetType();
3336 //   MESSAGE("BoundaryType : "<<BoundaryType);
3337   std::string icone ;
3338   std::string value ;
3339   switch (BoundaryType)
3340   {
3341     case 0 :
3342     { value = "BoundaryDiHomard" ;
3343       icone = "mesh_tree_mesh.png" ;
3344       break;
3345     }
3346     case 1 :
3347     { value = "BoundaryAnHomard" ;
3348       icone = "cylinderpointvector_2.png" ;
3349       break;
3350     }
3351     case 2 :
3352     { value = "BoundaryAnHomard" ;
3353       icone = "spherepoint_2.png" ;
3354       break;
3355     }
3356     case 3 :
3357     { value = "BoundaryAnHomard" ;
3358       icone = "conepointvector.png" ;
3359       break;
3360     }
3361     case 4 :
3362     { value = "BoundaryAnHomard" ;
3363       icone = "conedxyz.png" ;
3364       break;
3365     }
3366   }
3367   aResultSO = aStudyBuilder->NewObject(aSObject);
3368   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3369   return aResultSO._retn();
3370 }
3371 //=============================================================================
3372 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3373                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3374                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3375 {
3376   MESSAGE("PublishCaseInStudy pour "<<theName);
3377   SALOMEDS::SObject_var aResultSO;
3378
3379   if (CORBA::is_nil(theObject)) {
3380     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3381     return aResultSO._retn();
3382   }
3383   if (theStudy->_is_nil()) {
3384     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3385     return aResultSO._retn();
3386   }
3387
3388   // On recupere le module pere dans l etude
3389   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3390   if (theFatherHomard->_is_nil())
3391   {
3392     MESSAGE("theFatherHomard->_is_nil()");
3393     return aResultSO._retn();
3394   }
3395
3396   _tag_gene += 1 ;
3397   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3398   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3399   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3400                      _orb->object_to_string(theObject) ) ;
3401
3402   return aResultSO._retn();
3403 }
3404 //=============================================================================
3405 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3406                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3407                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3408 {
3409   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3410   SALOMEDS::SObject_var aResultSO;
3411
3412   // On recupere le module pere dans l etude
3413   // On ajoute la categorie des hypotheses dans l etude si necessaire
3414   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3415   if (theFatherHomard->_is_nil())
3416   {
3417     MESSAGE("theFatherHomard->_is_nil()");
3418     return aResultSO._retn();
3419   }
3420
3421   // On ajoute la categorie des hypotheses dans l etude si necessaire
3422   SALOMEDS::SObject_var aSObject;
3423   if ( _tag_hypo == 0 )
3424   {
3425     _tag_gene += 1 ;
3426     _tag_hypo = _tag_gene ;
3427   }
3428   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3429   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3430   {
3431     MESSAGE("Ajout de la categorie des hypotheses");
3432     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3433     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3434   }
3435   else { MESSAGE("La categorie des hypotheses existe deja."); }
3436
3437 // Creation du resultat dans l'etude
3438   aResultSO = aStudyBuilder->NewObject(aSObject);
3439   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3440
3441   return aResultSO._retn();
3442 }
3443 //=============================================================================
3444 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3445                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3446                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3447 {
3448   MESSAGE("PublishYACSInStudy pour "<<theName);
3449   SALOMEDS::SObject_var aResultSO;
3450
3451   // On recupere le module pere dans l etude
3452   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3453   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3454   if (theFatherHomard->_is_nil())
3455   {
3456     MESSAGE("theFatherHomard->_is_nil()");
3457     return aResultSO._retn();
3458   }
3459   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3460   if ( _tag_yacs == 0 )
3461   {
3462     _tag_gene += 1 ;
3463     _tag_yacs = _tag_gene ;
3464   }
3465   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3466   SALOMEDS::SObject_var aSObject;
3467   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3468   {
3469     MESSAGE("Ajout de la categorie des schemas YACS");
3470     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3471     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3472   }
3473   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3474
3475 // Creation du resultat dans l'etude
3476   aResultSO = aStudyBuilder->NewObject(aSObject);
3477   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3478
3479   return aResultSO._retn();
3480 }
3481
3482 //=============================================================================
3483 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3484                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3485                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3486 {
3487   MESSAGE("PublishZoneStudy pour "<<theName);
3488   SALOMEDS::SObject_var aResultSO;
3489   if (CORBA::is_nil(theObject))
3490   {
3491     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3492     return aResultSO._retn();
3493   }
3494   if (theStudy->_is_nil())
3495   {
3496     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3497     return aResultSO._retn();
3498   }
3499   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3500   if (theFatherHomard->_is_nil())
3501   {
3502     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3503     return aResultSO._retn();
3504   }
3505
3506   // Caracteristique de la zone
3507   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3508   CORBA::Long ZoneType = myZone->GetType();
3509
3510   // On ajoute la categorie des zones dans l etude si necessaire
3511   if ( _tag_zone == 0 )
3512   {
3513     _tag_gene += 1 ;
3514     _tag_zone = _tag_gene ;
3515   }
3516   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3517   SALOMEDS::SObject_var aSObject;
3518   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3519   {
3520     MESSAGE("Ajout de la categorie des zones");
3521     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3522     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3523   }
3524   else { MESSAGE("La categorie des zones existe deja."); }
3525
3526   aResultSO = aStudyBuilder->NewObject(aSObject);
3527   std::string icone ;
3528   switch (ZoneType)
3529   {
3530     case 11 :
3531     { }
3532     case 12 :
3533     { }
3534     case 13 :
3535     { icone = "boxdxy_2.png" ;
3536       break ;
3537     }
3538     case 2 :
3539     { icone = "boxdxyz_2.png" ;
3540       break ;
3541     }
3542     case 31 :
3543     { }
3544     case 32 :
3545     { }
3546     case 33 :
3547     { icone = "disk_2.png" ;
3548       break ;
3549      }
3550     case 4 :
3551     { icone = "spherepoint_2.png" ;
3552       break ;
3553     }
3554     case 5 :
3555     { icone = "cylinderpointvector_2.png" ;
3556       break ;
3557     }
3558     case 61 :
3559     { }
3560     case 62 :
3561     { }
3562     case 63 :
3563     { icone = "diskwithhole_2.png" ;
3564       break ;
3565      }
3566     case 7 :
3567     { icone = "pipe_2.png" ;
3568       break ;
3569     }
3570   }
3571   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3572
3573   return aResultSO._retn();
3574 }
3575 //===========================================================================
3576 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3577                                       SALOMEDS::SObject_var aResultSO,
3578                                       const char* name, const char* comment, const char* icone, const char* ior)
3579 {
3580   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3581 //   MESSAGE("icone = "<<icone);
3582 //   MESSAGE("ior   = "<<ior);
3583   SALOMEDS::GenericAttribute_var anAttr ;
3584 //  Ajout du nom
3585   if ( name != NULL )
3586   {
3587     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3588     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3589     aNameAttrib->SetValue(name);
3590   }
3591
3592 //  Ajout du commentaire
3593   if ( comment != NULL )
3594   {
3595     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3596     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3597     aCommentAttrib->SetValue(comment);
3598   }
3599
3600 //  Ajout de l'icone
3601   if ( icone != NULL  )
3602   {
3603     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3604     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3605     aPixmap->SetPixMap(icone);
3606   }
3607
3608 //  Ajout de l ior
3609   if ( ior != NULL  )
3610   {
3611     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3612     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3613     anIOR->SetValue(ior);
3614   }
3615 };
3616
3617 //=====================================================================================
3618 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3619 {
3620   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3621
3622   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3623   ASSERT(!CORBA::is_nil(myCase));
3624   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3625   ASSERT(!CORBA::is_nil(aCaseSO));
3626
3627   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3628   ASSERT(!CORBA::is_nil(myBoundary));
3629   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3630   ASSERT(!CORBA::is_nil(aBoundarySO));
3631
3632   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3633
3634   aStudyBuilder->NewCommand();
3635
3636   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3637   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3638
3639   aStudyBuilder->CommitCommand();
3640
3641 };
3642 //=====================================================================================
3643 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3644 {
3645   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3646
3647   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3648   ASSERT(!CORBA::is_nil(myYACS));
3649   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3650   ASSERT(!CORBA::is_nil(aYACSSO));
3651
3652   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3653   ASSERT(!CORBA::is_nil(myCase));
3654   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3655   ASSERT(!CORBA::is_nil(aCaseSO));
3656
3657   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3658
3659   aStudyBuilder->NewCommand();
3660
3661   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3662   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3663
3664   aStudyBuilder->CommitCommand();
3665
3666 };
3667 //=============================================================================
3668 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3669 //  Option = 0 : fichier issu d'une importation
3670 //  Option = 1 : fichier issu d'une execution HOMARD
3671 {
3672   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3673   if (CORBA::is_nil(myCurrentStudy))
3674   {
3675     SALOME::ExceptionStruct es;
3676     es.type = SALOME::BAD_PARAM;
3677     es.text = "Invalid study context";
3678     throw SALOME::SALOME_Exception(es);
3679     return ;
3680   };
3681
3682 // Le module SMESH est-il actif ?
3683   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3684 //
3685   if (!CORBA::is_nil(aSmeshSO))
3686   {
3687 // On verifie que le fichier n est pas deja publie
3688     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3689     for (; aIter->More(); aIter->Next())
3690     {
3691       SALOMEDS::SObject_var  aSO = aIter->Value();
3692       SALOMEDS::GenericAttribute_var aGAttr;
3693       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3694       {
3695         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3696         CORBA::String_var value=anAttr->Value();
3697         if (strcmp((const char*)value,NomFich) == 0)
3698         {
3699           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3700           // Pour un fichier importe, on ne republie pas
3701           if ( Option == 0 )
3702           {
3703             return;
3704           }
3705           // Pour un fichier calcule, on commence par faire la depublication
3706           else
3707           {
3708             MESSAGE ( "PublishResultInSmesh : depublication" );
3709             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3710             CORBA::String_var value2=anAttr2->Value();
3711             std::string MeshName = string(value2) ;
3712             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3713             DeleteResultInSmesh(NomFich, MeshName) ;
3714           }
3715         }
3716       }
3717     }
3718   }
3719
3720 // On enregistre le fichier
3721   MESSAGE( "Enregistrement du fichier");
3722   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3723   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3724   ASSERT(!CORBA::is_nil(aSmeshEngine));
3725   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3726   SMESH::DriverMED_ReadStatus theStatus;
3727   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3728
3729 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3730   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3731   for (int i = 0; i < mesMaillages->length();  i++)
3732   {
3733     MESSAGE( ". Mise a jour des attributs du maillage");
3734     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3735     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3736     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3737     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3738     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3739     anAttr->SetValue(NomFich);
3740     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3741     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3742     const char* icone ;
3743     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3744     else               { icone = "mesh_tree_mesh.png" ; }
3745     anAttr2->SetPixMap( icone );
3746   }
3747
3748 }
3749 //=============================================================================
3750 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3751 {
3752   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3753   if (CORBA::is_nil(myCurrentStudy))
3754   {
3755       SALOME::ExceptionStruct es;
3756       es.type = SALOME::BAD_PARAM;
3757       es.text = "Invalid study context";
3758       throw SALOME::SALOME_Exception(es);
3759       return ;
3760   };
3761
3762 // Le module SMESH est-il actif ?
3763   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3764 //
3765   if (CORBA::is_nil(aSmeshSO))
3766   {
3767       return ;
3768   };
3769 // On verifie que le fichier est deja publie
3770   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3771   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3772   for (; aIter->More(); aIter->Next())
3773   {
3774      SALOMEDS::SObject_var  aSO = aIter->Value();
3775      SALOMEDS::GenericAttribute_var aGAttr;
3776      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3777      {
3778        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3779        CORBA::String_var value=anAttr->Value();
3780        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3781        {
3782          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3783          {
3784            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3785            CORBA::String_var value2=anAttr2->Value();
3786            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3787            {
3788              myBuilder->RemoveObjectWithChildren( aSO ) ;
3789            }
3790          }
3791        }
3792      }
3793   }
3794   return ;
3795 }
3796 //=============================================================================
3797 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3798 {
3799 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3800   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3801
3802   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3803   if (CORBA::is_nil(myIteration))
3804   {
3805       SALOME::ExceptionStruct es;
3806       es.type = SALOME::BAD_PARAM;
3807       es.text = "Invalid iterationStudy Object";
3808       throw SALOME::SALOME_Exception(es);
3809       return ;
3810   };
3811
3812   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3813
3814   aStudyBuilder->NewCommand();
3815
3816   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3817 // Pour les fichiers med, on affiche une icone de maillage
3818 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3819 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3820   std::string icone ;
3821   std::string ior = " " ;
3822   if ( Commentaire[0] == 'I' )
3823   { icone = "med.png" ; }
3824   else
3825   { icone = "texte_2.png" ; }
3826   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3827
3828   aStudyBuilder->CommitCommand();
3829 }
3830 //
3831 //=============================================================================
3832 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3833 {
3834 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3835   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3836
3837   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3838   if (CORBA::is_nil(myYACS))
3839   {
3840       SALOME::ExceptionStruct es;
3841       es.type = SALOME::BAD_PARAM;
3842       es.text = "Invalid YACSStudy Object";
3843       throw SALOME::SALOME_Exception(es);
3844       return ;
3845   };
3846
3847   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3848
3849   aStudyBuilder->NewCommand();
3850
3851   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3852   std::string icone = "texte_2.png" ;
3853   std::string ior = " " ;
3854   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3855
3856   aStudyBuilder->CommitCommand();
3857 }
3858 //
3859 //=============================================================================
3860 //=============================================================================
3861 // YACS
3862 //=============================================================================
3863 //=============================================================================
3864 //=============================================================================
3865 // Creation d'un schema YACS
3866 // nomCas : nom du cas a traiter
3867 // FileName : nom du fichier contenant le script de lancement du calcul
3868 // DirName : le repertoire de lancement des calculs du schéma
3869 //=============================================================================
3870 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3871 {
3872   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3873   INFOS ( ". nomCas     : " << nomCas);
3874   INFOS ( ". ScriptFile : " << ScriptFile);
3875   INFOS ( ". DirName    : " << DirName);
3876   INFOS ( ". MeshFile   : " << MeshFile);
3877
3878   // A. Controle du nom :
3879   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3880   {
3881     SALOME::ExceptionStruct es;
3882     es.type = SALOME::BAD_PARAM;
3883     es.text = "This schema YACS has already been defined.";
3884     throw SALOME::SALOME_Exception(es);
3885     return 0;
3886   }
3887
3888   // B. Creation de l'objet
3889   HOMARD::HOMARD_YACS_var myYACS = newYACS();
3890   if (CORBA::is_nil(myYACS))
3891   {
3892     SALOME::ExceptionStruct es;
3893     es.type = SALOME::BAD_PARAM;
3894     es.text = "Unable to create the schema YACS";
3895     throw SALOME::SALOME_Exception(es);
3896     return 0;
3897   };
3898   myYACS->SetName( nomYACS ) ;
3899
3900   // C. Enregistrement
3901   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3902
3903   SALOMEDS::SObject_var aSO;
3904   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3905
3906   PublishCaseUnderYACS(nomYACS, nomCas);
3907
3908   // D. Caracterisation
3909   // D.1. Options
3910   myYACS->SetDirName( DirName ) ;
3911   myYACS->SetMeshFile( MeshFile ) ;
3912   myYACS->SetScriptFile( ScriptFile ) ;
3913   myYACS->SetCaseName( nomCas ) ;
3914   // D.2. Defaut
3915   // D.2.1. Type constant
3916   myYACS->SetType( 1 ) ;
3917   // D.2.2. Fichier de sauvegarde dans le repertoire du cas
3918   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
3919   std::string dirnamecase = caseyacs->GetDirName() ;
3920   std::string XMLFile ;
3921   XMLFile = dirnamecase + "/schema.xml" ;
3922   myYACS->SetXMLFile( XMLFile.c_str() ) ;
3923
3924   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3925 }
3926 //=============================================================================
3927 // Ecriture d'un schema YACS
3928 //=============================================================================
3929 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3930 {
3931   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3932 // Le repertoire du cas
3933   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3934   ASSERT(!CORBA::is_nil(myYACS));
3935 // Le nom du fichier du schema
3936   std::string XMLFile ;
3937   XMLFile = myYACS->GetXMLFile() ;
3938
3939   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
3940
3941   return codret ;
3942 }
3943 //=============================================================================
3944 // Ecriture d'un schema YACS sur un fichier donne
3945 //=============================================================================
3946 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
3947 {
3948   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
3949
3950   // A. Prealable
3951   int codret = 0;
3952
3953   // B. L'objet YACS
3954   // B.1. L'objet
3955   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3956   ASSERT(!CORBA::is_nil(myYACS));
3957   // B.2. Les caracteristiques
3958   std::string DirName = myYACS->GetDirName() ;
3959   std::string MeshFile = myYACS->GetMeshFile() ;
3960   std::string ScriptFile = myYACS->GetScriptFile() ;
3961
3962   // C. Le cas
3963   // C.1. L'objet cas
3964   const char* nomCas = myYACS->GetCaseName();
3965   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3966   ASSERT(!CORBA::is_nil(myCase));
3967   // C.2. Les instructions python associees au cas
3968   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3969   std::string pythonCas = dumpCorbaCase.in();
3970   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3971
3972   // D. Les iterations
3973   // D.1. L'iteration initiale
3974   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3975   std::string Iter0Name = myCase->GetIter0Name() ;
3976   MESSAGE (". Iter0Name = " << Iter0Name);
3977   std::string MeshName = Iter0->GetMeshName();
3978   MESSAGE (". MeshName = " << MeshName);
3979   // D.2. L'iteration numero 1
3980   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3981   int numberOfIter = maListe->length();
3982   if ( numberOfIter > 1 )
3983   {
3984     MESSAGE (". numberOfIter = " << numberOfIter);
3985     SALOME::ExceptionStruct es ;
3986     es.type = SALOME::BAD_PARAM;
3987     std::string text = "Une seule iteration est permise." ;
3988     es.text = CORBA::string_dup(text.c_str());
3989     throw SALOME::SALOME_Exception(es);
3990     return 0;
3991   }
3992   std::string Iter1Name = std::string((*maListe)[0]);
3993   MESSAGE ("... Iter1Name = " << Iter1Name);
3994   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3995   // D.3. Les instructions python associees a l'iteration
3996   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
3997   std::string pythonIter = dumpCorbaIter.in();
3998   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
3999
4000   // E. L'hypothese pour passer de l'iteration initiale a la suivante
4001   // E.1. La structure
4002   std::string nomHypo = Iter1->GetHypoName();
4003   MESSAGE (". nomHypo = " << nomHypo);
4004   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
4005   ASSERT(!CORBA::is_nil(myHypo));
4006   // E.2. Les caracteristiques de l'adaptation
4007   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
4008   ASSERT(ListTypes->length() == 3);
4009   int TypeAdap = (*ListTypes)[0];
4010 //   int TypeRaff = (*ListTypes)[1];
4011 //   int TypeDera = (*ListTypes)[2];
4012   // E.3. Les instructions python associees a l'hypothese
4013   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
4014   std::string pythonHypo = dumpCorbaHypo.in();
4015   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
4016
4017   // F. Le fichier du schema de reference
4018   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
4019   std::string XMLFile_base ;
4020   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
4021   else
4022   {
4023     SALOME::ExceptionStruct es ;
4024     es.type = SALOME::BAD_PARAM;
4025     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
4026     es.text = CORBA::string_dup(text.c_str());
4027     throw SALOME::SALOME_Exception(es);
4028     return 0;
4029   }
4030   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
4031 //   if ( _Langue ==
4032   MESSAGE("XMLFile_base ="<<XMLFile_base);
4033
4034   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4035   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
4036   std::ifstream fichier( XMLFile_base.c_str() );
4037   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
4038   {
4039     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
4040     std::string ligne; // variable contenant chaque ligne lue
4041     std::string mot_cle;
4042     while ( std::getline( fichier, ligne ) )
4043     {
4044       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
4045       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
4046       ligne_bis >> mot_cle ;
4047       // G.1.2. Le maillage initial
4048       if ( mot_cle == "DataInit_MeshFile" )
4049       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
4050       // G.1.3. Le script de lancement
4051       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
4052       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
4053       // G.1.4. Les options du cas
4054       else if ( mot_cle == "Iter_1_Case_Options" )
4055       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
4056       // G.1.5. Execution de HOMARD : le repertoire du cas
4057       else if ( mot_cle == "HOMARD_Exec_DirName" )
4058       { myDriver->Texte_HOMARD_Exec_DirName(); }
4059       // G.1.6. Execution de HOMARD : le nom du maillage
4060       else if ( mot_cle == "HOMARD_Exec_MeshName" )
4061       {
4062         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
4063         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
4064         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
4065       }
4066       // G.1.7. Execution de HOMARD : les options de l'hypothese
4067       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
4068       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
4069       // G.1.8. Execution de HOMARD : les options de l'iteration
4070       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
4071       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
4072       // G.1.9. Zones et frontieres : les creations
4073       else if ( mot_cle == "Iter_1" )
4074       {
4075         std::string texte_control = myDriver->Texte_Iter_1_control() ;
4076         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
4077         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
4078         myDriver->TexteAdd(texte_control);
4079       }
4080       // G.1.10. Les parametres
4081       else if ( mot_cle == "PARAMETRES" )
4082       { myDriver->TexteAddParametres(); }
4083       // G.1.n. La ligne est recopiee telle quelle
4084       else { myDriver->TexteAdd(ligne);  }
4085     }
4086     // G.2. Ecriture du texte dans le fichier
4087     if ( codret == 0 )
4088     { myDriver->CreeFichier(); }
4089   }
4090   else
4091   {
4092     SALOME::ExceptionStruct es;
4093     es.type = SALOME::BAD_PARAM;
4094     std::string text = "The reference file for the YACS schema cannot be read." ;
4095     es.text = CORBA::string_dup(text.c_str());
4096     throw SALOME::SALOME_Exception(es);
4097   }
4098
4099   delete myDriver;
4100
4101   // H. Publication du fichier dans l'arbre
4102
4103     std::string Commentaire = "xml" ;
4104     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
4105
4106   return codret ;
4107 }
4108 //=============================================================================
4109 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
4110 //=============================================================================
4111 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
4112 {
4113   MESSAGE ( "YACSDriverTexteZone" );
4114   // A. Les zones associees a cette hypothese
4115   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
4116   int numberOfZonesx2 = ListZone->length();
4117
4118   // B. Parcours des zones
4119   std::string texte_control ;
4120   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
4121   {
4122     // 1. Reperage de la zone
4123     std::string ZoneName = std::string((*ListZone)[iaux]);
4124     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
4125     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
4126     ASSERT(!CORBA::is_nil(myZone));
4127     // 2. Les instructions python associees a la zone
4128     //    La premiere ligne est un commentaire a eliminer
4129     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4130     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4131     std::string pythonStructure_0 = dumpCorbaZone.in();
4132     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4133     std::istringstream tout (pythonStructure_0) ;
4134     std::string ligne ;
4135     std::string pythonStructure ;
4136     while ( std::getline( tout, ligne ) )
4137     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4138     MESSAGE ("pythonStructure :\n"<<pythonStructure);
4139     // 3. Decodage du nom du service
4140     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4141     MESSAGE ( "... methode = " << methode);
4142     // 4. Mise en place des instructions
4143     int ZoneType = myZone->GetType();
4144     MESSAGE ( "... ZoneType = " << ZoneType);
4145     std::string texte_control_0 ;
4146     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
4147     texte_control += texte_control_0 ;
4148     // 5. Decalage
4149     iaux += 1 ;
4150   }
4151
4152   return texte_control ;
4153 }
4154 //=============================================================================
4155 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4156 //=============================================================================
4157 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4158 {
4159   MESSAGE ( "YACSDriverTexteBoundary" );
4160   // A. Les frontieres associees au cas
4161   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4162   int numberOfitems = ListBoundaryGroupType->length();
4163
4164   // B. Parcours des frontieres
4165   std::string texte_control ;
4166   std::list<std::string>  ListeBoundaryTraitees ;
4167   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4168   {
4169     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4170     MESSAGE ( "... BoundaryName = " << BoundaryName);
4171     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4172     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4173     int A_faire = 1 ;
4174     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4175     while (it != ListeBoundaryTraitees.end())
4176     {
4177       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4178       if ( BoundaryName == *it ) { A_faire = 0 ; }
4179       it++;
4180     }
4181     if ( A_faire == 1 )
4182     {
4183     // 1. Caracteristiques de la frontiere
4184       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4185       ASSERT(!CORBA::is_nil(myBoundary));
4186       // 2. Les instructions python associees a la frontiere
4187       //    La premiere ligne est un commentaire a eliminer
4188       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4189       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4190       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4191       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4192       std::istringstream tout (pythonStructure_0) ;
4193       std::string ligne ;
4194       std::string pythonStructure ;
4195       while ( std::getline( tout, ligne ) )
4196       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4197       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4198       // 3. Decodage du nom du service
4199       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4200       MESSAGE ( "... methode = " << methode);
4201       // 4. Mise en place des instructions
4202       int BoundaryType = myBoundary->GetType();
4203       MESSAGE ( "... BoundaryType = " << BoundaryType);
4204       std::string texte_control_0 ;
4205       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4206       texte_control += texte_control_0 ;
4207       // 5. Memorisation du traitement
4208       ListeBoundaryTraitees.push_back( BoundaryName );
4209     }
4210   }
4211
4212   return texte_control ;
4213 }
4214 //
4215 //=============================================================================
4216 //=============================================================================
4217 // Next functions are inherited from SALOMEDS::Driver interface
4218 //=============================================================================
4219 //=============================================================================
4220 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4221                                       const char* theURL,
4222                                       CORBA::Boolean isMultiFile)
4223 {
4224   MESSAGE ("Save for theURL = "<< theURL);
4225   SALOMEDS::TMPFile_var aStreamFile;
4226
4227   // get temporary directory name
4228   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4229
4230   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4231   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4232
4233   // HOMARD data file name
4234   std::string aFileName = "";
4235   if (isMultiFile)
4236     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4237   aFileName += "_HOMARD.dat";
4238
4239   // initialize sequence of file names
4240   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4241   aFileSeq->length(1);
4242   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4243
4244   // get full path to the data file
4245   aFileName = tmpDir + aFileName;
4246
4247   // save data
4248   // -> create file
4249   std::ofstream f(aFileName.c_str());
4250
4251   // clear temporary id map
4252   context._idmap.clear();
4253
4254   int id = 1;
4255
4256   // -> save cases
4257   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4258   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4259     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4260     PortableServer::ServantBase_var aServant = GetServant(aCas);
4261     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4262     if (aCasServant) {
4263       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4264       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4265     }
4266   }
4267   // -> save zones
4268   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4269   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4270     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4271     PortableServer::ServantBase_var aServant = GetServant(aZone);
4272     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4273     if (aZoneServant) {
4274       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4275       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4276     }
4277   }
4278   // -> save hypotheses
4279   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4280   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4281     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4282     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4283     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4284     if (aHypoServant) {
4285       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4286       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4287     }
4288   }
4289   // -> save iterations
4290   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4291   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4292     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4293     PortableServer::ServantBase_var aServant = GetServant(aIter);
4294     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4295     if (aIterServant) {
4296       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4297       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4298     }
4299   }
4300   // -> save boundaries
4301   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4302   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4303     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4304     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4305     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4306     if (aBoundaryServant) {
4307       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4308       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4309     }
4310   }
4311   // -> close file
4312   MESSAGE ("close file");
4313   f.close();
4314
4315   // put temporary files to the stream
4316   MESSAGE ("put temporary files to the stream");
4317   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4318
4319   // remove temporary files
4320   MESSAGE ("remove temporary files");
4321   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4322
4323   // return data stream
4324   MESSAGE ("return data stream");
4325   return aStreamFile._retn();
4326 };
4327
4328 //===========================================================================
4329 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4330                                            const char* theURL,
4331                                            CORBA::Boolean isMultiFile)
4332 {
4333   // No specific ASCII persistence
4334   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4335   return aStreamFile._retn();
4336 };
4337
4338 //===========================================================================
4339 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4340                                    const SALOMEDS::TMPFile& theStream,
4341                                    const char* theURL,
4342                                    CORBA::Boolean isMultiFile)
4343 {
4344   MESSAGE ("Load pour theURL = "<< theURL);
4345   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4346
4347   // set current study
4348   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4349     SetCurrentStudy(aStudy);
4350
4351   // get temporary directory name
4352   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4353
4354   // Convert the stream into sequence of files to process
4355   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4356                                                                             tmpDir.c_str(),
4357                                                                             isMultiFile);
4358   // HOMARD data file name
4359   std::string aFileName = "";
4360   if (isMultiFile)
4361     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4362   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4363
4364   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4365
4366   // save data
4367   // -> create file
4368   std::ifstream f(aFileName.c_str());
4369
4370   // clear context
4371   context._mesCas.clear();
4372   context._mesHypotheses.clear();
4373   context._mesIterations.clear();
4374   context._mesZones.clear();
4375   context._mesBoundarys.clear();
4376   context._idmap.clear();
4377
4378   int id = 1;
4379   std::string line;
4380
4381   while (f) {
4382     std::getline(f, line);
4383     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4384     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4385     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4386     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4387     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4388     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4389     if (line.substr(0, bounSignature.size()) == bounSignature) {
4390       // re-create boundary
4391       MESSAGE ("Recreation de la frontiere" );
4392       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4393       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4394       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4395       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4396         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4397         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4398       }
4399     }
4400     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4401       // re-create case
4402       MESSAGE ("Recreation du cas" );
4403       HOMARD::HOMARD_Cas_var aCase = newCase();
4404       PortableServer::ServantBase_var aServant = GetServant(aCase);
4405       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4406       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4407         context._mesCas[aCase->GetName()] = aCase;
4408         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4409       }
4410     }
4411     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4412       // re-create hypothesis
4413       MESSAGE ("Recreation de l hypothese" );
4414       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4415       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4416       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4417       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4418         context._mesHypotheses[aHypo->GetName()] = aHypo;
4419         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4420       }
4421     }
4422     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4423       // re-create iteration
4424       MESSAGE ("Recreation de l iteration" );
4425       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4426       PortableServer::ServantBase_var aServant = GetServant(aIter);
4427       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4428       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4429         context._mesIterations[aIter->GetName()] = aIter;
4430         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4431       }
4432     }
4433     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4434       MESSAGE ("Recreation de la zone" );
4435       // re-create zone
4436       HOMARD::HOMARD_Zone_var aZone = newZone();
4437       PortableServer::ServantBase_var aServant = GetServant(aZone);
4438       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4439       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4440         context._mesZones[aZone->GetName()] = aZone;
4441         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4442       }
4443     }
4444     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4445       MESSAGE ("Recreation du schema YACS" );
4446       // re-create YACS
4447       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4448       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4449       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4450       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4451         context._mesYACSs[aYACS->GetName()] = aYACS;
4452         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4453       }
4454     }
4455     id++;
4456   }
4457
4458   // -> close file
4459   f.close();
4460
4461   // Remove temporary files created from the stream
4462   if (!isMultiFile)
4463     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4464
4465   return true;
4466 };
4467
4468 //===========================================================================
4469 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4470                                         const SALOMEDS::TMPFile& theStream,
4471                                         const char* theURL,
4472                                         CORBA::Boolean isMultiFile)
4473 {
4474   // No specific ASCII persistence
4475   return Load(theComponent, theStream, theURL, isMultiFile);
4476 };
4477
4478 //===========================================================================
4479 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4480 {
4481   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4482     // clearing study context should be done here:
4483     // - destroy all servants and related CORBA objects
4484     // ... (TODO)
4485     // - remove context from myContextMap
4486     myContextMap.erase(theComponent->GetStudy()->StudyId());
4487     // - nullify myCurrentStudy
4488     myCurrentStudy = SALOMEDS::Study::_nil();
4489   }
4490 };
4491
4492 //===========================================================================
4493 char* HOMARD_Gen_i::ComponentDataType()
4494 {
4495   return CORBA::string_dup("HOMARD");
4496 };
4497
4498 //===========================================================================
4499 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4500                                             const char* IORString,
4501                                             CORBA::Boolean isMultiFile,
4502                                             CORBA::Boolean isASCII)
4503 {
4504   CORBA::String_var aString("");
4505   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4506     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4507     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4508     if (!CORBA::is_nil(anObj)) {
4509       PortableServer::ServantBase_var aServant = GetServant(anObj);
4510       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4511       if (aStorable) {
4512         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4513         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4514           if (it->second == aStorable) {
4515             std::stringstream os;
4516             os << it->first;
4517             aString = CORBA::string_dup(os.str().c_str());
4518           }
4519         }
4520       }
4521     }
4522   }
4523   return aString._retn();
4524 };
4525
4526 //===========================================================================
4527 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4528                                             const char* aLocalPersistentID,
4529                                             CORBA::Boolean isMultiFile,
4530                                             CORBA::Boolean isASCII)
4531 {
4532   CORBA::String_var aString("");
4533   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4534     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4535     int id = atoi(aLocalPersistentID);
4536     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4537       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4538       if (!CORBA::is_nil(object)) {
4539         aString = _orb->object_to_string(object);
4540       }
4541     }
4542   }
4543   return aString._retn();
4544 };
4545
4546 //===========================================================================
4547 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4548 {
4549   if(CORBA::is_nil(myCurrentStudy))
4550     return false;
4551
4552   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4553   if(!aCas->_is_nil())
4554     return true;
4555
4556   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4557   if(!aHypo->_is_nil())
4558     return true;
4559
4560   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4561   if(!aZone->_is_nil())
4562     return true;
4563
4564   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4565   if(!aBoundary->_is_nil())
4566     return true;
4567
4568   /* Iteration is not published directly
4569   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4570   if(!aIter->_is_nil())
4571     return true;
4572   */
4573   return false;
4574 };
4575
4576 //===========================================================================
4577 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4578 {
4579   // No Copy/Paste support
4580   return false;
4581 };
4582
4583 //===========================================================================
4584 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4585                                            CORBA::Long& theObjectID)
4586 {
4587   // No Copy/Paste support
4588   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4589   return aStreamFile._retn();
4590 };
4591
4592 //===========================================================================
4593 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4594                                         CORBA::Long theObjectID)
4595 {
4596   // No Copy/Paste support
4597   return false;
4598 };
4599
4600 //===========================================================================
4601 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4602                                                CORBA::Long theObjectID,
4603                                                SALOMEDS::SObject_ptr theSObject)
4604 {
4605   // No Copy/Paste support
4606   SALOMEDS::SObject_var aResultSO;
4607   return aResultSO._retn();
4608 };
4609
4610 //===========================================================================
4611 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4612 {
4613   PortableServer::Servant aServant = 0;
4614   if (!CORBA::is_nil(theObject)) {
4615     try {
4616       aServant = _poa->reference_to_servant(theObject);
4617     }
4618     catch (...) {
4619     }
4620   }
4621   return aServant;
4622 }
4623
4624 //==========================================================================
4625 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4626                                        CORBA::Boolean isPublished,
4627                                        CORBA::Boolean isMultiFile,
4628                                        CORBA::Boolean& isValidScript)
4629 {
4630    MESSAGE ("Entree dans DumpPython");
4631    isValidScript=1;
4632    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4633    if(CORBA::is_nil(aStudy))
4634      return new Engines::TMPFile(0);
4635
4636    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4637    if(CORBA::is_nil(aSO))
4638       return new Engines::TMPFile(0);
4639
4640    std::string aScript = "\"\"\"\n";
4641    aScript += "Python script for HOMARD\n";
4642    aScript += "Copyright EDF-R&D 2013\n";
4643    aScript += "\"\"\"\n";
4644    aScript += "__revision__ = \"V1.2\"\n";
4645    aScript += "import HOMARD\n";
4646    if( isMultiFile )
4647       aScript += "import salome\n";
4648    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4649    if( isMultiFile ) {
4650       aScript += "def RebuildData(theStudy):\n";
4651       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4652    }
4653    else
4654       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4655    MESSAGE (". Au depart \n"<<aScript);
4656
4657
4658    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4659    {
4660     MESSAGE (". Ecritures des frontieres");
4661     aScript += "#\n# Creation of the boundaries";
4662     aScript +=  "\n# ==========================";
4663    }
4664    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4665    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4666         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4667    {
4668     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4669     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4670     std::string dumpBoundary = dumpCorbaBoundary.in();
4671     MESSAGE (dumpBoundary<<"\n");
4672     aScript += dumpBoundary;
4673    }
4674
4675
4676    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4677    {
4678     MESSAGE (". Ecritures des zones");
4679     aScript += "#\n# Creation of the zones";
4680     aScript +=  "\n# =====================";
4681    }
4682    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4683    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4684          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4685    {
4686     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4687     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4688     std::string dumpZone = dumpCorbaZone.in();
4689     MESSAGE (dumpZone<<"\n");
4690     aScript += dumpZone;
4691    }
4692
4693
4694    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4695    {
4696     MESSAGE (". Ecritures des hypotheses");
4697     aScript += "#\n# Creation of the hypotheses";
4698     aScript +=  "\n# ==========================";
4699    }
4700    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4701    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4702          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4703    {
4704     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4705     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4706     std::string dumpHypo = dumpCorbaHypo.in();
4707     MESSAGE (dumpHypo<<"\n");
4708     aScript += dumpHypo;
4709    }
4710
4711
4712    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4713    {
4714     MESSAGE (". Ecritures des cas");
4715     aScript += "#\n# Creation of the cases";
4716     aScript += "\n# =====================";
4717    }
4718    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4719    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4720         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4721         {
4722            std::string nomCas = (*it_cas).first;
4723            std::string dumpCas = std::string("\n# Creation of the case ") ;
4724            dumpCas +=  nomCas + std::string("\n");
4725            dumpCas += std::string("\t") + nomCas;
4726            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4727
4728            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4729            CORBA::String_var cIter0= myCase->GetIter0Name();
4730            std::string iter0 = cIter0.in();
4731
4732            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4733            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4734            std::string mesh0 = cMesh0.in();
4735            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4736            std::string meshName0 = cMeshName0.in();
4737            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4738            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4739            std::string dumpCas2= dumpCorbaCase.in();
4740
4741            MESSAGE (dumpCas<<dumpCas2<<"\n");
4742            aScript += dumpCas + dumpCas2;
4743         };
4744
4745
4746    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4747    {
4748     MESSAGE (". Ecritures des iterations");
4749     aScript += "#\n# Creation of the iterations" ;
4750     aScript += "\n# ==========================";
4751    }
4752    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4753    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4754         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4755    {
4756     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4757     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4758     std::string dumpIter = dumpCorbaIter.in();
4759     MESSAGE (dumpIter<<"\n");
4760     aScript += dumpIter;
4761    }
4762
4763
4764    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4765    {
4766     MESSAGE (". Ecritures des schemas YACS");
4767     aScript += "#\n# Creation of the schemas YACS";
4768     aScript +=  "\n# ============================";
4769    }
4770    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4771    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4772          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4773    {
4774     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4775     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4776     std::string dumpYACS = dumpCorbaYACS.in();
4777     MESSAGE (dumpYACS<<"\n");
4778     aScript += dumpYACS;
4779    }
4780
4781   MESSAGE (". Ecritures finales");
4782   if( isMultiFile )
4783     aScript += "\n\tpass";
4784   aScript += "\n";
4785
4786   if( !isMultiFile ) // remove unnecessary tabulation
4787     aScript = RemoveTabulation( aScript );
4788
4789 //   MESSAGE ("A ecrire \n"<<aScript);
4790   const size_t aLen = strlen(aScript.c_str());
4791   char* aBuffer = new char[aLen+1];
4792   strcpy(aBuffer, aScript.c_str());
4793
4794   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4795   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4796
4797   MESSAGE ("Sortie de DumpPython");
4798   return aStreamFile._retn();
4799 }
4800
4801
4802 //=============================================================================
4803 //=============================================================================
4804 // Utilitaires
4805 //=============================================================================
4806 //=============================================================================
4807 void HOMARD_Gen_i::IsValidStudy( )
4808 {
4809 //   MESSAGE( "IsValidStudy" );
4810   if (CORBA::is_nil(myCurrentStudy))
4811   {
4812     SALOME::ExceptionStruct es;
4813     es.type = SALOME::BAD_PARAM;
4814     es.text = "Invalid study context";
4815     throw SALOME::SALOME_Exception(es);
4816   };
4817   return ;
4818 }
4819
4820 //=============================================================================
4821 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4822 {
4823   std::string casename = std::string("") ;
4824   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4825   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4826   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4827   {
4828    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4829    {
4830      casename = std::string(it->second->GetName()) ;
4831      break ;
4832    }
4833   }
4834   return CORBA::string_dup( casename.c_str() );
4835 }
4836 /*//=============================================================================
4837 void SALOMEException( std::string message )
4838 {
4839   SALOME::ExceptionStruct es;
4840   es.type = SALOME::BAD_PARAM;
4841   es.text = message;
4842   throw SALOME::SALOME_Exception(es);
4843   return ;
4844 }*/
4845 //=============================================================================
4846 char* HOMARD_Gen_i::getVersion()
4847 {
4848 #if HOMARD_DEVELOPMENT
4849   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4850 #else
4851   return CORBA::string_dup(HOMARD_VERSION_STR);
4852 #endif
4853 }
4854 //===============================================================================
4855 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4856 // ligne : la ligne a manipuler
4857 // texte : le texte a reperer
4858 // option : 0 : la chaine avant le texte
4859 //          1 : la chaine apres le texte
4860 // Si le texte est absent, on retourne la chaine totale
4861 //===============================================================================
4862 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4863 {
4864 //   MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4865 //
4866   std::string chaine = ligne ;
4867   int position = ligne.find_first_of( texte ) ;
4868   if ( position > 0 )
4869   {
4870     if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4871     else               { chaine = ligne.substr( position+1 ) ; }
4872   }
4873   return chaine ;
4874 //
4875 }
4876 // //===============================================================================
4877 // // Langue de SALOME
4878 // //===============================================================================
4879 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4880 {
4881 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4882   _LangueShort = LanguageShort ;
4883   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4884   else                        { _Langue = "English" ; }
4885   return ;
4886 }
4887 char* HOMARD_Gen_i::GetLanguageShort()
4888 {
4889 //   MESSAGE ("GetLanguageShort");
4890   return CORBA::string_dup( _LangueShort.c_str() );
4891 }
4892
4893 //=============================================================================
4894 extern "C"
4895 {
4896   HOMARDENGINE_EXPORT
4897   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4898                                                   PortableServer::POA_ptr poa,
4899                                                   PortableServer::ObjectId* contId,
4900                                                   const char* instanceName,
4901                                                   const char* interfaceName)
4902   {
4903     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4904     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4905     return myHOMARD_Gen->getId();
4906   }
4907 }