Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPointCalcul.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"
20 #include "TYPointCalcul.h"
21 #if TY_USE_IHM
23 #endif
24 
26 
28 {
30  _spectre = new TYSpectre();
31 }
32 
33 TYPointCalcul::TYPointCalcul(const TYPoint& other) : TYPoint(other, true) {}
34 
36 {
37  *this = other;
38 }
39 
41 
43 {
44  if (this != &other)
45  {
46  TYPoint::operator=(other);
47 
48  _spectre = new TYSpectre(*other._spectre);
49  }
50 
51  return *this;
52 }
53 
55 {
56  if (this != &other)
57  {
58  TYPoint::operator=(other);
59  }
60  return *this;
61 }
62 
63 bool TYPointCalcul::operator==(const TYPointCalcul& other) const
64 {
65  if (this != &other)
66  {
67  if (TYPoint::operator!=(other))
68  {
69  return false;
70  }
71  }
72  return true;
73 }
74 
75 bool TYPointCalcul::operator!=(const TYPointCalcul& other) const
76 {
77  return !operator==(other);
78 }
79 
80 bool TYPointCalcul::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
81 {
82  if (!TYPoint::deepCopy(pOther, copyId))
83  {
84  return false;
85  }
86 
87  TYPointCalcul* pOtherPtCalcul = (TYPointCalcul*)pOther;
88 
89  if (pOtherPtCalcul->getSpectre())
90  {
91  _spectre = new TYSpectre();
92  _spectre->deepCopy(pOtherPtCalcul->getSpectre(), false);
93  }
94 
95  return true;
96 }
97 
98 std::string TYPointCalcul::toString() const
99 {
100  std::string str =
101  "TYPointCalcul: X=" + doubleToStr(_x) + " Y=" + doubleToStr(_y) + " Z=" + doubleToStr(_z);
102  return str;
103 }
104 
106 {
107  // On surcharge completement depuis TYElement et non pas TYPoint
108  // car ce dernier ne conserve pas l'id
109  DOM_Element domNewElem = TYElement::toXML(domElement);
110 
111  domNewElem.setAttribute("x", doubleToStrPre(_x, 3).data());
112  domNewElem.setAttribute("y", doubleToStrPre(_y, 3).data());
113  domNewElem.setAttribute("z", doubleToStrPre(_z, 3).data());
114 
115  // Creation de la liste des etats des points de controle en fonction du calcul
116  // Ajoute un noeud pour l'etat des points de calcul
117  // DOM_Document domDoc = domElement.ownerDocument();
118 
119  // TYMapIdBool::iterator it_b;
120  // for (it_b = _tabEtats.begin(); it_b != _tabEtats.end(); ++it_b)
121  //{
122  // DOM_Element tmpNode = domDoc.createElement("etatCalcul");
123  // domNewElem.appendChild(tmpNode);
124 
125  // tmpNode.setAttribute("idCalcul", it_b->first);
126  // tmpNode.setAttribute("Etat", QString(intToStr(_tabEtats[it_b->first]).c_str()));
127  //}
128 
129  // if (TYProjet::gSaveValues)
130  //{
131  // // sauvegarde de l'ensemble des spectres
132  // TYMapIdSpectre::iterator it_s;
133  // for (it_s = _tabSpectre.begin(); it_s != _tabSpectre.end(); ++it_s)
134  // {
135  // TYSpectre* pSpectre = _tabSpectre[it_s->first];
136  // if (pSpectre != NULL)
137  // {
138  // DOM_Element spectreElem = pSpectre->toXML(domNewElem);
139  // QString idCalcul = it_s->first;
140  // spectreElem.setAttribute("idCalcul", idCalcul);
141  // }
142  // }
143  //}
144 
145  return domNewElem;
146 }
147 
149 {
150  // On surcharge completement depuis TYElement et non pas TYPoint
151  // car ce dernier ne conserve pas l'id
152  TYElement::fromXML(domElement);
153 
154  _x = TYXMLTools::getElementAttributeToDouble(domElement, "x");
155  _y = TYXMLTools::getElementAttributeToDouble(domElement, "y");
156  _z = TYXMLTools::getElementAttributeToDouble(domElement, "z");
157 
158  DOM_Element elemCur;
159 
160  // QString idCalcul = "";
161  int state = 0;
162 
163  QDomNodeList childs = domElement.childNodes();
164  for (unsigned int i = 0; i < childs.length(); i++)
165  {
166  elemCur = childs.item(i).toElement();
167 
168  if (elemCur.nodeName() == "state")
169  {
170  TYXMLTools::getElementIntValue(elemCur, "state", state);
171  }
172  // else if (elemCur.nodeName() == "etatCalcul")
173  //{
174  // idCalcul = TYXMLTools::getElementAttributeToString(elemCur, "idCalcul");
175  // bool bEtat = TYXMLTools::getElementAttributeToInt(elemCur, "Etat");
176  // _tabEtats[idCalcul] = bEtat;
177  //}
178  else if (elemCur.nodeName() == "Spectre")
179  {
180  _spectre->setParent(this);
181  _spectre->callFromXMLIfEqual(elemCur);
182  }
183 
184  // Cree et remplit le tableau des etats des points de controle si non existant
185  // if (bOldEtat && (idCalcul != ""))
186  //{
187  // _tabEtats[idCalcul] = !(state > 0);
188  //}
189  }
190 
191  setIsAcousticModified(true);
192 
193  return 1;
194 }
195 
196 // void TYPointCalcul::setSpectre(const TYSpectre& spectre, TYCalcul* pCalcul/* = NULL*/)
197 //{
198 // TYSpectre* pSpectre = getSpectre(pCalcul, true);
199 // *pSpectre = spectre;
200 // _dBA = pSpectre->valGlobDBA();
201 // _dBLin = pSpectre->valGlobDBLin();
202 // setIsAcousticModified(true);
203 //}
204 //
205 // TYSpectre* TYPointCalcul::getSpectre(TYCalcul* pCalcul, const bool& addToCalcul)
206 //{
207 // TYSpectre* pSpectre = NULL;
208 // QString idCalcul = "";
209 //
210 // if (_tabSpectre.size() == 1 && _isSpectreUnique)
211 // {
212 // // renvoit par defaut le spectre du 1er calcul disponible (cas des maillages)
213 // idCalcul = _tabSpectre.begin()->first;
214 // }
215 // else if (pCalcul != NULL)
216 // {
217 // idCalcul = pCalcul->getID().toString();
218 // }
219 //
220 // TYMapIdSpectre::iterator it = _tabSpectre.find(idCalcul);
221 // if (it == _tabSpectre.end())
222 // {
223 // pSpectre = new TYSpectre();
224 // pSpectre->setValid(false);
225 //
226 // if (addToCalcul)
227 // {
228 // pSpectre->setValid(true);
229 // _tabSpectre[idCalcul] = pSpectre;
230 // }
231 // }
232 // else
233 // {
234 // pSpectre = (*it).second;
235 //
236 // if (pSpectre == NULL)
237 // {
238 // // 1er acces au spectre --> Creation
239 // pSpectre = new TYSpectre();
240 // pSpectre->setValid(false); // Le spectre vide est invalide
241 // }
242 // }
243 //
244 // return pSpectre;
245 //}
246 
248 {
249  TYPoint retPoint;
251  LPTYMaillageGeoNode pMailNode = NULL;
252  LPTYProjet pProjet = dynamic_cast<TYProjet*>(pMail->getParent());
253  OMatrix matrix;
254 
255  // Recuperation de la matrice de changement de repere du maillage
256  if (pMail && pProjet)
257  {
258  pMailNode = pProjet->findMaillage(pMail);
259  if (pMailNode)
260  {
261  matrix = pMailNode->getMatrix();
262  }
263  }
264 
265  retPoint = matrix * (*this);
266 
267  // Passage dans le repere du SIG
268  LPTYSiteNode pSite = NULL;
269  if (pProjet)
270  {
271  pSite = pProjet->getSite();
272  }
273  if (pSite)
274  {
275  retPoint._x += pSite->getSIG_X();
276  retPoint._y += pSite->getSIG_Y();
277  }
278 
279  return retPoint;
280 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
outil IHM pour un point de calcul (fichier header)
TY_EXTENSION_INST(TYPointCalcul)
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
The 4x4 matrix class.
Definition: 3d.h:625
virtual const char * getClassName() const
Definition: TYElement.h:249
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
TYElement * getParent() const
Definition: TYElement.h:699
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:368
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
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 void setIsAcousticModified(bool isModified)
Definition: TYElement.cpp:248
OMatrix getMatrix() const
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
Definition: TYPointCalcul.h:33
virtual ~TYPointCalcul()
Destructeur Destructeur de la classe TYPointCalcul.
LPTYSpectre _spectre
bool operator==(const TYPointCalcul &other) const
Operateur ==.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYPointCalcul & operator=(TYPointCalcul &other)
Operateur =.
bool operator!=(const TYPointCalcul &other) const
Operateur !=.
virtual int fromXML(DOM_Element domElement)
TYPointCalcul()
Constructeur par defaut Constructeur par defaut de la classe TYPointCalcul.
virtual std::string toString() const
Copie du map calcul-spectre.
virtual LPTYSpectre getSpectre()
Get du spectre resultat d'un calcul donne.
virtual DOM_Element toXML(DOM_Element &domElement)
TYPoint getCoordSIG()
Passage en coordonnees SIG.
TYPoint & operator=(const TYPoint &other)
Operateur =.
Definition: TYPoint.cpp:54
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYPoint.cpp:92
classe de definition d'un projet.
Definition: TYProjet.h:45
LPTYMaillageGeoNode findMaillage(const LPTYMaillage pMaillage)
Retrouve le GeoNode associe a un maillage.
Definition: TYProjet.cpp:873
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
double getSIG_X()
Get/Set des coordonnees dans le repere du SIG.
Definition: TYSiteNode.h:558
double getSIG_Y()
Definition: TYSiteNode.h:571
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSpectre.cpp:142
static bool getElementIntValue(DOM_Element parentElem, DOMString nodeName, int &nodeValue)
Definition: TYXMLTools.cpp:129
static double getElementAttributeToDouble(DOM_Element parentElem, DOMString attName, bool *ok=NULL)
Definition: TYXMLTools.cpp:288
std::string doubleToStrPre(double val, int precision=2)
Definition: macros.h:205
std::string doubleToStr(double val)
Definition: macros.h:188