Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTopographie.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 "Tympan/core/logging.h"
19 #if TY_USE_IHM
23 #endif
24 #include "TYTopographie.h"
25 
28 
29 #define TR(id) OLocalizator::getString("OMessageManager", (id))
30 
31 // Declaration de la fonction utilisee par qsort pour le tri des terrains
32 static int compareSurfaceTerrains(const void* elem1, const void* elem2);
33 
35 {
37 
38  _pAltimetrie = new TYAltimetrie();
39  _pAltimetrie->setParent(this);
40 
41  LPTYTerrain pDefTerrain = new TYTerrain();
42  pDefTerrain->setParent(this);
43  pDefTerrain->setName(std::string("Terrain par defaut"));
44  addTerrain(pDefTerrain);
45  _DefTerrainIdx = 0;
46 
47  // Taille de topo par defaut (rectangle)
48  float sizeX = TAILLETOPOX;
49  float sizeY = TAILLETOPOY;
50 
51 #if TY_USE_IHM
52  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "DefaultDimX"))
53  {
54  sizeX = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "DefaultDimX");
55  }
56  else
57  {
58  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "DefaultDimX", sizeX);
59  }
60 
61  if (TYPreferenceManager::exists(TYDIRPREFERENCEMANAGER, "DefaultDimY"))
62  {
63  sizeY = TYPreferenceManager::getFloat(TYDIRPREFERENCEMANAGER, "DefaultDimY");
64  }
65  else
66  {
67  TYPreferenceManager::setFloat(TYDIRPREFERENCEMANAGER, "DefaultDimY", sizeY);
68  }
69 
70 #endif
71 
72  TYRectangle emprise;
73  emprise.setDimension(sizeX, sizeY);
74 
75  setEmprise(emprise.getContourFerme());
76 
78 
79  _pSortedTerrains = NULL;
80 }
81 
83 {
84  *this = other;
85 }
86 
88 {
89  if (_pSortedTerrains)
90  {
91  delete[] _pSortedTerrains;
92  _pSortedTerrains = NULL;
93  }
94 }
95 
97 {
98  if (this != &other)
99  {
100  TYElement::operator=(other);
101  _listPlanEau = other._listPlanEau;
102  _listCrsEau = other._listCrsEau;
103  _listTerrain = other._listTerrain;
104  _listCrbNiv = other._listCrbNiv;
106  _pAltimetrie = other._pAltimetrie;
107  _emprise = other._emprise;
109  }
110  return *this;
111 }
112 
113 bool TYTopographie::operator==(const TYTopographie& other) const
114 {
115  if (this != &other)
116  {
117  if (TYElement::operator!=(other))
118  {
119  return false;
120  }
121  if (!(_listPlanEau == other._listPlanEau))
122  {
123  return false;
124  }
125  if (!(_listCrsEau == other._listCrsEau))
126  {
127  return false;
128  }
129  if (!(_listTerrain == other._listTerrain))
130  {
131  return false;
132  }
133  if (!(_listCrbNiv == other._listCrbNiv))
134  {
135  return false;
136  }
137  if (_DefTerrainIdx != other._DefTerrainIdx)
138  {
139  return false;
140  }
141  if (_pAltimetrie != other._pAltimetrie)
142  {
143  return false;
144  }
145  if (_emprise != other._emprise)
146  {
147  return false;
148  }
149  if (_pSortedTerrains != other._pSortedTerrains)
150  {
151  return false;
152  }
153  }
154  return true;
155 }
156 
157 bool TYTopographie::operator!=(const TYTopographie& other) const
158 {
159  return !operator==(other);
160 }
161 
162 bool TYTopographie::deepCopy(const TYElement* pOther, bool copyId /*=true*/, bool pUseCopyTag /*=false*/)
163 {
164  if (!TYElement::deepCopy(pOther, copyId))
165  {
166  return false;
167  }
168 
169  TYTopographie* pOtherTopo = (TYTopographie*)pOther;
170 
171  _DefTerrainIdx = pOtherTopo->_DefTerrainIdx;
172 
173  _listCrbNiv.clear();
174  unsigned int i = 0;
175  for (i = 0; i < pOtherTopo->_listCrbNiv.size(); i++)
176  {
177  LPTYCourbeNiveauGeoNode pCrbNivGeoNode = new TYCourbeNiveauGeoNode(NULL, this);
178  pCrbNivGeoNode->deepCopy(pOtherTopo->_listCrbNiv[i], copyId);
179  pCrbNivGeoNode->getElement()->setParent(this);
180  pCrbNivGeoNode->setParent(this);
181  _listCrbNiv.push_back(pCrbNivGeoNode);
182  }
183 
184  _listTerrain.clear();
185  for (i = 0; i < pOtherTopo->_listTerrain.size(); i++)
186  {
187  LPTYTerrainGeoNode pTerrainGeoNode = new TYTerrainGeoNode(NULL, this);
188  pTerrainGeoNode->deepCopy(pOtherTopo->_listTerrain[i], copyId);
189  pTerrainGeoNode->getElement()->setParent(this);
190  pTerrainGeoNode->setParent(this);
191  _listTerrain.push_back(pTerrainGeoNode);
192  }
193 
194  _listCrsEau.clear();
195  for (i = 0; i < pOtherTopo->_listCrsEau.size(); i++)
196  {
197  LPTYCoursEauGeoNode pCrsEauGeoNode = new TYCoursEauGeoNode(NULL, this);
198  pCrsEauGeoNode->deepCopy(pOtherTopo->_listCrsEau[i], copyId);
199  pCrsEauGeoNode->getElement()->setParent(this);
200  pCrsEauGeoNode->setParent(this);
201  _listCrsEau.push_back(pCrsEauGeoNode);
202  }
203 
204  _listPlanEau.clear();
205  for (i = 0; i < pOtherTopo->_listPlanEau.size(); i++)
206  {
207  LPTYPlanEauGeoNode pPlanEauGeoNode = new TYPlanEauGeoNode(NULL, this);
208  pPlanEauGeoNode->deepCopy(pOtherTopo->_listPlanEau[i], copyId);
209  pPlanEauGeoNode->getElement()->setParent(this);
210  pPlanEauGeoNode->setParent(this);
211  _listPlanEau.push_back(pPlanEauGeoNode);
212  }
213 
214  resetEmprise();
215  for (i = 0; i < pOtherTopo->_emprise.size(); i++)
216  {
217  addPointEmprise(pOtherTopo->_emprise[i]);
218  }
219 
220  return true;
221 }
222 
223 std::string TYTopographie::toString() const
224 {
225  return "TYTopographie";
226 }
227 
229 {
230  unsigned int i = 0;
231 
232  DOM_Element domNewElem = TYElement::toXML(domElement);
233  DOM_Document domDoc = domElement.ownerDocument();
234  DOM_Element empriseNode = domDoc.createElement("Emprise");
235  domNewElem.appendChild(empriseNode);
236  DOM_Element listCrbNivNode = domDoc.createElement("ListCrbNiv");
237  domNewElem.appendChild(listCrbNivNode);
238  DOM_Element listTerrainNode = domDoc.createElement("ListTerrain");
239  domNewElem.appendChild(listTerrainNode);
240  DOM_Element listCrsEauNode = domDoc.createElement("ListCrsEau");
241  domNewElem.appendChild(listCrsEauNode);
242  DOM_Element listPlanEauNode = domDoc.createElement("ListPlanEau");
243  domNewElem.appendChild(listPlanEauNode);
244 
245  _pAltimetrie->toXML(domNewElem);
246 
247  TYXMLTools::addElementIntValue(domNewElem, "DefaultTerrain", _DefTerrainIdx);
248 
249  for (i = 0; i < _emprise.size(); i++)
250  {
251  _emprise[i].toXML(empriseNode);
252  }
253 
254  for (i = 0; i < _listCrbNiv.size(); i++)
255  {
256  // Ajout de la courbe de niveau
257  _listCrbNiv[i]->toXML(listCrbNivNode);
258  }
259 
260  for (i = 0; i < _listTerrain.size(); i++)
261  {
262  // Ajout du terrain
263  _listTerrain[i]->toXML(listTerrainNode);
264  }
265 
266  for (i = 0; i < _listCrsEau.size(); i++)
267  {
268  // Ajout du cours d'eau
269  _listCrsEau[i]->toXML(listCrsEauNode);
270  }
271 
272  for (i = 0; i < _listPlanEau.size(); i++)
273  {
274  // Ajout du plan d'eau
275  _listPlanEau[i]->toXML(listPlanEauNode);
276  }
277 
278  return domNewElem;
279 }
280 
282 {
283  TYElement::fromXML(domElement);
284 
285  purge();
286 
287  unsigned int i = 0, j = 0;
288  TYPoint pt;
289  LPTYCourbeNiveauGeoNode pCrbNivGeoNode = new TYCourbeNiveauGeoNode(NULL, this);
290  LPTYTerrainGeoNode pTerrainGeoNode = new TYTerrainGeoNode(NULL, this);
291  LPTYCoursEauGeoNode pCrsEauGeoNode = new TYCoursEauGeoNode(NULL, this);
292  LPTYPlanEauGeoNode pPlanEauGeoNode = new TYPlanEauGeoNode(NULL, this);
293 
294  bool bDefTerrainOk = false;
295  DOM_Element elemCur;
296 
297  QDomNodeList childs = domElement.childNodes();
298  unsigned int childcount = childs.length();
299  for (i = 0; i < childcount; i++)
300  {
301  elemCur = childs.item(i).toElement();
302  OMessageManager::get()->info("Charge element de topographie %d/%d.", i + 1, childcount);
303 
305 
306  // Compatibilite T3.2
307  LPTYTerrain pDefTerrainT32 = new TYTerrain();
308  pDefTerrainT32->setName(std::string("Terrain par defaut"));
309  if (pDefTerrainT32->callFromXMLIfEqual(elemCur))
310  {
311  addTerrain(pDefTerrainT32);
312  }
313 
314  TYXMLTools::getElementIntValue(elemCur, "DefaultTerrain", _DefTerrainIdx, bDefTerrainOk);
315 
316  // RELECTURE EMPRISE
317  if (elemCur.nodeName() == "Emprise")
318  {
319  DOM_Element elemCur2;
320  QDomNodeList childs2 = elemCur.childNodes();
321 
322  for (j = 0; j < childs2.length(); j++)
323  {
324  elemCur2 = childs2.item(j).toElement();
325 
326  if (pt.callFromXMLIfEqual(elemCur2))
327  {
328  _emprise.push_back(pt);
329  }
330  }
331  }
332 
333  // RELECTURE COURBES DE NIVEAU
334  else if (elemCur.nodeName() == "ListCrbNiv")
335  {
336  DOM_Element elemCur2;
337  QDomNodeList childs2 = elemCur.childNodes();
338 
339  for (j = 0; j < childs2.length(); j++)
340  {
341  elemCur2 = childs2.item(j).toElement();
342  if (pCrbNivGeoNode->callFromXMLIfEqual(elemCur2))
343  {
344  // Remove level curve defined with less than to points
345  if (dynamic_cast<TYCourbeNiveau*>(pCrbNivGeoNode->getElement())->getListPoints().size() >=
346  2)
347  {
348  addCrbNiv(pCrbNivGeoNode);
349  }
350 
351  pCrbNivGeoNode = new TYCourbeNiveauGeoNode(NULL, this);
352  }
353  }
354  }
355 
356  // RELECTURE TERRAINS
357  else if (elemCur.nodeName() == "ListTerrain")
358  {
359  DOM_Element elemCur2;
360  QDomNodeList childs2 = elemCur.childNodes();
361 
362  for (j = 0; j < childs2.length(); j++)
363  {
364  elemCur2 = childs2.item(j).toElement();
365 
366  if (pTerrainGeoNode->callFromXMLIfEqual(elemCur2))
367  {
368  addTerrain((LPTYTerrainGeoNode)pTerrainGeoNode);
369  pTerrainGeoNode = new TYTerrainGeoNode(NULL, this);
370  }
371  }
372  }
373 
374  // RELECTURE COURS D'EAU
375  else if (elemCur.nodeName() == "ListCrsEau")
376  {
377  DOM_Element elemCur2;
378  QDomNodeList childs2 = elemCur.childNodes();
379 
380  for (j = 0; j < childs2.length(); j++)
381  {
382  elemCur2 = childs2.item(j).toElement();
383  if (pCrsEauGeoNode->callFromXMLIfEqual(elemCur2))
384  {
385  addCrsEau(pCrsEauGeoNode);
386  pCrsEauGeoNode = new TYCoursEauGeoNode(NULL, this);
387  }
388  }
389  }
390 
391  // RELECTURE PLAN D'EAU
392  else if (elemCur.nodeName() == "ListPlanEau")
393  {
394  DOM_Element elemCur2;
395  QDomNodeList childs2 = elemCur.childNodes();
396 
397  for (j = 0; j < childs2.length(); j++)
398  {
399  elemCur2 = childs2.item(j).toElement();
400  if (pPlanEauGeoNode->callFromXMLIfEqual(elemCur2))
401  {
402  addPlanEau(pPlanEauGeoNode);
403  pPlanEauGeoNode = new TYPlanEauGeoNode(NULL, this);
404  }
405  }
406  }
407  }
408 
409  if (!bDefTerrainOk) // pas de terrain par defaut trouve, on suppose qu'il s'agit d'un fichier a l'ancien
410  // format...
411  {
412  // Pour tous les terrains
413  LPTYTerrain pTerrain = NULL;
414  for (i = 0; i < _listTerrain.size(); i++)
415  {
416  pTerrain = dynamic_cast<TYTerrain*>(_listTerrain[i]->getElement());
417 
418  // Si taille de la liste de point = 0
419  if (pTerrain && pTerrain->getListPoints().size() == 0)
420  {
421  // Ce terrain est l'ancien terrain par defaut
422  this->setDefTerrain(i);
423  }
424  }
425  }
426 
427  return 1;
428 }
429 
431 {
433  // Si la géométrie est modifiée, alors on invalide l'altimétrie
434  _pAltimetrie->setIsUpToDate(!isModified);
435  if (_pParent)
436  {
437  _pParent->setIsGeometryModified(isModified);
438  }
439 }
440 
442 {
443  _pAltimetrie->setParent(this);
444  unsigned int i = 0;
445  for (i = 0; i < _listCrbNiv.size(); i++)
446  {
447  _listCrbNiv[i]->setParent(this);
448  _listCrbNiv[i]->getElement()->setParent(this);
449  }
450 
451  for (i = 0; i < _listTerrain.size(); i++)
452  {
453  _listTerrain[i]->setParent(this);
454  _listTerrain[i]->getElement()->setParent(this);
455  }
456 
457  for (i = 0; i < _listCrsEau.size(); i++)
458  {
459  _listCrsEau[i]->setParent(this);
460  _listCrsEau[i]->getElement()->setParent(this);
461  }
462 
463  for (i = 0; i < _listPlanEau.size(); i++)
464  {
465  _listPlanEau[i]->setParent(this);
466  _listPlanEau[i]->getElement()->setParent(this);
467  }
468 }
469 
470 void TYTopographie::getChilds(LPTYElementArray& childs, bool recursif /*=true*/)
471 {
472  unsigned int i = 0;
473 
474  TYElement::getChilds(childs, recursif);
475  for (i = 0; i < _listCrbNiv.size(); i++)
476  {
477  childs.push_back(_listCrbNiv[i]);
478  childs.push_back(_listCrbNiv[i]->getElement());
479  }
480 
481  for (i = 0; i < _listPlanEau.size(); i++)
482  {
483  childs.push_back(_listPlanEau[i]);
484  childs.push_back(_listPlanEau[i]->getElement());
485  }
486 }
487 
488 void TYTopographie::updateCurrentCalcul(TYListID& listID, bool recursif) //=true
489 {
490  if (recursif) // On parcours les enfants si besoin est...
491  {
492  // Collecte des childs
493  LPTYElementArray childs;
494  getChilds(childs, false);
495  for (int i = 0; i < childs.size(); i++)
496  {
497  childs[i]->updateCurrentCalcul(listID, recursif);
498  }
499  }
500 
501  TYElement::updateCurrentCalcul(listID, false);
502 }
503 
505 {
506  resetEmprise();
507  remAllCrbNiv();
508  remAllCrsEau();
509  remAllTerrain();
510  remAllPlanEau();
511 
512  if (_pSortedTerrains)
513  {
514  delete[] _pSortedTerrains;
515  _pSortedTerrains = NULL;
516  }
517 
518  setIsGeometryModified(true);
519 }
520 
521 void TYTopographie::concatTopo(const TYTopographie* pTopo, bool emprise /*= true*/)
522 {
523  unsigned int i = 0;
524 
525  for (i = 0; i < pTopo->_listCrbNiv.size(); ++i)
526  {
527  _listCrbNiv.push_back(pTopo->_listCrbNiv[i]);
528  }
529 
530  for (i = 0; i < pTopo->_listTerrain.size(); ++i)
531  {
532  _listTerrain.push_back(pTopo->_listTerrain[i]);
533  }
534 
535  for (i = 0; i < pTopo->_listCrsEau.size(); ++i)
536  {
537  _listCrsEau.push_back(pTopo->_listCrsEau[i]);
538  }
539 
540  for (i = 0; i < pTopo->_listPlanEau.size(); ++i)
541  {
542  _listPlanEau.push_back(pTopo->_listPlanEau[i]);
543  }
544 
545  if (emprise)
546  {
547  resetEmprise();
548  for (i = 0; i < pTopo->_emprise.size(); ++i)
549  {
550  addPointEmprise(pTopo->_emprise[i]);
551  }
552  }
553 }
554 
556 {
557  assert(pPlanEauGeoNode);
558 
559  LPTYPlanEau pPlanEau = dynamic_cast<TYPlanEau*>(pPlanEauGeoNode->getElement());
560 
561  assert(pPlanEau);
562 
563  pPlanEauGeoNode->setParent(this);
564  pPlanEau->setParent(this);
565 
566  _listPlanEau.push_back(pPlanEauGeoNode);
567 
568  setIsGeometryModified(true);
569 
570  // L'alti n'est plus a jour non plus...
572 
573  return true;
574 }
575 
577 {
578  return addPlanEau(new TYPlanEauGeoNode((LPTYElement)pPlanEau));
579 }
580 
582 {
583  assert(pPlanEauGeoNode);
584  bool ret = false;
585  TYTabPlanEauGeoNode::iterator ite;
586 
587  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
588  {
589  if ((*ite) == pPlanEauGeoNode)
590  {
591  // #if TY_USE_IHM
592  // (*ite)->remFromAllRenderer();
593  // #endif
594  _listPlanEau.erase(ite);
595  ret = true;
596  break;
597  }
598  }
599 
600  setIsGeometryModified(true);
601 
602  // L'alti n'est plus a jour non plus...
604 
605  return ret;
606 }
607 
609 {
610  assert(pPlanEau);
611  bool ret = false;
612  TYTabPlanEauGeoNode::iterator ite;
613 
614  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
615  {
616  if (dynamic_cast<TYPlanEau*>((*ite)->getElement()) == pPlanEau)
617  {
618  // #if TY_USE_IHM
619  // (*ite)->remFromAllRenderer();
620  // #endif
621  _listPlanEau.erase(ite);
622  ret = true;
623  break;
624  }
625  }
626 
627  setIsGeometryModified(true);
628 
629  // L'alti n'est plus a jour non plus...
631 
632  return ret;
633 }
634 
635 bool TYTopographie::remPlanEau(QString idPlanEau)
636 {
637  bool ret = false;
638  TYTabPlanEauGeoNode::iterator ite;
639 
640  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
641  {
642  if ((*ite)->getElement()->getID().toString() == idPlanEau)
643  {
644  // #if TY_USE_IHM
645  // (*ite)->remFromAllRenderer();
646  // #endif
647  _listPlanEau.erase(ite);
648  ret = true;
649  break;
650  }
651  }
652 
653  setIsGeometryModified(true);
654 
655  // L'alti n'est plus a jour non plus...
657 
658  return ret;
659 }
660 
662 {
663  _listPlanEau.clear();
664 
665  setIsGeometryModified(true);
666 
667  // L'alti n'est plus a jour non plus...
669 }
670 
672 {
673  assert(pPlanEau);
674  TYTabPlanEauGeoNode::iterator ite;
675 
676  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
677  {
678  if (dynamic_cast<TYPlanEau*>((*ite)->getElement()) == pPlanEau)
679  {
680  return (*ite);
681  }
682  }
683 
684  return NULL;
685 }
686 
688 {
690  LPTYPlanEauGeoNode pPlanEauGeoNode;
691  for (int i = 0; i < _listPlanEau.size(); i++)
692  {
693  pPlanEauGeoNode = _listPlanEau[i];
694 
695  if (pPlanEauGeoNode->getElement()->isInCurrentCalcul())
696  {
697  ret.push_back(pPlanEauGeoNode);
698  }
699  }
700  return ret;
701 }
702 
704 {
705  assert(pCoursEauGeoNode);
706 
707  LPTYCoursEau pCoursEau = dynamic_cast<TYCoursEau*>(pCoursEauGeoNode->getElement());
708 
709  assert(pCoursEau);
710 
711  pCoursEauGeoNode->setParent(this);
712  pCoursEau->setParent(this);
713 
714  _listCrsEau.push_back(pCoursEauGeoNode);
715 
716  setIsGeometryModified(true);
717 
718  return true;
719 }
720 
722 {
723  return addCrsEau(new TYCoursEauGeoNode((LPTYElement)pCoursEau));
724 }
725 
726 bool TYTopographie::remCrsEau(const LPTYCoursEauGeoNode pCoursEauGeoNode)
727 {
728  assert(pCoursEauGeoNode);
729  bool ret = false;
730  TYTabCoursEauGeoNode::iterator ite;
731 
732  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
733  {
734  if ((*ite) == pCoursEauGeoNode)
735  {
736  // #if TY_USE_IHM
737  // (*ite)->remFromAllRenderer();
738  // #endif
739  _listCrsEau.erase(ite);
740  ret = true;
741  break;
742  }
743  }
744 
745  setIsGeometryModified(true);
746 
747  return ret;
748 }
749 
751 {
752  assert(pCoursEau);
753  bool ret = false;
754  TYTabCoursEauGeoNode::iterator ite;
755 
756  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
757  {
758  if (dynamic_cast<TYCoursEau*>((*ite)->getElement()) == pCoursEau)
759  {
760  // #if TY_USE_IHM
761  // (*ite)->remFromAllRenderer();
762  // #endif
763  _listCrsEau.erase(ite);
764  ret = true;
765  break;
766  }
767  }
768 
769  setIsGeometryModified(true);
770 
771  return ret;
772 }
773 
774 bool TYTopographie::remCrsEau(QString idCrsEau)
775 {
776  bool ret = false;
777  TYTabCoursEauGeoNode::iterator ite;
778 
779  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
780  {
781  if (dynamic_cast<TYCoursEau*>((*ite)->getElement())->getID().toString() == idCrsEau)
782  {
783  // #if TY_USE_IHM
784  // (*ite)->remFromAllRenderer();
785  // #endif
786  _listCrsEau.erase(ite);
787  ret = true;
788  break;
789  }
790  }
791 
792  setIsGeometryModified(true);
793 
794  return ret;
795 }
796 
798 {
799  _listCrsEau.clear();
800  setIsGeometryModified(true);
801 }
802 
804 {
805  assert(pCrsEau);
806  TYTabCoursEauGeoNode::iterator ite;
807 
808  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
809  {
810  if (dynamic_cast<TYCoursEau*>((*ite)->getElement()) == pCrsEau)
811  {
812  return (*ite);
813  }
814  }
815 
816  return NULL;
817 }
818 
820 {
821  assert(pTerGeoNode);
822 
823  TYTerrain* pTerrain = dynamic_cast<TYTerrain*>(pTerGeoNode->getElement());
824 
825  assert(pTerrain);
826 
827  pTerGeoNode->setParent(this);
828  pTerrain->setParent(this);
829 
830  _listTerrain.push_back(pTerGeoNode);
831 
832  setIsGeometryModified(true);
833 
834  return true;
835 }
836 
838 {
839  return addTerrain(new TYTerrainGeoNode((LPTYElement)pTer));
840 }
841 
843 {
844  assert(pTerGeoNode);
845  // On efface pas le terrain par defaut
846  if (pTerGeoNode == _listTerrain[_DefTerrainIdx])
847  {
848  return false;
849  }
850 
851  bool ret = false;
852  unsigned int terrainNbr = 0;
853 
854  TYTabTerrainGeoNode::iterator ite;
855 
856  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
857  {
858  if ((*ite) == pTerGeoNode)
859  {
860 
861  // #if TY_USE_IHM
862  // (*ite)->remFromAllRenderer();
863  // #endif
864  _listTerrain.erase(ite);
865 
866  if (terrainNbr < _DefTerrainIdx)
867  {
868  _DefTerrainIdx--;
869  } // Dans ce cas, on decremente l'indice du terrain par defaut
870 
871  ret = true;
872  break;
873  }
874 
875  terrainNbr++;
876  }
877 
878  setIsGeometryModified(true);
879 
880  return ret;
881 }
882 
884 {
885  assert(pTer);
886  bool ret = false;
887  unsigned int terrainNbr = 0;
888  TYTabTerrainGeoNode::iterator ite;
889 
890  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
891  {
892  if (dynamic_cast<TYTerrain*>((*ite)->getElement()) == pTer)
893  {
894  if ((*ite) == _listTerrain[_DefTerrainIdx])
895  {
896  return false;
897  }
898 
899  // #if TY_USE_IHM
900  // (*ite)->remFromAllRenderer();
901  // #endif
902  _listTerrain.erase(ite);
903 
904  if (terrainNbr < _DefTerrainIdx)
905  {
906  _DefTerrainIdx--;
907  } // Dans ce cas, on decremente l'indice du terrain par defaut
908 
909  ret = true;
910  break;
911  }
912 
913  terrainNbr++;
914  }
915 
916  setIsGeometryModified(true);
917 
918  return ret;
919 }
920 
921 bool TYTopographie::remTerrain(QString idTerrain)
922 {
923  bool ret = false;
924  unsigned int terrainNbr = 0;
925  TYTabTerrainGeoNode::iterator ite;
926 
927  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
928  {
929  if ((*ite)->getElement()->getID().toString() == idTerrain)
930  {
931  // #if TY_USE_IHM
932  // (*ite)->remFromAllRenderer();
933  // #endif
934  _listTerrain.erase(ite);
935 
936  if (terrainNbr < _DefTerrainIdx)
937  {
938  _DefTerrainIdx--;
939  } // Dans ce cas, on decremente l'indice du terrain par defaut
940 
941  ret = true;
942  break;
943  }
944 
945  terrainNbr++;
946  }
947 
948  setIsGeometryModified(true);
949 
950  return ret;
951 }
952 
954 {
955  _listTerrain.clear();
956  setIsGeometryModified(true);
957 }
958 
960 {
961  assert(pTerrain);
962  TYTabTerrainGeoNode::iterator ite;
963 
964  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
965  {
966  if (dynamic_cast<TYTerrain*>((*ite)->getElement()) == pTerrain)
967  {
968  return (*ite);
969  }
970  }
971 
972  return NULL;
973 }
974 
976 {
977  assert(pCrbNivGeoNode);
978 
979  TYCourbeNiveau* pCourbeNiv = dynamic_cast<TYCourbeNiveau*>(pCrbNivGeoNode->getElement());
980 
981  assert(pCourbeNiv);
982 
983  pCrbNivGeoNode->setParent(this);
984  pCourbeNiv->setParent(this);
985 
986  _listCrbNiv.push_back(pCrbNivGeoNode);
987 
988  setIsGeometryModified(true);
989 
990  // L'alti n'est plus a jour non plus...
992 
993  return true;
994 }
995 
997 {
998  return addCrbNiv(new TYCourbeNiveauGeoNode((LPTYElement)pCrbNiv));
999 }
1000 
1002 {
1003  assert(pCrbNivGeoNode);
1004  bool ret = false;
1005  TYTabCourbeNiveauGeoNode::iterator ite;
1006 
1007  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1008  {
1009  if ((*ite) == pCrbNivGeoNode)
1010  {
1011  // #if TY_USE_IHM
1012  // (*ite)->remFromAllRenderer();
1013  // #endif
1014  _listCrbNiv.erase(ite);
1015  ret = true;
1016  break;
1017  }
1018  }
1019 
1020  setIsGeometryModified(true);
1021 
1022  // L'alti n'est plus a jour non plus...
1024 
1025  return ret;
1026 }
1027 
1029 {
1030  assert(pCrbNiv);
1031  bool ret = false;
1032  TYTabCourbeNiveauGeoNode::iterator ite;
1033 
1034  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1035  {
1036  if (dynamic_cast<TYCourbeNiveau*>((*ite)->getElement()) == pCrbNiv.getRealPointer())
1037  {
1038  // #if TY_USE_IHM
1039  // (*ite)->remFromAllRenderer();
1040  // #endif
1041  _listCrbNiv.erase(ite);
1042  ret = true;
1043  break;
1044  }
1045  }
1046 
1047  setIsGeometryModified(true);
1048 
1049  // L'alti n'est plus a jour non plus...
1051 
1052  return ret;
1053 }
1054 
1055 bool TYTopographie::remCrbNiv(QString idCrbNiv)
1056 {
1057  bool ret = false;
1058  TYTabCourbeNiveauGeoNode::iterator ite;
1059 
1060  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1061  {
1062  if ((*ite)->getElement()->getID().toString() == idCrbNiv)
1063  {
1064  // #if TY_USE_IHM
1065  // (*ite)->remFromAllRenderer();
1066  // #endif
1067  _listCrbNiv.erase(ite);
1068  ret = true;
1069  break;
1070  }
1071  }
1072 
1073  setIsGeometryModified(true);
1074 
1075  // L'alti n'est plus a jour non plus...
1077 
1078  return ret;
1079 }
1080 
1082 {
1083  _listCrbNiv.clear();
1084 
1085  setIsGeometryModified(true);
1086 
1087  // L'alti n'est plus a jour non plus...
1089 }
1090 
1092 {
1094  LPTYCourbeNiveauGeoNode pCourbeNiveauGeoNode;
1095  for (int i = 0; i < _listCrbNiv.size(); i++)
1096  {
1097  pCourbeNiveauGeoNode = _listCrbNiv[i];
1098 
1099  if (pCourbeNiveauGeoNode->getElement()->isInCurrentCalcul())
1100  {
1101  ret.push_back(pCourbeNiveauGeoNode);
1102  }
1103  }
1104  return ret;
1105 }
1106 
1108 {
1109  assert(pCrbNiv);
1110  TYTabCourbeNiveauGeoNode::iterator ite;
1111 
1112  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1113  {
1114  if (dynamic_cast<TYCourbeNiveau*>((*ite)->getElement()) == pCrbNiv.getRealPointer())
1115  {
1116  return (*ite);
1117  }
1118  }
1119 
1120  return NULL;
1121 }
1122 
1124 {
1125  double longueur = 0;
1126 
1127  double minX = +20000;
1128  double maxX = -20000;
1129  double minY = +20000;
1130  double maxY = -20000;
1131 
1132  // On calcule la dimension caracteristique definie par les courbes de niveau
1133  TYTabCourbeNiveauGeoNode::iterator ite;
1134  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1135  {
1136  TYCourbeNiveau* pCourbe = dynamic_cast<TYCourbeNiveau*>((*ite)->getElement());
1137  TYTabPoint tabPoint = pCourbe->getListPoints();
1138 
1139  for (unsigned int i = 0; i < tabPoint.size(); i++)
1140  {
1141  if (tabPoint[i]._x < minX)
1142  {
1143  minX = tabPoint[i]._x;
1144  }
1145  if (tabPoint[i]._y < minY)
1146  {
1147  minY = tabPoint[i]._y;
1148  }
1149 
1150  if (tabPoint[i]._x > maxX)
1151  {
1152  maxX = tabPoint[i]._x;
1153  }
1154  if (tabPoint[i]._y > maxY)
1155  {
1156  maxY = tabPoint[i]._y;
1157  }
1158  }
1159  }
1160 
1161  OPoint3D ptMinCourbNiv(minX, minY, 0.0);
1162  OPoint3D ptMaxCourbNiv(maxX, maxY, 0.0);
1163  OSegment3D segCrbNiv(ptMinCourbNiv, ptMaxCourbNiv);
1164  double longueurCrb = segCrbNiv.longueur();
1165 
1166  // On calcule la dimension carateristique definie par l'emprise
1167 
1168  minX = +20000;
1169  maxX = -20000;
1170  minY = +20000;
1171  maxY = -20000;
1172  for (unsigned int i = 0; i < _emprise.size(); i++)
1173  {
1174  if (_emprise[i]._x < minX)
1175  {
1176  minX = _emprise[i]._x;
1177  }
1178  if (_emprise[i]._y < minY)
1179  {
1180  minY = _emprise[i]._y;
1181  }
1182 
1183  if (_emprise[i]._x > maxX)
1184  {
1185  maxX = _emprise[i]._x;
1186  }
1187  if (_emprise[i]._y > maxY)
1188  {
1189  maxY = _emprise[i]._y;
1190  }
1191  }
1192 
1193  OPoint3D ptMinEmprise = OPoint3D(minX, minY, 0.0);
1194  OPoint3D ptMaxEmprise = OPoint3D(maxX, maxY, 0.0);
1195  OSegment3D segEmprise(ptMinEmprise, ptMaxEmprise);
1196  double longueurEmprise = segEmprise.longueur();
1197 
1198  // On compare les deux et on prend le plus grand
1199 
1200  if (longueurCrb > longueurEmprise)
1201  {
1202  segDiagonale = segCrbNiv;
1203  return longueurCrb;
1204  }
1205  else
1206  {
1207  segDiagonale = segEmprise;
1208  return longueurEmprise;
1209  }
1210 
1211  return longueur;
1212 }
1213 
1214 void TYTopographie::setEmprise(const TYTabPoint& pts, const bool& defTerrain)
1215 {
1216  _emprise = pts;
1217 
1218  // On affecte au terrain par defaut le contour de l'emprise
1219  // getDefTerrain()->setListPoints(_emprise);
1220 
1221  // if (defTerrain) setDefTerrain(_DefTerrainIdx);
1222 
1223  setIsGeometryModified(true);
1224 }
1225 
1226 void TYTopographie::setDefTerrain(int defTerrainIdx)
1227 {
1228  if (_listTerrain.size() == 0)
1229  {
1230  return;
1231  }
1232  // assert( _listTerrain.size());
1233  TYTerrain* pTerrain = getDefTerrain();
1234 
1235  LPTYSol pSol = getTerrain(defTerrainIdx)->getSol();
1236  if ((defTerrainIdx > 0) && (defTerrainIdx < _listTerrain.size()))
1237  {
1238  _DefTerrainIdx = defTerrainIdx;
1239  }
1240  else
1241  {
1242  _DefTerrainIdx = 0;
1243  }
1244 
1245  // On affecte le sol du terrain choisi par defaut le perimetre defini par l'emprise
1246  if (pTerrain)
1247  {
1248  pTerrain->setSol(pSol);
1249  }
1250 }
1251 
1253 {
1254  assert(_DefTerrainIdx < _listTerrain.size()); // Securite
1255  return dynamic_cast<TYTerrain*>(_listTerrain[_DefTerrainIdx]._pObj->getElement());
1256 }
1257 
1259 {
1260  // 1. Nettoyage du tableau des terrains si non vide
1261  if (_pSortedTerrains)
1262  {
1263  delete[] _pSortedTerrains;
1264  _pSortedTerrains = NULL;
1265  }
1266  // 2. Generation du tableau des terrains
1267  size_t nbTerrains = _listTerrain.size();
1268  _pSortedTerrains = new TYTerrainGeoNode*[nbTerrains];
1269 
1270  for (size_t i = 0; i < nbTerrains; i++)
1271  {
1272  _pSortedTerrains[i] = _listTerrain[i]._pObj;
1273  }
1274 
1275  // 3. Tri du tableau
1276  qsort(_pSortedTerrains, nbTerrains, sizeof(TYTerrainGeoNode*), compareSurfaceTerrains);
1277 }
1278 
1279 int compareSurfaceTerrains(const void* elem1, const void* elem2)
1280 {
1281  TYTerrainGeoNode* pTerrainNode = *((TYTerrainGeoNode**)elem1);
1282  TYTerrain* Terrain1 = dynamic_cast<TYTerrain*>(pTerrainNode->getElement());
1283 
1284  pTerrainNode = *((TYTerrainGeoNode**)elem2);
1285  TYTerrain* Terrain2 = dynamic_cast<TYTerrain*>(pTerrainNode->getElement());
1286 
1287  // TODO return cmp(Terrain1->surface(), Terrain2->surface()) ?
1288  double res = Terrain1->surface() - Terrain2->surface();
1289  int sgn = int(res / fabs(res));
1290  return (sgn);
1291 }
1292 
1293 void TYTopographie::updateEmpriseAltitude(double empriseAltitude)
1294 {
1295  for (unsigned int i = 0; i < _emprise.size(); i++)
1296  {
1297  _emprise[i]._z = empriseAltitude;
1298  }
1299 }
1300 
1301 void TYTopographie::exportMesh(std::deque<OPoint3D>& points, std::deque<OTriangle>& triangles,
1302  std::deque<LPTYSol>& materials)
1303 {
1304  _pAltimetrie->exportMesh(points, triangles, materials);
1305 }
All base classes related to 3D manipulation.
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
std::vector< LPTYCourbeNiveauGeoNode > TYTabCourbeNiveauGeoNode
Collection de noeuds geometriques de type TYCourbeNiveau.
TYGeometryNode TYCourbeNiveauGeoNode
Noeud geometrique de type TYCourbeNiveau.
TYGeometryNode TYCoursEauGeoNode
Noeud geometrique de type TYCoursEau.
Definition: TYCoursEau.h:66
#define TAILLETOPOY
Largeur par defaut de la topographie.
Definition: TYDefines.h:421
std::vector< TYPoint > TYTabPoint
Collection de TYPoint.
Definition: TYDefines.h:340
#define TAILLETOPOX
Longueur par defaut de la topographie.
Definition: TYDefines.h:418
std::list< TYUUID > TYListID
Collection d'identifiants.
Definition: TYDefines.h:331
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:344
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
TYGeometryNode TYPlanEauGeoNode
Noeud geometrique de type TYPlanEau.
Definition: TYPlanEau.h:198
std::vector< LPTYPlanEauGeoNode > TYTabPlanEauGeoNode
Collection de noeuds geometriques de type TYPlanEau.
Definition: TYPlanEau.h:202
TYGeometryNode TYTerrainGeoNode
Noeud geometrique de type TYTerrain.
Definition: TYTerrain.h:177
Representation graphique d'une topographie (fichier header)
outil IHM pour une topographie (fichier header)
TY_EXTENSION_INST(TYTopographie)
TY_EXT_GRAPHIC_INST(TYTopographie)
static const OColor BLUE
Definition: color.h:87
static OMessageManager * get()
Definition: logging.cpp:108
virtual void info(const char *message,...)
Definition: logging.cpp:143
The 3D point class.
Definition: 3d.h:487
virtual const char * getClassName() const
Definition: TYElement.h:248
Class to define a segment.
Definition: 3d.h:1141
virtual double longueur() const
Return the segment length.
Definition: 3d.cpp:1238
T * getRealPointer()
Definition: smartptr.h:291
Assigne une altitude a chaque point de l'espace.
Definition: TYAltimetrie.h:35
void exportMesh(std::deque< OPoint3D > &vertices, std::deque< OTriangle > &faces, std::deque< LPTYSol > &materials)
virtual DOM_Element toXML(DOM_Element &domElement)
void setIsUpToDate(bool isUpToDate)
TYTabPoint & getListPoints()
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
QString _name
Nom courant de l'element.
Definition: TYElement.h:965
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:263
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:542
const TYUUID & getID() const
Definition: TYElement.cpp:176
TYElement * _pParent
Reference sur l'element parent.
Definition: TYElement.h:968
virtual void updateCurrentCalcul(TYListID &listID, bool recursif=true)
Definition: TYElement.cpp:458
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
Definition: TYElement.h:530
void setParent(TYElement *pParent)
Definition: TYElement.h:699
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:379
virtual void setIsGeometryModified(bool isModified)
Definition: TYElement.cpp:253
TYElement * getElement() const
QString generateName(const char *classname)
Retourne le nom de la classe associe a un nombre.
static TYNameManager * get()
Retourne l'instance singleton.
virtual TYTabPoint getContourFerme(int n=-1) const
void setDimension(float lon, float haut)
double surface()
Definition: TYTerrain.cpp:237
void setSol(const LPTYSol pSol)
Definition: TYTerrain.h:89
OColor _empriseColor
TYTerrain * getDefTerrain()
int _DefTerrainIdx
Terrain par default.
virtual void setIsGeometryModified(bool isModified)
LPTYCourbeNiveauGeoNode findCrbNiv(const LPTYCourbeNiveau pCrbNiv)
TYTerrainGeoNode ** _pSortedTerrains
void exportMesh(std::deque< OPoint3D > &points, std::deque< OTriangle > &triangles, std::deque< LPTYSol > &materials)
Export the altimetry as a triangular mesh.
virtual void getChilds(LPTYElementArray &childs, bool recursif=true)
LPTYTerrainGeoNode findTerrain(const LPTYTerrain pTerrain)
bool remCrbNiv(const LPTYCourbeNiveauGeoNode pCrbNivGeoNode)
bool addCrsEau(LPTYCoursEauGeoNode pCoursEauGeoNode)
virtual std::string toString() const
virtual int fromXML(DOM_Element domElement)
void resetEmprise()
virtual DOM_Element toXML(DOM_Element &domElement)
virtual void reparent()
void addPointEmprise(TYPoint pt)
virtual ~TYTopographie()
bool operator!=(const TYTopographie &other) const
Operateur !=.
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
LPTYPlanEauGeoNode findPlanEau(const LPTYPlanEau pPlanEau)
bool remPlanEau(const LPTYPlanEauGeoNode pPlanEauGeoNode)
bool operator==(const TYTopographie &other) const
Operateur ==.
void setDefTerrain(int defTerrainIdx)
LPTYCoursEauGeoNode findCrsEau(const LPTYCoursEau pCrsEau)
bool addCrbNiv(LPTYCourbeNiveauGeoNode pCrbNivGeoNode)
double getTopoSize(OSegment3D &segDiagonale)
virtual void updateCurrentCalcul(TYListID &listID, bool recursif=true)
TYTabPlanEauGeoNode _listPlanEau
Liste des plans d'eau.
TYTabCoursEauGeoNode _listCrsEau
Liste des cours d'eau.
const TYTabCourbeNiveauGeoNode getListCrbNivInCurrentCalcul() const
TYTabTerrainGeoNode _listTerrain
Liste des terrains.
TYTabCourbeNiveauGeoNode _listCrbNiv
Liste des courbes de niveau.
bool addPlanEau(LPTYPlanEauGeoNode pPlanEauGeoNode)
void updateEmpriseAltitude(double empriseAltitude)
Update z ccordinates of emprise points.
LPTYAltimetrie _pAltimetrie
Altimetrie.
LPTYTerrain getTerrain(int index)
bool remCrsEau(const LPTYCoursEauGeoNode pCoursEauGeoNode)
void setEmprise(const TYTabPoint &pts, const bool &defTerrain=true)
TYTopographie & operator=(const TYTopographie &other)
Operateur =.
bool addTerrain(LPTYTerrainGeoNode pTerGeoNode)
TYTabPoint _emprise
Emprise.
const TYTabPlanEauGeoNode getListPlanEauInCurrentCalcul() const
void concatTopo(const TYTopographie *pTopo, bool emprise=true)
void sortTerrainsBySurface()
bool remTerrain(const LPTYTerrainGeoNode pTerGeoNode)
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