Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSol.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) 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.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
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.00)
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, "FacteurSolDefault"))
41  {
42  _G = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "FacteurSolDefault");
43  }
44  else
45  {
46  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "FacteurSolDefault", _G);
47  }
48 
49  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "EpaisSolDefault"))
50  {
51  _epaisseur = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "EpaisSolDefault");
52  }
53  else
54  {
55  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "EpaisSolDefault", _epaisseur);
56  }
57 
58  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "EcartTypeDefault"))
59  {
60  _ecarttype = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "EcartTypeDefault");
61  }
62  else
63  {
64  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "EcartTypeDefault", _ecarttype);
65  }
66 
67  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "LongueurDefault"))
68  {
69  _longueur = TYPreferenceManager::getDouble(TYDIRPREFERENCEMANAGER, "LongueurDefault");
70  }
71  else
72  {
73  TYPreferenceManager::setDouble(TYDIRPREFERENCEMANAGER, "LongueurDefault", _longueur);
74  }
75 #endif
76 }
77 
78 TYSol::TYSol(const TYSol& other)
79 {
80  *this = other;
81 }
82 
84 
86 {
87  if (this != &other)
88  {
89  TYElement::operator=(other);
90  _resistivite = other._resistivite;
91  _epaisseur = other._epaisseur;
92  _ecarttype = other._ecarttype;
93  _longueur = other._longueur;
94  _G = other._G;
95  }
96  return *this;
97 }
98 
99 bool TYSol::operator==(const TYSol& other) const
100 {
101  if (this != &other)
102  {
103  if (TYElement::operator!=(other))
104  {
105  return false;
106  }
107  if (_resistivite != other._resistivite)
108  {
109  return false;
110  }
111  if (_epaisseur != other._epaisseur)
112  {
113  return false;
114  }
115  if (_ecarttype != other._ecarttype)
116  {
117  return false;
118  }
119  if (_longueur != other._longueur)
120  {
121  return false;
122  }
123  if (_G != other._G)
124  {
125  return false;
126  }
127  }
128  return true;
129 }
130 
131 bool TYSol::operator!=(const TYSol& other) const
132 {
133  return !operator==(other);
134 }
135 
136 bool TYSol::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
137 {
138  if (!TYElement::deepCopy(pOther, copyId))
139  {
140  return false;
141  }
142 
143  TYSol* pOtherSol = (TYSol*)pOther;
144 
145  _resistivite = pOtherSol->_resistivite;
146  _epaisseur = pOtherSol->_epaisseur;
147  _ecarttype = pOtherSol->_ecarttype;
148  _longueur = pOtherSol->_longueur;
149  _G = pOtherSol->_G;
150 
151  return true;
152 }
153 
154 std::string TYSol::toString() const
155 {
156  return "TYSol";
157 }
158 
160 {
161  DOM_Element domNewElem = TYElement::toXML(domElement);
162 
163  TYXMLTools::addElementDoubleValue(domNewElem, "resistivite", _resistivite);
164  TYXMLTools::addElementDoubleValue(domNewElem, "epaisseur", _epaisseur);
165  TYXMLTools::addElementDoubleValue(domNewElem, "ecart_type", _ecarttype);
166  TYXMLTools::addElementDoubleValue(domNewElem, "longueur", _longueur);
167  TYXMLTools::addElementDoubleValue(domNewElem, "facteur_G", _G);
168 
169  return domNewElem;
170 }
171 
173 {
174  TYElement::fromXML(domElement);
175 
176  bool resistiviteOk = false;
177  bool epaisseurOk = false;
178  bool ecarttypeOk = false;
179  bool longueurOk = false;
180  bool GOk = false;
181 
182  DOM_Element elemCur;
183  QDomNodeList childs = domElement.childNodes();
184  for (unsigned int i = 0; i < childs.length(); i++)
185  {
186  elemCur = childs.item(i).toElement();
187 
188  TYXMLTools::getElementDoubleValue(elemCur, "resistivite", _resistivite, resistiviteOk);
189  TYXMLTools::getElementDoubleValue(elemCur, "epaisseur", _epaisseur, epaisseurOk);
190  TYXMLTools::getElementDoubleValue(elemCur, "ecart_type", _ecarttype, ecarttypeOk);
191  TYXMLTools::getElementDoubleValue(elemCur, "longueur", _longueur, longueurOk);
192  TYXMLTools::getElementDoubleValue(elemCur, "facteur_G", _G, GOk);
193  }
194 
195  return 1;
196 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
outil IHM pour un sol (fichier header)
TY_EXTENSION_INST(TYSol)
virtual const char * getClassName() const
Definition: TYElement.h:248
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYElement.cpp:305
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:366
QString _name
Nom courant de l'element.
Definition: TYElement.h:956
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:263
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:379
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:99
bool operator!=(const TYSol &other) const
Operateur !=.
Definition: TYSol.cpp:131
double _resistivite
Resistance a l'ecoulement.
Definition: TYSol.h:137
double _epaisseur
Epaisseur du sol.
Definition: TYSol.h:140
virtual ~TYSol()
Definition: TYSol.cpp:83
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSol.cpp:136
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSol.cpp:159
TYSol()
Definition: TYSol.cpp:25
double _ecarttype
Ecart-type.
Definition: TYSol.h:143
virtual int fromXML(DOM_Element domElement)
Definition: TYSol.cpp:172
double _longueur
Longueur.
Definition: TYSol.h:146
virtual std::string toString() const
Definition: TYSol.cpp:154
TYSol & operator=(const TYSol &other)
Operateur =.
Definition: TYSol.cpp:85
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