Salome HOME
Introduction de la frontière CAO
[modules/homard.git] / src / HOMARD / YACSDriver.cxx
1 //  HOMARD HOMARD : implementation of HOMARD idl descriptions
2 //
3 // Copyright (C) 2011-2016  CEA/DEN, EDF R&D
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21
22 // Pilote l'ecriture du fichier xml pour lancer un schema YACS
23
24 #include <cstring>
25 #ifndef WIN32
26 #include <unistd.h>
27 #endif
28 #include <sys/stat.h>
29
30 #include "YACSDriver.hxx"
31 #include "HOMARD.hxx"
32 #include "Utils_SALOME_Exception.hxx"
33 #include "utilities.h"
34
35 //=============================================================================
36 //=============================================================================
37 YACSDriver::YACSDriver(const std::string XMLFile, const std::string DirName):
38   _XMLFile( "" ), _DirName( "" ),
39   _Texte( "" ),
40   _Texte_parametres( "" ),
41   _noeud_1( "CreateCase" ),
42   _bLu( false )
43 {
44   MESSAGE("XMLFile = "<<XMLFile<<", DirName ="<<DirName);
45   _XMLFile = XMLFile;
46   _DirName = DirName;
47 }
48 //=============================================================================
49 //=============================================================================
50 YACSDriver::~YACSDriver()
51 {
52 }
53 //===============================================================================
54 // Ajout d'une ligne simple
55 //===============================================================================
56 void YACSDriver::TexteAdd( const std::string ligne )
57 {
58 //   MESSAGE("TexteAdd, ligne ="<<ligne);
59 //
60   _Texte += ligne + "\n" ;
61 //
62 }
63 //===============================================================================
64 // Nom du fichier du maillage initial
65 //===============================================================================
66 void YACSDriver::Texte_DataInit_MeshFile( const std::string Meshfile )
67 {
68   MESSAGE("TexteInitMeshfile, Meshfile ="<<Meshfile);
69 //
70   _Texte += "         <value><string>" ;
71   _Texte += Meshfile ;
72   _Texte += "</string></value>\n" ;
73 //
74 }
75 //===============================================================================
76 // Le repertoire de calcul
77 // Le script de lancement
78 //===============================================================================
79 void YACSDriver::Texte_Alternance_Calcul_HOMARD_Calcul( const std::string FileName )
80 {
81   MESSAGE("Texte_Alternance_Calcul_HOMARD_Calcul, FileName : "<<FileName);
82 //
83   int position = FileName.find_last_of( '/' ) ;
84   std::string nomfic = FileName.substr( position+1 ) ;
85   position = nomfic.find_last_of( '.' ) ;;
86   nomfic = nomfic.substr( 0, position ) ;
87   MESSAGE("nomfic : "<<nomfic) ;
88 //
89   _Texte += "rep_calc = \"" + _DirName + "\"\n" ;
90   _Texte += "rep_script = os.path.dirname(\"" + FileName + "\")\n" ;
91   _Texte += "sys.path.append(rep_script)\n" ;
92   _Texte += "from " + nomfic + " import Script\n" ;
93 //
94 }
95 //===============================================================================
96 // Les options du cas
97 //===============================================================================
98 void YACSDriver::Texte_Iter_1_Case_Options( const std::string pythonTexte )
99 {
100   MESSAGE("Texte_Iter_1_Case_Options, pythonTexte\n"<<pythonTexte);
101 //
102   _Texte += "DirName = \"" + _DirName + "/HOMARD\"\n" ;
103   _Texte += "Case.SetDirName(DirName)\n" ;
104
105   Texte_python_1( pythonTexte, 1, "Case" ) ;
106 //
107 }
108 //===============================================================================
109 // La description des zones
110 // ZoneType : le type de la zone
111 // pythonStructure : le python correspondant a la zone
112 // methode : methode associee a la creation de la zone
113 // ZoneName : nom de la zone
114 //===============================================================================
115 std::string YACSDriver::Texte_Iter_1_Zone( int ZoneType, const std::string pythonStructure, const std::string methode, const std::string ZoneName )
116 {
117   MESSAGE("Texte_Iter_1_Zone, ZoneType = "<<ZoneType<<", pythonStructure = "<<pythonStructure);
118   MESSAGE("methode = "<<methode<<", ZoneName = "<<ZoneName );
119 //
120 // 1. Le nom du noeud
121   std::string noeud_2 = methode + "_" + ZoneName ;
122   std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1." ;
123   node += noeud_2 ;
124 // 2. Texte de controle : le noeud precedent est _noeud_1, le noeud courant noeud_2.
125 //                        A la fin, on bascule le courant dans le precedent
126   std::string texte_control = Texte_control (_noeud_1, noeud_2, 1) ;
127   _noeud_1 = noeud_2 ;
128 // 3. Definition du service
129   _Texte += "                           <service name=\"" + noeud_2 + "\">\n" ;
130   _Texte += "                              <node>Etude_Initialisation.SetCurrentStudy</node>\n" ;
131   _Texte += "                              <method>" + methode + "</method>\n" ;
132 // 4. Les inports
133 // 4.1. Le nom de la zone
134   _Texte += Texte_inport( "string", "ZoneName" ) ;
135    TexteParametre( node, "ZoneName", "string", ZoneName ) ;
136 // 4.2. Les valeurs numeriques
137 //      ATTENTION : les noms doivent etre les memes que dans Gen.xml, donc HOMARD_Gen.idl
138 // 4.2.1. Decodage des valeurs
139 // La chaine pythonStructure est de ce genre :
140 //   CreateZoneBox( "Zone_1", 0.144, 0.216, 0.096, 0.1464, 0.076, 0.12)
141   std::string ligne = pythonStructure ;
142 // On commence par ne garder que ce qui suit la premiere virgule
143   ligne = GetStringInTexte( ligne, ",", 1 );
144 // On boucle pour isoler toutes les chaines dans les virgules
145   std::string lignebis ;
146   std::string x0, x1, x2, x3, x4, x5, x6, x7, x8  ;
147   int iaux = 0  ;
148   while ( ligne != lignebis )
149   {
150     lignebis = GetStringInTexte ( ligne, ",", 0 ) ;
151 //     MESSAGE("lignebis = "<<lignebis );
152     if      ( iaux == 0 ) { x0 = lignebis ; }
153     else if ( iaux == 1 ) { x1 = lignebis ; }
154     else if ( iaux == 2 ) { x2 = lignebis ; }
155     else if ( iaux == 3 ) { x3 = lignebis ; }
156     else if ( iaux == 4 ) { x4 = lignebis ; }
157     else if ( iaux == 5 ) { x5 = lignebis ; }
158     else if ( iaux == 6 ) { x6 = lignebis ; }
159     else if ( iaux == 7 ) { x7 = lignebis ; }
160     ligne = GetStringInTexte( ligne, ",", 1 );
161     iaux += 1 ;
162   }
163 // La derniere valeur est toujours mise dans x8
164   x8 = GetStringInTexte ( ligne, ")", 0 ) ;
165   MESSAGE("coor = "<< x0<<","<<x1<< ","<< x2<< ","<< x3<<","<<x4<<","<<x5<<","<<x6<<","<<x7<<","<<x8);
166 // 4.2. Cas du parallelepipede (2)
167   if ( ZoneType == 2 )
168   {
169     _Texte += Texte_inport( "double", "Xmini" ) ;
170     _Texte += Texte_inport( "double", "Xmaxi" ) ;
171     _Texte += Texte_inport( "double", "Ymini" ) ;
172     _Texte += Texte_inport( "double", "Ymaxi" ) ;
173     _Texte += Texte_inport( "double", "Zmini" ) ;
174     _Texte += Texte_inport( "double", "Zmaxi" ) ;
175     TexteParametre( node, "Xmini", "double", x0 ) ;
176     TexteParametre( node, "Xmaxi", "double", x1 ) ;
177     TexteParametre( node, "Ymini", "double", x2 ) ;
178     TexteParametre( node, "Ymaxi", "double", x3 ) ;
179     TexteParametre( node, "Zmini", "double", x4 ) ;
180     TexteParametre( node, "Zmaxi", "double", x8 ) ;
181   }
182 //
183 // 4.2. Cas du rectangle (11, 12, 13)
184   else if ( ( ZoneType > 10 ) && ( ZoneType < 14 ) )
185   {
186     _Texte += Texte_inport( "double", "Umini" ) ;
187     _Texte += Texte_inport( "double", "Umaxi" ) ;
188     _Texte += Texte_inport( "double", "Vmini" ) ;
189     _Texte += Texte_inport( "double", "Vmaxi" ) ;
190     _Texte += Texte_inport( "long", "Orient" ) ;
191     TexteParametre( node, "Umini", "double", x0 ) ;
192     TexteParametre( node, "Umaxi", "double", x1 ) ;
193     TexteParametre( node, "Vmini", "double", x2 ) ;
194     TexteParametre( node, "Vmaxi", "double", x3 ) ;
195     TexteParametre( node, "Orient", "int", x8 ) ;
196   }
197 //
198 // 4.2. Cas du disque (31, 32, 33) ou du disque perce (61, 62, 63)
199   else if ( ( ( ZoneType > 30 ) && ( ZoneType < 34 ) ) || ( ( ZoneType > 60 ) && ( ZoneType < 64 ) ) )
200   {
201     _Texte += Texte_inport( "double", "Ucentre" ) ;
202     _Texte += Texte_inport( "double", "Vcentre" ) ;
203     _Texte += Texte_inport( "double", "Radius" ) ;
204     TexteParametre( node, "Ucentre", "double", x0 ) ;
205     TexteParametre( node, "Vcentre", "double", x1 ) ;
206     TexteParametre( node, "Radius", "double", x2 ) ;
207     if ( ZoneType > 60 )
208     {
209       _Texte += Texte_inport( "double", "InternalRadius" ) ;
210       TexteParametre( node, "InternalRadius", "double", x3 ) ;
211     }
212     _Texte += Texte_inport( "long", "Orient" ) ;
213     TexteParametre( node, "Orient", "int", x8 ) ;
214   }
215 //
216 // 4.2. Cas de la sphere (4)
217   else if ( ZoneType == 4 )
218   {
219     _Texte += Texte_inport( "double", "Xcentre" ) ;
220     _Texte += Texte_inport( "double", "Ycentre" ) ;
221     _Texte += Texte_inport( "double", "Zcentre" ) ;
222     _Texte += Texte_inport( "double", "Radius" ) ;
223     TexteParametre( node, "Xcentre", "double", x0 ) ;
224     TexteParametre( node, "Ycentre", "double", x1 ) ;
225     TexteParametre( node, "Zcentre", "double", x2 ) ;
226     TexteParametre( node, "Radius", "double", x8 ) ;
227   }
228 //
229 // 4.2. Cas du cylindre (5) ou du tuyau (7)
230   else if ( ZoneType == 5 || ZoneType == 7 )
231   {
232     _Texte += Texte_inport( "double", "Xcentre" ) ;
233     _Texte += Texte_inport( "double", "Ycentre" ) ;
234     _Texte += Texte_inport( "double", "Zcentre" ) ;
235     _Texte += Texte_inport( "double", "Xaxis" ) ;
236     _Texte += Texte_inport( "double", "Yaxis" ) ;
237     _Texte += Texte_inport( "double", "Zaxis" ) ;
238     _Texte += Texte_inport( "double", "Radius" ) ;
239     _Texte += Texte_inport( "double", "Height" ) ;
240     TexteParametre( node, "Xcentre", "double", x0 ) ;
241     TexteParametre( node, "Ycentre", "double", x1 ) ;
242     TexteParametre( node, "Zcentre", "double", x2 ) ;
243     TexteParametre( node, "Xaxis", "double", x3 ) ;
244     TexteParametre( node, "Yaxis", "double", x4 ) ;
245     TexteParametre( node, "Zaxis", "double", x5 ) ;
246     TexteParametre( node, "Radius", "double", x6 ) ;
247     if ( ZoneType == 5 )
248     {
249       TexteParametre( node, "Height", "double", x8 ) ;
250     }
251     else
252     {
253       _Texte += Texte_inport( "double", "InternalRadius" ) ;
254       TexteParametre( node, "Height", "double", x7 ) ;
255       TexteParametre( node, "InternalRadius", "double", x8 ) ;
256     }
257   }
258 //
259 // 4.2. Erreur
260   else
261   { VERIFICATION("Type de zone inconnu." == 0); }
262
263 //
264 // 5. La fin
265   _Texte += "                              <outport name=\"return\" type=\"HOMARD_Zone\"/>\n" ;
266   _Texte += "                           </service>\n" ;
267 //
268   return texte_control ;
269 //
270 }
271 //===============================================================================
272 // La description des frontieres
273 // BoundaryType : le type de la frontiere
274 // pythonStructure : le python correspondant a la frontiere
275 // methode : methode associee a la creation de la frontiere
276 // BoundaryName : nom de la frontiere
277 // MeshName : nom du maillage dans le cas d'une frontiere discrete
278 // MeshFile : nom du fichier du maillage dans le cas d'une frontiere discrete
279 //===============================================================================
280 std::string YACSDriver::Texte_Iter_1_Boundary( int BoundaryType, const std::string pythonStructure, const std::string methode, const std::string BoundaryName, const std::string MeshName, const std::string MeshFile )
281 {
282   MESSAGE("Texte_Iter_1_Boundary, BoundaryType = "<<BoundaryType<<", pythonStructure = "<<pythonStructure);
283   MESSAGE("methode = "<<methode<<", BoundaryName = "<<BoundaryName );
284   if (BoundaryType == 0) { MESSAGE("MeshName = "<<MeshName<<", MeshFile = "<<MeshFile ); }
285 //
286 // 1. Le nom du noeud
287   std::string noeud_2 = methode + "_" + BoundaryName ;
288   std::string node = "Boucle_de_convergence.Alternance_Calcul_HOMARD.Adaptation.p0_Adaptation_HOMARD.HOMARD_Initialisation.p1_Iter_1." ;
289   node += noeud_2 ;
290 // 2. Texte de controle : le noeud precedent est _noeud_1, le noeud courant noeud_2.
291 //                        A la fin, on bascule le courant dans le precedent
292   std::string texte_control = Texte_control (_noeud_1, noeud_2, 1) ;
293   _noeud_1 = noeud_2 ;
294 // 3. Definition du service
295   _Texte += "                           <service name=\"" + noeud_2 + "\">\n" ;
296   _Texte += "                              <node>Etude_Initialisation.SetCurrentStudy</node>\n" ;
297   _Texte += "                              <method>" + methode + "</method>\n" ;
298 // 4. Les inports
299 //    ATTENTION : les noms doivent etre les memes que dans Gen.xml, donc HOMARD_Gen.idl
300 // 4.1. Le nom de la frontiere
301   _Texte += Texte_inport( "string", "BoundaryName" ) ;
302   TexteParametre( node, "BoundaryName", "string", BoundaryName ) ;
303 // 4.2. Cas d une frontiere discrete
304   if (BoundaryType == 0)
305   {
306     _Texte += Texte_inport( "string", "MeshName" ) ;
307     TexteParametre( node, "MeshName", "string", MeshName ) ;
308     _Texte += Texte_inport( "string", "FileName" ) ;
309     TexteParametre( node, "FileName", "string", MeshFile ) ;
310   }
311 // 4.3. Cas d'une frontiere analytique : les valeurs numeriques
312   else
313   {
314 // 4.3.1. Decodage des valeurs
315 // La chaine pythonStructure est de ce genre :
316 //   CreateBoundaryCylinder('cyl_2', 17.5, -2.5, -12.5, -100., -75., -25., 50.)
317 //   CreateBoundaryDi("intersection", "PIQUAGE", "/scratch/D68518/Salome/script/sfr_2d_piquage.fr.med")
318     std::string ligne = pythonStructure ;
319 // On commence par ne garder que ce qui suit la premiere virgule
320     ligne = GetStringInTexte( ligne, ",", 1 );
321 // On boucle pour isoler toutes les chaines dans les virgules
322     std::string lignebis ;
323     std::string x0, x1, x2, x3, x4, x5, x6, x7  ;
324     int iaux = 0  ;
325     while ( ligne != lignebis )
326     {
327       lignebis = GetStringInTexte ( ligne, ",", 0 ) ;
328 //     MESSAGE("lignebis = "<<lignebis );
329       if      ( iaux == 0 ) { x0 = lignebis ; }
330       else if ( iaux == 1 ) { x1 = lignebis ; }
331       else if ( iaux == 2 ) { x2 = lignebis ; }
332       else if ( iaux == 3 ) { x3 = lignebis ; }
333       else if ( iaux == 4 ) { x4 = lignebis ; }
334       else if ( iaux == 5 ) { x5 = lignebis ; }
335       else if ( iaux == 6 ) { x6 = lignebis ; }
336       ligne = GetStringInTexte( ligne, ",", 1 );
337       iaux += 1 ;
338     }
339 // La derniere valeur est toujours mise dans x7
340     x7 = GetStringInTexte ( ligne, ")", 0 ) ;
341     MESSAGE("Valeurs = "<< x0<<", "<<x1<< ", "<< x2<< ", "<< x3<<", "<<x4<<", "<<x5<<", "<<x6<<", x7"<<x7);
342 //
343 // 4.3.2. Cas du cylindre (1)
344     if ( BoundaryType == 1 )
345     {
346       _Texte += Texte_inport( "double", "Xcentre" ) ;
347       _Texte += Texte_inport( "double", "Ycentre" ) ;
348       _Texte += Texte_inport( "double", "Zcentre" ) ;
349       _Texte += Texte_inport( "double", "Xaxis" ) ;
350       _Texte += Texte_inport( "double", "Yaxis" ) ;
351       _Texte += Texte_inport( "double", "Zaxis" ) ;
352       _Texte += Texte_inport( "double", "Radius" ) ;
353       TexteParametre( node, "Xcentre", "double", x0 ) ;
354       TexteParametre( node, "Ycentre", "double", x1 ) ;
355       TexteParametre( node, "Zcentre", "double", x2 ) ;
356       TexteParametre( node, "Xaxis", "double", x3 ) ;
357       TexteParametre( node, "Yaxis", "double", x4 ) ;
358       TexteParametre( node, "Zaxis", "double", x5 ) ;
359       TexteParametre( node, "Radius", "double", x7 ) ;
360     }
361 //
362 // 4.3.3. Cas de la sphere (2)
363     else if ( BoundaryType == 2 )
364     {
365       _Texte += Texte_inport( "double", "Xcentre" ) ;
366       _Texte += Texte_inport( "double", "Ycentre" ) ;
367       _Texte += Texte_inport( "double", "Zcentre" ) ;
368       _Texte += Texte_inport( "double", "Radius" ) ;
369       TexteParametre( node, "Xcentre", "double", x0 ) ;
370       TexteParametre( node, "Ycentre", "double", x1 ) ;
371       TexteParametre( node, "Zcentre", "double", x2 ) ;
372       TexteParametre( node, "Radius", "double", x7 ) ;
373     }
374 //
375 // 4.3.4. Cas d un cone defini par un axe et un angle
376     else if ( BoundaryType == 3 )
377     {
378       _Texte += Texte_inport( "double", "Xaxis" ) ;
379       _Texte += Texte_inport( "double", "Yaxis" ) ;
380       _Texte += Texte_inport( "double", "Zaxis" ) ;
381       _Texte += Texte_inport( "double", "Angle" ) ;
382       _Texte += Texte_inport( "double", "Xcentre" ) ;
383       _Texte += Texte_inport( "double", "Ycentre" ) ;
384       _Texte += Texte_inport( "double", "Zcentre" ) ;
385       TexteParametre( node, "Xaxis", "double", x0 ) ;
386       TexteParametre( node, "Yaxis", "double", x1 ) ;
387       TexteParametre( node, "Zaxis", "double", x2 ) ;
388       TexteParametre( node, "Angle", "double", x3 ) ;
389       TexteParametre( node, "Xcentre", "double", x4 ) ;
390       TexteParametre( node, "Ycentre", "double", x5 ) ;
391       TexteParametre( node, "Zcentre", "double", x7 ) ;
392     }
393 //
394 // 4.3.5. Cas d un cone defini par les 2 rayons
395     else if ( BoundaryType == 4 )
396     {
397       _Texte += Texte_inport( "double", "Xcentre1" ) ;
398       _Texte += Texte_inport( "double", "Ycentre1" ) ;
399       _Texte += Texte_inport( "double", "Zcentre1" ) ;
400       _Texte += Texte_inport( "double", "Radius1" ) ;
401       _Texte += Texte_inport( "double", "Xcentre2" ) ;
402       _Texte += Texte_inport( "double", "Ycentre2" ) ;
403       _Texte += Texte_inport( "double", "Zcentre2" ) ;
404       _Texte += Texte_inport( "double", "Radius2" ) ;
405       TexteParametre( node, "Xcentre1", "double", x0 ) ;
406       TexteParametre( node, "Ycentre1", "double", x1 ) ;
407       TexteParametre( node, "Zcentre1", "double", x2 ) ;
408       TexteParametre( node, "Radius1", "double", x3 ) ;
409       TexteParametre( node, "Xcentre2", "double", x4 ) ;
410       TexteParametre( node, "Ycentre2", "double", x5 ) ;
411       TexteParametre( node, "Zcentre2", "double", x6 ) ;
412       TexteParametre( node, "Radius2", "double", x7 ) ;
413     }
414 // 4.3.6. Cas du tore (5)
415     else if ( BoundaryType == 5 )
416     {
417       _Texte += Texte_inport( "double", "Xcentre" ) ;
418       _Texte += Texte_inport( "double", "Ycentre" ) ;
419       _Texte += Texte_inport( "double", "Zcentre" ) ;
420       _Texte += Texte_inport( "double", "Xaxis" ) ;
421       _Texte += Texte_inport( "double", "Yaxis" ) ;
422       _Texte += Texte_inport( "double", "Zaxis" ) ;
423       _Texte += Texte_inport( "double", "RRev" ) ;
424       _Texte += Texte_inport( "double", "RPri" ) ;
425       TexteParametre( node, "Xcentre", "double", x0 ) ;
426       TexteParametre( node, "Ycentre", "double", x1 ) ;
427       TexteParametre( node, "Zcentre", "double", x2 ) ;
428       TexteParametre( node, "Xaxis", "double", x3 ) ;
429       TexteParametre( node, "Yaxis", "double", x4 ) ;
430       TexteParametre( node, "Zaxis", "double", x5 ) ;
431       TexteParametre( node, "RRev", "double", x6 ) ;
432       TexteParametre( node, "RPri", "double", x7 ) ;
433     }
434 //
435 // 4.3.7. Erreur
436     else
437     { VERIFICATION("Type de frontiere inconnu." == 0); }
438   }
439 //
440 // 5. La fin
441   _Texte += "                              <outport name=\"return\" type=\"HOMARD_Boundary\"/>\n" ;
442   _Texte += "                           </service>\n" ;
443 //
444   return texte_control ;
445 //
446 }
447 //===============================================================================
448 // Fin du controle des enchainements de noeud dans le noeud Iter_1
449 //===============================================================================
450   std::string YACSDriver::Texte_Iter_1_control()
451 {
452   MESSAGE("Texte_Iter_1_control");
453 //
454   std::string texte ;
455   texte  = Texte_control (_noeud_1, "CreateHypothesis", 1) ;
456   texte += Texte_control ("CreateHypothesis", "Case_Options", 0) ;
457 //
458   return texte ;
459 //
460 }
461 //===============================================================================
462 // Controle des enchainements de noeuds
463 // noeud_1 : noeud de depart
464 // noeud_2 : noeud d'arrivee
465 // option : 0 : sans caractere de saut de ligne a la fin
466 //          1 : avec caractere de saut de ligne a la fin
467 //===============================================================================
468   std::string YACSDriver::Texte_control( const std::string noeud_1, const std::string noeud_2, int option )
469 {
470   MESSAGE("Texte_control, noeud_1 = "<<noeud_1<<", noeud_2 = "<<noeud_2<<", option = "<<option);
471 //
472   std::string texte ;
473   texte  = "                           <control> " ;
474   texte += "<fromnode>" + noeud_1 + "</fromnode>" ;
475   texte += " <tonode>"  + noeud_2 + "</tonode>" ;
476   texte += " </control>" ;
477   if ( option == 1 ) { texte += "\n" ; }
478
479   return texte ;
480 //
481 }
482 //===============================================================================
483 // Inport
484 // inport_type : type de la donnee a importer
485 // inport_nom : nom de la donnee a importer
486 //===============================================================================
487   std::string YACSDriver::Texte_inport( const std::string inport_type, const std::string inport_nom )
488 {
489 //   MESSAGE("Texte_inport, inport_type = "<<inport_type<<", inport_nom = "<<inport_nom);
490 //
491   std::string texte ;
492   texte  = "                              <inport " ;
493   texte += "name=\"" + inport_nom + "\" " ;
494   texte += "type=\"" + inport_type + "\"" ;
495   texte += "/>\n" ;
496
497   return texte ;
498 //
499 }
500 //===============================================================================
501 // Le repertoire d'execution
502 //===============================================================================
503 void YACSDriver::Texte_HOMARD_Exec_DirName( )
504 {
505   MESSAGE("Texte_HOMARD_Exec_DirName");
506 //
507   _Texte += "DirName = \"" + _DirName + "\"\n" ;
508 //
509 }
510 //===============================================================================
511 // Le nom du maillage
512 //===============================================================================
513 void YACSDriver::Texte_HOMARD_Exec_MeshName( const std::string MeshName )
514 {
515   MESSAGE("Texte_HOMARD_Exec_MeshName pour "<<MeshName);
516 //
517   _Texte += "MeshName = \"" + MeshName + "\"\n" ;
518 //
519 }
520 //===============================================================================
521 // Manipulation des instructions python - 1
522 // pythonTexte : le texte des instructions python a manipuler
523 // indice : numero de la premiere ligne voulue
524 // concept : nom du concept a inserer
525 //===============================================================================
526 void YACSDriver::Texte_python_1( const std::string pythonTexte, int indice, const std::string concept )
527 {
528   MESSAGE("Texte_python_1, pythonTexte\n"<<pythonTexte);
529   MESSAGE("indice = "<<indice<<", concept = "<<concept);
530 //
531 // Conversion de type
532   std::istringstream tout (pythonTexte) ;
533 //   MESSAGE("\ntout :"<<tout);
534   std::string ligne; // variable contenant chaque ligne de python
535   std::string ligne_bis ; // variable contenant la portion de ligne de python apres '.'
536   int cptr = 0 ;
537   indice -= 1 ;
538   while ( std::getline( tout, ligne ) )
539   {
540     if ( cptr > indice )
541     {
542       int position = ligne.find_first_of( "." ) ;
543       MESSAGE("\nposition : "<< position);
544       if ( position > 0 )
545       {
546         ligne_bis = ligne.substr( position );
547         MESSAGE("\nligne_bis : "<< ligne_bis);
548         _Texte += concept + ligne_bis + "\n" ;
549       }
550     }
551     cptr += 1 ;
552   }
553 //
554 }
555 //===============================================================================
556 // Manipulation des instructions python - 2
557 // pythonTexte : le texte des instructions python a manipuler
558 // mot_cle : mot-cle dans les lignes a inserer
559 // concept : nom du concept a inserer
560 //===============================================================================
561 void YACSDriver::Texte_python_2( const std::string pythonTexte, const std::string mot_cle, const std::string concept )
562 {
563   MESSAGE("Texte_python_2, pythonTexte\n"<<pythonTexte);
564   MESSAGE("mot_cle = "<<mot_cle<<", concept = "<<concept);
565 //
566 // Conversion de type
567   std::istringstream tout (pythonTexte) ;
568 //   MESSAGE("\ntout :"<<tout);
569   std::string ligne; // variable contenant chaque ligne de python
570   std::string ligne_bis ; // variable contenant la portion de ligne de python apres '.'
571   while ( std::getline( tout, ligne ) )
572   {
573     int reperage = ligne.find( mot_cle ) ;
574     if ( reperage > 0 )
575     {
576       int position = ligne.find_first_of( "." ) ;
577 //       MESSAGE("\nposition : "<< position);
578       if ( position > 0 )
579       {
580         ligne_bis = ligne.substr( position );
581 //         MESSAGE("\nligne_bis : "<< ligne_bis);
582         _Texte += concept + ligne_bis + "\n" ;
583       }
584     }
585   }
586 //
587 }
588 //===============================================================================
589 // Parametres de tests de convergence
590 //===============================================================================
591 void YACSDriver::TexteAnalyse_Test_Convergence( int MaxIter, int MaxNode, int MaxElem )
592 {
593 //
594 //   MESSAGE("TexteAnalyse_Test_Convergence");
595   std::string chaine ;
596   std::ostringstream oss1;
597   oss1 << MaxIter;
598   chaine = oss1.str();
599   _Texte += "MaxIter = " + chaine + "\n" ;
600   std::ostringstream oss2;
601   oss2 << MaxNode;
602   chaine = oss2.str();
603   _Texte += "MaxNode = " + chaine + "\n" ;
604   std::ostringstream oss3;
605   oss3 << MaxElem;
606   chaine = oss3.str();
607   _Texte += "MaxElem = " + chaine + "\n" ;
608 //
609 }
610 //===============================================================================
611 // Creation d'un parametre
612 //===============================================================================
613 void YACSDriver::TexteParametre( const std::string node, const std::string port, const std::string type_value, const std::string value )
614 {
615 //
616 //   MESSAGE("TexteParametre");
617   _Texte_parametres += "   <parameter>\n" ;
618   _Texte_parametres += "      <tonode>" + node + "</tonode>" ;
619   _Texte_parametres += "<toport>" + port + "</toport>\n" ;
620   _Texte_parametres += "      <value><" + type_value + ">" + value + "</" + type_value + "></value>\n" ;
621   _Texte_parametres += "   </parameter>\n" ;
622 //
623 }
624 //===============================================================================
625 // Ajout des parametres
626 //===============================================================================
627 void YACSDriver::TexteAddParametres( )
628 {
629 //
630   MESSAGE("TexteAddParametres");
631   TexteAdd(_Texte_parametres) ;
632 //
633 }
634 //===============================================================================
635 void YACSDriver::CreeFichier( )
636 {
637 //
638   MESSAGE("CreeFichier sur le fichier "<<_XMLFile);
639   std::ofstream Fic(_XMLFile.c_str(), std::ios::out ) ;
640   if (Fic.is_open() == true) { Fic << _Texte << std::endl ; }
641   Fic.close() ;
642 //
643 }
644 //===============================================================================
645 // REMARQUE : on devrait utiliser le GetStringInTexte de HOMARD_Gen_i mais je ne sais pas
646 //            comment l'appeler. ALors je clone.
647 // Recuperation de la chaine de caracteres par rapport l'apparition d'un texte
648 // ligne : la ligne a manipuler
649 // texte : le texte a reperer
650 // option : 0 : la chaine avant le texte
651 //          1 : la chaine apres le texte
652 // Si le texte est absent, on retourne la chaine totale
653 //===============================================================================
654 std::string YACSDriver::GetStringInTexte( const std::string ligne, const std::string texte, int option )
655 {
656 //   MESSAGE("GetStringInTexte, recherche de '"<<texte<<"' dans '"<<ligne<<"'"<<", option = "<<option);
657 //
658   std::string chaine = ligne ;
659   int position = ligne.find_first_of( texte ) ;
660   if ( position > 0 )
661   {
662     if ( option == 0 ) { chaine = ligne.substr( 0, position ) ; }
663     else               { chaine = ligne.substr( position+1 ) ; }
664   }
665 // Conversion de type
666   return chaine ;
667 //
668 }