Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYVegetation.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 #if TY_USE_IHM
18 #endif
19 
20 #include "Tympan/core/logging.h"
21 
22 #include "TYVegetation.h"
23 
25 
26 QString TYVegetation::_vegeName[] = {"pine", "spruce", "birch", "aspen", "oak"};
27 
28 TYVegetation::TYVegetation() : _bFoliage(false), _hauteur(10.)
29 {
30  //_name = TYNameManager::get()->generateName(getClassName());
31  _name = _vegeName[0];
32 
33  _pSpectreAtt = new TYSpectre();
35  _pSpectreAtt->setParent(this);
36 }
37 
39 {
40  *this = other;
41 }
42 
44 {
45  delete (_pSpectreAtt);
46  _pSpectreAtt = NULL;
47 }
48 
50 {
51  if (this != &other)
52  {
53  TYElement::operator=(other);
54  _pSpectreAtt = other._pSpectreAtt;
55  _hauteur = other._hauteur;
56  _bFoliage = other._bFoliage;
57  }
58  return *this;
59 }
60 
61 bool TYVegetation::operator==(const TYVegetation& other) const
62 {
63  if (this != &other)
64  {
65  if (TYElement::operator!=(other))
66  {
67  return false;
68  }
69  if (_pSpectreAtt != other._pSpectreAtt)
70  {
71  return false;
72  }
73  if (_hauteur != other._hauteur)
74  {
75  return false;
76  }
77  if (_bFoliage != other._bFoliage)
78  {
79  return false;
80  }
81  }
82  return true;
83 }
84 
85 bool TYVegetation::operator!=(const TYVegetation& other) const
86 {
87  return !operator==(other);
88 }
89 
90 bool TYVegetation::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
91 {
92  if (!TYElement::deepCopy(pOther, copyId))
93  {
94  return false;
95  }
96 
97  TYVegetation* pOtherVeget = (TYVegetation*)pOther;
98 
99  _hauteur = pOtherVeget->_hauteur;
100  _bFoliage = pOtherVeget->_bFoliage;
101 
102  _pSpectreAtt->deepCopy(pOtherVeget->_pSpectreAtt, copyId);
103 
104  return true;
105 }
106 
107 std::string TYVegetation::toString() const
108 {
109  return "TYVegetation";
110 }
111 
113 {
114  DOM_Element domNewElem = TYElement::toXML(domElement);
115 
116  TYXMLTools::addElementBoolValue(domNewElem, "foliage", _bFoliage);
117  TYXMLTools::addElementDoubleValue(domNewElem, "hauteur", _hauteur);
118  _pSpectreAtt->toXML(domNewElem);
119 
120  return domNewElem;
121 }
122 
124 {
125  TYElement::fromXML(domElement);
126 
127  bool hauteurOk = false, foliageOK = false;
128  DOM_Element elemCur;
129  QDomNodeList childs = domElement.childNodes();
130  for (unsigned int i = 0; i < childs.length(); i++)
131  {
132  elemCur = childs.item(i).toElement();
133  TYXMLTools::getElementBoolValue(elemCur, "foliage", _bFoliage, foliageOK);
134  TYXMLTools::getElementDoubleValue(elemCur, "hauteur", _hauteur, hauteurOk);
136  }
137 
138  return 1;
139 }
140 
142 {
143  _pSpectreAtt = pAtt;
144  _pSpectreAtt->setParent(this);
145 
147  {
149  } // Passage en lineaire si necessaire
150 }
151 
152 unsigned int TYVegetation::getIndexVegetation(const QString& vegeName)
153 {
154  unsigned int retValue = 0;
155 
156  for (unsigned int i = 0; i < 5; i++)
157  {
158  if (vegeName == _vegeName[i])
159  {
160  return i;
161  }
162  }
163 
164  return retValue;
165 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
outil IHM pour une vegetation (fichier header)
TY_EXTENSION_INST(TYVegetation)
OSpectreAbstract & toGPhy() const
Converts to physical quantity.
Definition: spectre.cpp:634
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:152
TYSpectreEtat getEtat() const
Get the spectrum state.
Definition: spectre.h:158
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
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
void setParent(TYElement *pParent)
Definition: TYElement.h:692
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
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
bool operator!=(const TYVegetation &other) const
Operateur !=.
virtual ~TYVegetation()
TYSpectre * _pSpectreAtt
Spectre d'attenuation.
Definition: TYVegetation.h:129
bool _bFoliage
Foliage.
Definition: TYVegetation.h:125
double _hauteur
Hauteur.
Definition: TYVegetation.h:127
static QString _vegeName[]
Definition: TYVegetation.h:119
virtual int fromXML(DOM_Element domElement)
bool operator==(const TYVegetation &other) const
Operateur ==.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
void setSpectreAtt(TYSpectre *pAtt)
virtual DOM_Element toXML(DOM_Element &domElement)
virtual std::string toString() const
static unsigned int getIndexVegetation(const QString &vegeName)
TYVegetation & operator=(const TYVegetation &other)
Operateur =.
static void addElementDoubleValue(DOM_Element &parentElem, DOMString nodeName, double nodeValue)
Definition: TYXMLTools.cpp:87
static bool getElementBoolValue(DOM_Element parentElem, DOMString nodeName, bool &nodeValue)
Definition: TYXMLTools.cpp:179
static bool getElementDoubleValue(DOM_Element parentElem, DOMString nodeName, double &nodeValue)
Definition: TYXMLTools.cpp:243
static void addElementBoolValue(DOM_Element &parentElem, DOMString nodeName, bool nodeValue)
Definition: TYXMLTools.cpp:77
@ SPECTRE_ETAT_LIN
Definition: spectre.h:46
@ SPECTRE_TYPE_ATT
Definition: spectre.h:28