Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourceLineic.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 "TYSourceLineic.h"
28 
31 
32 TYSourceLineic::TYSourceLineic() : _densiteSrcs(100.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);
52  _densiteSrcs = other._densiteSrcs;
53  _srcsCorr = other._srcsCorr;
55  }
56  return *this;
57 }
58 
60 {
61  if (this != &other)
62  {
63  if (TYSource::operator!=(other))
64  {
65  return false;
66  }
67  if (_densiteSrcs != other._densiteSrcs)
68  {
69  return false;
70  }
71  if (_srcsCorr != other._srcsCorr)
72  {
73  return false;
74  }
75  if (!(_listSrcPonct == other._listSrcPonct))
76  {
77  return false;
78  }
79  }
80  return true;
81 }
82 
84 {
85  return !operator==(other);
86 }
87 
88 bool TYSourceLineic::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
89 {
90  if (!TYSource::deepCopy(pOther, copyId))
91  {
92  return false;
93  }
94 
95  TYSourceLineic* pOtherSrc = (TYSourceLineic*)pOther;
96 
97  _densiteSrcs = pOtherSrc->_densiteSrcs;
98  _srcsCorr = pOtherSrc->_srcsCorr;
99 
100  purge();
101  for (unsigned int i = 0; i < _listSrcPonct.size(); i++)
102  {
104  pSrc->deepCopy(_listSrcPonct[i], copyId);
105  addSrc(pSrc);
106  }
107 
108  return true;
109 }
110 
111 std::string TYSourceLineic::toString() const
112 {
113  return "TYSourceLineic";
114 }
115 
117 {
118  DOM_Element domNewElem = TYSource::toXML(domElement);
119 
120  TYXMLTools::addElementIntValue(domNewElem, "nbSrcs", (int)getNbSrcs());
121  TYXMLTools::addElementDoubleValue(domNewElem, "densiteSrcs", _densiteSrcs);
122  TYXMLTools::addElementIntValue(domNewElem, "srcsCorr", _srcsCorr);
123 
124  for (unsigned int i = 0; i < _listSrcPonct.size(); i++)
125  {
126  assert(_listSrcPonct[i]);
127  _listSrcPonct[i]->toXML(domNewElem);
128  }
129 
130  return domNewElem;
131 }
132 
134 {
135  unsigned int i = 0;
136  TYSource::fromXML(domElement);
137 
138  remAllSrc();
139 
140  bool nbSrcsOk = false;
141  bool densiteSrcsOk = false;
142  bool srcsCorrOk = false;
143  int nbSrcs = 0;
144  DOM_Element elemCur;
145 
146  QDomNodeList childs = domElement.childNodes();
147 
148  for (i = 0; i < childs.length(); i++)
149  {
150  elemCur = childs.item(i).toElement();
151  TYXMLTools::getElementIntValue(elemCur, "nbSrcs", nbSrcs, nbSrcsOk);
152  if (nbSrcsOk)
153  {
154  _listSrcPonct.reserve(nbSrcs);
155  }
156 
157  TYXMLTools::getElementDoubleValue(elemCur, "densiteSrcs", _densiteSrcs, densiteSrcsOk);
158  TYXMLTools::getElementBoolValue(elemCur, "srcsCorr", _srcsCorr, srcsCorrOk);
159  }
160 
161  // Recupere l'ensemble des source ponctuelles et derivees
162  LPTYElementArray srcs = TYElement::findTypeCollectionAndCallFromXML(domElement, "TYSourcePonctuelle");
163 
164  // Ajoute les srcs trouvees
165  for (i = 0; i < srcs.size(); i++)
166  {
167  addSrc((LPTYSourcePonctuelle&)srcs[i]);
168  }
169 
170  return 1;
171 }
172 
174 {
175  if (pSrcPonct)
176  {
177  pSrcPonct->setParent(this);
178  _listSrcPonct.push_back(pSrcPonct);
179  return true;
180  }
181 
182  return false;
183 }
184 
186 {
187  bool ret = false;
188  if (pSrcPonct)
189  {
190  TYTabLPSourcePonctuelle::iterator ite;
191 
192  for (ite = _listSrcPonct.begin(); ite != _listSrcPonct.end(); ite++)
193  {
194  if ((*ite) == pSrcPonct)
195  {
196  _listSrcPonct.erase(ite);
197  ret = true;
198  break;
199  }
200  }
201  }
202  return ret;
203 }
204 
205 bool TYSourceLineic::remSrc(QString idSrc)
206 {
207  bool ret = false;
208  TYTabLPSourcePonctuelle::iterator ite;
209 
210  for (ite = _listSrcPonct.begin(); ite != _listSrcPonct.end(); ite++)
211  {
212  if ((*ite)->getID().toString() == idSrc)
213  {
214  _listSrcPonct.erase(ite);
215  ret = true;
216  break;
217  }
218  }
219 
220  return ret;
221 }
222 
224 {
225  _listSrcPonct.clear();
226 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:345
Representation graphique d'une source lineique (fichier header)
outil IHM pour une source lineique (fichier header)
TY_EXTENSION_INST(TYSourceLineic)
TY_EXT_GRAPHIC_INST(TYSourceLineic)
virtual OPrototype * clone() const =0
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.
bool operator==(const TYSourceLineic &other) const
Operateur ==.
bool addSrc(LPTYSourcePonctuelle pSrcPonct)
virtual DOM_Element toXML(DOM_Element &domElement)
bool remSrc(const LPTYSourcePonctuelle pSrcPonct)
size_t getNbSrcs() const
bool _srcsCorr
Indiquateur de correlation des sources ponctuelles.
virtual int fromXML(DOM_Element domElement)
TYTabLPSourcePonctuelle _listSrcPonct
Liste des sources ponctuelles.
bool operator!=(const TYSourceLineic &other) const
Operateur !=.
double _densiteSrcs
Densite des sources ponctuelles (exprimee en sources/metre).
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual ~TYSourceLineic()
virtual std::string toString() const
TYSourceLineic & operator=(const TYSourceLineic &other)
Operateur =.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
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