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