Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRay.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 <deque>
17 #include "TYRay.h"
18 #if TY_USE_IHM
20 #endif
21 
23 
24 #include "TYRay.h"
25 
27 {
28  _source = NULL;
29  _recepteur = NULL;
30 }
31 
32 TYRay::TYRay(const TYRay& ray)
33 {
34  *this = ray;
35 }
36 
38 
40 {
41  TYElement::operator=(other);
43  _source = other._source;
44  _recepteur = other._recepteur;
45 
46  return *this;
47 }
48 
49 bool TYRay::deepCopy(TYRay* pOther, bool copyId, bool pUseCopyTag /*=false*/)
50 {
51  assert(pOther);
52 
53  TYElement::deepCopy(pOther, copyId);
55 
56  _source = pOther->_source;
57  _recepteur = pOther->_recepteur;
58 
59  return true;
60 }
61 
63 {
64  DOM_Element domNewElem = TYElement::toXML(domElement);
65 
66  // Sauvegarde du nombre d'evènemenents
67  TYXMLTools::addElementUIntValue(domNewElem, "nb_events", _events.size());
68 
69  // Sauvegarde du type des evenements
70  // Cree un nouveau noeud pour l'ensemble des evenements
71  DOM_Document domDoc = domElement.ownerDocument();
72  DOM_Element events_type_list = domDoc.createElement("events_type");
73  domNewElem.appendChild(events_type_list);
74 
75  // Formatage des donnees
76  std::ostringstream oss;
77  for (size_t i = 0; i < _events.size() - 1; ++i)
78  {
79  oss << intToStr(_events[i]->type) << ' ';
80  }
81  oss << intToStr(_events[_events.size() - 1]->type);
82  DOMString tab(oss.str().c_str());
83 
84  // Ajout des donnees
85  QDomText data = domDoc.createTextNode(tab);
86 
87  events_type_list.appendChild(data);
88 
89  // Sauvegarde de la position des evenements
90  // Cree un nouveau noeud pour l'ensemble des evenements
91  DOM_Element listPosNode = domDoc.createElement("ListPosEvents");
92  domNewElem.appendChild(listPosNode);
93  TYPoint p;
94  for (size_t i = 0; i < _events.size(); i++)
95  {
96  p = _events[i]->pos;
97  p.toXML(listPosNode);
98  }
99 
100  return domNewElem;
101 }
102 
104 {
105  TYElement::fromXML(domElement);
106 
107  DOM_Element elemCur;
108  bool nbEventsOk = false;
109  std::deque<int> event_kind_tab;
110  std::deque<TYPoint> _listPoints;
111  unsigned int nb_events = 0;
112  int retVal = 0;
113  _events.clear();
114 
115  QDomNodeList childs = domElement.childNodes();
116 
117  for (unsigned int i = 0; i < childs.length(); i++)
118  {
119  elemCur = childs.item(i).toElement();
120 
121  TYXMLTools::getElementUIntValue(elemCur, "nb_events", nb_events, nbEventsOk);
122 
123  if (elemCur.nodeName() == "events_type" && nbEventsOk)
124  {
125  // On recupere les valeurs
126  QString tab;
127  TYXMLTools::getElementStringValue(elemCur, "events_type", tab);
128  std::istringstream iss(tab.toLatin1().data());
129 
130  int type_event = 0;
131  for (unsigned int i = 0; i < nb_events; ++i)
132  {
133  iss >> type_event;
134  event_kind_tab.push_back(type_event);
135  }
136  }
137  else if (elemCur.nodeName() == "ListPosEvents")
138  {
139  DOM_Element elemCur2;
140  QDomNodeList childs2 = elemCur.childNodes();
141 
142  for (int j = 0; j < childs2.length(); j++)
143  {
144  TYPoint pt;
145  elemCur2 = childs2.item(j).toElement();
146  if (pt.callFromXMLIfEqual(elemCur2, &retVal))
147  {
148  _listPoints.push_back(pt);
149  }
150  }
151  }
152  }
153 
154  // Reconstitution des evenements
155  assert((event_kind_tab.size() == nb_events) && (_listPoints.size() == nb_events));
156  for (size_t i = 0; i < nb_events; i++)
157  {
158  acoustic_event* ev = new acoustic_event(_listPoints.at(i));
159  ev->type = static_cast<ACOUSTIC_EVENT_TYPES>(event_kind_tab.at(i));
160 
161  _events.push_back(ev);
162  }
163 
164  return 1;
165 }
166 
168 {
169  SmartPtr<TYRay> a_ray = new TYRay(ap);
170  return a_ray;
171 }
QString DOMString
Definition: QT2DOM.h:31
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
SmartPtr< TYRay > build_ray(const acoustic_path &ap)
Build a TYRay from an acoustic_path (used by cython interface)
Definition: TYRay.cpp:167
TY_EXT_GRAPHIC_INST(TYRay)
ACOUSTIC_EVENT_TYPES
Definition: acoustic_path.h:22
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
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYPoint.cpp:112
Classe decrivant un rayon acoustique gere par un lancer de rayon. Cette classe doit permettre la mode...
Definition: TYRay.h:35
TYRay()
Constructeur par defaut.
Definition: TYRay.cpp:26
bool deepCopy(TYRay *pOther, bool copyId, bool pUseCopyTag=false)
Deep copy of a ray mainly the events tab.
Definition: TYRay.cpp:49
TYPointCalcul * _recepteur
Definition: TYRay.h:132
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYRay.cpp:62
TYSourcePonctuelle * _source
Definition: TYRay.h:131
virtual int fromXML(DOM_Element domElement)
Definition: TYRay.cpp:103
virtual TYRay & operator=(const TYRay &other)
equal operator
Definition: TYRay.cpp:39
~TYRay()
Definition: TYRay.cpp:37
static bool getElementStringValue(DOM_Element parentElem, DOMString nodeName, QString &nodeValue)
Definition: TYXMLTools.cpp:93
static void getElementUIntValue(DOM_Element parentElem, DOMString nodeName, unsigned int &nodeValue, bool &ok)
Definition: TYXMLTools.cpp:161
static void addElementUIntValue(DOM_Element &parentElem, DOMString nodeName, unsigned int nodeValue)
Definition: TYXMLTools.cpp:42
This class store data and provide functions to manipulate event in the acoustic context.
Definition: acoustic_path.h:40
ACOUSTIC_EVENT_TYPES type
Event type.
Definition: acoustic_path.h:60
Acoustic path.
Definition: acoustic_path.h:78
virtual bool deepCopy(acoustic_path *pOther)
Deep copy of a ray mainly the events tab.
virtual acoustic_path & operator=(const acoustic_path &other)
equal operator
tab_acoustic_events _events
Events vector containing the events list (and their positions) of the associated ray.
std::string intToStr(int val)
Definition: macros.h:158