Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceSurfacic.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
23 #endif
24 
25 #include "Tympan/core/logging.h"
26 
27 #include "TYSourceSurfacic.h"
28 
31 
32 TYSourceSurfacic::TYSourceSurfacic() : _densiteSrcsH(0.0), _densiteSrcsV(0.0), _srcsCorr(false)
33 {
35 }
36 
38 {
39  *this = other;
40 }
41 
43 {
44  remAllSrc();
45 }
46 
48 {
49  if (this != &other)
50  {
51  TYSource::operator=(other);
54  _srcsCorr = other._srcsCorr;
56  }
57  return *this;
58 }
59 
61 {
62  if (this != &other)
63  {
64  if (TYSource::operator!=(other))
65  {
66  return false;
67  }
68  if (_densiteSrcsH != other._densiteSrcsH)
69  {
70  return false;
71  }
72  if (_densiteSrcsV != other._densiteSrcsV)
73  {
74  return false;
75  }
76  if (_srcsCorr != other._srcsCorr)
77  {
78  return false;
79  }
80  if (!(_listSrcPonct == other._listSrcPonct))
81  {
82  return false;
83  }
84  }
85  return true;
86 }
87 
89 {
90  return !operator==(other);
91 }
92 
93 bool TYSourceSurfacic::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
94 {
95  if (!TYSource::deepCopy(pOther, copyId))
96  {
97  return false;
98  }
99 
100  TYSourceSurfacic* pOtherSrc = (TYSourceSurfacic*)pOther;
101 
102  _densiteSrcsH = pOtherSrc->_densiteSrcsH;
103  _densiteSrcsV = pOtherSrc->_densiteSrcsV;
104  _srcsCorr = pOtherSrc->_srcsCorr;
105 
106  purge();
107  for (unsigned int i = 0; i < pOtherSrc->_listSrcPonct.size(); i++)
108  {
109  LPTYSourcePonctuelle pSrc = (TYSourcePonctuelle*)pOtherSrc->_listSrcPonct[i]->clone();
110  pSrc->deepCopy(pOtherSrc->_listSrcPonct[i], copyId);
111  addSrc(pSrc);
112  }
113 
114  return true;
115 }
116 
117 std::string TYSourceSurfacic::toString() const
118 {
119  return "TYSourceSurfacic";
120 }
121 
123 {
124  DOM_Element domNewElem = TYSource::toXML(domElement);
125 
126  TYXMLTools::addElementIntValue(domNewElem, "nbSrcs", (int)getNbSrcs());
127  TYXMLTools::addElementDoubleValue(domNewElem, "densiteSrcsH", _densiteSrcsH);
128  TYXMLTools::addElementDoubleValue(domNewElem, "densiteSrcsV", _densiteSrcsV);
129  TYXMLTools::addElementIntValue(domNewElem, "srcsCorr", _srcsCorr);
130 
131  // On ne devrait pas sauvegarder les sources des sources surfaciques, mais on n'est force parceque c'est
132  // le bordel avec les sources bafflees !
133  for (unsigned int i = 0; i < _listSrcPonct.size(); i++)
134  {
135  assert(_listSrcPonct[i]);
136  _listSrcPonct[i]->toXML(domNewElem);
137  }
138 
139  return domNewElem;
140 }
141 
143 {
144  unsigned int i = 0;
145 
146  TYSource::fromXML(domElement);
147 
148  remAllSrc();
149 
150  bool nbSrcsOk = false;
151  bool densiteSrcsHOk = false;
152  bool densiteSrcsVOk = false;
153  bool srcsCorrOk = false;
154  int nbSrcs = 0;
155  DOM_Element elemCur;
156 
157  QDomNodeList childs = domElement.childNodes();
158 
159  for (i = 0; i < childs.length(); i++)
160  {
161  elemCur = childs.item(i).toElement();
162 
163  TYXMLTools::getElementIntValue(elemCur, "nbSrcs", nbSrcs, nbSrcsOk);
164  if (nbSrcsOk)
165  {
166  _listSrcPonct.reserve(nbSrcs);
167  }
168 
169  TYXMLTools::getElementDoubleValue(elemCur, "densiteSrcsH", _densiteSrcsH, densiteSrcsHOk);
170  TYXMLTools::getElementDoubleValue(elemCur, "densiteSrcsV", _densiteSrcsV, densiteSrcsVOk);
171  TYXMLTools::getElementBoolValue(elemCur, "srcsCorr", _srcsCorr, srcsCorrOk);
172  }
173 
174  // Les sources ponctuelles associees aux sources surfaciques ne sont plus sauvegardees
175  // Recupere l'ensemble des source ponctuelles et derivees
176  LPTYElementArray srcs = TYElement::findTypeCollectionAndCallFromXML(domElement, "TYSourcePonctuelle");
177 
178  // Ajoute les srcs trouvees
179  for (i = 0; i < srcs.size(); i++)
180  {
181  addSrc((LPTYSourcePonctuelle&)srcs[i]);
182  }
183  //*/
184  return 1;
185 }
186 
188 {
189  return (_densiteSrcsH * _densiteSrcsV);
190 }
191 
193 {
194  _densiteSrcsH = _densiteSrcsV = sqrt(densite);
195 }
196 
198 {
199  if (pSrcPonct)
200  {
201  pSrcPonct->setParent(this);
202  _listSrcPonct.push_back(pSrcPonct);
203 
204  return true;
205  }
206 
207  return false;
208 }
209 
211 {
212  bool ret = false;
213  if (pSrcPonct)
214  {
215  TYTabLPSourcePonctuelle::iterator ite;
216 
217  for (ite = _listSrcPonct.begin(); ite != _listSrcPonct.end(); ite++)
218  {
219  if ((*ite) == pSrcPonct)
220  {
221  _listSrcPonct.erase(ite);
222  ret = true;
223  break;
224  }
225  }
226  }
227 
228  return ret;
229 }
230 
231 bool TYSourceSurfacic::remSrc(QString idSrc)
232 {
233  bool ret = false;
234  TYTabLPSourcePonctuelle::iterator ite;
235 
236  for (ite = _listSrcPonct.begin(); ite != _listSrcPonct.end(); ite++)
237  {
238  if ((*ite)->getID().toString() == idSrc)
239  {
240  _listSrcPonct.erase(ite);
241  ret = true;
242  break;
243  }
244  }
245 
246  return ret;
247 }
248 
250 {
251  _listSrcPonct.clear();
252 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:345
Representation graphique d'une surface de source (fichier header)
outil IHM pour une source surfacique (fichier header)
TY_EXT_GRAPHIC_INST(TYSourceSurfacic)
TY_EXTENSION_INST(TYSourceSurfacic)
virtual const char * getClassName() const
Definition: TYElement.h:249
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
void setParent(TYElement *pParent)
Definition: TYElement.h:692
static LPTYElementArray findTypeCollectionAndCallFromXML(DOM_Element parentElem, const char *type)
Definition: TYElement.cpp:572
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYSourceSurfacic & operator=(const TYSourceSurfacic &other)
Operateur =.
bool operator!=(const TYSourceSurfacic &other) const
Operateur !=.
virtual ~TYSourceSurfacic()
bool operator==(const TYSourceSurfacic &other) const
Operateur ==.
TYTabLPSourcePonctuelle _listSrcPonct
Liste des sources ponctuelles.
bool remSrc(const LPTYSourcePonctuelle pSrcPonct)
virtual std::string toString() const
size_t getNbSrcs() const
void setDensiteSrcs(double densite)
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
double _densiteSrcsH
Densite horizontale des sources ponctuelles.
virtual DOM_Element toXML(DOM_Element &domElement)
double _densiteSrcsV
Densite verticale des sources ponctuelles.
double getDensiteSrcs() const
bool addSrc(LPTYSourcePonctuelle pSrcPonct)
bool _srcsCorr
Indiquateur de correlation des sources ponctuelles.
virtual int fromXML(DOM_Element domElement)
virtual int fromXML(DOM_Element domElement)
Definition: TYSource.cpp:97
TYSource & operator=(const TYSource &other)
Operateur =.
Definition: TYSource.cpp:40
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSource.cpp:71
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSource.cpp:90
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 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
static bool getElementDoubleValue(DOM_Element parentElem, DOMString nodeName, double &nodeValue)
Definition: TYXMLTools.cpp:243