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