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