Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYMateriauConstruction.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 "TYMateriauConstruction.h"
22 
25 
27 
29 {
30  if (_defSpectreTrans)
31  {
32  return _defSpectreTrans;
33  }
34  else
35  {
38  return _defSpectreTrans;
39  }
40 }
41 
43 {
44  if (_defSpectreAbso)
45  {
46  return _defSpectreAbso;
47  }
48  else
49  {
50  _defSpectreAbso = new TYSpectre();
52  return _defSpectreAbso;
53  }
54 }
55 
57 {
59 
60  _masseVol = 2500;
64 
67  _spectreAbso.setParent(this);
68 }
69 
71 {
72  *this = other;
73 }
74 
76 
78 {
79  TYSpectre s;
80  s.setDefaultValue(15.0);
81 
82 #if TY_USE_IHM
83  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "SpectreTransmDefault0"))
84  {
85  s = *TYPreferenceManager::getSpectre(TYDIRPREFERENCEMANAGER, "SpectreTransmDefault");
86  }
87  else
88  {
89  TYPreferenceManager::setSpectre(TYDIRPREFERENCEMANAGER, "SpectreTransmDefault", &s);
90  }
91 #endif
92 
93  return s;
94 }
95 
97 {
98  TYSpectre s;
99  s.setDefaultValue(0.2);
100 
101 #if TY_USE_IHM
102  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "SpectreAbsoDefault0"))
103  {
104  s = *TYPreferenceManager::getSpectre(TYDIRPREFERENCEMANAGER, "SpectreAbsoDefault");
105  }
106  else
107  {
108  TYPreferenceManager::setSpectre(TYDIRPREFERENCEMANAGER, "SpectreAbsoDefault", &s);
109  }
110 #endif
111 
112  return s;
113 }
114 
116 {
117  if (this != &other)
118  {
119  TYElement::operator=(other);
120  _masseVol = other._masseVol;
122  _spectreAbso = other._spectreAbso;
123  }
124  return *this;
125 }
126 
128 {
129  if (this != &other)
130  {
131  if (TYElement::operator!=(other))
132  {
133  return false;
134  }
135  if (_masseVol != other._masseVol)
136  {
137  return false;
138  }
139  if (_spectreTransm != other._spectreTransm)
140  {
141  return false;
142  }
143  if (_spectreAbso != other._spectreAbso)
144  {
145  return false;
146  }
147  }
148  return true;
149 }
150 
152 {
153  return !operator==(other);
154 }
155 
156 bool TYMateriauConstruction::deepCopy(const TYElement* pOther, bool copyId /*=true*/,
157  bool pUseCopyTag /*=false*/)
158 {
159  if (!TYElement::deepCopy(pOther, copyId))
160  {
161  return false;
162  }
163 
164  TYMateriauConstruction* pOtherMat = (TYMateriauConstruction*)pOther;
165 
166  _masseVol = pOtherMat->_masseVol;
167 
168  _spectreTransm.deepCopy(&pOtherMat->_spectreTransm, copyId);
169  _spectreAbso.deepCopy(&pOtherMat->_spectreAbso, copyId);
170 
171  return true;
172 }
173 
175 {
176  return "TYMateriauConstruction";
177 }
178 
180 {
181 
182  DOM_Element domNewElem = TYElement::toXML(domElement);
183  TYXMLTools::addElementDoubleValue(domNewElem, "masseVol", _masseVol);
184 
185  TYSpectre::setXMLPrecision(3); // sauvegarde du spectre avec 3 decimales
186 
187  _spectreTransm.toXML(domNewElem);
188  _spectreAbso.toXML(domNewElem);
189 
190  TYSpectre::setXMLPrecision(); // retour a la precision par defaut
191 
192  domElement.appendChild(domNewElem);
193 
194  return domNewElem;
195 }
196 
198 {
199  TYElement::fromXML(domElement);
200 
201  bool masseVolOk = false;
202  int spectreNb = 1;
203  DOM_Element elemCur;
204  QDomNodeList childs = domElement.childNodes();
205  for (unsigned int i = 0; i < childs.length(); i++)
206  {
207  elemCur = childs.item(i).toElement();
208  TYXMLTools::getElementDoubleValue(elemCur, "masseVol", _masseVol, masseVolOk);
209  if (elemCur.nodeName() == "Spectre")
210  {
211  if (spectreNb == 1)
212  {
213  _spectreTransm.fromXML(elemCur);
214  }
215  else if (spectreNb == 2)
216  {
217  _spectreAbso.fromXML(elemCur);
218  }
219  spectreNb++;
220  }
221  }
222 
225 
226  return 1;
227 }
NxReal s
Definition: NxVec3.cpp:317
QDomElement DOM_Element
Definition: QT2DOM.h:30
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
Outil IHM pour des materiaux de construction (fichier header)
TY_EXTENSION_INST(TYMateriauConstruction)
virtual const char * getClassName() const
Definition: TYElement.h:249
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:152
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
void setParent(TYElement *pParent)
Definition: TYElement.h:692
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
static TYSpectre * getDefSpectreAbso()
Spectre de Absortion par defaut.
static TYSpectre * _defSpectreTrans
TYSpectre _spectreTransm
Spectre de transmission.
TYMateriauConstruction & operator=(const TYMateriauConstruction &other)
Operateur =.
TYSpectre _spectreAbso
Spectre d'absorption.
static TYSpectre * _defSpectreAbso
virtual std::string toString() const
bool operator==(const TYMateriauConstruction &other) const
Operateur ==.
static TYSpectre _getDefSpectreTrans()
static TYSpectre _getDefSpectreAbso()
double _masseVol
Masse Volumique.
static TYSpectre * getDefSpectreTrans()
Spectre de transmission par defaut.
bool operator!=(const TYMateriauConstruction &other) const
Operateur !=.
virtual int fromXML(DOM_Element domElement)
virtual DOM_Element toXML(DOM_Element &domElement)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSpectre.cpp:164
static void setXMLPrecision(const int precision=2)
Get/Set de la precision de stockage des resultats (XML)
Definition: TYSpectre.h:174
virtual int fromXML(DOM_Element domElement)
Definition: TYSpectre.cpp:204
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSpectre.cpp:142
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
@ SPECTRE_TYPE_ATT
Definition: spectre.h:28
@ SPECTRE_TYPE_ABSO
Definition: spectre.h:29