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