]> SALOME platform Git repositories - modules/homard.git/blob - src/HOMARDGUI/HomardConfigFile.cxx
Salome HOME
Fix problems of 'make distcheck'
[modules/homard.git] / src / HOMARDGUI / HomardConfigFile.cxx
1 //
2 //  File   : HomardConfigFile.cxx
3 //  Author : Paul RASCLE, EDF
4 //  Module : HOMARD
5 //  cree un fichier de configuration HOMARD
6     
7 using namespace std;
8
9 #include "HomardConfigFile.hxx"
10 #include "utilities.h"
11 #include <iostream>
12 #include <fstream>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16
17
18
19
20 //=============================================================================
21 /*!
22  *
23  */
24 //=============================================================================
25
26 HomardConfigFile::HomardConfigFile():
27                         _nomFichier(string("HOMARD.Configuration")),
28                         _prefix(string(""))
29  {
30
31         string t1[] = {string("CCMaiN__"), string("CCNoMN__"), string("CCSolN__"), string("CCFronti"), 
32                        string("HOMaiN__"), string("RenumN__"), string("ListeStd"), string("PPBasFic"),
33                        string("CCAssoci"), string("NumeIter"), string("CCMaiNP1"), string("CCNoMNP1"),
34                        string("TypeElem"), string("TypeRaff"), string("TypeDera"), string("HOMaiN__"),
35                        string("HOMaiNP1"), string("CCNoChaI"), string("CCCoChaI"), string("CCNumOrI"),
36                        string("CCNumPTI"), string("SeuilBPE"), string("SeuilHPE"), string("CCIndica")};
37         std::list<motcle> l1(t1,t1+24);
38         _motscle_ss_valeur=l1;
39
40         string t2[] = {string("Aucun0__"), string("Nb_Enti2"), string("Interpe3"), string("Qualite5"),
41                        string("Nb_Enti7"), string("Connex11"), string("Taille13") };
42         std::list<motcle> l2(t2,t2+7);
43         _motscle_oui_non=l2;
44
45         string t3[] = {string("ModeHOMA"), string("EcriFiHO")};
46         std::list<motcle> l3(t3,t3+2);
47         _motscle_autre=l3;
48
49         _dictValeur[string("Nb_Enti2")]=string("oui") ;
50
51         _dictValeuroui[string("Aucun0__")]=0;
52         _dictValeuroui[string("Nb_Enti2")]=2;
53         _dictValeuroui[string("Interpe3")]=3;
54         _dictValeuroui[string("Qualite5")]=5;
55         _dictValeuroui[string("Nb_Enti7")]=7;
56         _dictValeuroui[string("Connex11")]=11;
57         _dictValeuroui[string("Taille13")]=13;
58
59  }
60 //=============================================================================
61 /*!
62  *
63  */
64 //=============================================================================
65 HomardConfigFile::~HomardConfigFile()
66 {
67 }
68 //=============================================================================
69 /*!
70  *
71  */
72 //=============================================================================
73 void HomardConfigFile::setBilan(bool etat)
74 {
75         _bBilan = etat;
76 }
77 //=============================================================================
78 /*!
79  *
80  */
81 //=============================================================================
82 bool HomardConfigFile::initVal(const string motclef ,const string valeur)
83 {
84         //SCRUTE(motclef);
85         //SCRUTE(valeur);
86         bool ok = false;
87         if ( cherche_dans_liste(_motscle_ss_valeur, motclef))
88         {
89            _dictValeur[motclef]=valeur;
90            ok = true;
91         }
92         else
93         {
94            if ( cherche_dans_liste(_motscle_oui_non,motclef))
95            {    
96                 if (valeur =="oui" || valeur == "non")
97                 {
98                    _dictValeur[motclef]=valeur;
99                    ok = true;
100                 }
101            }
102            else
103               if ( cherche_dans_liste(_motscle_autre,motclef))
104               // Il faudrait avoir un mecanisme de verification de la valeur //
105               // passee, non mis en place actuellement avec des strings ?    //
106               { 
107                    _dictValeur[motclef]=valeur;
108                    ok = true;
109               } 
110         }
111         return ok;
112 }
113
114 //=============================================================================
115 /*!
116  *
117  */
118 //=============================================================================
119 bool HomardConfigFile::cherche_dans_liste(std::list<motcle> & liste,  const motcle motclef )
120 {
121      bool ok = false;
122      std::list<motcle>::iterator it =liste.begin();
123      while ( it != liste.end())
124      {
125         if ( *it == motclef)
126         {
127            ok = true;
128            break;
129         }
130         it ++;
131      }
132      return ok;
133 }
134     
135 //=============================================================================
136 /*!
137  *
138  */
139 //=============================================================================
140 string HomardConfigFile::getMyDir()
141 {
142         return _myDir;
143 }
144 //=============================================================================
145 /*!
146  *
147  */
148 //=============================================================================
149 bool HomardConfigFile::createFile()
150 {
151     bool ok = true;
152
153     const char *a = "/tmp/ed.XXXXXX";
154     char * cible = new char[15];
155     strcpy(cible,a) ;
156     mkdtemp(cible);
157    
158     _myDir = string(cible);
159     string myfile=_myDir+string("/HOMARD.Configuration");
160
161     try
162     {
163        
164         ofstream ficHomard( myfile.c_str()) ;
165         int typeBilan = 1;
166
167         std::map<motcle,valeur>::iterator it = _dictValeur.begin();
168         for (; it != _dictValeur.end(); it++)
169         {
170            motcle motclef=(*it).first;
171            valeur valmot =(*it).second;
172            if ( cherche_dans_liste(_motscle_oui_non,motclef))
173            {
174                 if (valmot== "oui")
175                 {
176                   typeBilan=typeBilan*_dictValeuroui[motclef]; 
177                  }
178            }
179            else
180              ficHomard << motclef << " " << valmot << std::endl ; 
181         }
182                 
183         if (_bBilan  == true)
184         {
185           ficHomard << "TypeBila "<< typeBilan << std::endl ;
186         }
187         ficHomard.close();
188     }
189     catch (...)
190     {
191         ok = false;
192     }
193   return ok;
194    
195 }