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::updateCurrentCalcul(TYListID& listID, bool recursif) //=true
471 {
472  TYElement::updateCurrentCalcul(listID, false);
473 }
474 
476 {
477  resetEmprise();
478  remAllCrbNiv();
479  remAllCrsEau();
480  remAllTerrain();
481  remAllPlanEau();
482 
483  if (_pSortedTerrains)
484  {
485  delete[] _pSortedTerrains;
486  _pSortedTerrains = NULL;
487  }
488 
489  setIsGeometryModified(true);
490 }
491 
492 void TYTopographie::concatTopo(const TYTopographie* pTopo, bool emprise /*= true*/)
493 {
494  unsigned int i = 0;
495 
496  for (i = 0; i < pTopo->_listCrbNiv.size(); ++i)
497  {
498  _listCrbNiv.push_back(pTopo->_listCrbNiv[i]);
499  }
500 
501  for (i = 0; i < pTopo->_listTerrain.size(); ++i)
502  {
503  _listTerrain.push_back(pTopo->_listTerrain[i]);
504  }
505 
506  for (i = 0; i < pTopo->_listCrsEau.size(); ++i)
507  {
508  _listCrsEau.push_back(pTopo->_listCrsEau[i]);
509  }
510 
511  for (i = 0; i < pTopo->_listPlanEau.size(); ++i)
512  {
513  _listPlanEau.push_back(pTopo->_listPlanEau[i]);
514  }
515 
516  if (emprise)
517  {
518  resetEmprise();
519  for (i = 0; i < pTopo->_emprise.size(); ++i)
520  {
521  addPointEmprise(pTopo->_emprise[i]);
522  }
523  }
524 }
525 
527 {
528  assert(pPlanEauGeoNode);
529 
530  LPTYPlanEau pPlanEau = dynamic_cast<TYPlanEau*>(pPlanEauGeoNode->getElement());
531 
532  assert(pPlanEau);
533 
534  pPlanEauGeoNode->setParent(this);
535  pPlanEau->setParent(this);
536 
537  _listPlanEau.push_back(pPlanEauGeoNode);
538 
539  setIsGeometryModified(true);
540 
541  // L'alti n'est plus a jour non plus...
543 
544  return true;
545 }
546 
548 {
549  return addPlanEau(new TYPlanEauGeoNode((LPTYElement)pPlanEau));
550 }
551 
553 {
554  assert(pPlanEauGeoNode);
555  bool ret = false;
556  TYTabPlanEauGeoNode::iterator ite;
557 
558  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
559  {
560  if ((*ite) == pPlanEauGeoNode)
561  {
562  // #if TY_USE_IHM
563  // (*ite)->remFromAllRenderer();
564  // #endif
565  _listPlanEau.erase(ite);
566  ret = true;
567  break;
568  }
569  }
570 
571  setIsGeometryModified(true);
572 
573  // L'alti n'est plus a jour non plus...
575 
576  return ret;
577 }
578 
580 {
581  assert(pPlanEau);
582  bool ret = false;
583  TYTabPlanEauGeoNode::iterator ite;
584 
585  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
586  {
587  if (dynamic_cast<TYPlanEau*>((*ite)->getElement()) == pPlanEau)
588  {
589  // #if TY_USE_IHM
590  // (*ite)->remFromAllRenderer();
591  // #endif
592  _listPlanEau.erase(ite);
593  ret = true;
594  break;
595  }
596  }
597 
598  setIsGeometryModified(true);
599 
600  // L'alti n'est plus a jour non plus...
602 
603  return ret;
604 }
605 
606 bool TYTopographie::remPlanEau(QString idPlanEau)
607 {
608  bool ret = false;
609  TYTabPlanEauGeoNode::iterator ite;
610 
611  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
612  {
613  if ((*ite)->getElement()->getID().toString() == idPlanEau)
614  {
615  // #if TY_USE_IHM
616  // (*ite)->remFromAllRenderer();
617  // #endif
618  _listPlanEau.erase(ite);
619  ret = true;
620  break;
621  }
622  }
623 
624  setIsGeometryModified(true);
625 
626  // L'alti n'est plus a jour non plus...
628 
629  return ret;
630 }
631 
633 {
634  _listPlanEau.clear();
635 
636  setIsGeometryModified(true);
637 
638  // L'alti n'est plus a jour non plus...
640 }
641 
643 {
644  assert(pPlanEau);
645  TYTabPlanEauGeoNode::iterator ite;
646 
647  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
648  {
649  if (dynamic_cast<TYPlanEau*>((*ite)->getElement()) == pPlanEau)
650  {
651  return (*ite);
652  }
653  }
654 
655  return NULL;
656 }
657 
659 {
660  assert(pCoursEauGeoNode);
661 
662  LPTYCoursEau pCoursEau = dynamic_cast<TYCoursEau*>(pCoursEauGeoNode->getElement());
663 
664  assert(pCoursEau);
665 
666  pCoursEauGeoNode->setParent(this);
667  pCoursEau->setParent(this);
668 
669  _listCrsEau.push_back(pCoursEauGeoNode);
670 
671  setIsGeometryModified(true);
672 
673  return true;
674 }
675 
677 {
678  return addCrsEau(new TYCoursEauGeoNode((LPTYElement)pCoursEau));
679 }
680 
681 bool TYTopographie::remCrsEau(const LPTYCoursEauGeoNode pCoursEauGeoNode)
682 {
683  assert(pCoursEauGeoNode);
684  bool ret = false;
685  TYTabCoursEauGeoNode::iterator ite;
686 
687  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
688  {
689  if ((*ite) == pCoursEauGeoNode)
690  {
691  // #if TY_USE_IHM
692  // (*ite)->remFromAllRenderer();
693  // #endif
694  _listCrsEau.erase(ite);
695  ret = true;
696  break;
697  }
698  }
699 
700  setIsGeometryModified(true);
701 
702  return ret;
703 }
704 
706 {
707  assert(pCoursEau);
708  bool ret = false;
709  TYTabCoursEauGeoNode::iterator ite;
710 
711  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
712  {
713  if (dynamic_cast<TYCoursEau*>((*ite)->getElement()) == pCoursEau)
714  {
715  // #if TY_USE_IHM
716  // (*ite)->remFromAllRenderer();
717  // #endif
718  _listCrsEau.erase(ite);
719  ret = true;
720  break;
721  }
722  }
723 
724  setIsGeometryModified(true);
725 
726  return ret;
727 }
728 
729 bool TYTopographie::remCrsEau(QString idCrsEau)
730 {
731  bool ret = false;
732  TYTabCoursEauGeoNode::iterator ite;
733 
734  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
735  {
736  if (dynamic_cast<TYCoursEau*>((*ite)->getElement())->getID().toString() == idCrsEau)
737  {
738  // #if TY_USE_IHM
739  // (*ite)->remFromAllRenderer();
740  // #endif
741  _listCrsEau.erase(ite);
742  ret = true;
743  break;
744  }
745  }
746 
747  setIsGeometryModified(true);
748 
749  return ret;
750 }
751 
753 {
754  _listCrsEau.clear();
755  setIsGeometryModified(true);
756 }
757 
759 {
760  assert(pCrsEau);
761  TYTabCoursEauGeoNode::iterator ite;
762 
763  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
764  {
765  if (dynamic_cast<TYCoursEau*>((*ite)->getElement()) == pCrsEau)
766  {
767  return (*ite);
768  }
769  }
770 
771  return NULL;
772 }
773 
775 {
776  assert(pTerGeoNode);
777 
778  TYTerrain* pTerrain = dynamic_cast<TYTerrain*>(pTerGeoNode->getElement());
779 
780  assert(pTerrain);
781 
782  pTerGeoNode->setParent(this);
783  pTerrain->setParent(this);
784 
785  _listTerrain.push_back(pTerGeoNode);
786 
787  setIsGeometryModified(true);
788 
789  return true;
790 }
791 
793 {
794  return addTerrain(new TYTerrainGeoNode((LPTYElement)pTer));
795 }
796 
798 {
799  assert(pTerGeoNode);
800  // On efface pas le terrain par defaut
801  if (pTerGeoNode == _listTerrain[_DefTerrainIdx])
802  {
803  return false;
804  }
805 
806  bool ret = false;
807  unsigned int terrainNbr = 0;
808 
809  TYTabTerrainGeoNode::iterator ite;
810 
811  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
812  {
813  if ((*ite) == pTerGeoNode)
814  {
815 
816  // #if TY_USE_IHM
817  // (*ite)->remFromAllRenderer();
818  // #endif
819  _listTerrain.erase(ite);
820 
821  if (terrainNbr < _DefTerrainIdx)
822  {
823  _DefTerrainIdx--;
824  } // Dans ce cas, on decremente l'indice du terrain par defaut
825 
826  ret = true;
827  break;
828  }
829 
830  terrainNbr++;
831  }
832 
833  setIsGeometryModified(true);
834 
835  return ret;
836 }
837 
839 {
840  assert(pTer);
841  bool ret = false;
842  unsigned int terrainNbr = 0;
843  TYTabTerrainGeoNode::iterator ite;
844 
845  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
846  {
847  if (dynamic_cast<TYTerrain*>((*ite)->getElement()) == pTer)
848  {
849  if ((*ite) == _listTerrain[_DefTerrainIdx])
850  {
851  return false;
852  }
853 
854  // #if TY_USE_IHM
855  // (*ite)->remFromAllRenderer();
856  // #endif
857  _listTerrain.erase(ite);
858 
859  if (terrainNbr < _DefTerrainIdx)
860  {
861  _DefTerrainIdx--;
862  } // Dans ce cas, on decremente l'indice du terrain par defaut
863 
864  ret = true;
865  break;
866  }
867 
868  terrainNbr++;
869  }
870 
871  setIsGeometryModified(true);
872 
873  return ret;
874 }
875 
876 bool TYTopographie::remTerrain(QString idTerrain)
877 {
878  bool ret = false;
879  unsigned int terrainNbr = 0;
880  TYTabTerrainGeoNode::iterator ite;
881 
882  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
883  {
884  if ((*ite)->getElement()->getID().toString() == idTerrain)
885  {
886  // #if TY_USE_IHM
887  // (*ite)->remFromAllRenderer();
888  // #endif
889  _listTerrain.erase(ite);
890 
891  if (terrainNbr < _DefTerrainIdx)
892  {
893  _DefTerrainIdx--;
894  } // Dans ce cas, on decremente l'indice du terrain par defaut
895 
896  ret = true;
897  break;
898  }
899 
900  terrainNbr++;
901  }
902 
903  setIsGeometryModified(true);
904 
905  return ret;
906 }
907 
909 {
910  _listTerrain.clear();
911  setIsGeometryModified(true);
912 }
913 
915 {
916  assert(pTerrain);
917  TYTabTerrainGeoNode::iterator ite;
918 
919  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
920  {
921  if (dynamic_cast<TYTerrain*>((*ite)->getElement()) == pTerrain)
922  {
923  return (*ite);
924  }
925  }
926 
927  return NULL;
928 }
929 
931 {
932  assert(pCrbNivGeoNode);
933 
934  TYCourbeNiveau* pCourbeNiv = dynamic_cast<TYCourbeNiveau*>(pCrbNivGeoNode->getElement());
935 
936  assert(pCourbeNiv);
937 
938  pCrbNivGeoNode->setParent(this);
939  pCourbeNiv->setParent(this);
940 
941  _listCrbNiv.push_back(pCrbNivGeoNode);
942 
943  setIsGeometryModified(true);
944 
945  // L'alti n'est plus a jour non plus...
947 
948  return true;
949 }
950 
952 {
953  return addCrbNiv(new TYCourbeNiveauGeoNode((LPTYElement)pCrbNiv));
954 }
955 
957 {
958  assert(pCrbNivGeoNode);
959  bool ret = false;
960  TYTabCourbeNiveauGeoNode::iterator ite;
961 
962  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
963  {
964  if ((*ite) == pCrbNivGeoNode)
965  {
966  // #if TY_USE_IHM
967  // (*ite)->remFromAllRenderer();
968  // #endif
969  _listCrbNiv.erase(ite);
970  ret = true;
971  break;
972  }
973  }
974 
975  setIsGeometryModified(true);
976 
977  // L'alti n'est plus a jour non plus...
979 
980  return ret;
981 }
982 
984 {
985  assert(pCrbNiv);
986  bool ret = false;
987  TYTabCourbeNiveauGeoNode::iterator ite;
988 
989  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
990  {
991  if (dynamic_cast<TYCourbeNiveau*>((*ite)->getElement()) == pCrbNiv.getRealPointer())
992  {
993  // #if TY_USE_IHM
994  // (*ite)->remFromAllRenderer();
995  // #endif
996  _listCrbNiv.erase(ite);
997  ret = true;
998  break;
999  }
1000  }
1001 
1002  setIsGeometryModified(true);
1003 
1004  // L'alti n'est plus a jour non plus...
1006 
1007  return ret;
1008 }
1009 
1010 bool TYTopographie::remCrbNiv(QString idCrbNiv)
1011 {
1012  bool ret = false;
1013  TYTabCourbeNiveauGeoNode::iterator ite;
1014 
1015  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1016  {
1017  if ((*ite)->getElement()->getID().toString() == idCrbNiv)
1018  {
1019  // #if TY_USE_IHM
1020  // (*ite)->remFromAllRenderer();
1021  // #endif
1022  _listCrbNiv.erase(ite);
1023  ret = true;
1024  break;
1025  }
1026  }
1027 
1028  setIsGeometryModified(true);
1029 
1030  // L'alti n'est plus a jour non plus...
1032 
1033  return ret;
1034 }
1035 
1037 {
1038  _listCrbNiv.clear();
1039 
1040  setIsGeometryModified(true);
1041 
1042  // L'alti n'est plus a jour non plus...
1044 }
1045 
1047 {
1048  assert(pCrbNiv);
1049  TYTabCourbeNiveauGeoNode::iterator ite;
1050 
1051  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1052  {
1053  if (dynamic_cast<TYCourbeNiveau*>((*ite)->getElement()) == pCrbNiv.getRealPointer())
1054  {
1055  return (*ite);
1056  }
1057  }
1058 
1059  return NULL;
1060 }
1061 
1063 {
1064  double longueur = 0;
1065 
1066  double minX = +20000;
1067  double maxX = -20000;
1068  double minY = +20000;
1069  double maxY = -20000;
1070 
1071  // On calcule la dimension caracteristique definie par les courbes de niveau
1072  TYTabCourbeNiveauGeoNode::iterator ite;
1073  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1074  {
1075  TYCourbeNiveau* pCourbe = dynamic_cast<TYCourbeNiveau*>((*ite)->getElement());
1076  TYTabPoint tabPoint = pCourbe->getListPoints();
1077 
1078  for (unsigned int i = 0; i < tabPoint.size(); i++)
1079  {
1080  if (tabPoint[i]._x < minX)
1081  {
1082  minX = tabPoint[i]._x;
1083  }
1084  if (tabPoint[i]._y < minY)
1085  {
1086  minY = tabPoint[i]._y;
1087  }
1088 
1089  if (tabPoint[i]._x > maxX)
1090  {
1091  maxX = tabPoint[i]._x;
1092  }
1093  if (tabPoint[i]._y > maxY)
1094  {
1095  maxY = tabPoint[i]._y;
1096  }
1097  }
1098  }
1099 
1100  OPoint3D ptMinCourbNiv(minX, minY, 0.0);
1101  OPoint3D ptMaxCourbNiv(maxX, maxY, 0.0);
1102  OSegment3D segCrbNiv(ptMinCourbNiv, ptMaxCourbNiv);
1103  double longueurCrb = segCrbNiv.longueur();
1104 
1105  // On calcule la dimension carateristique definie par l'emprise
1106 
1107  minX = +20000;
1108  maxX = -20000;
1109  minY = +20000;
1110  maxY = -20000;
1111  for (unsigned int i = 0; i < _emprise.size(); i++)
1112  {
1113  if (_emprise[i]._x < minX)
1114  {
1115  minX = _emprise[i]._x;
1116  }
1117  if (_emprise[i]._y < minY)
1118  {
1119  minY = _emprise[i]._y;
1120  }
1121 
1122  if (_emprise[i]._x > maxX)
1123  {
1124  maxX = _emprise[i]._x;
1125  }
1126  if (_emprise[i]._y > maxY)
1127  {
1128  maxY = _emprise[i]._y;
1129  }
1130  }
1131 
1132  OPoint3D ptMinEmprise = OPoint3D(minX, minY, 0.0);
1133  OPoint3D ptMaxEmprise = OPoint3D(maxX, maxY, 0.0);
1134  OSegment3D segEmprise(ptMinEmprise, ptMaxEmprise);
1135  double longueurEmprise = segEmprise.longueur();
1136 
1137  // On compare les deux et on prend le plus grand
1138 
1139  if (longueurCrb > longueurEmprise)
1140  {
1141  segDiagonale = segCrbNiv;
1142  return longueurCrb;
1143  }
1144  else
1145  {
1146  segDiagonale = segEmprise;
1147  return longueurEmprise;
1148  }
1149 
1150  return longueur;
1151 }
1152 
1153 void TYTopographie::setEmprise(const TYTabPoint& pts, const bool& defTerrain)
1154 {
1155  _emprise = pts;
1156 
1157  // On affecte au terrain par defaut le contour de l'emprise
1158  // getDefTerrain()->setListPoints(_emprise);
1159 
1160  // if (defTerrain) setDefTerrain(_DefTerrainIdx);
1161 
1162  setIsGeometryModified(true);
1163 }
1164 
1165 void TYTopographie::setDefTerrain(int defTerrainIdx)
1166 {
1167  if (_listTerrain.size() == 0)
1168  {
1169  return;
1170  }
1171  // assert( _listTerrain.size());
1172  TYTerrain* pTerrain = getDefTerrain();
1173 
1174  LPTYSol pSol = getTerrain(defTerrainIdx)->getSol();
1175  if ((defTerrainIdx > 0) && (defTerrainIdx < _listTerrain.size()))
1176  {
1177  _DefTerrainIdx = defTerrainIdx;
1178  }
1179  else
1180  {
1181  _DefTerrainIdx = 0;
1182  }
1183 
1184  // On affecte le sol du terrain choisi par defaut le perimetre defini par l'emprise
1185  if (pTerrain)
1186  {
1187  pTerrain->setSol(pSol);
1188  }
1189 }
1190 
1192 {
1193  assert(_DefTerrainIdx < _listTerrain.size()); // Securite
1194  return dynamic_cast<TYTerrain*>(_listTerrain[_DefTerrainIdx]._pObj->getElement());
1195 }
1196 
1198 {
1199  // 1. Nettoyage du tableau des terrains si non vide
1200  if (_pSortedTerrains)
1201  {
1202  delete[] _pSortedTerrains;
1203  _pSortedTerrains = NULL;
1204  }
1205  // 2. Generation du tableau des terrains
1206  size_t nbTerrains = _listTerrain.size();
1207  _pSortedTerrains = new TYTerrainGeoNode*[nbTerrains];
1208 
1209  for (size_t i = 0; i < nbTerrains; i++)
1210  {
1211  _pSortedTerrains[i] = _listTerrain[i]._pObj;
1212  }
1213 
1214  // 3. Tri du tableau
1215  qsort(_pSortedTerrains, nbTerrains, sizeof(TYTerrainGeoNode*), compareSurfaceTerrains);
1216 }
1217 
1218 int compareSurfaceTerrains(const void* elem1, const void* elem2)
1219 {
1220  TYTerrainGeoNode* pTerrainNode = *((TYTerrainGeoNode**)elem1);
1221  TYTerrain* Terrain1 = dynamic_cast<TYTerrain*>(pTerrainNode->getElement());
1222 
1223  pTerrainNode = *((TYTerrainGeoNode**)elem2);
1224  TYTerrain* Terrain2 = dynamic_cast<TYTerrain*>(pTerrainNode->getElement());
1225 
1226  // TODO return cmp(Terrain1->surface(), Terrain2->surface()) ?
1227  double res = Terrain1->surface() - Terrain2->surface();
1228  int sgn = int(res / fabs(res));
1229  return (sgn);
1230 }
1231 
1232 void TYTopographie::updateEmpriseAltitude(double empriseAltitude)
1233 {
1234  for (unsigned int i = 0; i < _emprise.size(); i++)
1235  {
1236  _emprise[i]._z = empriseAltitude;
1237  }
1238 }
1239 
1240 void TYTopographie::exportMesh(std::deque<OPoint3D>& points, std::deque<OTriangle>& triangles,
1241  std::deque<LPTYSol>& materials)
1242 {
1243  _pAltimetrie->exportMesh(points, triangles, materials);
1244 }
All base classes related to 3D manipulation.
QDomDocument DOM_Document
Definition: QT2DOM.h:33
QDomElement DOM_Element
Definition: QT2DOM.h:30
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
#define TYDIRPREFERENCEMANAGER
Definition: TYElement.h:51
TYGeometryNode TYPlanEauGeoNode
Noeud geometrique de type TYPlanEau.
Definition: TYPlanEau.h:198
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
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.
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.
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.
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