Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRay.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
16 #include <deque>
17 #include "TYRay.h"
18 #if TY_USE_IHM
20 #endif
21 
23 
25 {
26  _source = NULL;
27  _recepteur = NULL;
28 }
29 
30 TYRay::TYRay(const TYRay& ray)
31 {
32  *this = ray;
33 }
34 
36 
38 {
39  TYElement::operator=(other);
41  _source = other._source;
42  _recepteur = other._recepteur;
43 
44  return *this;
45 }
46 
47 bool TYRay::deepCopy(TYRay* pOther, bool copyId, bool pUseCopyTag /*=false*/)
48 {
49  assert(pOther);
50 
51  TYElement::deepCopy(pOther, copyId);
53 
54  _source = pOther->_source;
55  _recepteur = pOther->_recepteur;
56 
57  return true;
58 }
59 
61 {
62  DOM_Element domNewElem = TYElement::toXML(domElement);
63 
64  // Sauvegarde du nombre d'evènemenents
65  TYXMLTools::addElementUIntValue(domNewElem, "nb_events", _events.size());
66 
67  // Sauvegarde du type des evenements
68  // Cree un nouveau noeud pour l'ensemble des evenements
69  DOM_Document domDoc = domElement.ownerDocument();
70  DOM_Element events_type_list = domDoc.createElement("events_type");
71  domNewElem.appendChild(events_type_list);
72 
73  // Formatage des donnees
74  std::ostringstream oss;
75  for (size_t i = 0; i < _events.size() - 1; ++i)
76  {
77  oss << intToStr(_events[i]->type) << ' ';
78  }
79  oss << intToStr(_events[_events.size() - 1]->type);
80  DOMString tab(oss.str().c_str());
81 
82  // Ajout des donnees
83  QDomText data = domDoc.createTextNode(tab);
84 
85  events_type_list.appendChild(data);
86 
87  // Sauvegarde de la position des evenements
88  // Cree un nouveau noeud pour l'ensemble des evenements
89  DOM_Element listPosNode = domDoc.createElement("ListPosEvents");
90  domNewElem.appendChild(listPosNode);
91  TYPoint p;
92  for (size_t i = 0; i < _events.size(); i++)
93  {
94  p = _events[i]->pos;
95  p.toXML(listPosNode);
96  }
97 
98  return domNewElem;
99 }
100 
102 {
103  TYElement::fromXML(domElement);
104 
105  DOM_Element elemCur;
106  bool nbEventsOk = false;
107  std::deque<int> event_kind_tab;
108  std::deque<TYPoint> _listPoints;
109  unsigned int nb_events = 0;
110  int retVal = 0;
111  _events.clear();
112 
113  QDomNodeList childs = domElement.childNodes();
114 
115  for (unsigned int i = 0; i < childs.length(); i++)
116  {
117  elemCur = childs.item(i).toElement();
118 
119  TYXMLTools::getElementUIntValue(elemCur, "nb_events", nb_events, nbEventsOk);
120 
121  if (elemCur.nodeName() == "events_type" && nbEventsOk)
122  {
123  // On recupere les valeurs
124  QString tab;
125  TYXMLTools::getElementStringValue(elemCur, "events_type", tab);
126  std::istringstream iss(tab.toLatin1().data());
127 
128  int type_event = 0;
129  for (unsigned int i = 0; i < nb_events; ++i)
130  {
131  iss >> type_event;
132  event_kind_tab.push_back(type_event);
133  }
134  }
135  else if (elemCur.nodeName() == "ListPosEvents")
136  {
137  DOM_Element elemCur2;
138  QDomNodeList childs2 = elemCur.childNodes();
139 
140  for (int j = 0; j < childs2.length(); j++)
141  {
142  TYPoint pt;
143  elemCur2 = childs2.item(j).toElement();
144  if (pt.callFromXMLIfEqual(elemCur2, &retVal))
145  {
146  _listPoints.push_back(pt);
147  }
148  }
149  }
150  }
151 
152  // Reconstitution des evenements
153  assert((event_kind_tab.size() == nb_events) && (_listPoints.size() == nb_events));
154  for (size_t i = 0; i < nb_events; i++)
155  {
156  acoustic_event* ev = new acoustic_event(_listPoints.at(i));
157  ev->type = static_cast<ACOUSTIC_EVENT_TYPES>(event_kind_tab.at(i));
158 
159  _events.push_back(ev);
160  }
161 
162  return 1;
163 }
164 
166 {
167  SmartPtr<TYRay> a_ray = new TYRay(ap);
168  return a_ray;
169 }
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:165
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:305
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:366
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:263
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:545
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:379
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:24
bool deepCopy(TYRay *pOther, bool copyId, bool pUseCopyTag=false)
Deep copy of a ray mainly the events tab.
Definition: TYRay.cpp:47
TYPointCalcul * _recepteur
Definition: TYRay.h:132
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYRay.cpp:60
TYSourcePonctuelle * _source
Definition: TYRay.h:131
virtual int fromXML(DOM_Element domElement)
Definition: TYRay.cpp:101
virtual TYRay & operator=(const TYRay &other)
equal operator
Definition: TYRay.cpp:37
~TYRay()
Definition: TYRay.cpp:35
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