Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRegime.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 /*
17  *
18  */
19 
20 #if TY_USE_IHM
22 #endif
23 
24 #include "TYRegime.h"
25 
27 
28 TYRegime::TYRegime() : _isRayonnant(true), _useAtt(false), _typeDistribution(0)
29 {
30  _name = TYNameManager::get()->generateName(getClassName());
31 
32  _spectre.setType(SPECTRE_TYPE_LW);
33  _pAtt = NULL;
34 }
35 
37 {
38  *this = other;
39 }
40 
42 {
43  _pAtt = NULL;
44 }
45 
47 {
48  if (this != &other)
49  {
50  TYElement::operator=(other);
51  _isRayonnant = other._isRayonnant;
52  _useAtt = other._useAtt;
54  _spectre = other._spectre; // Recopie du contenu du spectre
55 
56  // Recopie de l'attenuateur s'il existe
57  if (other._pAtt)
58  {
59  _pAtt = new TYAttenuateur();
60  _pAtt->deepCopy(other._pAtt);
61  }
62  }
63  return *this;
64 }
65 
66 bool TYRegime::operator==(const TYRegime& other) const
67 {
68  if (this != &other)
69  {
70  if (TYElement::operator!=(other))
71  {
72  return false;
73  }
74  if (_isRayonnant != other._isRayonnant)
75  {
76  return false;
77  }
78  if (_useAtt != other._useAtt)
79  {
80  return false;
81  }
82  if (_spectre != other._spectre)
83  {
84  return false;
85  }
86  if (_pAtt != other._pAtt)
87  {
88  return false;
89  }
90  }
91  return true;
92 }
93 
94 bool TYRegime::operator!=(const TYRegime& other) const
95 {
96  return !operator==(other);
97 }
98 
99 bool TYRegime::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
100 {
101  if (!TYElement::deepCopy(pOther, copyId))
102  {
103  return false;
104  }
105 
106  // TYRegime * pOtherRegime = (TYRegime *) pOther;
107 
108  _isRayonnant = ((TYRegime*)(pOther))->_isRayonnant;
109  _useAtt = ((TYRegime*)(pOther))->_useAtt;
111  _spectre.deepCopy(&((TYRegime*)(pOther))->_spectre, copyId); // Recopie du contenu du spectre
112 
113  if (((TYRegime*)(pOther))->_pAtt)
114  {
115  _pAtt = new TYAttenuateur();
116  _pAtt->deepCopy(((TYRegime*)(pOther))->_pAtt, copyId);
117  }
118 
119  return true;
120 }
121 
122 std::string TYRegime::toString() const
123 {
124  return "TYRegime";
125 }
126 
128 {
129  DOM_Element domNewElem = TYElement::toXML(domElement);
130 
131  TYXMLTools::addElementIntValue(domNewElem, "isRayonnant", _isRayonnant);
132  TYXMLTools::addElementIntValue(domNewElem, "useAtt", _useAtt);
133  TYXMLTools::addElementIntValue(domNewElem, "typeDistribution", _typeDistribution);
134 
136  {
137  _spectre.toXML(domNewElem);
138  }
139 
140  if (_useAtt && (_pAtt != NULL))
141  {
142  _pAtt->toXML(domNewElem);
143  }
144 
145  return domNewElem;
146 }
147 
149 {
150  TYElement::fromXML(domElement);
151 
152  DOM_Element elemCur;
153 
154  QDomNodeList childs = domElement.childNodes();
155 
156  bool typeDistributionOk = false;
157  bool useAttOk = false;
158  bool isRayonnantOk = false;
159 
160  LPTYAttenuateur pTempAtt = new TYAttenuateur();
161 
162  for (unsigned int i = 0; i < childs.length(); i++)
163  {
164  elemCur = childs.item(i).toElement();
165 
166  TYXMLTools::getElementBoolValue(elemCur, "isRayonnant", _isRayonnant, isRayonnantOk);
167  TYXMLTools::getElementBoolValue(elemCur, "useAtt", _useAtt, useAttOk);
168  TYXMLTools::getElementIntValue(elemCur, "typeDistribution", _typeDistribution, typeDistributionOk);
169 
170  _spectre.callFromXMLIfEqual(elemCur); // Relecture du spectre s'il a ete enregistre
171 
172  if (pTempAtt->callFromXMLIfEqual(elemCur))
173  {
174  _pAtt = pTempAtt;
175  }
176  }
177  return 1;
178 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
#define TY_EXTENSION_INST(classname)
Definition: TYElement.h:387
outil IHM pour un regime (fichier header)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual DOM_Element toXML(DOM_Element &domElement)
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
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
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.
bool _useAtt
Definition: TYRegime.h:197
bool _isRayonnant
Definition: TYRegime.h:196
TYRegime()
Definition: TYRegime.cpp:28
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYRegime.cpp:99
TYSpectre _spectre
Definition: TYRegime.h:199
virtual ~TYRegime()
Definition: TYRegime.cpp:41
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYRegime.cpp:127
TYRegime & operator=(const TYRegime &other)
Operateur =.
Definition: TYRegime.cpp:46
virtual int fromXML(DOM_Element domElement)
Definition: TYRegime.cpp:148
int _typeDistribution
Definition: TYRegime.h:198
@ TY_PUISSANCE_IMPOSEE
Definition: TYRegime.h:190
bool operator!=(const TYRegime &other) const
Operateur !=.
Definition: TYRegime.cpp:94
bool operator==(const TYRegime &other) const
Operateur ==.
Definition: TYRegime.cpp:66
LPTYAttenuateur _pAtt
Definition: TYRegime.h:200
virtual std::string toString() const
Definition: TYRegime.cpp:122
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSpectre.cpp:164
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSpectre.cpp:142
static bool getElementBoolValue(DOM_Element parentElem, DOMString nodeName, bool &nodeValue)
Definition: TYXMLTools.cpp:179
static void addElementIntValue(DOM_Element &parentElem, DOMString nodeName, int nodeValue)
Definition: TYXMLTools.cpp:72
static bool getElementIntValue(DOM_Element parentElem, DOMString nodeName, int &nodeValue)
Definition: TYXMLTools.cpp:129
@ SPECTRE_TYPE_LW
Definition: spectre.h:30