Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSegment.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 <math.h>
17 
18 #include "Tympan/core/logging.h"
19 #include "Tympan/core/defines.h"
20 #if TY_USE_IHM
23 #endif
24 #include "TYSegment.h"
25 
28 
30 {
32 
33  _ptA._x = 0;
34  _ptA._y = 0;
35  _ptA._z = 0;
36  _ptB._x = 0;
37  _ptB._y = 1;
38  _ptB._z = 0;
39 }
40 
42 {
43  *this = other;
44 }
45 
47 {
49 
50  _ptA = ptA;
51  _ptB = ptB;
52 }
53 
55 
57 {
58  if (this != &other)
59  {
60  TYElement::operator=(other);
62  _ptA = other._ptA;
63  _ptB = other._ptB;
64  }
65  return *this;
66 }
67 
68 bool TYSegment::operator==(const TYSegment& other) const
69 {
70  if (this != &other)
71  {
72  if (TYElement::operator!=(other))
73  {
74  return false;
75  }
76  if (TYColorInterface::operator!=(other))
77  {
78  return false;
79  }
80  if (_ptA != other._ptA)
81  {
82  return false;
83  }
84  if (_ptB != other._ptB)
85  {
86  return false;
87  }
88  }
89  return true;
90 }
91 
92 bool TYSegment::operator!=(const TYSegment& other) const
93 {
94  return !operator==(other);
95 }
96 
97 bool TYSegment::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
98 {
99  if (!TYElement::deepCopy(pOther, copyId))
100  {
101  return false;
102  }
103 
105 
106  TYSegment* pOtherSeg = (TYSegment*)pOther;
107 
108  _ptA = pOtherSeg->_ptA;
109  _ptB = pOtherSeg->_ptB;
110 
111  return true;
112 }
113 
114 std::string TYSegment::toString() const
115 {
116  std::string str = "TYSegment";
117  return str;
118 }
119 
121 {
122  DOM_Element domNewElem = TYElement::toXML(domElement);
123 
124  TYColorInterface::toXML(domNewElem);
125 
126  TYPoint ptA(_ptA), ptB(_ptB);
127 
128  ptA.toXML(domNewElem);
129  ptB.toXML(domNewElem);
130 
131  return domNewElem;
132 }
133 
135 {
136  int ptNb = 0;
137  DOM_Element elemCur;
138  TYPoint ptA, ptB;
139 
140  TYElement::fromXML(domElement);
141 
142  TYColorInterface::fromXML(domElement);
143 
144  QDomNodeList childs = domElement.childNodes();
145 
146  for (unsigned int i = 0; i < childs.length(); i++)
147  {
148  elemCur = childs.item(i).toElement();
149  if (ptNb == 0)
150  {
151  // Increment l'indice si le pt A est trouve
152  ptA.callFromXMLIfEqual(elemCur) ? ptNb++ : ptNb;
153  }
154  else if (ptNb == 1)
155  {
156  // Increment l'indice si le pt B est trouve
157  ptB.callFromXMLIfEqual(elemCur) ? ptNb++ : ptNb;
158  }
159  }
160 
161  _ptA = OPoint3D(ptA._x, ptA._y, ptA._z);
162  _ptB = OPoint3D(ptB._x, ptB._y, ptB._z);
163 
164  return 1;
165 }
166 
168 {
169  if (&s1 == &s2)
170  {
171  return true;
172  }
173  if (s1._ptA == s2._ptA && s1._ptB == s2._ptB)
174  {
175  return true;
176  }
177  if (s1._ptA == s2._ptB && s1._ptB == s2._ptA)
178  {
179  return true;
180  }
181  return false;
182 }
QDomElement DOM_Element
Definition: QT2DOM.h:30
Representation graphique d'un segment (fichier header)
outil IHM pour un segment (fichier header)
TY_EXTENSION_INST(TYSegment)
TY_EXT_GRAPHIC_INST(TYSegment)
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 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:249
OPoint3D _ptA
Point A of the segment.
Definition: 3d.h:1201
OPoint3D _ptB
Point B of the segment.
Definition: 3d.h:1203
int fromXML(DOM_Element domElement)
TYColorInterface & operator=(const TYColorInterface &other)
void deepCopy(const TYColorInterface *pOther, bool copyId=true, bool pUseCopyTag=false)
DOM_Element toXML(DOM_Element &domElement)
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
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
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 operator==(const TYSegment &other) const
Operateur ==.
Definition: TYSegment.cpp:68
virtual ~TYSegment()
Definition: TYSegment.cpp:54
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYSegment.cpp:97
virtual int fromXML(DOM_Element domElement)
Definition: TYSegment.cpp:134
virtual bool operator!=(const TYSegment &other) const
Operateur !=.
Definition: TYSegment.cpp:92
static bool unorderedIsEqual(const TYSegment &s1, const TYSegment &s2)
Comparison function for unordered segment.
Definition: TYSegment.cpp:167
virtual TYSegment & operator=(const TYSegment &other)
Operateur =.
Definition: TYSegment.cpp:56
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYSegment.cpp:120
virtual std::string toString() const
Definition: TYSegment.cpp:114