]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARD_I/HOMARD_Gen_i.cxx
Salome HOME
469c9b445d0bbee97052808f5006d7d2435111a8
[modules/homard.git] / src / HOMARD_I / HOMARD_Gen_i.cxx
1 // Copyright (C) 2011  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 "HomardDriver.hxx"
27 #include "HOMARD_DriverTools.hxx"
28 #include "HomardMedCommun.h"
29
30 #include "utilities.h"
31 #include "Utils_SINGLETON.hxx"
32 #include "Utils_CorbaException.hxx"
33 #include "SALOMEDS_Tool.hxx"
34 #include "SALOME_LifeCycleCORBA.hxx"
35 #include "SALOMEconfig.h"
36 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
37 #include CORBA_CLIENT_HEADER(SMESH_Gen)
38
39 #include <stdlib.h>
40 #include <sys/stat.h>
41 #include <dirent.h>
42 #include <string>
43 #include <iostream>
44 #include <iomanip>
45 #include <sys/stat.h>
46 #include <set>
47 #include <vector>
48 #include <stdio.h>
49
50
51 using  namespace std;
52
53 //=======================================================================
54 //function : RemoveTabulation
55 //purpose  :
56 //=======================================================================
57 std::string RemoveTabulation( std::string theScript )
58 {
59   std::string::size_type aPos = 0;
60   while( aPos < theScript.length() )
61   {
62     aPos = theScript.find( "\n\t", aPos );
63     if( aPos == std::string::npos )
64       break;
65     theScript.replace( aPos, 2, "\n" );
66     aPos++;
67   }
68   return theScript;
69 }
70
71 //=============================================================================
72 /*!
73  *  standard constructor
74  */
75 //=============================================================================
76 HOMARD_Gen_i::HOMARD_Gen_i( CORBA::ORB_ptr orb,
77                             PortableServer::POA_ptr poa,
78                             PortableServer::ObjectId * contId,
79                             const char *instanceName,
80                             const char *interfaceName) :
81 Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
82 {
83   MESSAGE("constructor");
84   _thisObj = this;
85   _id = _poa->activate_object(_thisObj);
86
87   myHomard = new ::HOMARD_Gen();
88   _NS = SINGLETON_<SALOME_NamingService>::Instance();
89   ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
90   _NS->init_orb(_orb);
91 }
92
93 //=================================
94 /*!
95  *  standard destructor
96  */
97 //================================
98 HOMARD_Gen_i::~HOMARD_Gen_i()
99 {
100 }
101 //=============================================================================
102 /*!
103  *  Ajoute le composant homard dans l etude si necessaire
104  */
105 //=============================================================================
106 void HOMARD_Gen_i::addInStudy(SALOMEDS::Study_ptr theStudy)
107 {
108   ASSERT(!CORBA::is_nil(theStudy));
109   MESSAGE("addInStudy: ajout eventuel du composant HOMARD dans current study ID = " << GetCurrentStudyID()) ;
110   SALOMEDS::StudyBuilder_var myBuilder = theStudy->NewBuilder();
111
112   // Create SComponent labelled 'homard' if it doesn't already exit
113   SALOMEDS::SComponent_var homardFather = theStudy->FindComponent(ComponentDataType());
114   if (CORBA::is_nil(homardFather))
115   {
116     myBuilder->NewCommand();
117     MESSAGE("Add Component HOMARD");
118
119     bool aLocked = theStudy->GetProperties()->IsLocked();
120     if (aLocked) theStudy->GetProperties()->SetLocked(false);
121
122     homardFather = myBuilder->NewComponent(ComponentDataType());
123     SALOMEDS::GenericAttribute_var anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributeName");
124     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
125     CORBA::Object_var objVarN = _NS->Resolve("/Kernel/ModulCatalog");
126     SALOME_ModuleCatalog::ModuleCatalog_var Catalogue =
127                 SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
128     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent(ComponentDataType());
129     if (!Comp->_is_nil())
130     {
131       aName->SetValue(ComponentDataType());
132     }
133
134     anAttr = myBuilder->FindOrCreateAttribute(homardFather,"AttributePixMap");
135     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
136     aPixmap->SetPixMap("HOMARD_2.png");
137     myBuilder->DefineComponentInstance(homardFather, HOMARD_Gen::_this());
138
139     if (aLocked) theStudy->GetProperties()->SetLocked(true);
140     myBuilder->CommitCommand();
141   }
142 }
143
144 //=============================================================================
145 /*!
146  *
147  *  Set current study
148  */
149 //=============================================================================
150 void HOMARD_Gen_i::SetCurrentStudy(SALOMEDS::Study_ptr theStudy)
151 {
152   MESSAGE("SetCurrentStudy: current study Id = " << GetCurrentStudyID());
153   myCurrentStudy = SALOMEDS::Study::_duplicate(theStudy);
154   this->addInStudy(myCurrentStudy);
155 }
156
157 //=============================================================================
158 SALOMEDS::Study_ptr HOMARD_Gen_i::GetCurrentStudy()
159 //=============================================================================
160 {
161   MESSAGE("GetCurrentStudy: study Id = " << GetCurrentStudyID());
162   return SALOMEDS::Study::_duplicate(myCurrentStudy);
163 }
164
165 //=============================================================================
166 int HOMARD_Gen_i::GetCurrentStudyID()
167 //=============================================================================
168 {
169   return myCurrentStudy->_is_nil() ? -1 : myCurrentStudy->StudyId();
170 }
171
172 //=============================================================================
173 void HOMARD_Gen_i::AssociateCaseIter(const char* nomCas, const char* nomIter, const char* labelIter)
174 {
175   MESSAGE( "AssociateCaseIter : " << nomCas << " ," << nomIter << ","  << labelIter );
176   IsValidStudy () ;
177
178   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
179   if (CORBA::is_nil(myCase))
180   {
181       SALOME::ExceptionStruct es;
182       es.type = SALOME::BAD_PARAM;
183       es.text = "Invalid Case ";
184       throw SALOME::SALOME_Exception(es);
185       return ;
186   };
187
188   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
189   if (CORBA::is_nil(myIteration))
190   {
191       SALOME::ExceptionStruct es;
192       es.type = SALOME::BAD_PARAM;
193       es.text = "Invalid Case ";
194       throw SALOME::SALOME_Exception(es);
195       return ;
196   };
197
198   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
199   SALOMEDS::SObject_var aCasSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myCase)));
200   if (CORBA::is_nil(aCasSO))
201   {
202       SALOME::ExceptionStruct es;
203       es.type = SALOME::BAD_PARAM;
204       es.text = "Invalid Case ";
205       throw SALOME::SALOME_Exception(es);
206       return ;
207   };
208
209   aStudyBuilder->NewCommand();
210   SALOMEDS::SObject_var newStudyIter = aStudyBuilder->NewObject(aCasSO);
211   PublishInStudyAttr(aStudyBuilder, newStudyIter, nomIter , labelIter,
212                      "iter_non_calculee.png", _orb->object_to_string(myIteration)) ;
213   aStudyBuilder->CommitCommand();
214
215   myCase->AddIteration(nomIter);
216   myIteration->SetCaseName(nomCas);
217 }
218
219 //=====================================================================================
220 void HOMARD_Gen_i::SetEtatIter(const char* nomIter, const bool EtatCalcul)
221 //=====================================================================================
222 {
223   MESSAGE( "SetEtatIter : nomIter  = " << nomIter << " etat " << EtatCalcul );
224   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
225   if (CORBA::is_nil(myIteration))
226   {
227       SALOME::ExceptionStruct es;
228       es.type = SALOME::BAD_PARAM;
229       es.text = "Invalid Iteration ";
230       throw SALOME::SALOME_Exception(es);
231       return ;
232   };
233
234   myIteration->SetEtat(EtatCalcul);
235
236   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
237   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
238   if (CORBA::is_nil(myIteration))
239   {
240       SALOME::ExceptionStruct es;
241       es.type = SALOME::BAD_PARAM;
242       es.text = "Invalid Iteration ";
243       throw SALOME::SALOME_Exception(es);
244       return ;
245   };
246
247   int number = myIteration->GetNumber() ;
248   const char* icone ;
249   if ( number == 0 )
250     icone = "iter0.png" ;
251   else if (EtatCalcul)
252     icone = "iter_calculee.png" ;
253   else
254     icone = "iter_non_calculee.png" ;
255   PublishInStudyAttr(aStudyBuilder, aIterSO, NULL , NULL, icone, NULL) ;
256
257   aStudyBuilder->CommitCommand();
258
259 }
260 //=====================================================================================
261 void HOMARD_Gen_i::InvalideBoundary(const char* BoundaryName)
262 //=====================================================================================
263 {
264   MESSAGE( "InvalideBoundary : BoundaryName    = " << BoundaryName  );
265   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
266   if (CORBA::is_nil(myBoundary))
267   {
268       SALOME::ExceptionStruct es;
269       es.type = SALOME::BAD_PARAM;
270       es.text = "Invalid Boundary ";
271       throw SALOME::SALOME_Exception(es);
272       return ;
273   };
274   SALOME::ExceptionStruct es;
275   es.type = SALOME::BAD_PARAM;
276   es.text = "No change is allowed in boundary. Ask for evolution.";
277   throw SALOME::SALOME_Exception(es);
278   return ;
279 /*  HOMARD::listeHypo* maListe = myBoundary->GetHypo();
280   int numberOfHypo = maListe->length();
281   for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
282   {
283       std::string nomHypo = std::string((*maListe)[NumeHypo]);
284       InvalideHypo(nomHypo.c_str());
285   }*/
286 }
287 //=====================================================================================
288 void HOMARD_Gen_i::InvalideZone(const char* ZoneName)
289 //=====================================================================================
290 {
291   MESSAGE( "InvalideZone : ZoneName    = " << ZoneName  );
292   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
293   if (CORBA::is_nil(myZone))
294   {
295       SALOME::ExceptionStruct es;
296       es.type = SALOME::BAD_PARAM;
297       es.text = "Invalid Zone ";
298       throw SALOME::SALOME_Exception(es);
299       return ;
300   };
301   HOMARD::listeHypo* maListe = myZone->GetHypo();
302   int numberOfHypo = maListe->length();
303   for (int NumeHypo = 0; NumeHypo< numberOfHypo; NumeHypo++)
304   {
305       std::string nomHypo = std::string((*maListe)[NumeHypo]);
306       InvalideHypo(nomHypo.c_str());
307   }
308 }
309 //=====================================================================================
310 void HOMARD_Gen_i::InvalideHypo(const char* nomHypo)
311 //=====================================================================================
312 {
313   MESSAGE( "InvalideHypo : nomHypo    = " << nomHypo  );
314   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
315   if (CORBA::is_nil(myHypo))
316   {
317       SALOME::ExceptionStruct es;
318       es.type = SALOME::BAD_PARAM;
319       es.text = "Invalid Hypothesis ";
320       throw SALOME::SALOME_Exception(es);
321       return ;
322   };
323
324   HOMARD::listeIters* maListe = myHypo->GetIterations();
325   int numberOfIter = maListe->length();
326   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
327   {
328       std::string nomIter = std::string((*maListe)[NumeIter]);
329       InvalideIter(nomIter.c_str());
330   }
331 }
332 //
333 //=====================================================================================
334 void HOMARD_Gen_i::InvalideIter(const char* nomIter)
335 //=====================================================================================
336 {
337   MESSAGE("InvalideIter : nomIter    = " << nomIter);
338   SetEtatIter(nomIter,false);
339   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
340   if (CORBA::is_nil(myIteration))
341   {
342       SALOME::ExceptionStruct es;
343       es.type = SALOME::BAD_PARAM;
344       es.text = "Invalid Iteration ";
345       throw SALOME::SALOME_Exception(es);
346       return ;
347   };
348
349   HOMARD::listeIterFilles* maListe = myIteration->GetIterations();
350   int numberOfIter = maListe->length();
351   for (int NumeIter = 0; NumeIter< numberOfIter; NumeIter++)
352   {
353       std::string nomIterFille = std::string((*maListe)[NumeIter]);
354       InvalideIter(nomIterFille.c_str());
355   }
356
357   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
358   SALOMEDS::ChildIterator_var  aIter = myCurrentStudy->NewChildIterator(aIterSO);
359   for (; aIter->More(); aIter->Next())
360   {
361       SALOMEDS::SObject_var so = aIter->Value();
362       SALOMEDS::GenericAttribute_var anAttr;
363       if (!so->FindAttribute(anAttr, "AttributeComment")) continue;
364       SALOMEDS::AttributeComment_var aCommentAttr = SALOMEDS::AttributeComment::_narrow(anAttr);
365       std::string value (aCommentAttr->Value());
366       if(value == std::string("HypoHomard")) continue;
367       SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
368       aStudyBuilder->RemoveObject(so);
369   }
370   const char * nomCas = myIteration->GetCaseName();
371   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
372   if (CORBA::is_nil(myCase))
373   {
374       SALOME::ExceptionStruct es;
375       es.type = SALOME::BAD_PARAM;
376       es.text = "Invalid Case Context ";
377       throw SALOME::SALOME_Exception(es);
378       return ;
379   };
380   const char* dirParent  = myCase->GetDirName();
381   const char* nomDir     = myIteration->GetDirName();
382   const char* nomFichier = myIteration->GetMeshFile();
383   std::string commande= "rm -rf " + std::string(dirParent) + "/" + std::string(nomDir);
384   commande = commande + ";rm -rf " + std::string(nomFichier);
385   if ((system(commande.c_str())) != 0)
386   {
387         SALOME::ExceptionStruct es;
388         es.type = SALOME::BAD_PARAM;
389         es.text = "Menage du repertoire de calcul impossible" ;
390         throw SALOME::SALOME_Exception(es);
391         return ;
392   }
393 // Suppression du maillage publie dans SMESH
394   const char* MeshName = myIteration->GetMeshName();
395   DeleteResultInSmesh(nomFichier, MeshName) ;
396 }
397 //
398 //=====================================================================================
399 void HOMARD_Gen_i::AssociateHypoZone(const char* ZoneName, const char* nomHypothesis)
400 {
401   MESSAGE ( "AssociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
402   IsValidStudy () ;
403
404   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
405   ASSERT(!CORBA::is_nil(myHypo));
406   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
407   ASSERT(!CORBA::is_nil(aHypoSO));
408
409   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
410   ASSERT(!CORBA::is_nil(myZone));
411   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
412   ASSERT(!CORBA::is_nil(aZoneSO));
413   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
414   aStudyBuilder->NewCommand();
415
416   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aHypoSO);
417   aStudyBuilder->Addreference(aSubSO, aZoneSO);
418   aStudyBuilder->CommitCommand();
419
420   myZone->AddHypo(nomHypothesis);
421   myHypo->AddZone(ZoneName);
422   MESSAGE ( "Fin de AssociateHypoZone");
423 };
424
425 //=====================================================================================
426 void HOMARD_Gen_i::DissociateHypoZone(const char* ZoneName, const char* nomHypothesis)
427 {
428   MESSAGE ( "DissociateHypoZone : ZoneName= " << ZoneName << ", nomHypo = " << nomHypothesis);
429   IsValidStudy () ;
430
431   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
432   ASSERT(!CORBA::is_nil(myHypo));
433   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
434   ASSERT(!CORBA::is_nil(aHypoSO));
435
436   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
437   ASSERT(!CORBA::is_nil(myZone));
438   SALOMEDS::SObject_var aZoneSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myZone)));
439   ASSERT(!CORBA::is_nil(aZoneSO));
440
441
442   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
443
444   SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator(aHypoSO);
445   for (; it->More(); it->Next())
446   {
447     SALOMEDS::SObject_var aHypObj = it->Value();
448     SALOMEDS::SObject_var ptrObj;
449     if (aHypObj->ReferencedObject(ptrObj))
450     {
451       if (std::string(ptrObj->GetName()) == std::string(aZoneSO->GetName()))
452       {
453         aStudyBuilder->NewCommand();
454         aStudyBuilder->RemoveObject(aHypObj);
455         aStudyBuilder->CommitCommand();
456         break;
457       }
458     }
459   }
460
461   myZone->SupprHypo(nomHypothesis);
462   myHypo->SupprZone(ZoneName);
463 };
464
465 //=============================================================================
466 void HOMARD_Gen_i::AssociateIterIter(const char* nomIterParent, const char* nomIter)
467 {
468   MESSAGE ( "AssociateIterIter : nomIter       = " << nomIter << " nomIterParent = " << nomIterParent);
469   IsValidStudy () ;
470
471   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
472   ASSERT(!CORBA::is_nil(myIterationParent));
473   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
474   ASSERT(!CORBA::is_nil(myIteration));
475
476   myIterationParent->AddIteration(nomIter);
477   myIteration->SetIterParent(nomIterParent);
478 }
479
480 //===================================================================================
481 void HOMARD_Gen_i::AssociateIterHypo(const char* nomIter, const char* nomHypo)
482 {
483   MESSAGE("AssociateIterHypo : nomHypo = " << nomHypo << " nomIter = " << nomIter);
484   IsValidStudy () ;
485
486   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
487   ASSERT(!CORBA::is_nil(myHypo));
488   SALOMEDS::SObject_var aHypoSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myHypo)));
489   ASSERT(!CORBA::is_nil(aHypoSO));
490
491   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIter];
492   ASSERT(!CORBA::is_nil(myIteration));
493   SALOMEDS::SObject_var aIterSO = SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
494   ASSERT(!CORBA::is_nil(aIterSO));
495
496   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
497
498   aStudyBuilder->NewCommand();
499
500   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
501   aStudyBuilder->Addreference(aSubSO, aHypoSO);
502
503   aStudyBuilder->CommitCommand();
504
505   myIteration->SetHypoName(nomHypo);
506   myHypo->AddIteration(nomIter);
507 };
508
509 //=============================================================================
510 CORBA::Boolean HOMARD_Gen_i::VerifieDir(const char* nomDir)
511 {
512   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
513   for (it  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
514         it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
515   {
516    if (std::string(nomDir) == std::string(it->second->GetDirName())) return false;
517   }
518   return true;
519 }
520
521 //=============================================================================
522 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::CreateCase(const char* nomCas, const char* MeshName, const char* MeshFile)
523 {
524   MESSAGE ( "CreateCase : nomCas = " << nomCas << ", MeshName = " << MeshName << ", MeshFile = " << MeshFile );
525   IsValidStudy () ;
526
527   if ((myContextMap[GetCurrentStudyID()]._mesCas).find(nomCas)!=(myContextMap[GetCurrentStudyID()]._mesCas).end())
528   {
529       SALOME::ExceptionStruct es;
530       es.type = SALOME::BAD_PARAM;
531       es.text = "This case has already been defined";
532       throw SALOME::SALOME_Exception(es);
533       return 0;
534   };
535
536   HOMARD::HOMARD_Cas_var myCase = newCase();
537   myCase->SetName(nomCas);
538   SALOMEDS::SObject_var aSO;
539   PublishInStudy(myCurrentStudy, aSO, myCase, nomCas);
540   myContextMap[GetCurrentStudyID()]._mesCas[nomCas] = myCase;
541
542
543   std::vector<double> LesExtremes =GetBoundingBoxInMedFile(MeshFile);
544   HOMARD::extrema_var aSeq = new HOMARD::extrema();
545   if (LesExtremes.size()!=10) { return false; }
546   aSeq->length(10);
547   for (int i =0; i< LesExtremes.size(); i++)
548        aSeq[i]=LesExtremes[i];
549   myCase->SetBoundingBox(aSeq);
550
551   std::set<std::string> LesGroupes  =GetListeGroupesInMedFile(MeshFile);
552   HOMARD::ListGroupType_var aSeqGroupe = new HOMARD::ListGroupType;
553   aSeqGroupe->length(LesGroupes.size());
554   std::set<std::string>::const_iterator it;
555   int i = 0;
556   for (it=LesGroupes.begin() ; it != LesGroupes.end(); it++)
557      aSeqGroupe[i++]=(*it).c_str();
558   myCase->SetGroups(aSeqGroupe);
559
560 // Valeurs par defaut des filtrages
561   myCase->SetNivMax(-1);
562   myCase->SetDiamMin(-1.0);
563
564 // Recherche d'un nom pour l'iteration 0. Par defaut, on prend le nom
565 // du maillage du cas. Si ce nom existe deja, on incremente avec 0, 1, 2, etc.
566   int monNum=0;
567   std::string nomIter = std::string(MeshName) ;
568   while ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIter) != (myContextMap[GetCurrentStudyID()]._mesIterations.end()))
569   {
570      std::ostringstream nom;
571      nom << MeshName << monNum;
572      nomIter=nom.str();
573      monNum = monNum+1;
574   }
575
576   HOMARD::HOMARD_Iteration_var anIter = newIteration();
577   myContextMap[GetCurrentStudyID()]._mesIterations[nomIter] = anIter;
578   std::ostringstream DirName;
579   DirName << "I_00";
580
581   anIter->SetDirName(DirName.str().c_str());
582   anIter->SetName(nomIter.c_str());
583   anIter->SetMeshFile(MeshFile);
584   anIter->SetMeshName(MeshName);
585   anIter->SetNumber(0);
586
587   AssociateCaseIter (nomCas,nomIter.c_str(),"IterationHomard");
588   SetEtatIter(nomIter.c_str(),true);
589 //
590   PublishResultInSmesh(MeshFile, 0);
591
592   return HOMARD::HOMARD_Cas::_duplicate(myCase);
593 }
594
595 //=============================================================================
596 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::GetCas(const char* nomCas)
597 {
598   IsValidStudy () ;
599   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
600   if (CORBA::is_nil(myCase))
601   {
602       SALOME::ExceptionStruct es;
603       es.type = SALOME::BAD_PARAM;
604       es.text = "Invalid Case";
605       throw SALOME::SALOME_Exception(es);
606       return 0;
607   };
608   return HOMARD::HOMARD_Cas::_duplicate(myCase);
609 }
610
611 //=============================================================================
612 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::GetZone(const char* ZoneName)
613 {
614   IsValidStudy () ;
615   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
616   ASSERT(!CORBA::is_nil(myZone));
617   return HOMARD::HOMARD_Zone::_duplicate(myZone);
618 }
619
620 //=============================================================================
621 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::GetHypothesis(const char* nomHypothesis)
622 {
623   MESSAGE ( "GetHypothesis : nomHypothesis = " << nomHypothesis );
624   IsValidStudy () ;
625   MESSAGE ( "GetHypothesis : GetCurrentStudyID() = " << GetCurrentStudyID() );
626   HOMARD::HOMARD_Hypothesis_var myHypothesis = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis];
627   ASSERT(!CORBA::is_nil(myHypothesis));
628   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
629 }
630
631 //=============================================================================
632 HOMARD::HOMARD_Iteration_ptr  HOMARD_Gen_i::GetIteration(const char* nomIteration)
633 {
634   IsValidStudy () ;
635   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
636   ASSERT(!CORBA::is_nil(myIteration));
637   return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
638 }
639 //=============================================================================
640 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::GetBoundary(const char* nomBoundary)
641 {
642   IsValidStudy () ;
643
644   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[nomBoundary];
645   ASSERT(!CORBA::is_nil(myBoundary));
646   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
647 }
648
649 //=============================================================================
650 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::CreateHypothesis(const char* nomHypothesis)
651 {
652   MESSAGE ( "CreateHypothesis : nomHypothesis  = " << nomHypothesis );
653   IsValidStudy () ;
654
655   if ((myContextMap[GetCurrentStudyID()]._mesHypotheses).find(nomHypothesis) != (myContextMap[GetCurrentStudyID()]._mesHypotheses).end())
656   {
657       SALOME::ExceptionStruct es;
658       es.type = SALOME::BAD_PARAM;
659       es.text = "This hypothesis is already defined.";
660       throw SALOME::SALOME_Exception(es);
661       return 0;
662     }
663
664   HOMARD::HOMARD_Hypothesis_var myHypothesis = newHypothesis();
665   myHypothesis->SetName(nomHypothesis);
666   myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypothesis] = myHypothesis;
667   SALOMEDS::SObject_var aSO;
668   PublishInStudy(myCurrentStudy, aSO, myHypothesis, nomHypothesis);
669
670   return HOMARD::HOMARD_Hypothesis::_duplicate(myHypothesis);
671 }
672
673 //============================================================================================================
674 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::CreateIteration(const char* nomIteration, const char* nomIterParent)
675 //============================================================================================================
676 {
677   MESSAGE ("CreateIteration : nomIteration  = " << nomIteration << "nomIterParent = " << nomIterParent);
678   IsValidStudy () ;
679
680   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterParent];
681   if (CORBA::is_nil(myIterationParent))
682   {
683       SALOME::ExceptionStruct es;
684       es.type = SALOME::BAD_PARAM;
685       es.text = "The parent iteration is not defined.";
686       throw SALOME::SALOME_Exception(es);
687       return 0;
688   };
689
690   const char* nomCas = GetCaseName(nomIterParent);
691   MESSAGE ("CreateIteration : nomCas = " << nomCas);
692   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
693   if (CORBA::is_nil(myCase))
694   {
695       SALOME::ExceptionStruct es;
696       es.type = SALOME::BAD_PARAM;
697       es.text = "Invalid Case Context ";
698       throw SALOME::SALOME_Exception(es);
699       return 0;
700   };
701
702   if ((myContextMap[GetCurrentStudyID()]._mesIterations).find(nomIteration)!=(myContextMap[GetCurrentStudyID()]._mesIterations).end())
703   {
704       SALOME::ExceptionStruct es;
705       es.type = SALOME::BAD_PARAM;
706       es.text = "This iteration is already defined. ";
707       throw SALOME::SALOME_Exception(es);
708       return 0;
709   };
710
711    HOMARD::HOMARD_Iteration_var myIteration = newIteration();
712    if (CORBA::is_nil(myIteration))
713   {
714       SALOME::ExceptionStruct es;
715       es.type = SALOME::BAD_PARAM;
716       es.text = "Unable to create Iteration ";
717       throw SALOME::SALOME_Exception(es);
718       return 0;
719   };
720    myContextMap[GetCurrentStudyID()]._mesIterations[std::string(nomIteration)] = myIteration;
721    myIteration->SetName(nomIteration);
722    myIteration->SetMeshName(nomIteration);
723
724    int numero = myIterationParent->GetNumber() + 1;
725    myIteration->SetNumber(numero);
726
727 // Nombre d'iterations deja connues pour le cas, permettant
728 // la creation d'un sous-repertoire unique
729    int nbitercase = myCase->GetNumber();
730    std::ostringstream iaux ;
731    iaux << std::setw(2) << std::setfill('0') << nbitercase ;
732    std::stringstream DirName;
733    DirName << "I" << iaux.str();
734    myIteration->SetDirName(DirName.str().c_str());
735
736 // Le nom du fichier du maillage MED est indice par le nombre d'iterations du cas.
737 // Si on a une chaine unique depuis le depart, ce nombre est le meme que le
738 // numero d'iteration dans la sucession : maill.01.med, maill.02.med, etc... C'est le
739 // cas le plus frequent.
740 // Si on a plusieurs branches, donc des iterations a meme niveau d'adaptation, utiliser
741 // le nombre d'iterations du cas permet d'eviter les collisions.
742    std::stringstream MeshFile;
743    const char* nomDir = myCase->GetDirName();
744    MeshFile << nomDir << "/maill." << iaux.str() << ".med";
745    myIteration->SetMeshFile(MeshFile.str().c_str());
746
747 // Association avec le cas et l'iteration precedente
748    std::string label = "IterationHomard_" + std::string(nomIterParent);
749    AssociateCaseIter(nomCas, nomIteration, label.c_str());
750    AssociateIterIter (nomIterParent,nomIteration);
751
752    return HOMARD::HOMARD_Iteration::_duplicate(myIteration);
753 }
754
755
756 //=============================================================================
757 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundary(const char* BoundaryName, CORBA::Long BoundaryType)
758 {
759   MESSAGE ("CreateBoundary : BoundaryName  = " << BoundaryName << ", BoundaryType = " << BoundaryType);
760   IsValidStudy () ;
761
762   if ((myContextMap[GetCurrentStudyID()]._mesBoundarys).find(BoundaryName)!=(myContextMap[GetCurrentStudyID()]._mesBoundarys).end())
763   {
764       SALOME::ExceptionStruct es;
765       es.type = SALOME::BAD_PARAM;
766       es.text = "This boundary has already been defined";
767       throw SALOME::SALOME_Exception(es);
768       return 0;
769   };
770
771   HOMARD::HOMARD_Boundary_var myBoundary = newBoundary();
772   myBoundary->SetName(BoundaryName);
773   myBoundary->SetBoundaryType(BoundaryType);
774
775   myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName] = myBoundary;
776
777   SALOMEDS::SObject_var aSO;
778   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myBoundary, BoundaryName);
779
780   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
781 }
782 //=============================================================================
783 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryDi(const char* BoundaryName, const char* MeshName, const char* MeshFile)
784 {
785   MESSAGE ("CreateBoundaryDi : BoundaryName  = " << BoundaryName << "MeshName = " << MeshName );
786   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 0);
787   myBoundary->SetMeshFile( MeshFile ) ;
788   myBoundary->SetMeshName( MeshName ) ;
789
790   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary);
791 }
792 //=============================================================================
793 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundaryCylinder(const char* BoundaryName,
794                                       double Xcentre, double Ycentre, double Zcentre,
795                                       double Xaxis, double Yaxis, double Zaxis,
796                                       double Rayon)
797 {
798   MESSAGE ("CreateBoundaryCylinder : BoundaryName  = " << BoundaryName ) ;
799   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 1) ;
800   myBoundary->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxis, Yaxis, Zaxis, Rayon ) ;
801
802   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
803 }
804 //=============================================================================
805 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::CreateBoundarySphere(const char* BoundaryName,
806                                       double Xcentre, double Ycentre, double Zcentre,
807                                       double Rayon)
808 {
809   MESSAGE ("CreateBoundarySphere : BoundaryName  = " << BoundaryName ) ;
810   HOMARD::HOMARD_Boundary_var myBoundary = CreateBoundary(BoundaryName, 2) ;
811   myBoundary->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
812
813   return HOMARD::HOMARD_Boundary::_duplicate(myBoundary) ;
814 }
815
816
817 //=============================================================================
818 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZone(const char* ZoneName, CORBA::Long ZoneType)
819 {
820   MESSAGE ("CreateZone : ZoneName  = " << ZoneName << ", ZoneType = " << ZoneType);
821   IsValidStudy () ;
822
823   if ((myContextMap[GetCurrentStudyID()]._mesZones).find(ZoneName)!=(myContextMap[GetCurrentStudyID()]._mesZones).end())
824   {
825       SALOME::ExceptionStruct es;
826       es.type = SALOME::BAD_PARAM;
827       es.text = "This zone has already been defined";
828       throw SALOME::SALOME_Exception(es);
829       return 0;
830   };
831
832   HOMARD::HOMARD_Zone_var myZone = newZone();
833   myZone->SetName(ZoneName);
834   myZone->SetZoneType(ZoneType);
835
836   myContextMap[GetCurrentStudyID()]._mesZones[ZoneName] = myZone;
837
838   SALOMEDS::SObject_var aSO;
839   SALOMEDS::SObject_var aResultSO=PublishInStudy(myCurrentStudy, aSO, myZone, ZoneName);
840
841   return HOMARD::HOMARD_Zone::_duplicate(myZone);
842 }
843 //=============================================================================
844 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox(const char* ZoneName,
845                                       double Xmini, double Xmaxi,
846                                       double Ymini, double Ymaxi,
847                                       double Zmini, double Zmaxi)
848 {
849   MESSAGE ("CreateZoneBox : ZoneName  = " << ZoneName ) ;
850   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 2) ;
851   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
852
853   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
854 }
855 //=============================================================================
856 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneSphere(const char* ZoneName,
857                                       double Xcentre, double Ycentre, double Zcentre, double Rayon)
858 {
859   MESSAGE ("CreateZoneSphere : ZoneName  = " << ZoneName ) ;
860   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 4) ;
861   myZone->SetSphere( Xcentre, Ycentre, Zcentre, Rayon ) ;
862
863   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
864 }
865 //=============================================================================
866 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneCylinder(const char* ZoneName,
867                                       double Xcentre, double Ycentre, double Zcentre,
868                                       double Xaxe, double Yaxe, double Zaxe,
869                                       double Rayon, double Haut)
870 {
871   MESSAGE ("CreateZoneCylinder : ZoneName  = " << ZoneName ) ;
872   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 5) ;
873   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut ) ;
874
875   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
876 }
877 //=============================================================================
878 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZonePipe(const char* ZoneName,
879                                       double Xcentre, double Ycentre, double Zcentre,
880                                       double Xaxe, double Yaxe, double Zaxe,
881                                       double Rayon, double Haut, double Rayonint)
882 {
883   MESSAGE ("CreateZonePipe : ZoneName  = " << ZoneName ) ;
884   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 7) ;
885   myZone->SetPipe( Xcentre, Ycentre, Zcentre, Xaxe, Yaxe, Zaxe, Rayon, Haut, Rayonint ) ;
886
887   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
888 }
889 //=============================================================================
890 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneBox2D(const char* ZoneName,
891                                       double Umini, double Umaxi,
892                                       double Vmini, double Vmaxi,
893                                       CORBA::Long Orient)
894 {
895   MESSAGE ("CreateZoneBox2D : ZoneName  = " << ZoneName ) ;
896 //   MESSAGE ("Umini = " << Umini << ", Umaxi =" << Umaxi ) ;
897 //   MESSAGE ("Vmini = " << Vmini << ", Vmaxi =" << Vmaxi ) ;
898 //   MESSAGE ("Orient = " << Orient ) ;
899
900   double Xmini, Xmaxi ;
901   double Ymini, Ymaxi ;
902   double Zmini, Zmaxi ;
903   if ( Orient == 1 )
904   { Xmini = Umini ;
905     Xmaxi = Umaxi ;
906     Ymini = Vmini ;
907     Ymaxi = Vmaxi ;
908     Zmini = 0. ;
909     Zmaxi = 0. ; }
910   else if ( Orient == 2 )
911   { Xmini = 0. ;
912     Xmaxi = 0. ;
913     Ymini = Umini ;
914     Ymaxi = Umaxi ;
915     Zmini = Vmini ;
916     Zmaxi = Vmaxi ; }
917   else if ( Orient == 3 )
918   { Xmini = Vmini ;
919     Xmaxi = Vmaxi ;
920     Ymini = 0. ;
921     Ymaxi = 0. ;
922     Zmini = Umini ;
923     Zmaxi = Umaxi ; }
924   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
925
926   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 10+Orient) ;
927   myZone->SetBox ( Xmini, Xmaxi, Ymini, Ymaxi, Zmini, Zmaxi) ;
928
929   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
930 }
931 //=============================================================================
932 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDisk(const char* ZoneName,
933                                       double Ucentre, double Vcentre,
934                                       double Rayon,
935                                       CORBA::Long Orient)
936 {
937   MESSAGE ("CreateZoneDisk : ZoneName  = " << ZoneName ) ;
938   double Xcentre ;
939   double Ycentre ;
940   double Zcentre ;
941   if ( Orient == 1 )
942   { Xcentre = Ucentre ;
943     Ycentre = Vcentre ;
944     Zcentre = 0. ; }
945   else if ( Orient == 2 )
946   { Xcentre = 0. ;
947     Ycentre = Ucentre ;
948     Zcentre = Vcentre ; }
949   else if ( Orient == 3 )
950   { Xcentre = Vcentre ;
951     Ycentre = 0. ;
952     Zcentre = Ucentre ; }
953   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
954
955   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 30+Orient) ;
956   myZone->SetCylinder( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1. ) ;
957
958   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
959 }
960 //=============================================================================
961 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::CreateZoneDiskWithHole(const char* ZoneName,
962                                       double Ucentre, double Vcentre,
963                                       double Rayon, double Rayonint,
964                                       CORBA::Long Orient)
965 {
966   MESSAGE ("CreateZoneDiskWithHole : ZoneName  = " << ZoneName ) ;
967   double Xcentre ;
968   double Ycentre ;
969   double Zcentre ;
970   if ( Orient == 1 )
971   { Xcentre = Ucentre ;
972     Ycentre = Vcentre ;
973     Zcentre = 0. ; }
974   else if ( Orient == 2 )
975   { Xcentre = 0. ;
976     Ycentre = Ucentre ;
977     Zcentre = Vcentre ; }
978   else if ( Orient == 3 )
979   { Xcentre = Vcentre ;
980     Ycentre = 0. ;
981     Zcentre = Ucentre ; }
982   else { ASSERT( Orient >= 1 and Orient <= 3 ) ; }
983
984   HOMARD::HOMARD_Zone_var myZone = CreateZone(ZoneName, 60+Orient) ;
985   myZone->SetPipe( Xcentre, Ycentre, Zcentre, 0., 0., 1., Rayon, 1., Rayonint ) ;
986
987   return HOMARD::HOMARD_Zone::_duplicate(myZone) ;
988 }
989
990
991
992
993 //=============================================================================
994 CORBA::Boolean HOMARD_Gen_i::Compute(const char* nomIteration, CORBA::Long etatMenage)
995 {
996   MESSAGE ( "Compute : calcul de " << nomIteration );
997   IsValidStudy () ;
998
999   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1000   ASSERT(!CORBA::is_nil(myIteration));
1001
1002 // on ne calcule pas l iteration 0
1003   int NumeIter = myIteration->GetNumber();
1004   if ( NumeIter == 0 )
1005   {
1006       SALOME::ExceptionStruct es;
1007       es.type = SALOME::BAD_PARAM;
1008       es.text = "This iteration is the first of the case and cannot be computed.";
1009       throw SALOME::SALOME_Exception(es);
1010       return 0;
1011   };
1012
1013 // on verifie qu il y a une hypothese (erreur improbable);
1014   const char* nomHypo = myIteration->GetHypoName();
1015   if (std::string(nomHypo) == std::string(""))
1016   {
1017       SALOME::ExceptionStruct es;
1018       es.type = SALOME::BAD_PARAM;
1019       es.text= "This iteration does not have any associated hypothesis.";
1020       throw SALOME::SALOME_Exception(es);
1021       return 0;
1022   }
1023   HOMARD::HOMARD_Hypothesis_var myHypo = myContextMap[GetCurrentStudyID()]._mesHypotheses[nomHypo];
1024   ASSERT(!CORBA::is_nil(myHypo));
1025
1026
1027   // A.4. L'iteration parent
1028   const char* nomIterationParent = myIteration->GetIterParent();
1029   HOMARD::HOMARD_Iteration_var myIterationParent = myContextMap[GetCurrentStudyID()]._mesIterations[nomIterationParent];
1030   ASSERT(!CORBA::is_nil(myIterationParent));
1031   if ( ! myIterationParent->GetEtat() )
1032   {
1033       /*
1034       SALOME::ExceptionStruct es;
1035       es.type = SALOME::BAD_PARAM;
1036       std::string text = "The iteration cannot be computed because the previous iteration " + std::string(nomIterationParent) + " is not valid.";
1037       es.text = CORBA::string_dup(text.c_str());
1038       throw SALOME::SALOME_Exception(es);
1039       return 0;
1040       */
1041       Compute(nomIterationParent, etatMenage);
1042   };
1043
1044   const char* nomCas = myIteration->GetCaseName();
1045   HOMARD::HOMARD_Cas_var myCase = myContextMap[GetCurrentStudyID()]._mesCas[nomCas];
1046   ASSERT(!CORBA::is_nil(myCase));
1047
1048   int codret = 0;
1049   std::stringstream saux0 ;
1050   saux0 << NumeIter - 1 ;
1051   std::string siter = saux0.str() ;
1052   if (NumeIter < 11) { siter = "0" + siter ; }
1053 //
1054   std::stringstream saux1 ;
1055   saux1 << NumeIter ;
1056   std::string siterp1 = saux1.str() ;
1057   if (NumeIter < 10) { siterp1 = "0" + siterp1 ; }
1058
1059   // A.3. Hypothese associee
1060   // B. Les repertoires
1061   // B.1. Le repertoire du cas
1062   const char* nomDir = myCase->GetDirName();
1063   MESSAGE ( ". nomDir = " << nomDir );
1064
1065   // B.2. Le sous-repertoire de l'iteration a calculer, puis le repertoire complet a creer
1066   // B.2.1. Le nom du sous-repertoire
1067    const char* nomDirIt = myIteration->GetDirName();
1068
1069   // B.2.2. Le nom complet du sous-repertoire
1070   std::stringstream DirCompute ;
1071   DirCompute << nomDir << "/" << nomDirIt;
1072   MESSAGE (". DirCompute = " << DirCompute.str() );
1073
1074   // B.2.3. Si le sous-repertoire n'existe pas, on le cree
1075   //        Si le sous-repertoire existe :
1076   //         etatMenage = 0 : on sort en erreur si le repertoire n'est pas vide
1077   //         etatMenage = 1 : on fait le menage du repertoire
1078   if (chdir(DirCompute.str().c_str()) != 0)
1079   {
1080 //  Creation du repertoire car il n'existe pas :
1081     if (mkdir(DirCompute.str().c_str(), S_IRWXU|S_IRGRP|S_IXGRP) != 0)
1082     {
1083        // GERALD -- QMESSAGE BOX
1084        std::cerr << "Pb Creation du repertoire DirCompute = " << DirCompute.str() << std::endl;
1085        ASSERT("Pb a la creation du repertoire" == 0);
1086     }
1087   }
1088   else
1089   {
1090 //  Le repertoire existe et on fait le menage de son contenu :
1091     if (etatMenage != 0)
1092     {
1093        MESSAGE (". Menage du repertoire DirCompute = " << DirCompute.str());
1094        std::string commande= "rm -rf " + DirCompute.str()+"/*" ;
1095        int codret = system(commande.c_str());
1096        if (codret != 0)
1097        {
1098          // GERALD -- QMESSAGE BOX
1099          std::cerr << ". Menage du repertoire de calcul" << DirCompute.str() << std::endl;
1100          ASSERT("Pb au menage du repertoire de calcul" == 0);
1101        }
1102     }
1103     else
1104     {
1105 //  Le repertoire existe et s'il n'est pas vide, on sort en erreur :
1106        DIR *dp;
1107        struct dirent *dirp;
1108        dp  = opendir(DirCompute.str().c_str());
1109        bool result = true;
1110        while ((dirp = readdir(dp)) != NULL && result )
1111        {
1112             std::string file_name(dirp->d_name);
1113             result = file_name.empty() || file_name == "." || file_name == ".."; //if any file - break and return false
1114        }
1115        closedir(dp);
1116        if ( result == false)
1117        {
1118           SALOME::ExceptionStruct es;
1119           es.type = SALOME::BAD_PARAM;
1120           std::string text = "Directory : " + DirCompute.str() + "is not empty";
1121           es.text = CORBA::string_dup(text.c_str());
1122           throw SALOME::SALOME_Exception(es);
1123           return false;
1124        }
1125     }
1126   }
1127
1128   // B.3. Le sous-repertoire de l'iteration precedente
1129   const char* nomDirItPa ;
1130   std::stringstream DirComputePa ;
1131   if (NumeIter == 1)
1132   {
1133     nomDirItPa = nomDirIt;
1134     DirComputePa << DirCompute.str();
1135   }
1136   else
1137   {
1138     nomDirItPa = myIterationParent->GetDirName();
1139     DirComputePa << nomDir << "/" << nomDirItPa;
1140   }
1141   MESSAGE( ". nomDirItPa = " << nomDirItPa);
1142   MESSAGE( ". DirComputePa = " << DirComputePa.str() );
1143
1144   // B.4. Le fichier des messages
1145   chdir(DirCompute.str().c_str()) ;
1146   std::string MessFile = DirCompute.str() + "/Liste." + siter + ".vers." + siterp1 ;
1147   MESSAGE (". MessFile = " << MessFile);
1148   myIteration->SetMessFile(MessFile.c_str());
1149
1150    // C. On passe dans le repertoire de l'iteration a calculer
1151   chdir(DirCompute.str().c_str()) ;
1152
1153   // D. Les donnees du calcul HOMARD
1154   // D.1. Le type de conformite
1155   int ConfType = myCase->GetConfType();
1156   MESSAGE ( ". ConfType = " << ConfType );
1157
1158   // D.2. Le maillage n
1159   const char* NomMeshParent = myIterationParent->GetMeshName();
1160   MESSAGE ( ". NomMeshParent = " << NomMeshParent );
1161   const char* MeshFileParent = myIterationParent->GetMeshFile();
1162   MESSAGE ( ". MeshFileParent = " << MeshFileParent );
1163
1164   // D.3. Le maillage n+1
1165   const char* NomMesh = myIteration->GetMeshName();
1166   MESSAGE ( ". NomMesh = " << NomMesh );
1167   const char* MeshFile = myIteration->GetMeshFile();
1168   MESSAGE ( ". MeshFile = " << MeshFile );
1169   FILE *file = fopen(MeshFile,"r");
1170   if (file != NULL)
1171   {
1172      fclose(file);
1173      if (etatMenage == 0)
1174      {
1175           SALOME::ExceptionStruct es;
1176           es.type = SALOME::BAD_PARAM;
1177           std::string text = "MeshFile : " + std::string(MeshFile) + " already exists ";
1178           es.text = CORBA::string_dup(text.c_str());
1179           throw SALOME::SALOME_Exception(es);
1180           return false;
1181      }
1182      else
1183      {
1184          std::string commande = "rm -f " + std::string(MeshFile);
1185          codret = system(commande.c_str());
1186          if (codret != 0)
1187          {
1188           SALOME::ExceptionStruct es;
1189           es.type = SALOME::BAD_PARAM;
1190           std::string text = "PB with meshfile destruction ";
1191           es.text = CORBA::string_dup(text.c_str());
1192           throw SALOME::SALOME_Exception(es);
1193           return false;
1194          }
1195       }
1196   }
1197   else
1198   {
1199      codret = 0 ;
1200   };
1201
1202
1203   // D.4. Les types de raffinement et de deraffinement
1204   // Les appels corba sont lourds, il vaut mieux les grouper
1205   HOMARD::listeTypes* ListTypes = myHypo->GetAdapRefinUnRef();
1206   ASSERT(ListTypes->length() == 3);
1207   int TypeAdap = (*ListTypes)[0];
1208   int TypeRaff = (*ListTypes)[1];
1209   int TypeDera = (*ListTypes)[2];
1210
1211   // D.6. L'option d'interpolation des champs
1212   int TypeFieldInterp = myHypo->GetTypeFieldInterp();
1213
1214   // E. Texte du fichier de configuration
1215   // E.1. Incontournables du texte
1216   HomardDriver* myDriver = new HomardDriver(siter, siterp1);
1217   myDriver->TexteInit(DirCompute.str(), DirComputePa.str(),MessFile);
1218   myDriver->TexteMaillage(NomMeshParent, MeshFileParent, 0);
1219   myDriver->TexteMaillage(NomMesh, MeshFile, 1);
1220   myDriver->TexteConfRaffDera(ConfType, TypeAdap, TypeRaff, TypeDera);
1221
1222   // E.2. Ajout des informations liees aux zones eventuelles
1223   if (TypeAdap == 0)
1224   {
1225     HOMARD::listeZonesHypo* ListZone = myHypo->GetZones();
1226     int numberOfZones = ListZone->length();
1227
1228     for (int NumZone = 0; NumZone< numberOfZones; NumZone++)
1229     {
1230       std::string ZoneName = std::string((*ListZone)[NumZone]);
1231       MESSAGE ( "... ZoneName = " << ZoneName);
1232       HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[ZoneName];
1233       ASSERT(!CORBA::is_nil(myZone));
1234
1235       int ZoneType = myZone->GetZoneType();
1236       MESSAGE ( "... ZoneType = " << ZoneType);
1237       HOMARD::double_array* zone = myZone->GetCoords();
1238       if ( ZoneType == 2 or ( ZoneType>=11 and ZoneType <=13 ) ) // Cas d un parallelepipede ou d'un rectangle
1239       {
1240         myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], 0., 0., 0.);
1241       }
1242       else if ( ZoneType == 4 ) // Cas d une sphere
1243       {
1244         myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], 0., 0., 0., 0., 0.);
1245       }
1246       else if ( ZoneType == 5 or ( ZoneType>=31 and ZoneType <=33 ) ) // Cas d un cylindre ou d'un disque
1247       {
1248         myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], 0.);
1249       }
1250       else if ( ZoneType == 7 or ( ZoneType>=61 and ZoneType <=63 ) ) // Cas d un tuyau ou disque perce
1251       {
1252         myDriver->TexteZone(NumZone+1, ZoneType, (*zone)[0], (*zone)[1], (*zone)[2], (*zone)[3], (*zone)[4], (*zone)[5], (*zone)[6], (*zone)[7], (*zone)[8]);
1253       }
1254       else { ASSERT("ZoneType est incorrect." == 0) ; }
1255     }
1256   }
1257   // E.3. Ajout des informations liees aux champs eventuels
1258   if (TypeAdap == 1)
1259   {
1260 //  Le fichier du champ
1261     char* FieldFile = myIteration->GetFieldFile();
1262     MESSAGE ( ". FieldFile = " << FieldFile );
1263     if (strlen(FieldFile) == 0)
1264     {
1265       // GERALD -- QMESSAGE BOX
1266       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1267       ASSERT("The file for the field is not given." == 0);
1268     }
1269 //  Les caracteristiques d'instants
1270     int TimeStep = myIteration->GetTimeStep();
1271     MESSAGE( ". TimeStep = " << TimeStep );
1272     int Rank = myIteration->GetRank();
1273     MESSAGE( ". Rank = " << Rank );
1274 //  Les informations sur les champ
1275     HOMARD::InfosHypo* aInfosHypo = myHypo->GetField();
1276 //  Le nom
1277     const char* FieldName = aInfosHypo->FieldName;
1278 //  Les seuils
1279     int TypeThR = aInfosHypo->TypeThR;
1280     double ThreshR = aInfosHypo->ThreshR;
1281     int TypeThC = aInfosHypo->TypeThC;
1282     double ThreshC = aInfosHypo->ThreshC;
1283 //  Saut entre mailles ou non ?
1284     int UsField = aInfosHypo->UsField;
1285     MESSAGE( ". UsField = " << UsField );
1286 //  L'usage des composantes
1287     int UsCmpI = aInfosHypo->UsCmpI;
1288     MESSAGE( ". UsCmpI = " << UsCmpI );
1289 //
1290     myDriver->TexteField(FieldName, FieldFile, TimeStep, Rank, TypeThR, ThreshR, TypeThC, ThreshC, UsField, UsCmpI);
1291 //
1292 //  Les composantes
1293     HOMARD::listeComposantsHypo* mescompo = myHypo->GetListComp();
1294     int numberOfCompos = mescompo->length();
1295     MESSAGE( ". numberOfCompos = " << numberOfCompos );
1296     for (int NumeComp = 0; NumeComp< numberOfCompos; NumeComp++)
1297     {
1298       std::string nomCompo = std::string((*mescompo)[NumeComp]);
1299       MESSAGE( "... nomCompo = " << nomCompo );
1300       myDriver->TexteCompo(NumeComp, nomCompo);
1301     }
1302   }
1303   // E.4. Ajout des informations liees au filtrage eventuel par les groupes
1304   HOMARD::ListGroupType* listeGroupes = myHypo->GetGroups();
1305   int numberOfGroups = listeGroupes->length();
1306   MESSAGE( ". numberOfGroups = " << numberOfGroups );
1307   if (numberOfGroups > 0)
1308   {
1309
1310     for (int NumGroup = 0; NumGroup< numberOfGroups; NumGroup++)
1311     {
1312       std::string GroupName = std::string((*listeGroupes)[NumGroup]);
1313       MESSAGE( "... GroupName = " << GroupName );
1314       myDriver->TexteGroup(GroupName);
1315     }
1316   }
1317
1318   // E.5. Ajout des informations liees a l'eventuel suivi de frontiere
1319   // On ecrit d'abord la definition des frontieres, puis les liens avec les groupes
1320   std::list<std::string>  ListeBoundaryTraitees ;
1321   HOMARD::ListBoundaryGroupType* ListBoundaryGroupType = myCase->GetBoundaryGroup();
1322   int numberOfitems = ListBoundaryGroupType->length();
1323   MESSAGE ( "... number of string for Boundary+Group = " << numberOfitems);
1324   int BoundaryOption = 1 ;
1325   int NumBoundaryAnalytical = 0 ;
1326   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1327   {
1328     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1329     MESSAGE ( "... BoundaryName = " << BoundaryName);
1330     int A_faire = 1 ;
1331     std::list<std::string>::const_iterator it = ListeBoundaryTraitees.begin();
1332     while (it != ListeBoundaryTraitees.end())
1333     {
1334       MESSAGE ( "... BoundaryNameTraitee = " << *it);
1335       if ( BoundaryName == *it ) { A_faire = 0 ; }
1336       it++;
1337     }
1338     if ( A_faire == 1 )
1339     {
1340 // Caracteristiques de la frontiere
1341       HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1342       ASSERT(!CORBA::is_nil(myBoundary));
1343       int BoundaryType = myBoundary->GetBoundaryType();
1344       MESSAGE ( "... BoundaryType = " << BoundaryType );
1345 // Ecriture selon le type
1346       if (BoundaryType == 0) // Cas d une frontiere discrete
1347       {
1348         const char* MeshName = myBoundary->GetMeshName() ;
1349         const char* MeshFile = myBoundary->GetMeshFile() ;
1350         myDriver->TexteBoundaryDi( MeshName, MeshFile);
1351         BoundaryOption = BoundaryOption*2 ;
1352       }
1353       else // Cas d une frontiere analytique
1354       {
1355         NumBoundaryAnalytical++ ;
1356         HOMARD::double_array* coor = myBoundary->GetCoords();
1357         if (BoundaryType == 1) // Cas d un cylindre
1358         {
1359           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], (*coor)[4], (*coor)[5], (*coor)[6]);
1360           BoundaryOption = BoundaryOption*3 ;
1361         }
1362         else if (BoundaryType == 2) // Cas d une sphere
1363         {
1364           myDriver->TexteBoundaryAn(BoundaryName, NumBoundaryAnalytical, BoundaryType, (*coor)[0], (*coor)[1], (*coor)[2], (*coor)[3], 0., 0., 0.);
1365           BoundaryOption = BoundaryOption*3 ;
1366         }
1367       }
1368 // Memorisation du traitement
1369       ListeBoundaryTraitees.push_back( BoundaryName );
1370     }
1371   }
1372   NumBoundaryAnalytical = 0 ;
1373   for (int NumBoundary = 0; NumBoundary< numberOfitems; NumBoundary=NumBoundary+2)
1374   {
1375     std::string BoundaryName = std::string((*ListBoundaryGroupType)[NumBoundary]);
1376     MESSAGE ( "... BoundaryName = " << BoundaryName);
1377     HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[BoundaryName];
1378     ASSERT(!CORBA::is_nil(myBoundary));
1379     int BoundaryType = myBoundary->GetBoundaryType();
1380     MESSAGE ( "... BoundaryType = " << BoundaryType );
1381 //  Recuperation du nom du groupe
1382     std::string GroupName = std::string((*ListBoundaryGroupType)[NumBoundary+1]);
1383     MESSAGE ( "... GroupName = " << GroupName);
1384     if (BoundaryType == 0) // Cas d une frontiere discrete
1385     {
1386       if ( GroupName.size() > 0 ) { myDriver->TexteBoundaryDiGr ( GroupName ) ; }
1387     }
1388     else // Cas d une frontiere analytique
1389     {
1390       NumBoundaryAnalytical++ ;
1391       myDriver->TexteBoundaryAnGr ( BoundaryName, NumBoundaryAnalytical, GroupName ) ;
1392     }
1393   }
1394   myDriver->TexteBoundaryOption(BoundaryOption);
1395
1396   // E.6. Ajout des informations liees a l'eventuelle interpolation des champs
1397   MESSAGE( "... TypeFieldInterp = " << TypeFieldInterp );
1398   if (TypeFieldInterp != 0)
1399   {
1400 //  Le fichier des champs
1401     char* FieldFile = myIteration->GetFieldFile();
1402     MESSAGE ( ". FieldFile = " << FieldFile );
1403     if (strlen(FieldFile) == 0)
1404     {
1405       // GERALD -- QMESSAGE BOX
1406       std::cerr << "Le fichier du champ n'a pas ete fourni." << std::endl;
1407       ASSERT("The file for the field is not given." == 0);
1408     }
1409 //  Les caracteristiques d'instants
1410     int TimeStep = myIteration->GetTimeStep();
1411     MESSAGE( ". TimeStep = " << TimeStep );
1412     int Rank = myIteration->GetRank();
1413     MESSAGE( ". Rank = " << Rank );
1414 //
1415     myDriver->TexteFieldInterp(TypeFieldInterp, FieldFile, MeshFile, TimeStep, Rank);
1416 //  Les champs
1417     if (TypeFieldInterp == 2)
1418     {
1419       HOMARD::listFieldInterpHypo* meschamps = myHypo->GetListFieldInterp();
1420       int numberOfFields = meschamps->length();
1421       MESSAGE( ". numberOfFields = " << numberOfFields );
1422       for (int NumeChamp = 0; NumeChamp< numberOfFields; NumeChamp++)
1423       {
1424         std::string nomChamp = std::string((*meschamps)[NumeChamp]);
1425         MESSAGE( "... nomChamp = " << nomChamp );
1426         myDriver->TexteFieldInterpName(NumeChamp, nomChamp);
1427       }
1428     }
1429   }
1430   // E.7. Ajout des options avancees
1431   int NivMax = myCase->GetNivMax();
1432   MESSAGE ( ". NivMax = " << NivMax );
1433   if ( NivMax > 0 )
1434   {
1435     double DiamMin = myCase->GetDiamMin();
1436     MESSAGE ( ". DiamMin = " << DiamMin );
1437     myDriver->TexteAdvanced(NivMax, DiamMin);
1438   }
1439
1440   // F. Ecriture du texte dans le fichier
1441   if (codret == 0)
1442   {
1443     myDriver->CreeFichier();
1444   }
1445
1446 // G. Execution
1447 //
1448   int codretexec = 1 ;
1449   if (codret == 0)
1450   {
1451     codretexec = myDriver->ExecuteHomard();
1452 //
1453     if (codretexec == 0)
1454     {
1455       SetEtatIter(nomIteration,true);
1456     }
1457     else
1458     {
1459       // GERALD -- QMESSAGE BOX
1460       SetEtatIter(nomIteration,false);
1461     }
1462   }
1463
1464   // H. Gestion des resultats
1465   if (codret == 0)
1466   {
1467     // H.1. Le fichier des messages, dans tous les cas
1468     std::stringstream saux1 ;
1469     saux1 << "Mess " << NumeIter ;
1470     PublishFileUnderIteration(nomIteration, MessFile.c_str(), saux1.str().c_str());
1471
1472     // H.2. Si tout s'est bien passe :
1473     if (codretexec == 0)
1474     {
1475     // H.2.1. Le fichier de bilan
1476       std::stringstream saux2 ;
1477       saux2 << "Summary " << NumeIter ;
1478       std::string SummaryFile = DirCompute.str() + "/apad." + siterp1 + ".bilan" ;
1479       PublishFileUnderIteration(nomIteration, SummaryFile.c_str(), saux2.str().c_str());
1480     // H.2.2. Le fichier de  maillage obtenu
1481       std::stringstream saux0 ;
1482       saux0 <<"Iteration " << NumeIter ;
1483       PublishFileUnderIteration(nomIteration, MeshFile, saux0.str().c_str());
1484       PublishResultInSmesh(MeshFile, 1);
1485     }
1486   // H.3 Message d'erreur en cas de probleme
1487     else
1488     {
1489       SALOME::ExceptionStruct es;
1490       es.type = SALOME::BAD_PARAM;
1491       std::string text = "Error during the adaptation.\n" ;
1492       try
1493       {
1494           ifstream fichier(MessFile.c_str(), ios::in);
1495           string ligne;
1496           while(getline(fichier, ligne) and (ligne != "===== HOMARD ===== STOP ====="));
1497           while (getline(fichier, ligne)) { text += ligne+ "\n";};
1498       }
1499       catch (...) {
1500         text += "no log file ....";
1501       }
1502       es.text = CORBA::string_dup(text.c_str());
1503       throw SALOME::SALOME_Exception(es);
1504     }
1505   }
1506
1507   // I. Menage
1508   if (codret == 0)
1509   {
1510     delete myDriver;
1511   }
1512   //
1513   if (codret == 0) { return true; }
1514   else { return false; }
1515 }
1516
1517 //===========================================================================
1518 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
1519                                                    SALOMEDS::SObject_ptr theSObject,
1520                                                    CORBA::Object_ptr theObject,
1521                                                    const char* theName)
1522 {
1523   MESSAGE("PublishInStudy pour " << theName);
1524   SALOMEDS::SObject_var aResultSO;
1525   if (CORBA::is_nil(theStudy))
1526   {
1527     SALOME::ExceptionStruct es;
1528     es.type = SALOME::BAD_PARAM;
1529     es.text = "Invalid Study Context ";
1530     throw SALOME::SALOME_Exception(es);
1531     return 0;
1532   };
1533
1534 // Recuperation de l'objet correspondant, en essayant chacun des types possibles
1535 // Rq : Iteration est publiee ailleurs
1536   HOMARD::HOMARD_Cas_var        aCase  = HOMARD::HOMARD_Cas::_narrow(theObject);
1537   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theObject);
1538   HOMARD::HOMARD_Zone_var       aZone = HOMARD::HOMARD_Zone::_narrow(theObject);
1539   HOMARD::HOMARD_Boundary_var   aBoundary = HOMARD::HOMARD_Boundary::_narrow(theObject);
1540
1541    addInStudy(theStudy);
1542
1543 // Controle de la non publication d'un objet de meme nom
1544    if ((!aHypo->_is_nil()) or (!aZone->_is_nil()) or (!aBoundary->_is_nil()))
1545     {
1546       SALOMEDS::Study::ListOfSObject_var listSO = theStudy->FindObjectByName(theName, ComponentDataType());
1547       if (listSO->length() >= 1)
1548       {
1549           MESSAGE("This name "<<theName<<" is already used "<<listSO->length()<<" time(s)");
1550           std::cerr <<"This name "<<theName<<" is already used "<<listSO->length()<<" time(s)" << std::endl;
1551           aResultSO = listSO[0];
1552           return aResultSO._retn();
1553       }
1554     }
1555
1556   // Caracteristiques de l'etude
1557   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
1558   aStudyBuilder->NewCommand();
1559   if(!aCase->_is_nil())
1560     aResultSO = PublishCaseInStudy(theStudy, aStudyBuilder, aCase, theName);
1561   else if(!aHypo->_is_nil())
1562     aResultSO = PublishHypotheseInStudy(theStudy, aStudyBuilder, aHypo, theName);
1563   else if(!aZone->_is_nil())
1564     aResultSO = PublishZoneInStudy(theStudy, aStudyBuilder, aZone, theName);
1565   else if(!aBoundary->_is_nil())
1566     aResultSO = PublishBoundaryInStudy(theStudy, aStudyBuilder, aBoundary, theName);
1567
1568     aStudyBuilder->CommitCommand();
1569   return aResultSO._retn();
1570 };
1571 //=============================================================================
1572 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishCaseInStudy(SALOMEDS::Study_ptr theStudy,
1573                                                        SALOMEDS::StudyBuilder_var aStudyBuilder,
1574                                                        HOMARD::HOMARD_Cas_ptr theObject, const char* theName)
1575 {
1576   MESSAGE("PublishCaseInStudy pour "<<theName);
1577   SALOMEDS::SObject_var aResultSO;
1578   SALOMEDS::GenericAttribute_var anAttr;
1579
1580   if (CORBA::is_nil(theObject)) {
1581     MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1582     return aResultSO._retn();
1583   }
1584   if (theStudy->_is_nil()) {
1585     MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1586     return aResultSO._retn();
1587   }
1588
1589   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1590   if (theFatherHomard->_is_nil())
1591   {
1592     MESSAGE("theFatherHomard->_is_nil()");
1593     return aResultSO._retn();
1594   }
1595
1596   aResultSO = aStudyBuilder->NewObject(theFatherHomard);
1597   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "CasHomard", "cas_calcule.png",
1598                      _orb->object_to_string(theObject) ) ;
1599   return aResultSO._retn();
1600 }
1601
1602 //=============================================================================
1603 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishZoneInStudy(SALOMEDS::Study_ptr theStudy,
1604                     SALOMEDS::StudyBuilder_var aStudyBuilder,
1605                    HOMARD::HOMARD_Zone_ptr theObject, const char* theName)
1606 {
1607   MESSAGE("PublishZoneStudy pour "<<theName);
1608   SALOMEDS::SObject_var aResultSO;
1609   SALOMEDS::GenericAttribute_var anAttr;
1610
1611   if (CORBA::is_nil(theObject))
1612   {
1613     MESSAGE("HOMARD_Gen_i.cxx::theObject->_is_nil()");
1614     return aResultSO._retn();
1615   }
1616   if (theStudy->_is_nil())
1617   {
1618     MESSAGE("HOMARD_Gen_i.cxx::theStudy->_is_nil()");
1619     return aResultSO._retn();
1620   }
1621   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1622   if (theFatherHomard->_is_nil())
1623   {
1624     MESSAGE("theFatherHomard->_is_nil()");
1625     return aResultSO._retn();
1626   }
1627
1628   // Caracteristique de la zone
1629   HOMARD::HOMARD_Zone_var myZone = myContextMap[GetCurrentStudyID()]._mesZones[theName];
1630   CORBA::Long ZoneType = myZone->GetZoneType();
1631
1632   // On ajoute la categorie des zones dans l etude si necessaire
1633   SALOMEDS::SObject_var aSOZone;
1634   if (!theFatherHomard->FindSubObject(100, aSOZone))
1635   {
1636     MESSAGE("Ajout de la categorie des zones");
1637     aSOZone = aStudyBuilder->NewObjectToTag(theFatherHomard, 100);
1638     PublishInStudyAttr(aStudyBuilder, aSOZone, "Zones", "ZoneList", "zone_icone_2.png", NULL ) ;
1639   }
1640   else { MESSAGE("La categorie des zones existe deja."); }
1641
1642   aResultSO = aStudyBuilder->NewObject(aSOZone);
1643   const char* icone ;
1644   switch (ZoneType)
1645   {
1646     case 11 :
1647     { }
1648     case 12 :
1649     { }
1650     case 13 :
1651     { icone = "boxdxy_2.png" ;
1652       break ;
1653     }
1654     case 2 :
1655     { icone = "boxdxyz_2.png" ;
1656       break ;
1657     }
1658     case 31 :
1659     { }
1660     case 32 :
1661     { }
1662     case 33 :
1663     { icone = "disk_2.png" ;
1664       break ;
1665      }
1666     case 4 :
1667     { icone = "spherepoint_2.png" ;
1668       break ;
1669     }
1670     case 5 :
1671     { icone = "cylinderpointvector_2.png" ;
1672       break ;
1673     }
1674     case 61 :
1675     { }
1676     case 62 :
1677     { }
1678     case 63 :
1679     { icone = "diskwithhole_2.png" ;
1680       break ;
1681      }
1682     case 7 :
1683     { icone = "pipe_2.png" ;
1684       break ;
1685     }
1686   }
1687   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "ZoneHomard", icone, _orb->object_to_string(theObject) ) ;
1688
1689   return aResultSO._retn();
1690 }
1691 //=============================================================================
1692 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishBoundaryInStudy(SALOMEDS::Study_ptr theStudy,
1693                    SALOMEDS::StudyBuilder_var aStudyBuilder,
1694                    HOMARD::HOMARD_Boundary_ptr theObject, const char* theName)
1695 {
1696   MESSAGE("PublishBoundaryStudy pour "<<theName);
1697   SALOMEDS::SObject_var aResultSO;
1698   SALOMEDS::GenericAttribute_var anAttr;
1699
1700   // Caracteristique de la Boundary
1701   HOMARD::HOMARD_Boundary_var myBoundary = myContextMap[GetCurrentStudyID()]._mesBoundarys[theName];
1702
1703   // On recupere le module pere dans l etude
1704   SALOMEDS::SComponent_var       theFatherHomard = theStudy->FindComponent(ComponentDataType());
1705   if (theFatherHomard->_is_nil())
1706   {
1707     MESSAGE("theFatherHomard->_is_nil()");
1708     return aResultSO._retn();
1709   }
1710
1711   // On ajoute la categorie des boundarys dans l etude si necessaire
1712   SALOMEDS::SObject_var aSOBoundary;
1713   if (!theFatherHomard->FindSubObject(101, aSOBoundary))
1714   {
1715     MESSAGE("Ajout de la categorie des boundarys");
1716     aSOBoundary = aStudyBuilder->NewObjectToTag(theFatherHomard, 101);
1717     PublishInStudyAttr(aStudyBuilder, aSOBoundary, "Boundaries", "BoundList", "zone_icone_2.png", NULL ) ;
1718   }
1719   else { MESSAGE("La categorie des boundarys existe deja."); }
1720
1721   aResultSO = aStudyBuilder->NewObject(aSOBoundary);
1722   CORBA::Long BoundaryType = myBoundary->GetBoundaryType();
1723 //   MESSAGE("BoundaryType : "<<BoundaryType);
1724   const char* icone ;
1725   const char* value ;
1726   switch (BoundaryType)
1727   {
1728     case 0 :
1729     { value = "BoundaryDiHomard" ;
1730       icone = "mesh_tree_mesh.png" ;
1731       break;
1732     }
1733     case 1 :
1734     { value = "BoundaryAnHomard" ;
1735       icone = "cylinderpointvector_2.png" ;
1736       break;
1737     }
1738     case 2 :
1739     { value = "BoundaryAnHomard" ;
1740       icone = "spherepoint_2.png" ;
1741       break;
1742     }
1743   }
1744   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, value, icone, _orb->object_to_string(theObject));
1745   return aResultSO._retn();
1746 }
1747
1748 //=============================================================================
1749 SALOMEDS::SObject_ptr HOMARD_Gen_i::PublishHypotheseInStudy(SALOMEDS::Study_ptr theStudy,
1750                    SALOMEDS::StudyBuilder_var aStudyBuilder,
1751                    HOMARD::HOMARD_Hypothesis_ptr theObject, const char* theName)
1752 {
1753   MESSAGE("PublishHypotheseInStudy pour "<<theName);
1754   SALOMEDS::SObject_var aResultSO;
1755   SALOMEDS::GenericAttribute_var anAttr;
1756
1757   // On recupere le module pere dans l etude
1758   // On ajoute la categorie des hypotheses dans l etude si necessaire
1759   SALOMEDS::SComponent_var theFatherHomard = theStudy->FindComponent(ComponentDataType());
1760   if (theFatherHomard->_is_nil())
1761   {
1762     MESSAGE("theFatherHomard->_is_nil()");
1763     return aResultSO._retn();
1764   }
1765   SALOMEDS::SObject_var aSOHypothese;
1766   if (!theFatherHomard->FindSubObject(0, aSOHypothese))
1767   {
1768     MESSAGE("Ajout de la categorie des hypotheses");
1769     aSOHypothese = aStudyBuilder->NewObjectToTag(theFatherHomard, 0);
1770     PublishInStudyAttr(aStudyBuilder, aSOHypothese, "Hypothesis", "HypoList","hypotheses.png", NULL);
1771   }
1772   else { MESSAGE("La categorie des hypotheses existe deja."); }
1773
1774 // Creation du resultat dans l'etude
1775   aResultSO = aStudyBuilder->NewObject(aSOHypothese);
1776   PublishInStudyAttr(aStudyBuilder, aResultSO, theName, "HypoHomard", NULL, _orb->object_to_string(theObject) ) ;
1777
1778   return aResultSO._retn();
1779 }
1780 //===========================================================================
1781 void HOMARD_Gen_i::PublishInStudyAttr(SALOMEDS::StudyBuilder_var aStudyBuilder,
1782                                       SALOMEDS::SObject_var aResultSO,
1783                                       const char* name, const char* value, const char* icone, const char* ior)
1784 {
1785   SALOMEDS::GenericAttribute_var anAttr ;
1786 //  Ajout du nom
1787   if ( name != NULL )
1788   {
1789     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
1790     SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
1791     aNameAttrib->SetValue(name);
1792   }
1793
1794 //  Ajout du commentaire
1795   if ( value != NULL )
1796   {
1797     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeComment");
1798     SALOMEDS::AttributeComment_var aCommentAttrib = SALOMEDS::AttributeComment::_narrow(anAttr);
1799     aCommentAttrib->SetValue(value);
1800   }
1801
1802 //  Ajout de l'icone
1803   if ( icone != NULL  )
1804   {
1805     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO,"AttributePixMap");
1806     SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1807     aPixmap->SetPixMap(icone);
1808   }
1809
1810 //  Ajout de l ior
1811   if ( ior != NULL  )
1812   {
1813     anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
1814     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1815     anIOR->SetValue(ior);
1816   }
1817 };
1818
1819 //=============================================================================
1820 HOMARD::listeCases* HOMARD_Gen_i::GetAllCases()
1821 {
1822   MESSAGE("GetAllCases");
1823   IsValidStudy () ;
1824
1825   HOMARD::listeCases_var ret = new HOMARD::listeCases;
1826   ret->length(myContextMap[GetCurrentStudyID()]._mesCas.size());
1827   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it;
1828   int i = 0;
1829   for (it  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
1830         it != myContextMap[GetCurrentStudyID()]._mesCas.end(); it++)
1831   {
1832     ret[i++] = CORBA::string_dup((*it).first.c_str());
1833   }
1834
1835   return ret._retn();
1836 }
1837
1838 //=============================================================================
1839 HOMARD::listeHypotheses* HOMARD_Gen_i::GetAllHypotheses()
1840 {
1841   MESSAGE("GetAllHypotheses");
1842   IsValidStudy () ;
1843
1844   HOMARD::listeHypotheses_var ret = new HOMARD::listeHypotheses;
1845   ret->length(myContextMap[GetCurrentStudyID()]._mesHypotheses.size());
1846   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it;
1847   int i = 0;
1848   for (it  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
1849   it != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it++)
1850   {
1851     ret[i++] = CORBA::string_dup((*it).first.c_str());
1852   }
1853
1854   return ret._retn();
1855 }
1856
1857 //=============================================================================
1858 HOMARD::listeZones* HOMARD_Gen_i::GetAllZones()
1859 {
1860   MESSAGE("GetAllZones");
1861   IsValidStudy () ;
1862
1863   HOMARD::listeZones_var ret = new HOMARD::listeZones;
1864   ret->length(myContextMap[GetCurrentStudyID()]._mesZones.size());
1865   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it;
1866   int i = 0;
1867   for (it  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
1868   it != myContextMap[GetCurrentStudyID()]._mesZones.end(); it++)
1869   {
1870     ret[i++] = CORBA::string_dup((*it).first.c_str());
1871   }
1872
1873   return ret._retn();
1874 }
1875
1876 //=============================================================================
1877 HOMARD::listeIterations* HOMARD_Gen_i::GetAllIterations()
1878 {
1879   MESSAGE("GetAllIterations");
1880   IsValidStudy () ;
1881
1882   HOMARD::listeIterations_var ret = new HOMARD::listeIterations;
1883   ret->length(myContextMap[GetCurrentStudyID()]._mesIterations.size());
1884   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it;
1885   int i = 0;
1886   for (it  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
1887   it != myContextMap[GetCurrentStudyID()]._mesIterations.end(); it++)
1888   {
1889     ret[i++] = CORBA::string_dup((*it).first.c_str());
1890   }
1891
1892   return ret._retn();
1893 }
1894 //=============================================================================
1895 HOMARD::listeBoundarys* HOMARD_Gen_i::GetAllBoundarys()
1896 {
1897   MESSAGE("GetAllBoundarys");
1898   IsValidStudy () ;
1899
1900   HOMARD::listeBoundarys_var ret = new HOMARD::listeBoundarys;
1901   ret->length(myContextMap[GetCurrentStudyID()]._mesBoundarys.size());
1902   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it;
1903   int i = 0;
1904   for (it  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
1905   it != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); it++)
1906   {
1907     ret[i++] = CORBA::string_dup((*it).first.c_str());
1908   }
1909
1910   return ret._retn();
1911 }
1912
1913 //=============================================================================
1914 char* HOMARD_Gen_i::GetCaseName(const char* nomIteration)
1915 {
1916   if (CORBA::is_nil(myCurrentStudy))
1917   {
1918       SALOME::ExceptionStruct es;
1919       es.type = SALOME::BAD_PARAM;
1920       es.text = "Invalid Study Context ";
1921       throw SALOME::SALOME_Exception(es);
1922       return 0;
1923   };
1924
1925   HOMARD::HOMARD_Iteration_var monIter = myContextMap[GetCurrentStudyID()]._mesIterations[nomIteration];
1926   ASSERT(!CORBA::is_nil(monIter));
1927   return CORBA::string_dup(monIter->GetCaseName());
1928 }
1929 //=============================================================================
1930 void HOMARD_Gen_i::PublishResultInSmesh(const char* NomFich, CORBA::Long IconeType)
1931 {
1932   MESSAGE( "PublishResultInSmesh " << NomFich);
1933   if (CORBA::is_nil(myCurrentStudy))
1934   {
1935       SALOME::ExceptionStruct es;
1936       es.type = SALOME::BAD_PARAM;
1937       es.text = "Invalid Study Context ";
1938       throw SALOME::SALOME_Exception(es);
1939       return ;
1940   };
1941
1942 // Le module SMESH est-il actif ?
1943   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
1944 //
1945   if (!CORBA::is_nil(aSmeshSO))
1946   {
1947 // On verifie que le fichier n est pas deja publie
1948     SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
1949     for (; aIter->More(); aIter->Next())
1950     {
1951        SALOMEDS::SObject_var  aSO = aIter->Value();
1952        SALOMEDS::GenericAttribute_var aGAttr;
1953        if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
1954        {
1955            SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1956            CORBA::String_var value=anAttr->Value();
1957            if (strcmp((const char*)value,NomFich) == 0)
1958            {
1959                 // GERALD -- QMESSAGE BOX
1960                 std::cerr << "fichier : "<< NomFich << " deja publie "<< std::endl;
1961                 return;
1962            }
1963        }
1964      }
1965
1966   }
1967
1968 // On enregistre le fichier
1969   MESSAGE( "Enregistrement du fichier");
1970   SALOME_LifeCycleCORBA* myLCC = new SALOME_LifeCycleCORBA(_NS);
1971   SMESH::SMESH_Gen_var aSmeshEngine = SMESH::SMESH_Gen::_narrow(myLCC->FindOrLoad_Component("FactoryServer","SMESH"));
1972   ASSERT(!CORBA::is_nil(aSmeshEngine));
1973   aSmeshEngine->SetCurrentStudy(myCurrentStudy);
1974   SMESH::DriverMED_ReadStatus theStatus;
1975   //aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1976
1977 // On met a jour les attributs AttributeExternalFileDef et AttributePixMap
1978   SMESH::mesh_array* mesMaillages=aSmeshEngine->CreateMeshesFromMED(NomFich, theStatus);
1979   for (int i = 0; i < mesMaillages->length();  i++)
1980   {
1981     MESSAGE( ". Mise a jour des attributs du maillage");
1982     SMESH::SMESH_Mesh_var monMaillage= (*mesMaillages)[i];
1983     SALOMEDS::SObject_var aSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(monMaillage)));
1984     SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1985     SALOMEDS::GenericAttribute_var aGAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributeExternalFileDef");
1986     SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
1987     anAttr->SetValue(NomFich);
1988     SALOMEDS::GenericAttribute_var aPixMap = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePixMap" );
1989     SALOMEDS::AttributePixMap_var anAttr2 = SALOMEDS::AttributePixMap::_narrow(aPixMap);
1990 //  IconeType = 0 : fichier issu d'une importation
1991 //  IconeType = 1 : fichier issu d'une execution HOMARD
1992     const char* icone ;
1993     if ( IconeType == 0 ) { icone = "mesh_tree_importedmesh.png" ; }
1994     else                  { icone = "mesh_tree_mesh.png" ; }
1995     anAttr2->SetPixMap( icone );
1996   }
1997
1998 }
1999 //=============================================================================
2000 void HOMARD_Gen_i::DeleteResultInSmesh(const char* NomFich, const char* MeshName)
2001 {
2002   MESSAGE (" DeleteResultInSmesh pour "<< NomFich << "et le maillage "<< MeshName);
2003   if (CORBA::is_nil(myCurrentStudy))
2004   {
2005       SALOME::ExceptionStruct es;
2006       es.type = SALOME::BAD_PARAM;
2007       es.text = "Invalid Study Context ";
2008       throw SALOME::SALOME_Exception(es);
2009       return ;
2010   };
2011
2012 // Le module SMESH est-il actif ?
2013   SALOMEDS::SObject_var aSmeshSO = myCurrentStudy->FindComponent("SMESH");
2014 //
2015   if (CORBA::is_nil(aSmeshSO))
2016   {
2017       return ;
2018   };
2019 // On verifie que le fichier est deja publie
2020   SALOMEDS::StudyBuilder_var myBuilder = myCurrentStudy->NewBuilder();
2021   SALOMEDS::ChildIterator_var aIter = myCurrentStudy->NewChildIterator(aSmeshSO);
2022   for (; aIter->More(); aIter->Next())
2023   {
2024      SALOMEDS::SObject_var  aSO = aIter->Value();
2025      SALOMEDS::GenericAttribute_var aGAttr;
2026      if (aSO->FindAttribute(aGAttr,"AttributeExternalFileDef"))
2027      {
2028        SALOMEDS::AttributeExternalFileDef_var anAttr = SALOMEDS::AttributeExternalFileDef::_narrow(aGAttr);
2029        CORBA::String_var value=anAttr->Value();
2030        if (strcmp((const char*)value,NomFich) == 0)
2031        {
2032          if (aSO->FindAttribute(aGAttr,"AttributeName"))
2033          {
2034            SALOMEDS::AttributeName_var anAttr2 = SALOMEDS::AttributeName::_narrow(aGAttr);
2035            CORBA::String_var value2=anAttr2->Value();
2036            if (strcmp((const char*)value2,MeshName) == 0)
2037            {
2038              myBuilder->RemoveObjectWithChildren( aSO ) ;
2039            }
2040          }
2041        }
2042      }
2043   }
2044
2045 }
2046 //=============================================================================
2047 void HOMARD_Gen_i::PublishFileUnderIteration(const char* NomIter, const char* NomFich, const char* Commentaire)
2048 {
2049   if (CORBA::is_nil(myCurrentStudy))
2050   {
2051       SALOME::ExceptionStruct es;
2052       es.type = SALOME::BAD_PARAM;
2053       es.text = "Invalid Study Context ";
2054       throw SALOME::SALOME_Exception(es);
2055       return ;
2056   };
2057
2058   HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[NomIter];
2059   if (CORBA::is_nil(myIteration))
2060   {
2061       SALOME::ExceptionStruct es;
2062       es.type = SALOME::BAD_PARAM;
2063       es.text = "Invalid Iteration ";
2064       throw SALOME::SALOME_Exception(es);
2065       return ;
2066   };
2067   SALOMEDS::SObject_var aIterSO=SALOMEDS::SObject::_narrow(myCurrentStudy->FindObjectIOR(_orb->object_to_string(myIteration)));
2068   if (CORBA::is_nil(myIteration))
2069   {
2070       SALOME::ExceptionStruct es;
2071       es.type = SALOME::BAD_PARAM;
2072       es.text = "Invalid Iteration Study Object";
2073       throw SALOME::SALOME_Exception(es);
2074       return ;
2075   };
2076
2077   SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
2078
2079   aStudyBuilder->NewCommand();
2080
2081   SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aIterSO);
2082 // Pour les fichiers med, on affiche une icone de maillage
2083 // Pour les fichiers qui sont texte, on affiche une icone de fichier texte 'texte'
2084 // Le reperage se fait par la 1ere lettre du commentaire : I pour Iteration n
2085   const char* icone ;
2086   const char* ior = " " ;
2087   if ( Commentaire[0] == 'I' )
2088   { icone = "med.png" ; }
2089   else
2090   { icone = "texte_2.png" ; }
2091   PublishInStudyAttr(aStudyBuilder, aSubSO, NomFich, Commentaire, icone, ior ) ;
2092
2093   aStudyBuilder->CommitCommand();
2094 }
2095
2096 //=====================================================================================
2097 void HOMARD_Gen_i::IsValidStudy( )
2098 //=====================================================================================
2099 {
2100   MESSAGE( "IsValidStudy" );
2101   if (CORBA::is_nil(myCurrentStudy))
2102   {
2103     SALOME::ExceptionStruct es;
2104     es.type = SALOME::BAD_PARAM;
2105     es.text = "Invalid Study Context";
2106     throw SALOME::SALOME_Exception(es);
2107   };
2108   return ;
2109 }
2110
2111 //===========================================================================
2112 //
2113 // Next functions are inherited from SALOMEDS::Driver interface
2114 //
2115 //===========================================================================
2116
2117 //===========================================================================
2118 SALOMEDS::TMPFile* HOMARD_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
2119                                       const char* theURL,
2120                                       bool isMultiFile)
2121 {
2122   MESSAGE (" Save pour theURL = "<< theURL);
2123   SALOMEDS::TMPFile_var aStreamFile;
2124
2125   // get temporary directory name
2126   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2127
2128   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2129   StudyContext& context = myContextMap[ aStudy->StudyId() ];
2130
2131   // HOMARD data file name
2132   std::string aFileName = "";
2133   if (isMultiFile)
2134     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2135   aFileName += "_HOMARD.dat";
2136
2137   // initialize sequence of file names
2138   SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2139   aFileSeq->length(1);
2140   aFileSeq[0] = CORBA::string_dup(aFileName.c_str()) ;
2141
2142   // get full path to the data file
2143   aFileName = tmpDir + aFileName;
2144
2145   // save data
2146   // -> create file
2147   std::ofstream f(aFileName.c_str());
2148
2149   // clear temporary id map
2150   context._idmap.clear();
2151
2152   int id = 1;
2153
2154   // -> dump cases
2155   std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_case;
2156   for (it_case = context._mesCas.begin(); it_case != context._mesCas.end(); ++it_case) {
2157     HOMARD::HOMARD_Cas_var aCas = it_case->second;
2158     PortableServer::ServantBase_var aServant = GetServant(aCas);
2159     HOMARD_Cas_i* aCasServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2160     if (aCasServant) {
2161       f << HOMARD::GetSignature(HOMARD::Case) << aCasServant->Dump() << std::endl;
2162       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aCasServant);
2163     }
2164   }
2165   // -> dump zones
2166   std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2167   for (it_zone = context._mesZones.begin(); it_zone != context._mesZones.end(); ++it_zone) {
2168     HOMARD::HOMARD_Zone_var aZone = it_zone->second;
2169     PortableServer::ServantBase_var aServant = GetServant(aZone);
2170     HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2171     if (aZoneServant) {
2172       f << HOMARD::GetSignature(HOMARD::Zone) << aZoneServant->Dump() << std::endl;
2173       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2174     }
2175   }
2176   // -> dump hypotheses
2177   std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2178   for (it_hypo = context._mesHypotheses.begin(); it_hypo != context._mesHypotheses.end(); ++it_hypo) {
2179     HOMARD::HOMARD_Hypothesis_var aHypo = it_hypo->second;
2180     PortableServer::ServantBase_var aServant = GetServant(aHypo);
2181     HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2182     if (aHypoServant) {
2183       f << HOMARD::GetSignature(HOMARD::Hypothesis) << aHypoServant->Dump() << std::endl;
2184       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2185     }
2186   }
2187   // -> dump iterations
2188   std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2189   for (it_iter = context._mesIterations.begin(); it_iter != context._mesIterations.end(); ++it_iter) {
2190     HOMARD::HOMARD_Iteration_var aIter = it_iter->second;
2191     PortableServer::ServantBase_var aServant = GetServant(aIter);
2192     HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2193     if (aIterServant) {
2194       f << HOMARD::GetSignature(HOMARD::Iteration) << aIterServant->Dump() << std::endl;
2195       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2196     }
2197   }
2198   // -> dump boundaries
2199   std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2200   for (it_boundary = context._mesBoundarys.begin(); it_boundary != context._mesBoundarys.end(); ++it_boundary) {
2201     HOMARD::HOMARD_Boundary_var aBoundary = it_boundary->second;
2202     PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2203     HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2204     if (aBoundaryServant) {
2205       f << HOMARD::GetSignature(HOMARD::Boundary) << aBoundaryServant->Dump() << std::endl;
2206       context._idmap[id++] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2207     }
2208   }
2209   // -> close file
2210   MESSAGE ("close file");
2211   f.close();
2212
2213   // put temporary files to the stream
2214   MESSAGE ("put temporary files to the stream");
2215   aStreamFile = SALOMEDS_Tool::PutFilesToStream(tmpDir.c_str(), aFileSeq.in(), isMultiFile);
2216
2217   // remove temporary files
2218   MESSAGE ("remove temporary files");
2219   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2220
2221   // return data stream
2222   MESSAGE ("return data stream");
2223   return aStreamFile._retn();
2224 };
2225
2226 //===========================================================================
2227 SALOMEDS::TMPFile* HOMARD_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
2228                                            const char* theURL,
2229                                            bool isMultiFile)
2230 {
2231   // No specific ASCII persistence
2232   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
2233   return aStreamFile._retn();
2234 };
2235
2236 //===========================================================================
2237 CORBA::Boolean HOMARD_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
2238                                    const SALOMEDS::TMPFile& theStream,
2239                                    const char* theURL,
2240                                    bool isMultiFile)
2241 {
2242   MESSAGE (" Load pour theURL = "<< theURL);
2243   SALOMEDS::Study_var aStudy = theComponent->GetStudy();
2244
2245   // set current study
2246   if (myCurrentStudy->_is_nil() || aStudy->StudyId() != myCurrentStudy->StudyId())
2247     SetCurrentStudy(aStudy);
2248
2249   // get temporary directory name
2250   std::string tmpDir = isMultiFile ? std::string(theURL) : SALOMEDS_Tool::GetTmpDir();
2251
2252   // Convert the stream into sequence of files to process
2253   SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles(theStream,
2254                                                                             tmpDir.c_str(),
2255                                                                             isMultiFile);
2256   // HOMARD data file name
2257   std::string aFileName = "";
2258   if (isMultiFile)
2259     aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL());
2260   aFileName = tmpDir + aFileName + "_HOMARD.dat";
2261
2262   StudyContext& context = myContextMap[ aStudy->StudyId() ];
2263
2264   // save data
2265   // -> create file
2266   std::ifstream f(aFileName.c_str());
2267
2268   // clear context
2269   context._mesCas.clear();
2270   context._mesHypotheses.clear();
2271   context._mesIterations.clear();
2272   context._mesZones.clear();
2273   context._mesBoundarys.clear();
2274   context._idmap.clear();
2275
2276   int id = 1;
2277   std::string line;
2278
2279   while (f) {
2280     std::getline(f, line);
2281     std::string caseSignature = HOMARD::GetSignature(HOMARD::Case);
2282     std::string zoneSignature = HOMARD::GetSignature(HOMARD::Zone);
2283     std::string iterSignature = HOMARD::GetSignature(HOMARD::Iteration);
2284     std::string hypoSignature = HOMARD::GetSignature(HOMARD::Hypothesis);
2285     std::string bounSignature = HOMARD::GetSignature(HOMARD::Boundary);
2286     if (line.substr(0, caseSignature.size()) == caseSignature) {
2287       // re-create case
2288       MESSAGE (" Recreation du cas" );
2289       HOMARD::HOMARD_Cas_var aCase = newCase();
2290       PortableServer::ServantBase_var aServant = GetServant(aCase);
2291       HOMARD_Cas_i* aCaseServant = dynamic_cast<HOMARD_Cas_i*>(aServant.in());
2292       if (aCaseServant && aCaseServant->Restore(line.substr(caseSignature.size()))) {
2293         context._mesCas[aCase->GetName()] = aCase;
2294         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aCaseServant);
2295       }
2296     }
2297     else if (line.substr(0, zoneSignature.size()) == zoneSignature) {
2298       MESSAGE (" Recreation de la zone" );
2299       // re-create zone
2300       HOMARD::HOMARD_Zone_var aZone = newZone();
2301       PortableServer::ServantBase_var aServant = GetServant(aZone);
2302       HOMARD_Zone_i* aZoneServant = dynamic_cast<HOMARD_Zone_i*>(aServant.in());
2303       if (aZoneServant && aZoneServant->Restore(line.substr(zoneSignature.size()))) {
2304         context._mesZones[aZone->GetName()] = aZone;
2305         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aZoneServant);
2306       }
2307     }
2308     else if (line.substr(0, iterSignature.size()) == iterSignature) {
2309       // re-create iteration
2310       MESSAGE (" Recreation de l iteration" );
2311       HOMARD::HOMARD_Iteration_var aIter = newIteration();
2312       PortableServer::ServantBase_var aServant = GetServant(aIter);
2313       HOMARD_Iteration_i* aIterServant = dynamic_cast<HOMARD_Iteration_i*>(aServant.in());
2314       if (aIterServant && aIterServant->Restore(line.substr(iterSignature.size()))) {
2315         context._mesIterations[aIter->GetName()] = aIter;
2316         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aIterServant);
2317       }
2318     }
2319     else if (line.substr(0, hypoSignature.size()) == hypoSignature) {
2320       // re-create hypothesis
2321       MESSAGE (" Recreation de l hypothese" );
2322       HOMARD::HOMARD_Hypothesis_var aHypo = newHypothesis();
2323       PortableServer::ServantBase_var aServant = GetServant(aHypo);
2324       HOMARD_Hypothesis_i* aHypoServant = dynamic_cast<HOMARD_Hypothesis_i*>(aServant.in());
2325       if (aHypoServant && aHypoServant->Restore(line.substr(hypoSignature.size()))) {
2326         context._mesHypotheses[aHypo->GetName()] = aHypo;
2327         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aHypoServant);
2328       }
2329     }
2330     else if (line.substr(0, bounSignature.size()) == bounSignature) {
2331       // re-create boundary
2332       MESSAGE (" Recreation de la frontiere" );
2333       HOMARD::HOMARD_Boundary_var aBoundary = newBoundary();
2334       PortableServer::ServantBase_var aServant = GetServant(aBoundary);
2335       HOMARD_Boundary_i* aBoundaryServant = dynamic_cast<HOMARD_Boundary_i*>(aServant.in());
2336       if (aBoundaryServant && aBoundaryServant->Restore(line.substr(bounSignature.size()))) {
2337         context._mesBoundarys[aBoundary->GetName()] = aBoundary;
2338         context._idmap[id] = dynamic_cast<PortableServer::ServantBase*>(aBoundaryServant);
2339       }
2340     }
2341     id++;
2342   }
2343
2344   // -> close file
2345   f.close();
2346
2347   // Remove temporary files created from the stream
2348   if (!isMultiFile)
2349     SALOMEDS_Tool::RemoveTemporaryFiles(tmpDir.c_str(), aFileSeq.in(), true);
2350
2351   return true;
2352 };
2353
2354 //===========================================================================
2355 CORBA::Boolean HOMARD_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
2356                                         const SALOMEDS::TMPFile& theStream,
2357                                         const char* theURL,
2358                                         bool isMultiFile)
2359 {
2360   // No specific ASCII persistence
2361   return Load(theComponent, theStream, theURL, isMultiFile);
2362 };
2363
2364 //===========================================================================
2365 void HOMARD_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
2366 {
2367   if (theComponent->GetStudy()->StudyId() == GetCurrentStudyID()) {
2368     // clearing study context should be done here:
2369     // - destroy all servants and related CORBA objects
2370     // ... (TODO)
2371     // - remove context from myContextMap
2372     myContextMap.erase(theComponent->GetStudy()->StudyId());
2373     // - nullify myCurrentStudy
2374     myCurrentStudy = SALOMEDS::Study::_nil();
2375   }
2376 };
2377
2378 //===========================================================================
2379 char* HOMARD_Gen_i::ComponentDataType()
2380 {
2381   return CORBA::string_dup("HOMARD");
2382 };
2383
2384 //===========================================================================
2385 char* HOMARD_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
2386                                             const char* IORString,
2387                                             CORBA::Boolean isMultiFile,
2388                                             CORBA::Boolean isASCII)
2389 {
2390   CORBA::String_var aString("");
2391   if (!CORBA::is_nil(theSObject) && strcmp(IORString, "") != 0) {
2392     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2393     CORBA::Object_var anObj = _orb->string_to_object(IORString);
2394     if (!CORBA::is_nil(anObj)) {
2395       PortableServer::ServantBase_var aServant = GetServant(anObj);
2396       PortableServer::ServantBase* aStorable = dynamic_cast<PortableServer::ServantBase*>(aServant.in());
2397       if (aStorable) {
2398         std::map<int, PortableServer::ServantBase*>::const_iterator it;
2399         for (it = context._idmap.begin(); it != context._idmap.end(); ++it) {
2400           if (it->second == aStorable) {
2401             std::stringstream os;
2402             os << it->first;
2403             aString = CORBA::string_dup(os.str().c_str());
2404           }
2405         }
2406       }
2407     }
2408   }
2409   return aString._retn();
2410 };
2411
2412 //===========================================================================
2413 char* HOMARD_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
2414                                             const char* aLocalPersistentID,
2415                                             CORBA::Boolean isMultiFile,
2416                                             CORBA::Boolean isASCII)
2417 {
2418   CORBA::String_var aString("");
2419   if (!CORBA::is_nil(theSObject) && strcmp(aLocalPersistentID, "") != 0) {
2420     StudyContext context = myContextMap[ theSObject->GetStudy()->StudyId() ];
2421     int id = atoi(aLocalPersistentID);
2422     if (id > 0 && context._idmap.find(id) != context._idmap.end()) {
2423       CORBA::Object_var object = _poa->servant_to_reference(context._idmap[ id ]);
2424       if (!CORBA::is_nil(object)) {
2425         aString = _orb->object_to_string(object);
2426       }
2427     }
2428   }
2429   return aString._retn();
2430 };
2431
2432 //===========================================================================
2433 bool HOMARD_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
2434 {
2435   if(CORBA::is_nil(myCurrentStudy))
2436     return false;
2437
2438   HOMARD::HOMARD_Cas_var aCas = HOMARD::HOMARD_Cas::_narrow(theIOR);
2439   if(!aCas->_is_nil())
2440     return true;
2441
2442   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(theIOR);
2443   if(!aHypo->_is_nil())
2444     return true;
2445
2446   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(theIOR);
2447   if(!aZone->_is_nil())
2448     return true;
2449
2450   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(theIOR);
2451   if(!aBoundary->_is_nil())
2452     return true;
2453
2454   /* Iteration is not published directly
2455   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(theIOR);
2456   if(!aIter->_is_nil())
2457     return true;
2458   */
2459   return false;
2460 };
2461
2462 //===========================================================================
2463 CORBA::Boolean HOMARD_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject)
2464 {
2465   // No Copy/Paste support
2466   return false;
2467 };
2468
2469 //===========================================================================
2470 SALOMEDS::TMPFile* HOMARD_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject,
2471                                            CORBA::Long& theObjectID)
2472 {
2473   // No Copy/Paste support
2474   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
2475   return aStreamFile._retn();
2476 };
2477
2478 //===========================================================================
2479 CORBA::Boolean  HOMARD_Gen_i::CanPaste(const char *theComponentName,
2480                                         CORBA::Long theObjectID)
2481 {
2482   // No Copy/Paste support
2483   return false;
2484 };
2485
2486 //===========================================================================
2487 SALOMEDS::SObject_ptr HOMARD_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
2488                                                CORBA::Long theObjectID,
2489                                                SALOMEDS::SObject_ptr theSObject)
2490 {
2491   // No Copy/Paste support
2492   SALOMEDS::SObject_var aResultSO;
2493   return aResultSO._retn();
2494 };
2495
2496 //===========================================================================
2497 PortableServer::ServantBase_var HOMARD_Gen_i::GetServant(CORBA::Object_ptr theObject)
2498 {
2499   PortableServer::Servant aServant = 0;
2500   if (!CORBA::is_nil(theObject)) {
2501     try {
2502       aServant = _poa->reference_to_servant(theObject);
2503     }
2504     catch (...) {
2505     }
2506   }
2507   return aServant;
2508 }
2509
2510 //===========================================================================
2511 HOMARD::HOMARD_Cas_ptr HOMARD_Gen_i::newCase()
2512 {
2513   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2514   HOMARD_Cas_i* aServant = new HOMARD_Cas_i(_orb, engine);
2515   HOMARD::HOMARD_Cas_var aCase = HOMARD::HOMARD_Cas::_narrow(aServant->_this());
2516   return aCase._retn();
2517 }
2518
2519 //===========================================================================
2520 HOMARD::HOMARD_Hypothesis_ptr HOMARD_Gen_i::newHypothesis()
2521 {
2522   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2523   HOMARD_Hypothesis_i* aServant = new HOMARD_Hypothesis_i(_orb, engine);
2524   HOMARD::HOMARD_Hypothesis_var aHypo = HOMARD::HOMARD_Hypothesis::_narrow(aServant->_this());
2525   return aHypo._retn();
2526 }
2527
2528 //===========================================================================
2529 HOMARD::HOMARD_Iteration_ptr HOMARD_Gen_i::newIteration()
2530 {
2531   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2532   HOMARD_Iteration_i* aServant = new HOMARD_Iteration_i(_orb, engine);
2533   HOMARD::HOMARD_Iteration_var aIter = HOMARD::HOMARD_Iteration::_narrow(aServant->_this());
2534   return aIter._retn();
2535 }
2536
2537 //===========================================================================
2538 HOMARD::HOMARD_Boundary_ptr HOMARD_Gen_i::newBoundary()
2539 {
2540   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2541   HOMARD_Boundary_i* aServant = new HOMARD_Boundary_i(_orb, engine);
2542   HOMARD::HOMARD_Boundary_var aBoundary = HOMARD::HOMARD_Boundary::_narrow(aServant->_this());
2543   return aBoundary._retn();
2544 }
2545 //===========================================================================
2546 HOMARD::HOMARD_Zone_ptr HOMARD_Gen_i::newZone()
2547 {
2548   HOMARD::HOMARD_Gen_var engine = POA_HOMARD::HOMARD_Gen::_this();
2549   HOMARD_Zone_i* aServant = new HOMARD_Zone_i(_orb, engine);
2550   HOMARD::HOMARD_Zone_var aZone = HOMARD::HOMARD_Zone::_narrow(aServant->_this());
2551   return aZone._retn();
2552 }
2553 //==========================================================================
2554 Engines::TMPFile* HOMARD_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
2555                                        CORBA::Boolean isPublished,
2556                                        CORBA::Boolean isMultiFile,
2557                                        CORBA::Boolean& isValidScript)
2558 {
2559    MESSAGE ("Entree dans DumpPython");
2560    isValidScript=1;
2561    SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
2562    if(CORBA::is_nil(aStudy))
2563      return new Engines::TMPFile(0);
2564
2565    SALOMEDS::SObject_var aSO = aStudy->FindComponent("HOMARD");
2566    if(CORBA::is_nil(aSO))
2567       return new Engines::TMPFile(0);
2568
2569    std::string aScript = "\"\"\"\n";
2570    aScript += "Python script for HOMARD\n";
2571    aScript += "Copyright EDF-R&D 2010\n";
2572    aScript += "\"\"\"\n";
2573    aScript += "__revision__ = \"V1.2\"\n";
2574    aScript += "import HOMARD\n";
2575    if( isMultiFile )
2576       aScript += "import salome\n";
2577    aScript += "homard = salome.lcc.FindOrLoadComponent('FactoryServer','HOMARD')\n";
2578    if( isMultiFile ) {
2579       aScript += "def RebuildData(theStudy):\n";
2580       aScript += "\thomard.SetCurrentStudy(theStudy)\n";
2581    }
2582    else
2583       aScript += "\thomard.SetCurrentStudy(salome.myStudy)\n";
2584
2585
2586    if (myContextMap[GetCurrentStudyID()]._mesBoundarys.size() > 0)
2587    {
2588     aScript += "#\n# Creation of the boundaries";
2589     aScript +=  "\n# ==========================";
2590    }
2591    std::map<std::string, HOMARD::HOMARD_Boundary_var>::const_iterator it_boundary;
2592    for (it_boundary  = myContextMap[GetCurrentStudyID()]._mesBoundarys.begin();
2593         it_boundary != myContextMap[GetCurrentStudyID()]._mesBoundarys.end(); ++it_boundary)
2594    {
2595     HOMARD::HOMARD_Boundary_var maBoundary = (*it_boundary).second;
2596     CORBA::String_var dumpCorbaBoundary = maBoundary->GetDumpPython();
2597     std::string dumpBoundary = dumpCorbaBoundary.in();
2598     aScript+=dumpBoundary;
2599    }
2600
2601
2602    if (myContextMap[GetCurrentStudyID()]._mesZones.size() > 0)
2603    {
2604     aScript += "#\n# Creation of the zones";
2605     aScript +=  "\n# =====================";
2606    }
2607    std::map<std::string, HOMARD::HOMARD_Zone_var>::const_iterator it_zone;
2608    for ( it_zone  = myContextMap[GetCurrentStudyID()]._mesZones.begin();
2609          it_zone != myContextMap[GetCurrentStudyID()]._mesZones.end(); ++it_zone)
2610    {
2611     HOMARD::HOMARD_Zone_var maZone = (*it_zone).second;
2612     CORBA::String_var dumpCorbaZone = maZone->GetDumpPython();
2613     std::string dumpZone = dumpCorbaZone.in();
2614     aScript+=dumpZone;
2615    }
2616
2617
2618    aScript += "#\n# Creation of the hypotheses";
2619    aScript +=  "\n# ==========================";
2620    std::map<std::string, HOMARD::HOMARD_Hypothesis_var>::const_iterator it_hypo;
2621    for ( it_hypo  = myContextMap[GetCurrentStudyID()]._mesHypotheses.begin();
2622          it_hypo != myContextMap[GetCurrentStudyID()]._mesHypotheses.end(); it_hypo++)
2623    {
2624     HOMARD::HOMARD_Hypothesis_var monHypo = (*it_hypo).second;
2625     CORBA::String_var dumpCorbaHypo = monHypo->GetDumpPython();
2626     std::string dumpHypo = dumpCorbaHypo.in();
2627     aScript+=dumpHypo;
2628    }
2629
2630
2631    aScript += "#\n# Creation of the cases";
2632    aScript += "\n# =====================";
2633    std::map<std::string, HOMARD::HOMARD_Cas_var>::const_iterator it_cas;
2634    for (it_cas  = myContextMap[GetCurrentStudyID()]._mesCas.begin();
2635         it_cas != myContextMap[GetCurrentStudyID()]._mesCas.end(); it_cas++)
2636         {
2637            std::string nomCas = (*it_cas).first;
2638            std::string dumpCas = std::string("\n# Creation of the case ") ;
2639            dumpCas +=  nomCas + std::string("\n");
2640            dumpCas += std::string("\t") + nomCas;
2641            dumpCas += std::string(" = homard.CreateCase('") + nomCas + std::string("', '");
2642
2643            HOMARD::HOMARD_Cas_var myCase = (*it_cas).second;
2644            CORBA::String_var cIter0= myCase->GetIter0Name();
2645            std::string iter0 = cIter0.in();
2646
2647            HOMARD::HOMARD_Iteration_var myIteration = myContextMap[GetCurrentStudyID()]._mesIterations[iter0];
2648            CORBA::String_var cMesh0= myIteration->GetMeshFile();
2649            std::string mesh0 = cMesh0.in();
2650            CORBA::String_var cMeshName0= myIteration->GetMeshName();
2651            std::string meshName0 = cMeshName0.in();
2652            dumpCas += meshName0 + std::string("', '")+ mesh0 + std::string("')\n");
2653            CORBA::String_var dumpCorbaCase = myCase->GetDumpPython();
2654            std::string dumpCas2= dumpCorbaCase.in();
2655
2656            aScript+=dumpCas + dumpCas2;
2657         };
2658
2659
2660    aScript += "#\n# Creation of the iterations" ;
2661    aScript += "\n# ==========================";
2662    std::map<std::string, HOMARD::HOMARD_Iteration_var>::const_iterator it_iter;
2663    for (it_iter  = myContextMap[GetCurrentStudyID()]._mesIterations.begin();
2664         it_iter != myContextMap[GetCurrentStudyID()]._mesIterations.end(); ++it_iter)
2665    {
2666     HOMARD::HOMARD_Iteration_var aIter = (*it_iter).second;
2667     CORBA::String_var dumpCorbaIter = aIter->GetDumpPython();
2668     std::string dumpIter = dumpCorbaIter.in();
2669     aScript+=dumpIter;
2670    }
2671
2672     if( isMultiFile )
2673       aScript += "\n\tpass";
2674     aScript += "\n";
2675
2676     if( !isMultiFile ) // remove unnecessary tabulation
2677       aScript = RemoveTabulation( aScript );
2678
2679    const size_t aLen = strlen(aScript.c_str());
2680    char* aBuffer = new char[aLen+1];
2681    strcpy(aBuffer, aScript.c_str());
2682
2683    CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
2684    Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
2685
2686    return aStreamFile._retn();
2687 }
2688
2689 //=============================================================================
2690 extern "C"
2691 {
2692   PortableServer::ObjectId* HOMARDEngine_factory(CORBA::ORB_ptr orb,
2693                                                   PortableServer::POA_ptr poa,
2694                                                   PortableServer::ObjectId* contId,
2695                                                   const char* instanceName,
2696                                                   const char* interfaceName)
2697   {
2698     MESSAGE("PortableServer::ObjectId* HOMARDEngine_factory()");
2699     HOMARD_Gen_i* myHOMARD_Gen = new HOMARD_Gen_i(orb, poa, contId, instanceName, interfaceName);
2700     return myHOMARD_Gen->getId();
2701   }
2702 }