Salome HOME
Message d'erreur en cas de mauvais répertoire pour le cas en GUI
[modules/homard.git] / src / HOMARD_I / HOMARD_Gen_i.cxx
1 // Copyright (C) 2011-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "HOMARD_Gen_i.hxx"
21 #include "HOMARD_Cas_i.hxx"
22 #include "HOMARD_Hypothesis_i.hxx"
23 #include "HOMARD_Iteration_i.hxx"
24 #include "HOMARD_Boundary_i.hxx"
25 #include "HOMARD_Zone_i.hxx"
26 #include "HOMARD_YACS_i.hxx"
27 #include "HomardDriver.hxx"
28 #include "HOMARD_DriverTools.hxx"
29 #include "HomardMedCommun.h"
30 #include "YACSDriver.hxx"
31 #include "HOMARD.hxx"
32
33 #include "HOMARD_version.h"
34
35 #include "utilities.h"
36 #include "Utils_SINGLETON.hxx"
37 #include "Utils_CorbaException.hxx"
38 #include "SALOMEDS_Tool.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
40 #include "SALOMEconfig.h"
41 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
42 #include CORBA_CLIENT_HEADER(SMESH_Gen)
43
44 #include <cmath>
45 #include <stdlib.h>
46 #include <sys/stat.h>
47 #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     // En mode adaptation, on ajuste l'etat de l'iteration
2383     if ( modeHOMARD == 1 )
2384     {
2385       if (codretexec == 0) { SetEtatIter(NomIteration,2); }
2386       else                 { SetEtatIter(NomIteration,1); }
2387       // GERALD -- QMESSAGE BOX
2388     }
2389   }
2390
2391   // H. Gestion des resultats
2392   if (codret == 0)
2393   {
2394     std::string Commentaire ;
2395     // H.1. Le fichier des messages, dans tous les cas
2396     Commentaire = "log" ;
2397     if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2398     else                   { Commentaire += "Info" ; }
2399     PublishFileUnderIteration(NomIteration, LogFile.c_str(), Commentaire.c_str());
2400
2401     // H.2. Si tout s'est bien passe :
2402     if (codretexec == 0)
2403     {
2404     // H.2.1. Le fichier de bilan
2405       Commentaire = "Summary" ;
2406       if ( modeHOMARD == 1 ) { Commentaire += " " + siterp1 ; }
2407       else                   { Commentaire += "Info" ; }
2408       PublishFileUnderIteration(NomIteration, FileInfo.c_str(), Commentaire.c_str());
2409     // H.2.2. Le fichier de  maillage obtenu
2410       if ( modeHOMARD == 1 )
2411       {
2412         std::stringstream saux0 ;
2413         Commentaire = "Mesh" ;
2414         Commentaire += " " + siterp1 ;
2415         PublishFileUnderIteration(NomIteration, MeshFile, Commentaire.c_str());
2416         if ( Option2 % 2 == 0 ) { PublishResultInSmesh(MeshFile, 1); }
2417       }
2418     }
2419   // H.3 Message d'erreur
2420     if (codretexec != 0)
2421     {
2422       std::string text ;
2423       // Message d'erreur en cas de probleme en adaptation
2424       if ( modeHOMARD == 1 )
2425       {
2426         text = "Error during the adaptation.\n" ;
2427         bool stopvu = false ;
2428         std::ifstream fichier( LogFile.c_str() );
2429         if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
2430         {
2431           std::string ligne; // variable contenant chaque ligne lue
2432           while ( std::getline( fichier, ligne ) )
2433           {
2434 //             INFOS(ligne);
2435             if ( stopvu )
2436             { text += ligne+ "\n"; }
2437             else
2438             {
2439               int position = ligne.find( "===== HOMARD ===== STOP =====" ) ;
2440               if ( position > 0 ) { stopvu = true ; }
2441             }
2442           }
2443         }
2444       }
2445       else
2446       {
2447         text = "Voir le fichier Liste.log.\n" ;
2448       }
2449       INFOS ( text ) ;
2450       SALOME::ExceptionStruct es;
2451       es.type = SALOME::BAD_PARAM;
2452       es.text = CORBA::string_dup(text.c_str());
2453       throw SALOME::SALOME_Exception(es);
2454 //
2455       // En mode information, on force le succes pour pouvoir consulter le fichier log
2456       if ( modeHOMARD != 1 ) { codretexec = 0 ; }
2457     }
2458   }
2459
2460   // I. Menage et retour dans le repertoire du cas
2461   if (codret == 0)
2462   {
2463     delete myDriver;
2464     MESSAGE ( ". On retourne dans nomDirWork = " << nomDirWork );
2465     chdir(nomDirWork.c_str());
2466   }
2467
2468   return codretexec ;
2469 }
2470 //=============================================================================
2471 // Calcul d'une iteration : partie specifique a l'adaptation
2472 //=============================================================================
2473 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)
2474 {
2475   MESSAGE ( "ComputeAdap" );
2476
2477   // A. Prealable
2478   // A.1. Bases
2479   int codret = 0;
2480   // Etat de l'iteration
2481   int etat = myIteration->GetState();
2482   // Numero de l'iteration
2483   int NumeIter = myIteration->GetNumber();
2484   std::stringstream saux0 ;
2485   saux0 << NumeIter-1 ;
2486   std::string siter = saux0.str() ;
2487   if (NumeIter < 11) { siter = "0" + siter ; }
2488
2489   // A.2. On ne calcule pas l iteration initiale
2490   if ( etat <= 0 )
2491   {
2492     MESSAGE ( "etat = "<<etat );
2493     SALOME::ExceptionStruct es;
2494     es.type = SALOME::BAD_PARAM;
2495     es.text = "This iteration is the first of the case and cannot be computed.";
2496     throw SALOME::SALOME_Exception(es);
2497     return 1;
2498   };
2499
2500   // A.3. On verifie qu il y a une hypothese (erreur improbable);
2501   const char* nomHypo = myIteration->GetHypoName();
2502   if (std::string(nomHypo) == std::string(""))
2503   {
2504       SALOME::ExceptionStruct es;
2505       es.type = SALOME::BAD_PARAM;
2506       es.text = "This iteration does not have any associated hypothesis.";
2507       throw SALOME::SALOME_Exception(es);
2508       return 2;
2509   };
2510   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
2511   ASSERT(!CORBA::is_nil(myHypo));
2512
2513   // B. L'iteration parent
2514   const char* nomIterationParent = myIteration->GetIterParentName();
2515   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2516   ASSERT(!CORBA::is_nil(myIterationParent));
2517   // Si l'iteration parent n'est pas calculee, on le fait (recursivite amont)
2518   if ( myIterationParent->GetState() == 1 )
2519   {
2520     int iaux = 1 ;
2521     int codret = Compute(nomIterationParent, etatMenage, iaux, Option1, Option2);
2522     if (codret != 0)
2523     {
2524       // GERALD -- QMESSAGE BOX
2525       VERIFICATION("Pb au calcul de l'iteration precedente" == 0);
2526     }
2527   };
2528
2529   // C. Le sous-repertoire de l'iteration precedente
2530   char* DirComputePa = ComputeDirPaManagement(myCase, myIteration);
2531   MESSAGE( ". DirComputePa = " << DirComputePa );
2532
2533   // D. Les donnees de l'adaptation HOMARD
2534   // D.1. Le type de conformite
2535   int ConfType = myCase->GetConfType();
2536   MESSAGE ( ". ConfType = " << ConfType );
2537
2538   // D.2. Le maillage de depart
2539   const char* NomMeshParent = myIterationParent->GetMeshName();
2540   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
2541   const char* MeshFileParent = myIterationParent->GetMeshFile();
2542   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
2543
2544   // D.3. Le maillage associe a l'iteration
2545   const char* MeshFile = myIteration->GetMeshFile();
2546   MESSAGE ( ". MeshFile = " << MeshFile );
2547   FILE *file = fopen(MeshFile,"r");
2548   if (file != NULL)
2549   {
2550     fclose(file);
2551     if (etatMenage == 0)
2552     {
2553       SALOME::ExceptionStruct es;
2554       es.type = SALOME::BAD_PARAM;
2555       std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
2556       es.text = CORBA::string_dup(text.c_str());
2557       throw SALOME::SALOME_Exception(es);
2558       return 4;
2559     }
2560     else
2561     {
2562       std::string commande = "rm -f " + std::string(MeshFile);
2563       codret = system(commande.c_str());
2564       if (codret != 0)
2565       {
2566         SALOME::ExceptionStruct es;
2567         es.type = SALOME::BAD_PARAM;
2568         es.text = "The mesh file cannot be deleted.";
2569         throw SALOME::SALOME_Exception(es);
2570         return 5;
2571       }
2572     }
2573   }
2574
2575   // D.4. Les types de raffinement et de deraffinement
2576   // Les appels corba sont lourds, il vaut mieux les grouper
2577   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
2578   ASSERT(ListTypes->length() == 3);
2579   int TypeAdap = (*ListTypes)[0];
2580   int TypeRaff = (*ListTypes)[1];
2581   int TypeDera = (*ListTypes)[2];
2582
2583   // E. Texte du fichier de configuration
2584   // E.1. Incontournables du texte
2585   myDriver->TexteAdap();
2586   int iaux = 0 ;
2587   myDriver->TexteMaillageHOMARD( DirComputePa, siter, iaux ) ;
2588   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
2589   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
2590
2591   // E.2. Ajout des informations liees aux zones eventuelles
2592   if ( TypeAdap == 0 )
2593   { DriverTexteZone(myHypo, myDriver) ; }
2594
2595   // E.3. Ajout des informations liees aux champs eventuels
2596   if ( TypeAdap == 1 )
2597   { DriverTexteField(myIteration, myHypo, myDriver) ; }
2598
2599   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
2600   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
2601   int numberOfGroups = listeGroupes->length();
2602   MESSAGE( ". Filtrage par " << numberOfGroups << " groupes");
2603   if (numberOfGroups > 0)
2604   {
2605     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
2606     {
2607       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
2608       MESSAGE( "... GroupName = " << GroupName );
2609       myDriver->TexteGroup(GroupName);
2610     }
2611   }
2612
2613   // E.5. Ajout des informations liees a l'eventuelle interpolation des champs
2614   DriverTexteFieldInterp(myIteration, myHypo, myDriver) ;
2615
2616   // E.6. Ajout des options avancees
2617   int Pyram = myCase->GetPyram();
2618   MESSAGE ( ". Pyram = " << Pyram );
2619   int NivMax = myHypo->GetNivMax();
2620   MESSAGE ( ". NivMax = " << NivMax );
2621   double DiamMin = myHypo->GetDiamMin() ;
2622   MESSAGE ( ". DiamMin = " << DiamMin );
2623   int AdapInit = myHypo->GetAdapInit();
2624   MESSAGE ( ". AdapInit = " << AdapInit );
2625   int LevelOutput = myHypo->GetLevelOutput();
2626   MESSAGE ( ". LevelOutput = " << LevelOutput );
2627   myDriver->TexteAdvanced(Pyram, NivMax, DiamMin, AdapInit, LevelOutput);
2628
2629   // E.7. Ajout des informations sur le deroulement de l'execution
2630   int MessInfo = myIteration->GetInfoCompute();
2631   MESSAGE ( ". MessInfo = " << MessInfo );
2632   myDriver->TexteInfoCompute(MessInfo);
2633
2634   return codret ;
2635 }
2636 //=============================================================================
2637 // Creation d'un nom de sous-repertoire pour l'iteration au sein d'un repertoire parent
2638 //  nomrep : nom du repertoire parent
2639 //  num : le nom du sous-repertoire est sous la forme 'In', n est >= num
2640 //=============================================================================
2641 char* HOMARD_Gen_i::CreateDirNameIter(const char* nomrep, CORBA::Long num )
2642 {
2643   MESSAGE ( "CreateDirNameIter : nomrep ="<< nomrep << ", num = "<<num);
2644   // On verifie que le repertoire parent existe
2645   int codret = chdir(nomrep) ;
2646   if ( codret != 0 )
2647   {
2648     SALOME::ExceptionStruct es;
2649     es.type = SALOME::BAD_PARAM;
2650     es.text = "The directory of the case does not exist.";
2651     throw SALOME::SALOME_Exception(es);
2652     return 0;
2653   };
2654   std::string nomDirActuel = getenv("PWD") ;
2655   std::string DirName ;
2656   // On boucle sur tous les noms possibles jusqu'a trouver un nom correspondant a un repertoire inconnu
2657   bool a_chercher = true ;
2658   while ( a_chercher )
2659   {
2660     // On passe dans le repertoire parent
2661     chdir(nomrep);
2662     // On recherche un nom sous la forme Iabc, avec abc representant le numero
2663     int jaux ;
2664     if      ( num <    100 ) { jaux = 2 ; }
2665     else if ( num <   1000 ) { jaux = 3 ; }
2666     else if ( num <  10000 ) { jaux = 4 ; }
2667     else if ( num < 100000 ) { jaux = 5 ; }
2668     else                     { jaux = 9 ; }
2669     std::ostringstream iaux ;
2670     iaux << std::setw(jaux) << std::setfill('0') << num ;
2671     std::ostringstream DirNameA ;
2672     DirNameA << "I" << iaux.str();
2673     // Si on ne pas peut entrer dans le repertoire, on doit verifier
2674     // que c'est bien un probleme d'absence
2675     if ( chdir(DirNameA.str().c_str()) != 0 )
2676     {
2677       bool existe = false ;
2678       DIR *dp;
2679       struct dirent *dirp;
2680       dp  = opendir(nomrep);
2681       while ( (dirp = readdir(dp)) != NULL )
2682       {
2683         std::string file_name(dirp->d_name);
2684         if ( file_name == DirNameA.str() ) { existe = true ; }
2685       }
2686       closedir(dp);
2687       if ( not existe )
2688       {
2689         DirName = DirNameA.str() ;
2690         a_chercher = false ;
2691         break ;
2692       }
2693     }
2694     num += 1;
2695   }
2696
2697   MESSAGE ( "==> DirName = " << DirName);
2698   MESSAGE ( ". On retourne dans nomDirActuel = " << nomDirActuel );
2699   chdir(nomDirActuel.c_str());
2700
2701   return CORBA::string_dup( DirName.c_str() );
2702 }
2703 //=============================================================================
2704 // Calcul d'une iteration : gestion du repertoire de calcul
2705 //        Si le sous-repertoire existe :
2706 //         etatMenage =  0 : on sort en erreur si le repertoire n'est pas vide
2707 //         etatMenage =  1 : on fait le menage du repertoire
2708 //         etatMenage = -1 : on ne fait rien
2709 //=============================================================================
2710 char* HOMARD_Gen_i::ComputeDirManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration, CORBA::Long etatMenage)
2711 {
2712   MESSAGE ( "ComputeDirManagement : repertoires pour le calcul" );
2713   // B.2. Le repertoire du cas
2714   const char* nomDirCase = myCase->GetDirName();
2715   MESSAGE ( ". nomDirCase = " << nomDirCase );
2716
2717   // B.3. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
2718   // B.3.1. Le nom du sous-repertoire
2719   const char* nomDirIt = myIteration->GetDirNameLoc();
2720
2721   // B.3.2. Le nom complet du sous-repertoire
2722   std::stringstream DirCompute ;
2723   DirCompute << nomDirCase << "/" << nomDirIt;
2724   MESSAGE (". DirCompute = " << DirCompute.str() );
2725
2726   // B.3.3. Si le sous-repertoire n'existe pas, on le cree
2727   if (chdir(DirCompute.str().c_str()) != 0)
2728   {
2729 //  Creation du repertoire car il n'existe pas :
2730     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
2731     {
2732        // GERALD -- QMESSAGE BOX
2733        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
2734        VERIFICATION("Pb a la creation du repertoire" == 0);
2735     }
2736   }
2737   else
2738   {
2739 //  Le repertoire existe
2740 //  On demande de faire le menage de son contenu :
2741     if (etatMenage == 1)
2742     {
2743       MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
2744       std::string commande = "rm -rf " + DirCompute.str()+"/*" ;
2745       int codret = system(commande.c_str());
2746       if (codret != 0)
2747       {
2748         // GERALD -- QMESSAGE BOX
2749         std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
2750         VERIFICATION("Pb au menage du repertoire de calcul" == 0);
2751       }
2752     }
2753 //  On n'a pas demande de faire le menage de son contenu : on sort en erreur :
2754     else
2755     {
2756       if (etatMenage == 0)
2757       {
2758         DIR *dp;
2759         struct dirent *dirp;
2760         dp  = opendir(DirCompute.str().c_str());
2761         bool result = true;
2762         while ((dirp = readdir(dp)) != NULL && result )
2763         {
2764           std::string file_name(dirp->d_name);
2765           result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
2766         }
2767         closedir(dp);
2768         if ( result == false)
2769         {
2770           SALOME::ExceptionStruct es;
2771           es.type = SALOME::BAD_PARAM;
2772           std::string text = "Directory : " + DirCompute.str() + "is not empty";
2773           es.text = CORBA::string_dup(text.c_str());
2774           throw SALOME::SALOME_Exception(es);
2775           VERIFICATION("Directory is not empty" == 0);
2776         }
2777       }
2778     }
2779   }
2780
2781   return CORBA::string_dup( DirCompute.str().c_str() );
2782 }
2783 //=============================================================================
2784 // Calcul d'une iteration : gestion du repertoire de calcul de l'iteration parent
2785 //=============================================================================
2786 char* HOMARD_Gen_i::ComputeDirPaManagement(HOMARD::HOMARD_Cas_var myCase, HOMARD::HOMARD_Iteration_var myIteration)
2787 {
2788   MESSAGE ( "ComputeDirPaManagement : repertoires pour le calcul" );
2789   // Le repertoire du cas
2790   const char* nomDirCase = myCase->GetDirName();
2791   MESSAGE ( ". nomDirCase = " << nomDirCase );
2792
2793   // Le sous-repertoire de l'iteration precedente
2794
2795   const char* nomIterationParent = myIteration->GetIterParentName();
2796   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
2797   const char* nomDirItPa = myIterationParent->GetDirNameLoc();
2798   std::stringstream DirComputePa ;
2799   DirComputePa << nomDirCase << "/" << nomDirItPa;
2800   MESSAGE( ". nomDirItPa = " << nomDirItPa);
2801   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
2802
2803   return CORBA::string_dup( DirComputePa.str().c_str() );
2804 }
2805 //=============================================================================
2806 // Calcul d'une iteration : ecriture des zones dans le fichier de configuration
2807 //=============================================================================
2808 void HOMARD_Gen_i::DriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2809 {
2810   MESSAGE ( "... DriverTexteZone" );
2811   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
2812   int numberOfZonesx2 = ListZone->length();
2813   int NumZone ;
2814
2815   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
2816   {
2817     std::string ZoneName = std::string((*ListZone)[iaux]);
2818     MESSAGE ( "... ZoneName = " << ZoneName);
2819     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
2820     ASSERT(!CORBA::is_nil(myZone));
2821
2822     int ZoneType = myZone->GetType();
2823     std::string TypeUsestr = std::string((*ListZone)[iaux+1]);
2824     int TypeUse = atoi( TypeUsestr.c_str() );
2825     MESSAGE ( "... ZoneType = " << ZoneType << ", TypeUse = "<<TypeUse);
2826     NumZone = iaux/2 + 1 ;
2827     HOMARD::double_array* zone = myZone->GetCoords();
2828     if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
2829     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.); }
2830     else if ( ZoneType == 4 ) // Cas d une sphere
2831     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.); }
2832     else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
2833     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.); }
2834     else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
2835     { myDriver->TexteZone(NumZone, ZoneType, TypeUse, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]); }
2836     else { VERIFICATION("ZoneType est incorrect." == 0) ; }
2837     iaux += 1 ;
2838   }
2839   return ;
2840 }
2841 //=============================================================================
2842 // Calcul d'une iteration : ecriture des champs dans le fichier de configuration
2843 //=============================================================================
2844 void HOMARD_Gen_i::DriverTexteField(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
2845 {
2846   MESSAGE ( "... DriverTexteField" );
2847 //  Le fichier du champ
2848   char* FieldFile = myIteration->GetFieldFile();
2849   MESSAGE ( ". FieldFile = " << FieldFile );
2850   if (strlen(FieldFile) == 0)
2851   {
2852     // GERALD -- QMESSAGE BOX
2853     std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
2854     VERIFICATION("The file for the field is not given." == 0);
2855   }
2856 //  Les caracteristiques d'instants du champ de pilotage
2857   int TimeStep = myIteration->GetTimeStep();
2858   MESSAGE( ". TimeStep = " << TimeStep );
2859   int Rank = myIteration->GetRank();
2860   MESSAGE( ". Rank = " << Rank );
2861 //  Les informations sur les champs
2862   HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
2863 //  Le nom
2864   const char* FieldName = aInfosHypo->FieldName;
2865 //  Les seuils
2866   int TypeThR = aInfosHypo->TypeThR;
2867   double ThreshR = aInfosHypo->ThreshR;
2868   int TypeThC = aInfosHypo->TypeThC;
2869   double ThreshC = aInfosHypo->ThreshC;
2870 //  Saut entre mailles ou non ?
2871   int UsField = aInfosHypo->UsField;
2872   MESSAGE( ". UsField = " << UsField );
2873 //  L'usage des composantes
2874   int UsCmpI = aInfosHypo->UsCmpI;
2875   MESSAGE( ". UsCmpI = " << UsCmpI );
2876 //
2877   myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
2878 //
2879 //  Les composantes
2880   HOMARD::listeComposantsHypo* mescompo = myHypo->GetComps();
2881   int numberOfCompos = mescompo->length();
2882   MESSAGE( ". numberOfCompos = " << numberOfCompos );
2883   for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
2884   {
2885     std::string nomCompo = std::string((*mescompo)[NumeComp]);
2886     MESSAGE( "... nomCompo = " << nomCompo );
2887     myDriver->TexteCompo(NumeComp, nomCompo);
2888   }
2889   return ;
2890 }
2891 //=============================================================================
2892 // Calcul d'une iteration : ecriture des frontieres dans le fichier de configuration
2893 // On ecrit dans l'ordre :
2894 //    1. la definition des frontieres
2895 //    2. les liens avec les groupes
2896 //    3. un entier resumant le type de comportement pour les frontieres
2897 //=============================================================================
2898 void HOMARD_Gen_i::DriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, HomardDriver* myDriver)
2899 {
2900   MESSAGE ( "... DriverTexteBoundary" );
2901   // 1. Recuperation des frontieres
2902   std::list<std::string>  ListeBoundaryTraitees ;
2903   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
2904   int numberOfitems = ListBoundaryGroupType->length();
2905   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
2906   int BoundaryOption = 1 ;
2907   // 2. Parcours des frontieres pour ecrire leur description
2908   int NumBoundaryAnalytical = 0 ;
2909   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2910   {
2911     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2912     MESSAGE ( "... BoundaryName = " << BoundaryName);
2913     // 2.1. La frontiere a-t-elle deja ete ecrite ?
2914     //      Cela arrive quand elle estliéé a plusieurs groupes. Il ne faut l'ecrire que la premiere fois
2915     int A_faire = 1 ;
2916     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
2917     while (it != ListeBoundaryTraitees.end())
2918     {
2919       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
2920       if ( BoundaryName == *it ) { A_faire = 0 ; }
2921       it++;
2922     }
2923     // 2.2. Ecriture de la frontiere
2924     if ( A_faire == 1 )
2925     {
2926       // 2.2.1. Caracteristiques de la frontiere
2927       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2928       ASSERT(!CORBA::is_nil(myBoundary));
2929       int BoundaryType = myBoundary->GetType();
2930       MESSAGE ( "... BoundaryType = " << BoundaryType );
2931       // 2.2.2. Ecriture selon le type
2932       // 2.2.2.1. Cas d une frontiere discrete
2933       if (BoundaryType == 0)
2934       {
2935         const char* MeshName = myBoundary->GetMeshName() ;
2936         const char* MeshFile = myBoundary->GetMeshFile() ;
2937         myDriver->TexteBoundaryDi( MeshName, MeshFile);
2938         if ( BoundaryOption % 2 != 0 ) { BoundaryOption = BoundaryOption*2 ; }
2939       }
2940       // 2.2.2.1. Cas d une frontiere analytique
2941       else
2942       {
2943         NumBoundaryAnalytical++ ;
2944         HOMARD::double_array* coor = myBoundary->GetCoords();
2945         if (BoundaryType == 1) // Cas d un cylindre
2946         {
2947           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2948           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2949         }
2950         else if (BoundaryType == 2) // Cas d une sphere
2951         {
2952           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0., 0.);
2953           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2954         }
2955         else if (BoundaryType == 3) // Cas d un cone defini par un axe et un angle
2956         {
2957           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], 0.);
2958           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2959         }
2960         else if (BoundaryType == 4) // Cas d un cone defini par les 2 rayons
2961         {
2962           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6], (*coor)[7]);
2963           if ( BoundaryOption % 3 != 0 ) { BoundaryOption = BoundaryOption*3 ; }
2964         }
2965       }
2966       // 2.2.3. Memorisation du traitement
2967       ListeBoundaryTraitees.push_back( BoundaryName );
2968     }
2969   }
2970   // 3. Parcours des frontieres pour ecrire les liens avec les groupes
2971   NumBoundaryAnalytical = 0 ;
2972   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
2973   {
2974     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
2975     MESSAGE ( "... BoundaryName = " << BoundaryName);
2976     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
2977     ASSERT(!CORBA::is_nil(myBoundary));
2978     int BoundaryType = myBoundary->GetType();
2979     MESSAGE ( "... BoundaryType = " << BoundaryType );
2980     // 3.1. Recuperation du nom du groupe
2981     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
2982     MESSAGE ( "... GroupName = " << GroupName);
2983     // 3.2. Cas d une frontiere discrete
2984     if ( BoundaryType == 0 )
2985     {
2986       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
2987     }
2988     // 3.3. Cas d une frontiere analytique
2989     else
2990     {
2991       NumBoundaryAnalytical++ ;
2992       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
2993     }
2994   }
2995   // 4. Ecriture de l'option finale
2996   myDriver->TexteBoundaryOption(BoundaryOption);
2997 //
2998   return ;
2999 }
3000 //=============================================================================
3001 // Calcul d'une iteration : ecriture des interpolations dans le fichier de configuration
3002 //=============================================================================
3003 void HOMARD_Gen_i::DriverTexteFieldInterp(HOMARD::HOMARD_Iteration_var myIteration, HOMARD::HOMARD_Hypothesis_var myHypo, HomardDriver* myDriver)
3004 {
3005   MESSAGE ( "... DriverTexteFieldInterp" );
3006   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
3007   MESSAGE ( "... TypeFieldInterp = " << TypeFieldInterp);
3008   if (TypeFieldInterp != 0)
3009   {
3010 //  Le fichier des champs
3011     char* FieldFile = myIteration->GetFieldFile();
3012     MESSAGE ( ". FieldFile = " << FieldFile );
3013     if (strlen(FieldFile) == 0)
3014     {
3015       // GERALD -- QMESSAGE BOX
3016       VERIFICATION("The file for the field is not given." == 0);
3017     }
3018   //
3019     const char* MeshFile = myIteration->GetMeshFile();
3020     myDriver->TexteFieldInterp(FieldFile, MeshFile);
3021
3022   // Les champs
3023   // Interpolation de tous les champs
3024     if ( TypeFieldInterp == 1 )
3025     {
3026       myDriver->TexteFieldInterpAll();
3027     }
3028   // Interpolation de certains champs
3029     else if (TypeFieldInterp == 2)
3030     {
3031       // Les champs et leurs instants pour l'iteration
3032       HOMARD::listeFieldInterpTSRsIter* ListFieldTSR = myIteration->GetFieldInterpsTimeStepRank();
3033       int numberOfFieldsx3 = ListFieldTSR->length();
3034       MESSAGE( ". pour iteration, numberOfFields = " << numberOfFieldsx3/3 );
3035       // Les champs pour l'hypothese
3036       HOMARD::listeFieldInterpsHypo* ListField = myHypo->GetFieldInterps();
3037       int numberOfFieldsx2 = ListField->length();
3038       MESSAGE( ". pour hypothese, numberOfFields = " << numberOfFieldsx2/2 );
3039       // On parcourt tous les champs de  l'hypothese
3040       int NumField = 0 ;
3041       for (int iaux = 0; iaux< numberOfFieldsx2; iaux++)
3042       {
3043         // Le nom du champ
3044         std::string FieldName = std::string((*ListField)[iaux]) ;
3045         // Le type d'interpolation
3046         std::string TypeInterpstr = std::string((*ListField)[iaux+1]) ;
3047         MESSAGE( "... FieldName = " << FieldName << ", TypeInterp = " << TypeInterpstr );
3048         // On cherche à savoir si des instants ont été précisés pour cette itération
3049         int tsrvu = 0;
3050         for (int jaux = 0; jaux< numberOfFieldsx3; jaux++)
3051         {
3052         // Le nom du champ
3053           std::string FieldName2 = std::string((*ListFieldTSR)[jaux]) ;
3054           MESSAGE( "..... FieldName2 = " << FieldName2 );
3055         // Quand c'est le bon champ, on ecrit le pas de temps
3056           if ( FieldName == FieldName2 )
3057           {
3058             tsrvu = 1 ;
3059             // Le pas de temps
3060             std::string TimeStepstr = std::string((*ListFieldTSR)[jaux+1]) ;
3061             // Le numero d'ordre
3062             std::string Rankstr = std::string((*ListFieldTSR)[jaux+2]) ;
3063             MESSAGE( "..... TimeStepstr = " << TimeStepstr <<", Rankstr = "<<Rankstr );
3064             NumField += 1 ;
3065             int TimeStep = atoi( TimeStepstr.c_str() );
3066             int Rank = atoi( Rankstr.c_str() );
3067             myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, TimeStep, Rank);
3068           }
3069           jaux += 2 ;
3070         }
3071         // Si aucun instant n'a été défini
3072         if ( tsrvu == 0 )
3073         {
3074           NumField += 1 ;
3075           myDriver->TexteFieldInterpNameType(NumField, FieldName, TypeInterpstr, -1, -1);
3076         }
3077         iaux++ ;
3078       }
3079     }
3080   }
3081   return ;
3082 }
3083 //===========================================================================
3084 //===========================================================================
3085
3086
3087 //===========================================================================
3088 //===========================================================================
3089 // Publications
3090 //===========================================================================
3091 //===========================================================================
3092 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
3093                                                    SALOMEDS::SObject_ptr theSObject,
3094                                                    CORBA::Object_ptr theObject,
3095                                                    const char* theName)
3096 {
3097   MESSAGE("PublishInStudy pour " << theName);
3098   SALOMEDS::SObject_var aResultSO;
3099   if (CORBA::is_nil(theStudy))
3100   {
3101     SALOME::ExceptionStruct es;
3102     es.type = SALOME::BAD_PARAM;
3103     es.text = "Invalid study context";
3104     throw SALOME::SALOME_Exception(es);
3105     return 0;
3106   };
3107
3108 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
3109 // Rq : Iteration est publiee ailleurs
3110   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
3111   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
3112   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
3113   HOMARD::HOMARD_YACS_var       aYACS = HOMARD::HOMARD_YACS::_narrow(theObject);
3114   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
3115
3116    addInStudy(theStudy);
3117
3118 // Controle de la non publication d'un objet de meme nom
3119    if ( (!aBoundary->_is_nil()) or (!aHypo->_is_nil()) or (!aYACS->_is_nil()) or (!aZone->_is_nil()) )
3120   {
3121     SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
3122     if (listSO->length() >= 1)
3123     {
3124       MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
3125       aResultSO = listSO[0];
3126       return aResultSO._retn();
3127     }
3128   }
3129
3130   // Caracteristiques de l'etude
3131   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
3132   aStudyBuilder->NewCommand();
3133   if(!aBoundary->_is_nil())
3134     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
3135   else if(!aCase->_is_nil())
3136     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
3137   else if(!aHypo->_is_nil())
3138     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
3139   else if(!aYACS->_is_nil())
3140     aResultSO = PublishYACSInStudy(theStudy, aStudyBuilder, aYACS, theName);
3141   else if(!aZone->_is_nil())
3142     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
3143
3144   aStudyBuilder->CommitCommand();
3145
3146   return aResultSO._retn();
3147 };
3148 //=============================================================================
3149 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
3150                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3151                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
3152 {
3153   MESSAGE("PublishBoundaryStudy pour "<<theName);
3154   SALOMEDS::SObject_var aResultSO;
3155
3156   // Caracteristique de la Boundary
3157   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
3158
3159   // On recupere le module pere dans l etude
3160   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
3161   if (theFatherHomard->_is_nil())
3162   {
3163     MESSAGE("theFatherHomard->_is_nil()");
3164     return aResultSO._retn();
3165   }
3166
3167   // On ajoute la categorie des boundarys dans l etude si necessaire
3168   if ( _tag_boun == 0 )
3169   {
3170     _tag_gene += 1 ;
3171     _tag_boun = _tag_gene ;
3172   }
3173   MESSAGE("PublishBoundaryInStudy _tag_gene = "<<_tag_gene << ", _tag_boun = "<<_tag_boun );
3174   SALOMEDS::SObject_var aSObject;
3175   if (!theFatherHomard->FindSubObject(_tag_boun, aSObject))
3176   {
3177     MESSAGE("Ajout de la categorie des boundarys");
3178     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_boun);
3179     PublishInStudyAttr(aStudyBuilder, aSObject, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
3180   }
3181   else { MESSAGE("La categorie des boundarys existe deja."); }
3182
3183   CORBA::Long BoundaryType = myBoundary->GetType();
3184 //   MESSAGE("BoundaryType : "<<BoundaryType);
3185   std::string icone ;
3186   std::string value ;
3187   switch (BoundaryType)
3188   {
3189     case 0 :
3190     { value = "BoundaryDiHomard" ;
3191       icone = "mesh_tree_mesh.png" ;
3192       break;
3193     }
3194     case 1 :
3195     { value = "BoundaryAnHomard" ;
3196       icone = "cylinderpointvector_2.png" ;
3197       break;
3198     }
3199     case 2 :
3200     { value = "BoundaryAnHomard" ;
3201       icone = "spherepoint_2.png" ;
3202       break;
3203     }
3204     case 3 :
3205     { value = "BoundaryAnHomard" ;
3206       icone = "conepointvector.png" ;
3207       break;
3208     }
3209     case 4 :
3210     { value = "BoundaryAnHomard" ;
3211       icone = "conedxyz.png" ;
3212       break;
3213     }
3214   }
3215   aResultSO = aStudyBuilder->NewObject(aSObject);
3216   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value.c_str(), icone.c_str(), _orb->object_to_string(theObject));
3217   return aResultSO._retn();
3218 }
3219 //=============================================================================
3220 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
3221                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
3222                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
3223 {
3224   MESSAGE("PublishCaseInStudy pour "<<theName);
3225   SALOMEDS::SObject_var aResultSO;
3226
3227   if (CORBA::is_nil(theObject)) {
3228     MESSAGE("HOMARD_Gen_i::theObject->_is_nil()");
3229     return aResultSO._retn();
3230   }
3231   if (theStudy->_is_nil()) {
3232     MESSAGE("HOMARD_Gen_i::theStudy->_is_nil()");
3233     return aResultSO._retn();
3234   }
3235
3236   // On recupere le module pere dans l etude
3237   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3238   if (theFatherHomard->_is_nil())
3239   {
3240     MESSAGE("theFatherHomard->_is_nil()");
3241     return aResultSO._retn();
3242   }
3243
3244   _tag_gene += 1 ;
3245   MESSAGE("PublishCaseInStudy _tag_gene = "<<_tag_gene );
3246   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
3247   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
3248                      _orb->object_to_string(theObject) ) ;
3249
3250   return aResultSO._retn();
3251 }
3252 //=============================================================================
3253 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
3254                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3255                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
3256 {
3257   MESSAGE("PublishHypotheseInStudy pour "<<theName);
3258   SALOMEDS::SObject_var aResultSO;
3259
3260   // On recupere le module pere dans l etude
3261   // On ajoute la categorie des hypotheses dans l etude si necessaire
3262   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3263   if (theFatherHomard->_is_nil())
3264   {
3265     MESSAGE("theFatherHomard->_is_nil()");
3266     return aResultSO._retn();
3267   }
3268
3269   // On ajoute la categorie des hypotheses dans l etude si necessaire
3270   SALOMEDS::SObject_var aSObject;
3271   if ( _tag_hypo == 0 )
3272   {
3273     _tag_gene += 1 ;
3274     _tag_hypo = _tag_gene ;
3275   }
3276   MESSAGE("PublishHypotheseInStudy _tag_gene = "<<_tag_gene << ", _tag_hypo = "<<_tag_hypo );
3277   if (!theFatherHomard->FindSubObject(_tag_hypo, aSObject))
3278   {
3279     MESSAGE("Ajout de la categorie des hypotheses");
3280     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_hypo);
3281     PublishInStudyAttr(aStudyBuilder, aSObject, "Hypothesis", "HypoList", "hypotheses.png", NULL);
3282   }
3283   else { MESSAGE("La categorie des hypotheses existe deja."); }
3284
3285 // Creation du resultat dans l'etude
3286   aResultSO = aStudyBuilder->NewObject(aSObject);
3287   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
3288
3289   return aResultSO._retn();
3290 }
3291 //=============================================================================
3292 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishYACSInStudy(SALOMEDS::Study_ptr theStudy,
3293                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3294                    HOMARD::HOMARD_YACS_ptr theObject, const char* theName)
3295 {
3296   MESSAGE("PublishYACSInStudy pour "<<theName);
3297   SALOMEDS::SObject_var aResultSO;
3298
3299   // On recupere le module pere dans l etude
3300   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3301   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3302   if (theFatherHomard->_is_nil())
3303   {
3304     MESSAGE("theFatherHomard->_is_nil()");
3305     return aResultSO._retn();
3306   }
3307   // On ajoute la categorie des schemas YACS dans l etude si necessaire
3308   if ( _tag_yacs == 0 )
3309   {
3310     _tag_gene += 1 ;
3311     _tag_yacs = _tag_gene ;
3312   }
3313   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_yacs = "<<_tag_yacs );
3314   SALOMEDS::SObject_var aSObject;
3315   if (!theFatherHomard->FindSubObject(_tag_yacs, aSObject))
3316   {
3317     MESSAGE("Ajout de la categorie des schemas YACS");
3318     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_yacs);
3319     PublishInStudyAttr(aStudyBuilder, aSObject, "YACS", "YACSList", "full_view.png", NULL);
3320   }
3321   else { MESSAGE("La categorie des schemas YACS existe deja."); }
3322
3323 // Creation du resultat dans l'etude
3324   aResultSO = aStudyBuilder->NewObject(aSObject);
3325   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "YACSHomard", "schema.png", _orb->object_to_string(theObject) ) ;
3326
3327   return aResultSO._retn();
3328 }
3329
3330 //=============================================================================
3331 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
3332                    SALOMEDS::StudyBuilder_var aStudyBuilder,
3333                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
3334 {
3335   MESSAGE("PublishZoneStudy pour "<<theName);
3336   SALOMEDS::SObject_var aResultSO;
3337   if (CORBA::is_nil(theObject))
3338   {
3339     MESSAGE("PublishZoneInStudy : theObject->_is_nil()");
3340     return aResultSO._retn();
3341   }
3342   if (theStudy->_is_nil())
3343   {
3344     MESSAGE("PublishZoneInStudy : theStudy->_is_nil()");
3345     return aResultSO._retn();
3346   }
3347   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
3348   if (theFatherHomard->_is_nil())
3349   {
3350     MESSAGE("PublishZoneInStudy : theFatherHomard->_is_nil()");
3351     return aResultSO._retn();
3352   }
3353
3354   // Caracteristique de la zone
3355   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
3356   CORBA::Long ZoneType = myZone->GetType();
3357
3358   // On ajoute la categorie des zones dans l etude si necessaire
3359   if ( _tag_zone == 0 )
3360   {
3361     _tag_gene += 1 ;
3362     _tag_zone = _tag_gene ;
3363   }
3364   MESSAGE("PublishZoneStudy _tag_gene = "<<_tag_gene << ", _tag_zone = "<<_tag_zone );
3365   SALOMEDS::SObject_var aSObject;
3366   if (!theFatherHomard->FindSubObject(_tag_zone, aSObject))
3367   {
3368     MESSAGE("Ajout de la categorie des zones");
3369     aSObject = aStudyBuilder->NewObjectToTag(theFatherHomard, _tag_zone);
3370     PublishInStudyAttr(aStudyBuilder, aSObject, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
3371   }
3372   else { MESSAGE("La categorie des zones existe deja."); }
3373
3374   aResultSO = aStudyBuilder->NewObject(aSObject);
3375   std::string icone ;
3376   switch (ZoneType)
3377   {
3378     case 11 :
3379     { }
3380     case 12 :
3381     { }
3382     case 13 :
3383     { icone = "boxdxy_2.png" ;
3384       break ;
3385     }
3386     case 2 :
3387     { icone = "boxdxyz_2.png" ;
3388       break ;
3389     }
3390     case 31 :
3391     { }
3392     case 32 :
3393     { }
3394     case 33 :
3395     { icone = "disk_2.png" ;
3396       break ;
3397      }
3398     case 4 :
3399     { icone = "spherepoint_2.png" ;
3400       break ;
3401     }
3402     case 5 :
3403     { icone = "cylinderpointvector_2.png" ;
3404       break ;
3405     }
3406     case 61 :
3407     { }
3408     case 62 :
3409     { }
3410     case 63 :
3411     { icone = "diskwithhole_2.png" ;
3412       break ;
3413      }
3414     case 7 :
3415     { icone = "pipe_2.png" ;
3416       break ;
3417     }
3418   }
3419   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone.c_str(), _orb->object_to_string(theObject) ) ;
3420
3421   return aResultSO._retn();
3422 }
3423 //===========================================================================
3424 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
3425                                       SALOMEDS::SObject_var aResultSO,
3426                                       const char* name, const char* comment, const char* icone, const char* ior)
3427 {
3428   MESSAGE("PublishInStudyAttr pour name = "<<name<<", comment = "<<comment);
3429 //   MESSAGE("icone = "<<icone);
3430 //   MESSAGE("ior   = "<<ior);
3431   SALOMEDS::GenericAttribute_var anAttr ;
3432 //  Ajout du nom
3433   if ( name != NULL )
3434   {
3435     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
3436     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
3437     aNameAttrib->SetValue(name);
3438   }
3439
3440 //  Ajout du commentaire
3441   if ( comment != NULL )
3442   {
3443     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
3444     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
3445     aCommentAttrib->SetValue(comment);
3446   }
3447
3448 //  Ajout de l'icone
3449   if ( icone != NULL  )
3450   {
3451     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
3452     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
3453     aPixmap->SetPixMap(icone);
3454   }
3455
3456 //  Ajout de l ior
3457   if ( ior != NULL  )
3458   {
3459     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
3460     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3461     anIOR->SetValue(ior);
3462   }
3463 };
3464
3465 //=====================================================================================
3466 void HOMARD_Gen_i::PublishBoundaryUnderCase(const char* CaseName, const char* BoundaryName)
3467 {
3468   MESSAGE ( "PublishBoundaryUnderCase : CaseName = " << CaseName << ", BoundaryName= " << BoundaryName );
3469
3470   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3471   ASSERT(!CORBA::is_nil(myCase));
3472   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3473   ASSERT(!CORBA::is_nil(aCaseSO));
3474
3475   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
3476   ASSERT(!CORBA::is_nil(myBoundary));
3477   SALOMEDS::SObject_var aBoundarySO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myBoundary)));
3478   ASSERT(!CORBA::is_nil(aBoundarySO));
3479
3480   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3481
3482   aStudyBuilder->NewCommand();
3483
3484   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aCaseSO);
3485   aStudyBuilder->Addreference(aSubSO, aBoundarySO);
3486
3487   aStudyBuilder->CommitCommand();
3488
3489 };
3490 //=====================================================================================
3491 void HOMARD_Gen_i::PublishCaseUnderYACS(const char* nomYACS, const char* CaseName)
3492 {
3493   MESSAGE ( "PublishCaseUnderYACS : nomYACS = " << nomYACS << ", CaseName= " << CaseName );
3494
3495   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3496   ASSERT(!CORBA::is_nil(myYACS));
3497   SALOMEDS::SObject_var aYACSSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3498   ASSERT(!CORBA::is_nil(aYACSSO));
3499
3500   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[CaseName];
3501   ASSERT(!CORBA::is_nil(myCase));
3502   SALOMEDS::SObject_var aCaseSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
3503   ASSERT(!CORBA::is_nil(aCaseSO));
3504
3505   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3506
3507   aStudyBuilder->NewCommand();
3508
3509   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3510   aStudyBuilder->Addreference(aSubSO, aCaseSO);
3511
3512   aStudyBuilder->CommitCommand();
3513
3514 };
3515 //=============================================================================
3516 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long Option)
3517 //  Option = 0 : fichier issu d'une importation
3518 //  Option = 1 : fichier issu d'une execution HOMARD
3519 {
3520   MESSAGE( "PublishResultInSmesh " << NomFich << ", avec Option = " << Option);
3521   if (CORBA::is_nil(myCurrentStudy))
3522   {
3523     SALOME::ExceptionStruct es;
3524     es.type = SALOME::BAD_PARAM;
3525     es.text = "Invalid study context";
3526     throw SALOME::SALOME_Exception(es);
3527     return ;
3528   };
3529
3530 // Le module SMESH est-il actif ?
3531   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3532 //
3533   if (!CORBA::is_nil(aSmeshSO))
3534   {
3535 // On verifie que le fichier n est pas deja publie
3536     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3537     for (; aIter->More(); aIter->Next())
3538     {
3539       SALOMEDS::SObject_var  aSO = aIter->Value();
3540       SALOMEDS::GenericAttribute_var aGAttr;
3541       if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3542       {
3543         SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3544         CORBA::String_var value=anAttr->Value();
3545         if (strcmp((const char*)value,NomFich) == 0)
3546         {
3547           MESSAGE ( "PublishResultInSmesh : le fichier " << NomFich << " est deja publie." );
3548           // Pour un fichier importe, on ne republie pas
3549           if ( Option == 0 )
3550           {
3551             return;
3552           }
3553           // Pour un fichier calcule, on commence par faire la depublication
3554           else
3555           {
3556             MESSAGE ( "PublishResultInSmesh : depublication" );
3557             SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3558             CORBA::String_var value2=anAttr2->Value();
3559             std::string MeshName = string(value2) ;
3560             MESSAGE ( "PublishResultInSmesh : depublication de " << MeshName );
3561             DeleteResultInSmesh(NomFich, MeshName) ;
3562           }
3563         }
3564       }
3565     }
3566   }
3567
3568 // On enregistre le fichier
3569   MESSAGE( "Enregistrement du fichier");
3570   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
3571   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
3572   ASSERT(!CORBA::is_nil(aSmeshEngine));
3573   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
3574   SMESH::DriverMED_ReadStatus theStatus;
3575   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3576
3577 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
3578   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
3579   for (int i = 0; i < mesMaillages->length();  i++)
3580   {
3581     MESSAGE( ". Mise a jour des attributs du maillage");
3582     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
3583     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
3584     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3585     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
3586     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3587     anAttr->SetValue(NomFich);
3588     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
3589     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
3590     const char* icone ;
3591     if ( Option == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
3592     else               { icone = "mesh_tree_mesh.png" ; }
3593     anAttr2->SetPixMap( icone );
3594   }
3595
3596 }
3597 //=============================================================================
3598 void HOMARD_Gen_i::DeleteResultInSmesh(std::string NomFich, std::string MeshName)
3599 {
3600   MESSAGE ("DeleteResultInSmesh pour le maillage " << MeshName << " dans le fichier " << NomFich );
3601   if (CORBA::is_nil(myCurrentStudy))
3602   {
3603       SALOME::ExceptionStruct es;
3604       es.type = SALOME::BAD_PARAM;
3605       es.text = "Invalid study context";
3606       throw SALOME::SALOME_Exception(es);
3607       return ;
3608   };
3609
3610 // Le module SMESH est-il actif ?
3611   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
3612 //
3613   if (CORBA::is_nil(aSmeshSO))
3614   {
3615       return ;
3616   };
3617 // On verifie que le fichier est deja publie
3618   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
3619   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
3620   for (; aIter->More(); aIter->Next())
3621   {
3622      SALOMEDS::SObject_var  aSO = aIter->Value();
3623      SALOMEDS::GenericAttribute_var aGAttr;
3624      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
3625      {
3626        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
3627        CORBA::String_var value=anAttr->Value();
3628        if (strcmp((const char*)value,NomFich.c_str()) == 0)
3629        {
3630          if (aSO->FindAttribute(aGAttr,"AttributeName"))
3631          {
3632            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
3633            CORBA::String_var value2=anAttr2->Value();
3634            if (strcmp((const char*)value2,MeshName.c_str()) == 0)
3635            {
3636              myBuilder->RemoveObjectWithChildren( aSO ) ;
3637            }
3638          }
3639        }
3640      }
3641   }
3642   return ;
3643 }
3644 //=============================================================================
3645 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
3646 {
3647 //   MESSAGE ("PublishFileUnderIteration pour l'iteration " << NomIter << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3648   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
3649
3650   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
3651   if (CORBA::is_nil(myIteration))
3652   {
3653       SALOME::ExceptionStruct es;
3654       es.type = SALOME::BAD_PARAM;
3655       es.text = "Invalid iterationStudy Object";
3656       throw SALOME::SALOME_Exception(es);
3657       return ;
3658   };
3659
3660   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3661
3662   aStudyBuilder->NewCommand();
3663
3664   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
3665 // Pour les fichiers med, on affiche une icone de maillage
3666 // Pour les fichiers qui sont du texte, on affiche une icone de fichier texte 'texte'
3667 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
3668   std::string icone ;
3669   std::string ior = " " ;
3670   if ( Commentaire[0] == 'I' )
3671   { icone = "med.png" ; }
3672   else
3673   { icone = "texte_2.png" ; }
3674   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3675
3676   aStudyBuilder->CommitCommand();
3677 }
3678 //
3679 //=============================================================================
3680 void HOMARD_Gen_i::PublishFileUnderYACS(const char* nomYACS, const char* NomFich, const char* Commentaire)
3681 {
3682 //   MESSAGE ("PublishFileUnderYACS pour le schema " << nomYACS << " du fichier " << NomFich << " avec le commentaire " << Commentaire );
3683   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3684
3685   SALOMEDS::SObject_var aYACSSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myYACS)));
3686   if (CORBA::is_nil(myYACS))
3687   {
3688       SALOME::ExceptionStruct es;
3689       es.type = SALOME::BAD_PARAM;
3690       es.text = "Invalid YACSStudy Object";
3691       throw SALOME::SALOME_Exception(es);
3692       return ;
3693   };
3694
3695   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
3696
3697   aStudyBuilder->NewCommand();
3698
3699   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aYACSSO);
3700   std::string icone = "texte_2.png" ;
3701   std::string ior = " " ;
3702   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone.c_str(), ior.c_str() ) ;
3703
3704   aStudyBuilder->CommitCommand();
3705 }
3706 //
3707 //=============================================================================
3708 //=============================================================================
3709 // YACS
3710 //=============================================================================
3711 //=============================================================================
3712 //=============================================================================
3713 // Creation d'un schema YACS
3714 // nomCas : nom du cas a traiter
3715 // FileName : nom du fichier contenant le script de lancement du calcul
3716 // DirName : le repertoire de lancement des calculs du schéma
3717 //=============================================================================
3718 HOMARD::HOMARD_YACS_ptr HOMARD_Gen_i::CreateYACSSchema (const char* nomYACS, const char* nomCas, const char* ScriptFile, const char* DirName, const char* MeshFile)
3719 {
3720   INFOS ( "CreateYACSSchema : Schema YACS " << nomYACS );
3721   INFOS ( ". nomCas     : " << nomCas);
3722   INFOS ( ". ScriptFile : " << ScriptFile);
3723   INFOS ( ". DirName    : " << DirName);
3724   INFOS ( ". MeshFile   : " << MeshFile);
3725
3726   // A. Controle du nom :
3727   if ((myContextMap[GetCurrentStudyID()]._mesYACSs).find(nomYACS) != (myContextMap[GetCurrentStudyID()]._mesYACSs).end())
3728   {
3729     SALOME::ExceptionStruct es;
3730     es.type = SALOME::BAD_PARAM;
3731     es.text = "This schema YACS has already been defined.";
3732     throw SALOME::SALOME_Exception(es);
3733     return 0;
3734   }
3735
3736   // B. Creation de l'objet
3737   HOMARD::HOMARD_YACS_var myYACS = newYACS();
3738   if (CORBA::is_nil(myYACS))
3739   {
3740     SALOME::ExceptionStruct es;
3741     es.type = SALOME::BAD_PARAM;
3742     es.text = "Unable to create the schema YACS";
3743     throw SALOME::SALOME_Exception(es);
3744     return 0;
3745   };
3746   myYACS->SetName( nomYACS ) ;
3747
3748   // C. Enregistrement
3749   myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS] = myYACS;
3750
3751   SALOMEDS::SObject_var aSO;
3752   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myYACS, nomYACS);
3753
3754   PublishCaseUnderYACS(nomYACS, nomCas);
3755
3756   // D. Caracterisation
3757   // D.1. Options
3758   myYACS->SetDirName( DirName ) ;
3759   myYACS->SetMeshFile( MeshFile ) ;
3760   myYACS->SetScriptFile( ScriptFile ) ;
3761   myYACS->SetCaseName( nomCas ) ;
3762   // D.2. Defaut
3763   // D.2.1. Type constant
3764   myYACS->SetType( 1 ) ;
3765   // D.2.2. Fichier de sauvegarde dans le repertoire du cas
3766   HOMARD::HOMARD_Cas_ptr caseyacs = GetCase(nomCas) ;
3767   std::string dirnamecase = caseyacs->GetDirName() ;
3768   std::string XMLFile ;
3769   XMLFile = dirnamecase + "/schema.xml" ;
3770   myYACS->SetXMLFile( XMLFile.c_str() ) ;
3771
3772   return HOMARD::HOMARD_YACS::_duplicate(myYACS);
3773 }
3774 //=============================================================================
3775 // Ecriture d'un schema YACS
3776 //=============================================================================
3777 CORBA::Long HOMARD_Gen_i::YACSWrite(const char* nomYACS)
3778 {
3779   INFOS ( "YACSWrite : Ecriture de " << nomYACS );
3780 // Le repertoire du cas
3781   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3782   ASSERT(!CORBA::is_nil(myYACS));
3783 // Le nom du fichier du schema
3784   std::string XMLFile ;
3785   XMLFile = myYACS->GetXMLFile() ;
3786
3787   int codret = YACSWriteOnFile(nomYACS, XMLFile.c_str()) ;
3788
3789   return codret ;
3790 }
3791 //=============================================================================
3792 // Ecriture d'un schema YACS sur un fichier donne
3793 //=============================================================================
3794 CORBA::Long HOMARD_Gen_i::YACSWriteOnFile(const char* nomYACS, const char* XMLFile)
3795 {
3796   INFOS ( "YACSWriteOnFile : Ecriture de " << nomYACS << " sur " << XMLFile );
3797
3798   // A. Prealable
3799   int codret = 0;
3800
3801   // B. L'objet YACS
3802   // B.1. L'objet
3803   HOMARD::HOMARD_YACS_var myYACS = myContextMap[GetCurrentStudyID()]._mesYACSs[nomYACS];
3804   ASSERT(!CORBA::is_nil(myYACS));
3805   // B.2. Les caracteristiques
3806   std::string DirName = myYACS->GetDirName() ;
3807   std::string MeshFile = myYACS->GetMeshFile() ;
3808   std::string ScriptFile = myYACS->GetScriptFile() ;
3809
3810   // C. Le cas
3811   // C.1. L'objet cas
3812   const char* nomCas = myYACS->GetCaseName();
3813   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
3814   ASSERT(!CORBA::is_nil(myCase));
3815   // C.2. Les instructions python associees au cas
3816   CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
3817   std::string pythonCas = dumpCorbaCase.in();
3818   MESSAGE ("pythonCas :\n"<<pythonCas<<"\n");
3819
3820   // D. Les iterations
3821   // D.1. L'iteration initiale
3822   HOMARD::HOMARD_Iteration_var Iter0 = myCase->GetIter0() ;
3823   std::string Iter0Name = myCase->GetIter0Name() ;
3824   MESSAGE (". Iter0Name = " << Iter0Name);
3825   std::string MeshName = Iter0->GetMeshName();
3826   MESSAGE (". MeshName = " << MeshName);
3827   // D.2. L'iteration numero 1
3828   HOMARD::listeIterFilles* maListe = Iter0->GetIterations();
3829   int numberOfIter = maListe->length();
3830   if ( numberOfIter > 1 )
3831   {
3832     MESSAGE (". numberOfIter = " << numberOfIter);
3833     SALOME::ExceptionStruct es ;
3834     es.type = SALOME::BAD_PARAM;
3835     std::string text = "Une seule iteration est permise." ;
3836     es.text = CORBA::string_dup(text.c_str());
3837     throw SALOME::SALOME_Exception(es);
3838     return 0;
3839   }
3840   std::string Iter1Name = std::string((*maListe)[0]);
3841   MESSAGE ("... Iter1Name = " << Iter1Name);
3842   HOMARD::HOMARD_Iteration_var Iter1 = GetIteration(Iter1Name.c_str()) ;
3843   // D.3. Les instructions python associees a l'iteration
3844   CORBA::String_var dumpCorbaIter = Iter1->GetDumpPython();
3845   std::string pythonIter = dumpCorbaIter.in();
3846   MESSAGE ("pythonIter :\n"<<pythonIter<<"\n");
3847
3848   // E. L'hypothese pour passer de l'iteration initiale a la suivante
3849   // E.1. La structure
3850   std::string nomHypo = Iter1->GetHypoName();
3851   MESSAGE (". nomHypo = " << nomHypo);
3852   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
3853   ASSERT(!CORBA::is_nil(myHypo));
3854   // E.2. Les caracteristiques de l'adaptation
3855   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
3856   ASSERT(ListTypes->length() == 3);
3857   int TypeAdap = (*ListTypes)[0];
3858 //   int TypeRaff = (*ListTypes)[1];
3859 //   int TypeDera = (*ListTypes)[2];
3860   // E.3. Les instructions python associees a l'hypothese
3861   CORBA::String_var dumpCorbaHypo = myHypo->GetDumpPython();
3862   std::string pythonHypo = dumpCorbaHypo.in();
3863   MESSAGE ("pythonHypo :\n"<<pythonHypo<<"\n");
3864
3865   // F. Le fichier du schema de reference
3866   // HOMARD_ROOT_DIR : repertoire ou se trouve le module HOMARD
3867   std::string XMLFile_base ;
3868   if ( getenv("HOMARD_ROOT_DIR") != NULL ) { XMLFile_base = getenv("HOMARD_ROOT_DIR") ; }
3869   else
3870   {
3871     SALOME::ExceptionStruct es ;
3872     es.type = SALOME::BAD_PARAM;
3873     std::string text = "HOMARD_ROOT_DIR est inconnu." ;
3874     es.text = CORBA::string_dup(text.c_str());
3875     throw SALOME::SALOME_Exception(es);
3876     return 0;
3877   }
3878   XMLFile_base += "/share/salome/resources/homard/yacs_01." + _LangueShort + ".xml" ;
3879 //   if ( _Langue ==
3880   MESSAGE("XMLFile_base ="<<XMLFile_base);
3881
3882   // G. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3883   YACSDriver* myDriver = new YACSDriver(XMLFile, DirName);
3884   std::ifstream fichier( XMLFile_base.c_str() );
3885   if ( fichier ) // ce test échoue si le fichier n'est pas ouvert
3886   {
3887     // G.1. Lecture du schema de reference et insertion des donnees propres au fil de la rencontre des mots-cles
3888     std::string ligne; // variable contenant chaque ligne lue
3889     std::string mot_cle;
3890     while ( std::getline( fichier, ligne ) )
3891     {
3892       // G.1.1. Pour la ligne courante, on identifie le premier mot : le mot-cle eventuel
3893       std::istringstream ligne_bis(ligne); // variable contenant chaque ligne sous forme de flux
3894       ligne_bis >> mot_cle ;
3895       // G.1.2. Le maillage initial
3896       if ( mot_cle == "DataInit_MeshFile" )
3897       { myDriver->Texte_DataInit_MeshFile(MeshFile); }
3898       // G.1.3. Le script de lancement
3899       else if ( mot_cle == "Alternance_Calcul_HOMARD_Calcul" )
3900       { myDriver->Texte_Alternance_Calcul_HOMARD_Calcul(ScriptFile); }
3901       // G.1.4. Les options du cas
3902       else if ( mot_cle == "Iter_1_Case_Options" )
3903       { myDriver->Texte_Iter_1_Case_Options(pythonCas); }
3904       // G.1.5. Execution de HOMARD : le repertoire du cas
3905       else if ( mot_cle == "HOMARD_Exec_DirName" )
3906       { myDriver->Texte_HOMARD_Exec_DirName(); }
3907       // G.1.6. Execution de HOMARD : le nom du maillage
3908       else if ( mot_cle == "HOMARD_Exec_MeshName" )
3909       {
3910         myDriver->Texte_HOMARD_Exec_MeshName(MeshName);
3911         std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1.CreateCase" ;
3912         myDriver->TexteParametre( node, "MeshName", "string", MeshName ) ;
3913       }
3914       // G.1.7. Execution de HOMARD : les options de l'hypothese
3915       else if ( mot_cle == "HOMARD_Exec_Hypo_Options" )
3916       { myDriver->Texte_python_1( pythonHypo, 3, "Hypo" ) ;  }
3917       // G.1.8. Execution de HOMARD : les options de l'iteration
3918       else if ( mot_cle == "HOMARD_Exec_Iter_Options" )
3919       { myDriver->Texte_python_2( pythonIter, "TimeStep", "Iter" ) ;  }
3920       // G.1.9. Zones et frontieres : les creations
3921       else if ( mot_cle == "Iter_1" )
3922       {
3923         std::string texte_control = myDriver->Texte_Iter_1_control() ;
3924         if ( TypeAdap == 0 ) { texte_control += YACSDriverTexteZone( myHypo, myDriver ) ; }
3925         texte_control += YACSDriverTexteBoundary( myCase, myDriver ) ;
3926         myDriver->TexteAdd(texte_control);
3927       }
3928       // G.1.10. Les parametres
3929       else if ( mot_cle == "PARAMETRES" )
3930       { myDriver->TexteAddParametres(); }
3931       // G.1.n. La ligne est recopiee telle quelle
3932       else { myDriver->TexteAdd(ligne);  }
3933     }
3934     // G.2. Ecriture du texte dans le fichier
3935     if ( codret == 0 )
3936     { myDriver->CreeFichier(); }
3937   }
3938   else
3939   {
3940     SALOME::ExceptionStruct es;
3941     es.type = SALOME::BAD_PARAM;
3942     std::string text = "The reference file for the YACS schema cannot be read." ;
3943     es.text = CORBA::string_dup(text.c_str());
3944     throw SALOME::SALOME_Exception(es);
3945   }
3946
3947   delete myDriver;
3948
3949   // H. Publication du fichier dans l'arbre
3950
3951     std::string Commentaire = "xml" ;
3952     PublishFileUnderYACS(nomYACS, XMLFile, Commentaire.c_str());
3953
3954   return codret ;
3955 }
3956 //=============================================================================
3957 // Ecriture d'un schema YACS : ecriture des zones associees a une hypothese
3958 //=============================================================================
3959 std::string HOMARD_Gen_i::YACSDriverTexteZone(HOMARD::HOMARD_Hypothesis_var myHypo, YACSDriver* myDriver)
3960 {
3961   MESSAGE ( "YACSDriverTexteZone" );
3962   // A. Les zones associees a cette hypothese
3963   HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
3964   int numberOfZonesx2 = ListZone->length();
3965
3966   // B. Parcours des zones
3967   std::string texte_control ;
3968   for (int iaux = 0; iaux< numberOfZonesx2; iaux++)
3969   {
3970     // 1. Reperage de la zone
3971     std::string ZoneName = std::string((*ListZone)[iaux]);
3972     MESSAGE ( "\n. ZoneName = " << ZoneName << " - " <<iaux);
3973     HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
3974     ASSERT(!CORBA::is_nil(myZone));
3975     // 2. Les instructions python associees a la zone
3976     //    La premiere ligne est un commentaire a eliminer
3977     //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
3978     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
3979     std::string pythonStructure_0 = dumpCorbaZone.in();
3980     MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
3981     std::istringstream tout (pythonStructure_0) ;
3982     std::string ligne ;
3983     std::string pythonStructure ;
3984     while ( std::getline( tout, ligne ) )
3985     { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
3986     MESSAGE ("pythonStructure :\n"<<pythonStructure);
3987     // 3. Decodage du nom du service
3988     std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
3989     MESSAGE ( "... methode = " << methode);
3990     // 4. Mise en place des instructions
3991     int ZoneType = myZone->GetType();
3992     MESSAGE ( "... ZoneType = " << ZoneType);
3993     std::string texte_control_0 ;
3994     texte_control_0 = myDriver->Texte_Iter_1_Zone(ZoneType, pythonStructure, methode, ZoneName );
3995     texte_control += texte_control_0 ;
3996     // 5. Decalage
3997     iaux += 1 ;
3998   }
3999
4000   return texte_control ;
4001 }
4002 //=============================================================================
4003 // Ecriture d'un schema YACS : ecriture des frontieres associees au cas
4004 //=============================================================================
4005 std::string HOMARD_Gen_i::YACSDriverTexteBoundary(HOMARD::HOMARD_Cas_var myCase, YACSDriver* myDriver)
4006 {
4007   MESSAGE ( "YACSDriverTexteBoundary" );
4008   // A. Les frontieres associees au cas
4009   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
4010   int numberOfitems = ListBoundaryGroupType->length();
4011
4012   // B. Parcours des frontieres
4013   std::string texte_control ;
4014   std::list<std::string>  ListeBoundaryTraitees ;
4015   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
4016   {
4017     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
4018     MESSAGE ( "... BoundaryName = " << BoundaryName);
4019     // Attention a n'ecrire la definition qu'une seule fois car elle peut se trouver
4020     // plusieurs fois dans la definition du cas, d'ou la liste ListeBoundaryTraitees
4021     int A_faire = 1 ;
4022     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
4023     while (it != ListeBoundaryTraitees.end())
4024     {
4025       MESSAGE ( "..... BoundaryNameTraitee = " << *it);
4026       if ( BoundaryName == *it ) { A_faire = 0 ; }
4027       it++;
4028     }
4029     if ( A_faire == 1 )
4030     {
4031     // 1. Caracteristiques de la frontiere
4032       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
4033       ASSERT(!CORBA::is_nil(myBoundary));
4034       // 2. Les instructions python associees a la frontiere
4035       //    La premiere ligne est un commentaire a eliminer
4036       //    La seconde ligne est l'instruction a proprement parler ; on ne garde que ce qui suit le "."
4037       CORBA::String_var dumpCorbaBoundary = myBoundary->GetDumpPython();
4038       std::string pythonStructure_0 = dumpCorbaBoundary.in();
4039       MESSAGE ("pythonStructure_0 :"<<pythonStructure_0);
4040       std::istringstream tout (pythonStructure_0) ;
4041       std::string ligne ;
4042       std::string pythonStructure ;
4043       while ( std::getline( tout, ligne ) )
4044       { pythonStructure = GetStringInTexte ( ligne, ".", 1 ) ; }
4045       MESSAGE ("pythonStructure :\n"<<pythonStructure);
4046       // 3. Decodage du nom du service
4047       std::string methode = GetStringInTexte ( pythonStructure, "(", 0 ) ;
4048       MESSAGE ( "... methode = " << methode);
4049       // 4. Mise en place des instructions
4050       int BoundaryType = myBoundary->GetType();
4051       MESSAGE ( "... BoundaryType = " << BoundaryType);
4052       std::string texte_control_0 ;
4053       texte_control_0 = myDriver->Texte_Iter_1_Boundary(BoundaryType, pythonStructure, methode, BoundaryName );
4054       texte_control += texte_control_0 ;
4055       // 5. Memorisation du traitement
4056       ListeBoundaryTraitees.push_back( BoundaryName );
4057     }
4058   }
4059
4060   return texte_control ;
4061 }
4062 //
4063 //=============================================================================
4064 //=============================================================================
4065 // Next functions are inherited from SALOMEDS::Driver interface
4066 //=============================================================================
4067 //=============================================================================
4068 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
4069                                       const char* theURL,
4070                                       CORBA::Boolean isMultiFile)
4071 {
4072   MESSAGE ("Save for theURL = "<< theURL);
4073   SALOMEDS::TMPFile_var aStreamFile;
4074
4075   // get temporary directory name
4076   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4077
4078   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4079   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4080
4081   // HOMARD data file name
4082   std::string aFileName = "";
4083   if (isMultiFile)
4084     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4085   aFileName += "_HOMARD.dat";
4086
4087   // initialize sequence of file names
4088   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
4089   aFileSeq->length(1);
4090   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
4091
4092   // get full path to the data file
4093   aFileName = tmpDir + aFileName;
4094
4095   // save data
4096   // -> create file
4097   std::ofstream f(aFileName.c_str());
4098
4099   // clear temporary id map
4100   context._idmap.clear();
4101
4102   int id = 1;
4103
4104   // -> save cases
4105   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
4106   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
4107     HOMARD::HOMARD_Cas_var aCas = it_case->second;
4108     PortableServer::ServantBase_var aServant = GetServant(aCas);
4109     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4110     if (aCasServant) {
4111       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
4112       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
4113     }
4114   }
4115   // -> save zones
4116   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4117   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
4118     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
4119     PortableServer::ServantBase_var aServant = GetServant(aZone);
4120     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4121     if (aZoneServant) {
4122       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
4123       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4124     }
4125   }
4126   // -> save hypotheses
4127   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4128   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
4129     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
4130     PortableServer::ServantBase_var aServant = GetServant(aHypo);
4131     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4132     if (aHypoServant) {
4133       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
4134       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4135     }
4136   }
4137   // -> save iterations
4138   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4139   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
4140     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
4141     PortableServer::ServantBase_var aServant = GetServant(aIter);
4142     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4143     if (aIterServant) {
4144       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
4145       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4146     }
4147   }
4148   // -> save boundaries
4149   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4150   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
4151     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
4152     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4153     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4154     if (aBoundaryServant) {
4155       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
4156       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4157     }
4158   }
4159   // -> close file
4160   MESSAGE ("close file");
4161   f.close();
4162
4163   // put temporary files to the stream
4164   MESSAGE ("put temporary files to the stream");
4165   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
4166
4167   // remove temporary files
4168   MESSAGE ("remove temporary files");
4169   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4170
4171   // return data stream
4172   MESSAGE ("return data stream");
4173   return aStreamFile._retn();
4174 };
4175
4176 //===========================================================================
4177 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
4178                                            const char* theURL,
4179                                            CORBA::Boolean isMultiFile)
4180 {
4181   // No specific ASCII persistence
4182   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
4183   return aStreamFile._retn();
4184 };
4185
4186 //===========================================================================
4187 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
4188                                    const SALOMEDS::TMPFile& theStream,
4189                                    const char* theURL,
4190                                    CORBA::Boolean isMultiFile)
4191 {
4192   MESSAGE ("Load pour theURL = "<< theURL);
4193   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
4194
4195   // set current study
4196   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
4197     SetCurrentStudy(aStudy);
4198
4199   // get temporary directory name
4200   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
4201
4202   // Convert the stream into sequence of files to process
4203   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
4204                                                                             tmpDir.c_str(),
4205                                                                             isMultiFile);
4206   // HOMARD data file name
4207   std::string aFileName = "";
4208   if (isMultiFile)
4209     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
4210   aFileName = tmpDir + aFileName + "_HOMARD.dat";
4211
4212   StudyContext& context = myContextMap[ aStudy->StudyId() ];
4213
4214   // save data
4215   // -> create file
4216   std::ifstream f(aFileName.c_str());
4217
4218   // clear context
4219   context._mesCas.clear();
4220   context._mesHypotheses.clear();
4221   context._mesIterations.clear();
4222   context._mesZones.clear();
4223   context._mesBoundarys.clear();
4224   context._idmap.clear();
4225
4226   int id = 1;
4227   std::string line;
4228
4229   while (f) {
4230     std::getline(f, line);
4231     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
4232     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
4233     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
4234     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
4235     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
4236     std::string yacsSignature = HOMARD::GetSignature(HOMARD::YACS);
4237     if (line.substr(0, bounSignature.size()) == bounSignature) {
4238       // re-create boundary
4239       MESSAGE ("Recreation de la frontiere" );
4240       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
4241       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
4242       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
4243       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
4244         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
4245         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
4246       }
4247     }
4248     else if (line.substr(0, caseSignature.size()) == caseSignature) {
4249       // re-create case
4250       MESSAGE ("Recreation du cas" );
4251       HOMARD::HOMARD_Cas_var aCase = newCase();
4252       PortableServer::ServantBase_var aServant = GetServant(aCase);
4253       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
4254       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
4255         context._mesCas[aCase->GetName()] = aCase;
4256         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
4257       }
4258     }
4259     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
4260       // re-create hypothesis
4261       MESSAGE ("Recreation de l hypothese" );
4262       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
4263       PortableServer::ServantBase_var aServant = GetServant(aHypo);
4264       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
4265       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
4266         context._mesHypotheses[aHypo->GetName()] = aHypo;
4267         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
4268       }
4269     }
4270     else if (line.substr(0, iterSignature.size()) == iterSignature) {
4271       // re-create iteration
4272       MESSAGE ("Recreation de l iteration" );
4273       HOMARD::HOMARD_Iteration_var aIter = newIteration();
4274       PortableServer::ServantBase_var aServant = GetServant(aIter);
4275       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
4276       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
4277         context._mesIterations[aIter->GetName()] = aIter;
4278         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
4279       }
4280     }
4281     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
4282       MESSAGE ("Recreation de la zone" );
4283       // re-create zone
4284       HOMARD::HOMARD_Zone_var aZone = newZone();
4285       PortableServer::ServantBase_var aServant = GetServant(aZone);
4286       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
4287       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
4288         context._mesZones[aZone->GetName()] = aZone;
4289         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
4290       }
4291     }
4292     else if (line.substr(0, zoneSignature.size()) == yacsSignature) {
4293       MESSAGE ("Recreation du schema YACS" );
4294       // re-create YACS
4295       HOMARD::HOMARD_YACS_var aYACS = newYACS();
4296       PortableServer::ServantBase_var aServant = GetServant(aYACS);
4297       HOMARD_YACS_i* aYACSServant = dynamic_cast<HOMARD_YACS_i*>(aServant.in());
4298       if (aYACSServant && aYACSServant->Restore(line.substr(yacsSignature.size()))) {
4299         context._mesYACSs[aYACS->GetName()] = aYACS;
4300         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aYACSServant);
4301       }
4302     }
4303     id++;
4304   }
4305
4306   // -> close file
4307   f.close();
4308
4309   // Remove temporary files created from the stream
4310   if (!isMultiFile)
4311     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
4312
4313   return true;
4314 };
4315
4316 //===========================================================================
4317 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
4318                                         const SALOMEDS::TMPFile& theStream,
4319                                         const char* theURL,
4320                                         CORBA::Boolean isMultiFile)
4321 {
4322   // No specific ASCII persistence
4323   return Load(theComponent, theStream, theURL, isMultiFile);
4324 };
4325
4326 //===========================================================================
4327 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
4328 {
4329   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
4330     // clearing study context should be done here:
4331     // - destroy all servants and related CORBA objects
4332     // ... (TODO)
4333     // - remove context from myContextMap
4334     myContextMap.erase(theComponent->GetStudy()->StudyId());
4335     // - nullify myCurrentStudy
4336     myCurrentStudy = SALOMEDS::Study::_nil();
4337   }
4338 };
4339
4340 //===========================================================================
4341 char* HOMARD_Gen_i::ComponentDataType()
4342 {
4343   return CORBA::string_dup("HOMARD");
4344 };
4345
4346 //===========================================================================
4347 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
4348                                             const char* IORString,
4349                                             CORBA::Boolean isMultiFile,
4350                                             CORBA::Boolean isASCII)
4351 {
4352   CORBA::String_var aString("");
4353   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
4354     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4355     CORBA::Object_var anObj = _orb->string_to_object(IORString);
4356     if (!CORBA::is_nil(anObj)) {
4357       PortableServer::ServantBase_var aServant = GetServant(anObj);
4358       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
4359       if (aStorable) {
4360         std::map<int, PortableServer::ServantBase*>::const_iterator it;
4361         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
4362           if (it->second == aStorable) {
4363             std::stringstream os;
4364             os << it->first;
4365             aString = CORBA::string_dup(os.str().c_str());
4366           }
4367         }
4368       }
4369     }
4370   }
4371   return aString._retn();
4372 };
4373
4374 //===========================================================================
4375 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
4376                                             const char* aLocalPersistentID,
4377                                             CORBA::Boolean isMultiFile,
4378                                             CORBA::Boolean isASCII)
4379 {
4380   CORBA::String_var aString("");
4381   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
4382     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
4383     int id = atoi(aLocalPersistentID);
4384     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
4385       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
4386       if (!CORBA::is_nil(object)) {
4387         aString = _orb->object_to_string(object);
4388       }
4389     }
4390   }
4391   return aString._retn();
4392 };
4393
4394 //===========================================================================
4395 CORBA::Boolean HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
4396 {
4397   if(CORBA::is_nil(myCurrentStudy))
4398     return false;
4399
4400   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
4401   if(!aCas->_is_nil())
4402     return true;
4403
4404   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
4405   if(!aHypo->_is_nil())
4406     return true;
4407
4408   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
4409   if(!aZone->_is_nil())
4410     return true;
4411
4412   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
4413   if(!aBoundary->_is_nil())
4414     return true;
4415
4416   /* Iteration is not published directly
4417   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
4418   if(!aIter->_is_nil())
4419     return true;
4420   */
4421   return false;
4422 };
4423
4424 //===========================================================================
4425 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
4426 {
4427   // No Copy/Paste support
4428   return false;
4429 };
4430
4431 //===========================================================================
4432 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
4433                                            CORBA::Long& theObjectID)
4434 {
4435   // No Copy/Paste support
4436   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
4437   return aStreamFile._retn();
4438 };
4439
4440 //===========================================================================
4441 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
4442                                         CORBA::Long theObjectID)
4443 {
4444   // No Copy/Paste support
4445   return false;
4446 };
4447
4448 //===========================================================================
4449 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
4450                                                CORBA::Long theObjectID,
4451                                                SALOMEDS::SObject_ptr theSObject)
4452 {
4453   // No Copy/Paste support
4454   SALOMEDS::SObject_var aResultSO;
4455   return aResultSO._retn();
4456 };
4457
4458 //===========================================================================
4459 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
4460 {
4461   PortableServer::Servant aServant = 0;
4462   if (!CORBA::is_nil(theObject)) {
4463     try {
4464       aServant = _poa->reference_to_servant(theObject);
4465     }
4466     catch (...) {
4467     }
4468   }
4469   return aServant;
4470 }
4471
4472 //==========================================================================
4473 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
4474                                        CORBA::Boolean isPublished,
4475                                        CORBA::Boolean isMultiFile,
4476                                        CORBA::Boolean& isValidScript)
4477 {
4478    MESSAGE ("Entree dans DumpPython");
4479    isValidScript=1;
4480    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
4481    if(CORBA::is_nil(aStudy))
4482      return new Engines::TMPFile(0);
4483
4484    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
4485    if(CORBA::is_nil(aSO))
4486       return new Engines::TMPFile(0);
4487
4488    std::string aScript = "\"\"\"\n";
4489    aScript += "Python script for HOMARD\n";
4490    aScript += "Copyright EDF-R&D 2013\n";
4491    aScript += "\"\"\"\n";
4492    aScript += "__revision__ = \"V1.2\"\n";
4493    aScript += "import HOMARD\n";
4494    if( isMultiFile )
4495       aScript += "import salome\n";
4496    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
4497    if( isMultiFile ) {
4498       aScript += "def RebuildData(theStudy):\n";
4499       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
4500    }
4501    else
4502       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
4503    MESSAGE (". Au depart \n"<<aScript);
4504
4505
4506    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
4507    {
4508     MESSAGE (". Ecritures des frontieres");
4509     aScript += "#\n# Creation of the boundaries";
4510     aScript +=  "\n# ==========================";
4511    }
4512    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
4513    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
4514         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
4515    {
4516     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
4517     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
4518     std::string dumpBoundary = dumpCorbaBoundary.in();
4519     MESSAGE (dumpBoundary<<"\n");
4520     aScript += dumpBoundary;
4521    }
4522
4523
4524    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
4525    {
4526     MESSAGE (". Ecritures des zones");
4527     aScript += "#\n# Creation of the zones";
4528     aScript +=  "\n# =====================";
4529    }
4530    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
4531    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
4532          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
4533    {
4534     HOMARD::HOMARD_Zone_var myZone = (*it_zone).second;
4535     CORBA::String_var dumpCorbaZone = myZone->GetDumpPython();
4536     std::string dumpZone = dumpCorbaZone.in();
4537     MESSAGE (dumpZone<<"\n");
4538     aScript += dumpZone;
4539    }
4540
4541
4542    if (myContextMap[GetCurrentStudyID()]._mesHypotheses.size() > 0)
4543    {
4544     MESSAGE (". Ecritures des hypotheses");
4545     aScript += "#\n# Creation of the hypotheses";
4546     aScript +=  "\n# ==========================";
4547    }
4548    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
4549    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
4550          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
4551    {
4552     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
4553     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
4554     std::string dumpHypo = dumpCorbaHypo.in();
4555     MESSAGE (dumpHypo<<"\n");
4556     aScript += dumpHypo;
4557    }
4558
4559
4560    if (myContextMap[GetCurrentStudyID()]._mesCas.size() > 0)
4561    {
4562     MESSAGE (". Ecritures des cas");
4563     aScript += "#\n# Creation of the cases";
4564     aScript += "\n# =====================";
4565    }
4566    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
4567    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4568         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
4569         {
4570            std::string nomCas = (*it_cas).first;
4571            std::string dumpCas = std::string("\n# Creation of the case ") ;
4572            dumpCas +=  nomCas + std::string("\n");
4573            dumpCas += std::string("\t") + nomCas;
4574            dumpCas += std::string(" = homard.CreateCase(\"") + nomCas + std::string("\", \"");
4575
4576            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
4577            CORBA::String_var cIter0= myCase->GetIter0Name();
4578            std::string iter0 = cIter0.in();
4579
4580            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
4581            CORBA::String_var cMesh0= myIteration->GetMeshFile();
4582            std::string mesh0 = cMesh0.in();
4583            CORBA::String_var cMeshName0= myIteration->GetMeshName();
4584            std::string meshName0 = cMeshName0.in();
4585            dumpCas += meshName0 + std::string("\", \"")+ mesh0 + std::string("\")\n");
4586            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
4587            std::string dumpCas2= dumpCorbaCase.in();
4588
4589            MESSAGE (dumpCas<<dumpCas2<<"\n");
4590            aScript += dumpCas + dumpCas2;
4591         };
4592
4593
4594    if (myContextMap[GetCurrentStudyID()]._mesIterations.size() > 0)
4595    {
4596     MESSAGE (". Ecritures des iterations");
4597     aScript += "#\n# Creation of the iterations" ;
4598     aScript += "\n# ==========================";
4599    }
4600    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
4601    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
4602         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
4603    {
4604     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
4605     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
4606     std::string dumpIter = dumpCorbaIter.in();
4607     MESSAGE (dumpIter<<"\n");
4608     aScript += dumpIter;
4609    }
4610
4611
4612    if (myContextMap[GetCurrentStudyID()]._mesYACSs.size() > 0)
4613    {
4614     MESSAGE (". Ecritures des schemas YACS");
4615     aScript += "#\n# Creation of the schemas YACS";
4616     aScript +=  "\n# ============================";
4617    }
4618    std::map<std::string, HOMARD::HOMARD_YACS_var>::const_iterator it_yacs;
4619    for ( it_yacs  = myContextMap[GetCurrentStudyID()]._mesYACSs.begin();
4620          it_yacs != myContextMap[GetCurrentStudyID()]._mesYACSs.end(); ++it_yacs)
4621    {
4622     HOMARD::HOMARD_YACS_var myYACS = (*it_yacs).second;
4623     CORBA::String_var dumpCorbaYACS = myYACS->GetDumpPython();
4624     std::string dumpYACS = dumpCorbaYACS.in();
4625     MESSAGE (dumpYACS<<"\n");
4626     aScript += dumpYACS;
4627    }
4628
4629   MESSAGE (". Ecritures finales");
4630   if( isMultiFile )
4631     aScript += "\n\tpass";
4632   aScript += "\n";
4633
4634   if( !isMultiFile ) // remove unnecessary tabulation
4635     aScript = RemoveTabulation( aScript );
4636
4637 //   MESSAGE ("A ecrire \n"<<aScript);
4638   const size_t aLen = strlen(aScript.c_str());
4639   char* aBuffer = new char[aLen+1];
4640   strcpy(aBuffer, aScript.c_str());
4641
4642   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
4643   Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
4644
4645   MESSAGE ("Sortie de DumpPython");
4646   return aStreamFile._retn();
4647 }
4648
4649
4650 //=============================================================================
4651 //=============================================================================
4652 // Utilitaires
4653 //=============================================================================
4654 //=============================================================================
4655 void HOMARD_Gen_i::IsValidStudy( )
4656 {
4657 //   MESSAGE( "IsValidStudy" );
4658   if (CORBA::is_nil(myCurrentStudy))
4659   {
4660     SALOME::ExceptionStruct es;
4661     es.type = SALOME::BAD_PARAM;
4662     es.text = "Invalid study context";
4663     throw SALOME::SALOME_Exception(es);
4664   };
4665   return ;
4666 }
4667
4668 //=============================================================================
4669 char* HOMARD_Gen_i::VerifieDir(const char* nomDir)
4670 {
4671   std::string casename = std::string("") ;
4672   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
4673   for (it = myContextMap[GetCurrentStudyID()]._mesCas.begin();
4674   it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
4675   {
4676    if (std::string(nomDir) == std::string(it->second->GetDirName()))
4677    {
4678      casename = std::string(it->second->GetName()) ;
4679      break ;
4680    }
4681   }
4682   return CORBA::string_dup( casename.c_str() );
4683 }
4684 /*//=============================================================================
4685 void SALOMEException( std::string message )
4686 {
4687   SALOME::ExceptionStruct es;
4688   es.type = SALOME::BAD_PARAM;
4689   es.text = message;
4690   throw SALOME::SALOME_Exception(es);
4691   return ;
4692 }*/
4693 //=============================================================================
4694 char* HOMARD_Gen_i::getVersion()
4695 {
4696 #if HOMARD_DEVELOPMENT
4697   return CORBA::string_dup(HOMARD_VERSION_STR"dev");
4698 #else
4699   return CORBA::string_dup(HOMARD_VERSION_STR);
4700 #endif
4701 }
4702 //===============================================================================
4703 // Recuperation de la chaine de caracteres par rapport a l'apparition d'un texte
4704 // ligne : la ligne a manipuler
4705 // texte : le texte a reperer
4706 // option : 0 : la chaine avant le texte
4707 //          1 : la chaine apres le texte
4708 // Si le texte est absent, on retourne la chaine totale
4709 //===============================================================================
4710 std::string HOMARD_Gen_i::GetStringInTexte( const std::string ligne, const std::string texte, int option )
4711 {
4712 //   MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
4713 //
4714   std::string chaine = ligne ;
4715   int position = ligne.find_first_of( texte ) ;
4716   if ( position > 0 )
4717   {
4718     if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
4719     else               { chaine = ligne.substr( position+1 ) ; }
4720   }
4721   return chaine ;
4722 //
4723 }
4724 // //===============================================================================
4725 // // Langue de SALOME
4726 // //===============================================================================
4727 void HOMARD_Gen_i::SetLanguageShort(const char* LanguageShort)
4728 {
4729 //   MESSAGE ("SetLanguageShort pour LanguageShort = " << LanguageShort );
4730   _LangueShort = LanguageShort ;
4731   if ( _LangueShort == "fr" ) { _Langue = "Francais" ; }
4732   else                        { _Langue = "English" ; }
4733   return ;
4734 }
4735 char* HOMARD_Gen_i::GetLanguageShort()
4736 {
4737 //   MESSAGE ("GetLanguageShort");
4738   return CORBA::string_dup( _LangueShort.c_str() );
4739 }
4740
4741 //=============================================================================
4742 extern "C"
4743 {
4744   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
4745                                                   PortableServer::POA_ptr poa,
4746                                                   PortableServer::ObjectId* contId,
4747                                                   const char* instanceName,
4748                                                   const char* interfaceName)
4749   {
4750     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
4751     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
4752     return myHOMARD_Gen->getId();
4753   }
4754 }