Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPoint.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
22 #endif
23 
24 #include "Tympan/core/logging.h"
25 
26 #include "TYPoint.h"
27 
29 
30 TYPoint::TYPoint(bool PutInInstanceList /*= false */) : TYElement(NULL, PutInInstanceList), OPoint3D() {}
31 
32 TYPoint::TYPoint(const TYPoint& other, bool PutInInstanceList /*= false */)
33  : TYElement(NULL, PutInInstanceList), OPoint3D(other)
34 {
35 }
36 
37 TYPoint::TYPoint(const OCoord3D& other, bool PutInInstanceList /*= false */)
38  : TYElement(NULL, PutInInstanceList), OPoint3D(other)
39 {
40 }
41 
42 TYPoint::TYPoint(const OVector3D& other, bool PutInInstanceList /*= false */)
43  : TYElement(NULL, PutInInstanceList), OPoint3D(other)
44 {
45 }
46 
47 TYPoint::TYPoint(double x, double y, double z, bool PutInInstanceList /*= false */)
48  : TYElement(NULL, PutInInstanceList), OPoint3D(x, y, z)
49 {
50 }
51 
53 
55 {
56  if (this != &other)
57  {
58  TYElement::operator=(other);
59  // TYColorInterface::operator =(other);
60  OCoord3D::operator=(other);
61  }
62  return *this;
63 }
64 
65 bool TYPoint::operator==(const TYPoint& other) const
66 {
67  if (this != &other)
68  {
69  if (TYElement::operator!=(other))
70  {
71  return false;
72  }
73  // if (TYColorInterface::operator !=(other)) return false;
74  if (OCoord3D::operator!=(other))
75  {
76  return false;
77  }
78  }
79  return true;
80 }
81 
82 bool TYPoint::operator!=(const TYPoint& other) const
83 {
84  return !operator==(other);
85 }
86 
87 bool TYPoint::isEqual(const TYPoint& point) const
88 {
89  return OCoord3D::operator==(point);
90 }
91 
92 bool TYPoint::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
93 {
94  if (!TYElement::deepCopy(pOther, copyId))
95  {
96  return false;
97  }
98 
99  // TYColorInterface::deepCopy((TYColorInterface*)pOther, copyId);
100 
101  OCoord3D::operator=(*(TYPoint*)pOther);
102 
103  return true;
104 }
105 
106 std::string TYPoint::toString() const
107 {
108  std::string str = "TYPoint: X=" + doubleToStr(_x) + " Y=" + doubleToStr(_y) + " Z=" + doubleToStr(_z);
109  return str;
110 }
111 
113 {
114  DOM_Element domNewElem = TYElement::toXML(domElement);
115 
116  // TYColorInterface::toXML(domNewElem);
117 
118  // L'ID et le name d'un point n'ont pas besoin d'etre conserves
119  domNewElem.removeAttribute("id");
120  domNewElem.removeAttribute("name");
121 
122  // On enleve les 4 derniers chiffres, pour garder seulement
123  // 2 chiffres apres la virgule
124  domNewElem.setAttribute("x", doubleToStrPre(_x, 3).data());
125  domNewElem.setAttribute("y", doubleToStrPre(_y, 3).data());
126  domNewElem.setAttribute("z", doubleToStrPre(_z, 3).data());
127 
128  return domNewElem;
129 }
130 
132 {
133  TYElement::fromXML(domElement);
134 
135  // TYColorInterface::fromXML(domElement);
136 
137  // On genere un nouvel ID car l'ID des pts est supprime ! (cf + haut)
138  // regenerateID();
139 
140  _x = TYXMLTools::getElementAttributeToDouble(domElement, "x");
141  _y = TYXMLTools::getElementAttributeToDouble(domElement, "y");
142  _z = TYXMLTools::getElementAttributeToDouble(domElement, "z");
143 
144  return 1;
145 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
outil IHM pour un point (fichier header)
TY_EXTENSION_INST(TYPoint)
The 3D coordinate class.
Definition: 3d.h:226
double _y
y coordinate of OCoord3D
Definition: 3d.h:283
OCoord3D & operator=(const OCoord3D &coord)
operator=
Definition: 3d.cpp:40
double _z
z coordinate of OCoord3D
Definition: 3d.h:284
double _x
x coordinate of OCoord3D
Definition: 3d.h:282
bool operator==(const OCoord3D &coord) const
operator==
Definition: 3d.cpp:51
The 3D point class.
Definition: 3d.h:487
The 3D vector class.
Definition: 3d.h:298
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
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
virtual ~TYPoint()
Definition: TYPoint.cpp:52
virtual std::string toString() const
Definition: TYPoint.cpp:106
bool operator!=(const TYPoint &other) const
Operateur !=.
Definition: TYPoint.cpp:82
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYPoint.cpp:112
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
bool isEqual(const TYPoint &point) const
Tests equality using only coordiantes.
Definition: TYPoint.cpp:87
bool operator==(const TYPoint &other) const
Operateur ==.
Definition: TYPoint.cpp:65
virtual int fromXML(DOM_Element domElement)
Definition: TYPoint.cpp:131
TYPoint(bool PutInInstanceList=false)
Definition: TYPoint.cpp:30
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