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