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