Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSol.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #include "Tympan/core/logging.h"
17 #if TY_USE_IHM
20 #endif
21 #include "TYSol.h"
22 
24 
25 TYSol::TYSol() : _resistivite(20000), _epaisseur(1.0), _ecarttype(0), _longueur(0.001), _G(0.50)
26 {
28 
29  // TODO RAJOUTER AUX PREFERENCES
30 #if TY_USE_IHM
31  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "ResisSolDefault"))
32  {
33  _resistivite = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "ResisSolDefault");
34  }
35  else
36  {
37  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "ResisSolDefault", _resistivite);
38  }
39 
40  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "EpaisSolDefault"))
41  {
42  _epaisseur = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "EpaisSolDefault");
43  }
44  else
45  {
46  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "EpaisSolDefault", _epaisseur);
47  }
48 
49  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "EcartTypeDefault"))
50  {
51  _ecarttype = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "EcartTypeDefault");
52  }
53  else
54  {
55  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "EcartTypeDefault", _ecarttype);
56  }
57 
58  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "LongueurDefault"))
59  {
60  _longueur = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "LongueurDefault");
61  }
62  else
63  {
64  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "LongueurDefault", _longueur);
65  }
66 #endif
67 }
68 
69 TYSol::TYSol(const TYSol& other)
70 {
71  *this = other;
72 }
73 
75 
77 {
78  if (this != &other)
79  {
80  TYElement::operator=(other);
81  _resistivite = other._resistivite;
82  _epaisseur = other._epaisseur;
83  _ecarttype = other._ecarttype;
84  _longueur = other._longueur;
85  _G = other._G;
86  }
87  return *this;
88 }
89 
90 bool TYSol::operator==(const TYSol& other) const
91 {
92  if (this != &other)
93  {
94  if (TYElement::operator!=(other))
95  {
96  return false;
97  }
98  if (_resistivite != other._resistivite)
99  {
100  return false;
101  }
102  if (_epaisseur != other._epaisseur)
103  {
104  return false;
105  }
106  if (_ecarttype != other._ecarttype)
107  {
108  return false;
109  }
110  if (_longueur != other._longueur)
111  {
112  return false;
113  }
114  if (_G != other._G)
115  {
116  return false;
117  }
118  }
119  return true;
120 }
121 
122 bool TYSol::operator!=(const TYSol& other) const
123 {
124  return !operator==(other);
125 }
126 
127 bool TYSol::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
128 {
129  if (!TYElement::deepCopy(pOther, copyId))
130  {
131  return false;
132  }
133 
134  TYSol* pOtherSol = (TYSol*)pOther;
135 
136  _resistivite = pOtherSol->_resistivite;
137  _epaisseur = pOtherSol->_epaisseur;
138  _ecarttype = pOtherSol->_ecarttype;
139  _longueur = pOtherSol->_longueur;
140  _G = pOtherSol->_G;
141 
142  return true;
143 }
144 
145 std::string TYSol::toString() const
146 {
147  return "TYSol";
148 }
149 
151 {
152  DOM_Element domNewElem = TYElement::toXML(domElement);
153 
154  TYXMLTools::addElementDoubleValue(domNewElem, "resistivite", _resistivite);
155  TYXMLTools::addElementDoubleValue(domNewElem, "epaisseur", _epaisseur);
156  TYXMLTools::addElementDoubleValue(domNewElem, "ecart_type", _ecarttype);
157  TYXMLTools::addElementDoubleValue(domNewElem, "longueur", _longueur);
158  TYXMLTools::addElementDoubleValue(domNewElem, "facteur_G", _G);
159 
160  return domNewElem;
161 }
162 
164 {
165  TYElement::fromXML(domElement);
166 
167  bool resistiviteOk = false;
168  bool epaisseurOk = false;
169  bool ecarttypeOk = false;
170  bool longueurOk = false;
171  bool GOk = false;
172 
173  DOM_Element elemCur;
174  QDomNodeList childs = domElement.childNodes();
175  for (unsigned int i = 0; i < childs.length(); i++)
176  {
177  elemCur = childs.item(i).toElement();
178 
179  TYXMLTools::getElementDoubleValue(elemCur, "resistivite", _resistivite, resistiviteOk);
180  TYXMLTools::getElementDoubleValue(elemCur, "epaisseur", _epaisseur, epaisseurOk);
181  TYXMLTools::getElementDoubleValue(elemCur, "ecart_type", _ecarttype, ecarttypeOk);
182  TYXMLTools::getElementDoubleValue(elemCur, "longueur", _longueur, longueurOk);
183  TYXMLTools::getElementDoubleValue(elemCur, "facteur_G", _G, GOk);
184  }
185 
186  return 1;
187 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
outil IHM pour un sol (fichier header)
TY_EXTENSION_INST(TYSol)
virtual const char * getClassName() const
Definition: TYElement.h:249
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYElement.cpp:307
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:368
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
Definition: TYSol.h:25
bool operator==(const TYSol &other) const
Operateur ==.
Definition: TYSol.cpp:90
bool operator!=(const TYSol &other) const
Operateur !=.
Definition: TYSol.cpp:122
double _resistivite
Resistance a l'ecoulement.
Definition: TYSol.h:137
double _epaisseur
Epaisseur du sol.
Definition: TYSol.h:140
virtual ~TYSol()
Definition: TYSol.cpp:74
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSol.cpp:127
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSol.cpp:150
TYSol()
Definition: TYSol.cpp:25
double _ecarttype
Ecart-type.
Definition: TYSol.h:143
virtual int fromXML(DOM_Element domElement)
Definition: TYSol.cpp:163
double _longueur
Longueur.
Definition: TYSol.h:146
virtual std::string toString() const
Definition: TYSol.cpp:145
TYSol & operator=(const TYSol &other)
Operateur =.
Definition: TYSol.cpp:76
double _G
Facteur G.
Definition: TYSol.h:149
static void addElementDoubleValue(DOM_Element &parentElem, DOMString nodeName, double nodeValue)
Definition: TYXMLTools.cpp:87
static bool getElementDoubleValue(DOM_Element parentElem, DOMString nodeName, double &nodeValue)
Definition: TYXMLTools.cpp:243