Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSourcePonctuelle.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 <typeinfo>
17 
18 #include "Tympan/core/logging.h"
27 #if TY_USE_IHM
31 #endif
32 #include "TYSourcePonctuelle.h"
33 
36 
38  : _type(TypeSurface), _typeRaynt(SPHERIC), _object(0), _hauteur(0.0), Directivity(NULL)
39 {
41 
42  float r = 255.0f, g = 0.0f, b = 0.0f;
43 
44 #if TY_USE_IHM
45  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "SrcPonctGraphicColorR"))
46  {
47  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "SrcPonctGraphicColor", r, g, b);
48  }
49  else
50  {
51  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "SrcPonctGraphicColor", r, g, b);
52  }
53 
54 #endif
55 
56  // Couleur de preference.
57  setColor(OColor(r / 255, g / 255, b / 255));
58 
59  _pPos = new TYPoint();
60 }
61 
63 {
64  *this = other;
65 }
66 
68 {
69  if (Directivity)
70  {
71  delete Directivity;
72  }
73 
74  Directivity = NULL;
75 }
76 
78 {
79  if (this != &other)
80  {
81  TYSource::operator=(other);
83  _pPos = other._pPos;
84  _orientation = other._orientation;
85  _type = other._type;
86  _typeRaynt = other._typeRaynt;
87  _hauteur = other._hauteur;
88  _object = other._object;
89  }
90  return *this;
91 }
92 
94 {
95  if (this != &other)
96  {
97  if (TYSource::operator!=(other))
98  {
99  return false;
100  }
101  if (TYColorInterface::operator!=(other))
102  {
103  return false;
104  }
105  if (_pPos != other._pPos)
106  {
107  return false;
108  }
109  if (_orientation != other._orientation)
110  {
111  return false;
112  }
113  if (_type != other._type)
114  {
115  return false;
116  }
117  if (_typeRaynt != other._typeRaynt)
118  {
119  return false;
120  }
121  if (_hauteur != other._hauteur)
122  {
123  return false;
124  }
125  if (_object != other._object)
126  {
127  return false;
128  }
129  }
130  return true;
131 }
132 
134 {
135  return !operator==(other);
136 }
137 
138 bool TYSourcePonctuelle::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
139 {
140  if (!TYSource::deepCopy(pOther, copyId, pUseCopyTag))
141  {
142  return false;
143  }
144 
145  TYSourcePonctuelle* pOtherSrc = (TYSourcePonctuelle*)pOther;
146  TYColorInterface::deepCopy((TYColorInterface*)pOtherSrc, copyId);
147 
148  _orientation = pOtherSrc->_orientation;
149  _type = pOtherSrc->_type;
150  _typeRaynt = pOtherSrc->_typeRaynt;
151  _pPos->deepCopy(pOtherSrc->_pPos, copyId);
152  _hauteur = pOtherSrc->_hauteur;
153  _object = pOtherSrc->_object;
154 
155  return true;
156 }
157 
158 std::string TYSourcePonctuelle::toString() const
159 {
160  return "TYSourcePonctuelle";
161 }
162 
164 {
165  DOM_Element domNewElem = TYSource::toXML(domElement);
166  TYColorInterface::toXML(domNewElem);
167 
168  _pPos->toXML(domNewElem);
169 
170  DOM_Document domDoc = domElement.ownerDocument();
171 
172  DOM_Element vectorXElem = domDoc.createElement("Vector");
173  domNewElem.appendChild(vectorXElem);
174  vectorXElem.setAttribute("x", doubleToStrPre(_orientation._x, 3).data());
175  vectorXElem.setAttribute("y", doubleToStrPre(_orientation._y, 3).data());
176  vectorXElem.setAttribute("z", doubleToStrPre(_orientation._z, 3).data());
177 
178  TYXMLTools::addElementIntValue(domNewElem, "type", _type);
179 
180  if (_type == TypeUser)
181  {
182  TYXMLTools::addElementStringValue(domNewElem, "hauteur", doubleToStrPre(_hauteur, 3).data());
183  }
184 
185  TYXMLTools::addElementIntValue(domNewElem, "typeRaynt", _typeRaynt);
186  TYXMLTools::addElementIntValue(domNewElem, "formeObjet", _object);
187 
188  return domNewElem;
189 }
190 
192 {
193  TYSource::fromXML(domElement);
194  TYColorInterface::fromXML(domElement);
195 
196  // Reset
197  bool typeOk = false;
198  bool hauteurOk = false;
199  bool typeRayntOk = false;
200  bool formeObjetOk = false;
201 
202  DOM_Element elemCur;
203  QDomNodeList childs = domElement.childNodes();
204 
205  for (unsigned int i = 0; i < childs.length(); i++)
206  {
207  elemCur = childs.item(i).toElement();
208 
209  _pPos->callFromXMLIfEqual(elemCur);
210  if (elemCur.nodeName() == "Vector")
211  {
215  }
216 
217  TYXMLTools::getElementIntValue(elemCur, "type", _type, typeOk);
218  TYXMLTools::getElementDoubleValue(elemCur, "hauteur", _hauteur, hauteurOk);
219  TYXMLTools::getElementIntValue(elemCur, "typeRaynt", _typeRaynt, typeRayntOk);
220  TYXMLTools::getElementIntValue(elemCur, "formeObjet", _object, formeObjetOk);
221  }
222 
223  return 1;
224 }
225 
227 {
228  _type = type;
229 
230  // Si c'est une source utilisateur, il faut lui affecter une orientation
232  {
233  _orientation = OVector3D(1, 0, 0);
234  }
235 }
All base classes related to 3D manipulation.
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
Representation graphique d'une source ponctuelle (fichier header)
outil IHM pour une source ponctuelle (fichier header)
TY_EXTENSION_INST(TYSourcePonctuelle)
TY_EXT_GRAPHIC_INST(TYSourcePonctuelle)
@ SPHERIC
Definition: color.h:31
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
virtual const char * getClassName() const
Definition: TYElement.h:249
The 3D vector class.
Definition: 3d.h:298
int fromXML(DOM_Element domElement)
TYColorInterface & operator=(const TYColorInterface &other)
virtual void setColor(const OColor &color)
void deepCopy(const TYColorInterface *pOther, bool copyId=true, bool pUseCopyTag=false)
DOM_Element toXML(DOM_Element &domElement)
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYPoint.cpp:112
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYPoint.cpp:92
int _type
Type de cette source.
virtual int fromXML(DOM_Element domElement)
bool operator!=(const TYSourcePonctuelle &other) const
Operateur !=.
double _hauteur
La hauteur de la source par rapport a l'altitude (dans le cas de source utilisateur).
int _typeRaynt
Type de rayonnement.
OVector3D _orientation
Orientation.
virtual DOM_Element toXML(DOM_Element &domElement)
TYSourcePonctuelle & operator=(const TYSourcePonctuelle &other)
Operateur =.
TYDirectivity * Directivity
int _object
Object representant la source.
LPTYPoint _pPos
Position.
bool operator==(const TYSourcePonctuelle &other) const
Operateur ==.
virtual std::string toString() const
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 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 double getElementAttributeToDouble(DOM_Element parentElem, DOMString attName, bool *ok=NULL)
Definition: TYXMLTools.cpp:288
static bool getElementDoubleValue(DOM_Element parentElem, DOMString nodeName, double &nodeValue)
Definition: TYXMLTools.cpp:243
static void addElementStringValue(DOM_Element &parentElem, DOMString nodeName, DOMString nodeValue)
Definition: TYXMLTools.cpp:24
std::string doubleToStrPre(double val, int precision=2)
Definition: macros.h:205