Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRepere.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 "TYRepere.h"
27 
29 
31 {
33 }
34 
36 {
37  *this = other;
38 }
39 
40 TYRepere::TYRepere(const OPoint3D& origin, const OVector3D& vecX, const OVector3D& vecY,
41  const OVector3D& vecZ)
42  : ORepere3D(origin, vecX, vecY, vecZ)
43 {
45 }
46 
47 TYRepere::TYRepere(const ORepere3D& repere) : ORepere3D(repere)
48 {
50 }
51 
53 
55 {
56  if (this != &other)
57  {
58  TYElement::operator=(other);
59  ORepere3D::operator=(other);
60  }
61  return *this;
62 }
63 
64 bool TYRepere::operator==(const TYRepere& other) const
65 {
66  if (this != &other)
67  {
68  if (TYElement::operator!=(other))
69  {
70  return false;
71  }
72  if (ORepere3D::operator!=(other))
73  {
74  return false;
75  }
76  }
77  return true;
78 }
79 
80 bool TYRepere::operator!=(const TYRepere& other) const
81 {
82  return !operator==(other);
83 }
84 
85 bool TYRepere::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
86 {
87  if (!TYElement::deepCopy(pOther, copyId))
88  {
89  return false;
90  }
91 
92  ORepere3D::operator=(*(TYRepere*)pOther);
93 
94  return true;
95 }
96 
97 std::string TYRepere::toString() const
98 {
99  return "TYRepere";
100 }
101 
103 {
104  DOM_Element domNewElem = TYElement::toXML(domElement);
105  DOM_Document domDoc = domElement.ownerDocument();
106  DOM_Element pointElem = domDoc.createElement("Point");
107  domNewElem.appendChild(pointElem);
108  pointElem.setAttribute("x", doubleToStrPre(_origin._x, 12).data());
109  pointElem.setAttribute("y", doubleToStrPre(_origin._y, 12).data());
110  pointElem.setAttribute("z", doubleToStrPre(_origin._z, 12).data());
111 
112  DOM_Element vectorXElem = domDoc.createElement("Vector");
113  domNewElem.appendChild(vectorXElem);
114  vectorXElem.setAttribute("x", doubleToStrPre(_vecI._x, 12).data());
115  vectorXElem.setAttribute("y", doubleToStrPre(_vecI._y, 12).data());
116  vectorXElem.setAttribute("z", doubleToStrPre(_vecI._z, 12).data());
117 
118  DOM_Element vectorYElem = domDoc.createElement("Vector");
119  domNewElem.appendChild(vectorYElem);
120  vectorYElem.setAttribute("x", doubleToStrPre(_vecJ._x, 12).data());
121  vectorYElem.setAttribute("y", doubleToStrPre(_vecJ._y, 12).data());
122  vectorYElem.setAttribute("z", doubleToStrPre(_vecJ._z, 12).data());
123 
124  DOM_Element vectorZElem = domDoc.createElement("Vector");
125  domNewElem.appendChild(vectorZElem);
126  vectorZElem.setAttribute("x", doubleToStrPre(_vecK._x, 12).data());
127  vectorZElem.setAttribute("y", doubleToStrPre(_vecK._y, 12).data());
128  vectorZElem.setAttribute("z", doubleToStrPre(_vecK._z, 12).data());
129 
130  return domNewElem;
131 }
132 
134 {
135  int res = 0;
136 
137  int vecNb = 0;
138  DOM_Element elemCur;
139 
140  TYElement::fromXML(domElement);
141 
142  QDomNodeList childs = domElement.childNodes();
143 
144  for (unsigned int i = 0; i < childs.length(); i++)
145  {
146  elemCur = childs.item(i).toElement();
147  if (elemCur.nodeName() == "Point")
148  {
152  }
153 
154  if (elemCur.nodeName() == "Vector")
155  {
156 
157  if (vecNb == 0) // Vector X
158  {
162  }
163  else if (vecNb == 1) // Vector Y
164  {
168  }
169  else if (vecNb == 2) // Vector Z
170  {
174  }
175 
176  // Increment l'indice car un vector est trouve
177  vecNb++;
178  }
179  }
180  if (isRepereValid())
181  res = 1;
182  return res;
183 }
184 
186 {
187  OVector3D nullVector = OVector3D();
188  if (_vecI == nullVector || _vecJ == nullVector || _vecK == nullVector)
189  return false;
190  return true;
191 }
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
Outil IHM pour un repere (fichier header)
TY_EXTENSION_INST(TYRepere)
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
3D frame with a point and 3 vectors.
Definition: 3d.h:1211
OVector3D _vecK
Vector K for the Z axis.
Definition: 3d.h:1285
OVector3D _vecJ
Vector J for the Y axis.
Definition: 3d.h:1283
ORepere3D & operator=(const ORepere3D &repere)
operator=
Definition: 3d.cpp:1386
OVector3D _vecI
Vector I for the X axis.
Definition: 3d.h:1281
OPoint3D _origin
The origin point.
Definition: 3d.h:1279
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
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
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: TYRepere.cpp:102
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYRepere.cpp:85
virtual int fromXML(DOM_Element domElement)
Definition: TYRepere.cpp:133
TYRepere()
Definition: TYRepere.cpp:30
virtual ~TYRepere()
Definition: TYRepere.cpp:52
virtual std::string toString() const
Definition: TYRepere.cpp:97
bool isRepereValid()
Definition: TYRepere.cpp:185
bool operator!=(const TYRepere &other) const
Operateur !=.
Definition: TYRepere.cpp:80
bool operator==(const TYRepere &other) const
Operateur ==.
Definition: TYRepere.cpp:64
TYRepere & operator=(const TYRepere &other)
Operateur =.
Definition: TYRepere.cpp:54
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