Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPointControl.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 "Tympan/core/logging.h"
21 #include "TYPointControl.h"
22 
23 #if TY_USE_IHM
26 #endif
27 
30 
31 TYPointControl::TYPointControl() : _object(0), _statusSIG(false)
32 {
34 
35  // Par defaut : Un point de controle est bleu
36  float r = 85.0f, g = 0.0f, b = 255.0f;
37 
38 #if TY_USE_IHM
39  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "PointControlGraphicColorR"))
40  {
41  TYPreferenceManager::getColor(TYDIRPREFERENCEMANAGER, "PointControlGraphicColor", r, g, b);
42  }
43  else
44  {
45  TYPreferenceManager::setColor(TYDIRPREFERENCEMANAGER, "PointControlGraphicColor", r, g, b);
46  }
47 #endif
48  OColor color;
49  color.r = r / 255;
50  color.g = g / 255;
51  color.b = b / 255;
52 
53  setColor(color);
54 
55  _hauteur = 2.0;
56 }
57 
59 {
60  _hauteur = 2.0;
61  _object = 0;
62 }
63 
65 {
66  *this = other;
67 }
68 
70 
72 {
73  if (this != &other)
74  {
77  copyEtats(const_cast<TYPointControl*>(&other)); // Copie les etats
78  _hauteur = other._hauteur;
79  _object = other._object;
80  _statusSIG = other._statusSIG;
81  }
82  return *this;
83 }
84 
86 {
87  if (this != &other)
88  {
90  }
91  return *this;
92 }
93 
95 {
96  if (this != &other)
97  {
98  if (TYPointCalcul::operator!=(other))
99  {
100  return false;
101  }
102  if (TYColorInterface::operator!=(other))
103  {
104  return false;
105  }
106  if (_hauteur != other._hauteur)
107  {
108  return false;
109  }
110  if (_object != other._object)
111  {
112  return false;
113  }
114  if (_statusSIG != other._statusSIG)
115  {
116  return false;
117  }
118  }
119  return true;
120 }
121 
123 {
124  return !operator==(other);
125 }
126 
127 bool TYPointControl::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
128 {
129  if (!TYPointCalcul::deepCopy(pOther, copyId))
130  {
131  return false;
132  }
133 
134  TYPointControl* pOtherPtControl = (TYPointControl*)pOther;
135  copyEtats(pOtherPtControl);
136 
137  _hauteur = pOtherPtControl->_hauteur;
138  _object = pOtherPtControl->_object;
139  _statusSIG = pOtherPtControl->_statusSIG;
140 
141  return true;
142 }
143 
144 std::string TYPointControl::toString() const
145 {
146  std::string str = "TYPointControl: X=" + doubleToStr(_x) + " Y=" + doubleToStr(_y) +
147  " Z=" + doubleToStr(_z) + " Hauteur=" + doubleToStr(_hauteur);
148  return str;
149 }
150 
152 {
153  DOM_Element domNewElem = TYPointCalcul::toXML(domElement);
154  TYColorInterface::toXML(domNewElem);
155 
156  TYXMLTools::addElementStringValue(domNewElem, "hauteur", doubleToStrPre(_hauteur, 3).data());
157  TYXMLTools::addElementIntValue(domNewElem, "formeObjet", _object);
158 
159  // Ajoute un noeud pour l'etat des points de calcul
160  DOM_Document domDoc = domElement.ownerDocument();
161 
162  TYMapIdBool::iterator it_b;
163  for (it_b = _tabEtats.begin(); it_b != _tabEtats.end(); ++it_b)
164  {
165  DOM_Element tmpNode = domDoc.createElement("etatCalcul");
166  domNewElem.appendChild(tmpNode);
167 
168  tmpNode.setAttribute("idCalcul", it_b->first.toString());
169  tmpNode.setAttribute("Etat", QString(intToStr(_tabEtats[it_b->first]).c_str()));
170  }
171 
172  return domNewElem;
173 }
174 
176 {
177  TYPointCalcul::fromXML(domElement);
178  TYColorInterface::fromXML(domElement);
179 
180  bool hauteurOk = false;
181  bool formeObjetOk = false;
182  bool bOldDatas = false;
183  TYUUID idCalcul;
184  std::map<TYUUID, LPTYSpectre>* compatibilityVector = new std::map<TYUUID, LPTYSpectre>();
185 
186  DOM_Element elemCur;
187 
188  QDomNodeList childs = domElement.childNodes();
189  for (unsigned int i = 0; i < childs.length(); i++)
190  {
191  elemCur = childs.item(i).toElement();
192 
193  TYXMLTools::getElementDoubleValue(elemCur, "hauteur", _hauteur, hauteurOk);
194  TYXMLTools::getElementIntValue(elemCur, "formeObjet", _object, formeObjetOk);
195 
196  if (elemCur.nodeName() == "etatCalcul")
197  {
198  QString strIdCalcul = TYXMLTools::getElementAttributeToString(elemCur, "idCalcul");
199  idCalcul.FromString(strIdCalcul);
200  bool bEtat = TYXMLTools::getElementAttributeToInt(elemCur, "Etat");
201  _tabEtats[idCalcul] = bEtat;
202  }
203  else if (elemCur.nodeName() == "Spectre")
204  {
205  bOldDatas = true;
206  LPTYSpectre pSpectre = new TYSpectre();
207  pSpectre->callFromXMLIfEqual(elemCur);
208 
209  // recupere le calcul associe au spectre
210  QString strId = TYXMLTools::getElementAttributeToString(elemCur, "idCalcul");
211  idCalcul.FromString(strId);
212  compatibilityVector->operator[](idCalcul) = pSpectre;
213  }
214  }
215 
216  if (bOldDatas == true)
217  {
218  // Cleaning compatibility data
219  std::map<TYUUID, LPTYSpectre>::iterator it;
220  for (it = compatibilityVector->begin(); it != compatibilityVector->end();)
221  {
222  if (_tabEtats[(*it).first] == false)
223  {
224  it = compatibilityVector->erase(it);
225  }
226  else
227  {
228  it++;
229  }
230  }
231 
232  setAllUses((void*)compatibilityVector);
233  }
234  else
235  {
236  delete compatibilityVector;
237  }
238 
239  return 1;
240 }
241 
243 {
245  TYSiteNode* pSite = NULL;
246  if (pProjet)
247  {
248  pSite = pProjet->getSite();
249  }
250 
251  if (pSite && !_statusSIG)
252  {
253  _x += pSite->getSIG_X();
254  _y += pSite->getSIG_Y();
255  _statusSIG = true;
256  }
257 }
258 
260 {
262  TYSiteNode* pSite = NULL;
263  if (pProjet)
264  {
265  pSite = pProjet->getSite();
266  }
267 
268  if (pSite && _statusSIG)
269  {
270  _x -= pSite->getSIG_X();
271  _y -= pSite->getSIG_Y();
272  _statusSIG = false;
273  }
274 }
275 
277 {
279  LPTYSiteNode pSite = NULL;
280  if (pCalcul)
281  {
282  pSite = pCalcul->getSite();
283  }
284 
285  if (pSite)
286  {
287  return pSite->getSIGType();
288  }
289 
290  return 0;
291 }
292 
293 void TYPointControl::setEtat(const TYUUID& id_calc, bool etat)
294 {
295  _tabEtats[id_calc] = etat;
296 }
297 
299 {
300  TYUUID id_calc = dynamic_cast<TYProjet*>(getParent())->getCurrentCalcul()->getID();
301 
302  return etat(id_calc);
303 }
304 
305 bool TYPointControl::etat(const TYUUID& id_calc)
306 {
307  // Constrol point knows the calcul
308  TYMapIdBool::iterator it = _tabEtats.find(id_calc);
309  if (it != _tabEtats.end())
310  {
311  return (*it).second;
312  }
313  else
314  {
315  _tabEtats[id_calc] = false;
316  }
317 
318  return false;
319 }
320 
321 bool TYPointControl::etat(const TYCalcul* pCalc)
322 {
323  assert(pCalc != nullptr);
324  return etat(pCalc->getID());
325 }
326 
328 {
329  _tabEtats.clear(); // On vide la map actuelle
330 
331  TYMapIdBool::iterator it_b;
332  for (it_b = pOther->_tabEtats.begin(); it_b != pOther->_tabEtats.end(); ++it_b)
333  {
334  _tabEtats[it_b->first] = it_b->second;
335  }
336 }
337 
338 void TYPointControl::duplicateEtat(const TYUUID& idCalculRef, const TYUUID& idCalculNew)
339 {
340  _tabEtats[idCalculNew] = _tabEtats[idCalculRef];
341 }
342 
344 {
345  return dynamic_cast<TYProjet*>(getParent())->getCurrentCalcul()->getSpectre(this);
346 }
347 
349 {
350  assert(pCalcul);
351  TYUUID id = pCalcul->getID();
352 
353  TYMapIdBool::iterator it = _tabEtats.find(id);
354  if (it != _tabEtats.end())
355  {
356  _tabEtats.erase(it);
357  return true;
358  }
359 
360  return false;
361 }
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
class OGenID TYUUID
Definition: TYDefines.h:59
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:52
Representation graphique d'un point de controle (fichier header)
outil IHM pour un point de controle (fichier header)
TY_EXTENSION_INST(TYPointControl)
TY_EXT_GRAPHIC_INST(TYPointControl)
Definition: color.h:31
float b
Definition: color.h:33
float r
Definition: color.h:33
float g
Definition: color.h:33
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
virtual const char * getClassName() const
Definition: TYElement.h:249
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
Calculation program.
Definition: TYCalcul.h:50
LPTYSiteNode getSite()
Get calculation site.
Definition: TYCalcul.cpp:856
int fromXML(DOM_Element domElement)
TYColorInterface & operator=(const TYColorInterface &other)
virtual void setColor(const OColor &color)
DOM_Element toXML(DOM_Element &domElement)
TYElement * getParent() const
Definition: TYElement.h:699
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
const TYUUID & getID() const
Definition: TYElement.cpp:176
void setAllUses(void *allUses)
Definition: TYElement.h:936
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
Classe de definition d'un point de calcul.C'est une classe derivee a TYPoint avec en plus un spectrep...
Definition: TYPointCalcul.h:33
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
TYPointCalcul & operator=(TYPointCalcul &other)
Operateur =.
virtual int fromXML(DOM_Element domElement)
virtual DOM_Element toXML(DOM_Element &domElement)
Classe de definition d'un point de controle.Le point de controle est un point de calcul avec une haut...
TYPointControl()
Constructeur par defaut. Constructeur par defaut de la classe TYPointControl.
bool remEtat(TYCalcul *pCalcul)
Remove calcul from "etat" map.
void copyEtats(TYPointControl *pOther)
Copie du map calcul-etat.
void duplicateEtat(const TYUUID &idCalculRef, const TYUUID &idCalculNew)
Duplique l'etat defini pour un calcul pour un autre calcul.
bool operator==(const TYPointControl &other) const
Operateur ==.
int _object
shape of the point in GUI
int getSIGType()
Retourne le type de SIG.
bool operator!=(const TYPointControl &other) const
Operateur !=.
virtual LPTYSpectre getSpectre()
Get du spectre resultat d'un calcul donne.
TYPointControl & operator=(const TYPointControl &other)
Operateur =.
bool _statusSIG
Etat des coordonnees par rapport au SIG (position dans le repere SIG ou pas)
virtual DOM_Element toXML(DOM_Element &domElement)
void toSIG()
Conversion dans le repere du Systeme d'Information Geographique.
TYMapIdBool _tabEtats
L'etat du point pour un calcul donne.
virtual void setEtat(const TYUUID &id_calc, bool etat)
virtual ~TYPointControl()
Destructeur Destructeur de la classe TYPointControl .
double _hauteur
La hauteur du point par rapport a l'altitude.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
virtual std::string toString() const
Copie du map calcul-spectre.
virtual bool etat()
virtual int fromXML(DOM_Element domElement)
classe de definition d'un projet.
Definition: TYProjet.h:45
LPTYSiteNode getSite()
Get du site.
Definition: TYProjet.h:169
double getSIG_X()
Get/Set des coordonnees dans le repere du SIG.
Definition: TYSiteNode.h:558
int getSIGType()
Get/Set du choix du systeme de repere du SIG.
Definition: TYSiteNode.h:544
double getSIG_Y()
Definition: TYSiteNode.h:571
static int getElementAttributeToInt(DOM_Element parentElem, DOMString attName, bool *ok=NULL)
Definition: TYXMLTools.cpp:293
static QString getElementAttributeToString(DOM_Element parentElem, DOMString attName)
Definition: TYXMLTools.cpp:276
static void addElementIntValue(DOM_Element &parentElem, DOMString nodeName, int nodeValue)
Definition: TYXMLTools.cpp:72
static bool getElementIntValue(DOM_Element parentElem, DOMString nodeName, int &nodeValue)
Definition: TYXMLTools.cpp:129
static bool getElementDoubleValue(DOM_Element parentElem, DOMString nodeName, double &nodeValue)
Definition: TYXMLTools.cpp:243
static void addElementStringValue(DOM_Element &parentElem, DOMString nodeName, DOMString nodeValue)
Definition: TYXMLTools.cpp:24
std::string doubleToStrPre(double val, int precision=2)
Definition: macros.h:205
std::string doubleToStr(double val)
Definition: macros.h:188
std::string intToStr(int val)
Definition: macros.h:158