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