Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYTopographie.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #include "Tympan/core/logging.h"
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 
434  if (_pParent)
435  {
436  _pParent->setIsGeometryModified(isModified);
437  }
438 }
439 
441 {
442  _pAltimetrie->setParent(this);
443  unsigned int i = 0;
444  for (i = 0; i < _listCrbNiv.size(); i++)
445  {
446  _listCrbNiv[i]->setParent(this);
447  _listCrbNiv[i]->getElement()->setParent(this);
448  }
449 
450  for (i = 0; i < _listTerrain.size(); i++)
451  {
452  _listTerrain[i]->setParent(this);
453  _listTerrain[i]->getElement()->setParent(this);
454  }
455 
456  for (i = 0; i < _listCrsEau.size(); i++)
457  {
458  _listCrsEau[i]->setParent(this);
459  _listCrsEau[i]->getElement()->setParent(this);
460  }
461 
462  for (i = 0; i < _listPlanEau.size(); i++)
463  {
464  _listPlanEau[i]->setParent(this);
465  _listPlanEau[i]->getElement()->setParent(this);
466  }
467 }
468 
469 void TYTopographie::updateCurrentCalcul(TYListID& listID, bool recursif) //=true
470 {
471  TYElement::updateCurrentCalcul(listID, false);
472 }
473 
475 {
476  resetEmprise();
477  remAllCrbNiv();
478  remAllCrsEau();
479  remAllTerrain();
480  remAllPlanEau();
481 
482  if (_pSortedTerrains)
483  {
484  delete[] _pSortedTerrains;
485  _pSortedTerrains = NULL;
486  }
487 
488  setIsGeometryModified(true);
489 }
490 
491 void TYTopographie::concatTopo(const TYTopographie* pTopo, bool emprise /*= true*/)
492 {
493  unsigned int i = 0;
494 
495  for (i = 0; i < pTopo->_listCrbNiv.size(); ++i)
496  {
497  _listCrbNiv.push_back(pTopo->_listCrbNiv[i]);
498  }
499 
500  for (i = 0; i < pTopo->_listTerrain.size(); ++i)
501  {
502  _listTerrain.push_back(pTopo->_listTerrain[i]);
503  }
504 
505  for (i = 0; i < pTopo->_listCrsEau.size(); ++i)
506  {
507  _listCrsEau.push_back(pTopo->_listCrsEau[i]);
508  }
509 
510  for (i = 0; i < pTopo->_listPlanEau.size(); ++i)
511  {
512  _listPlanEau.push_back(pTopo->_listPlanEau[i]);
513  }
514 
515  if (emprise)
516  {
517  resetEmprise();
518  for (i = 0; i < pTopo->_emprise.size(); ++i)
519  {
520  addPointEmprise(pTopo->_emprise[i]);
521  }
522  }
523 }
524 
526 {
527  assert(pPlanEauGeoNode);
528 
529  LPTYPlanEau pPlanEau = dynamic_cast<TYPlanEau*>(pPlanEauGeoNode->getElement());
530 
531  assert(pPlanEau);
532 
533  pPlanEauGeoNode->setParent(this);
534  pPlanEau->setParent(this);
535 
536  _listPlanEau.push_back(pPlanEauGeoNode);
537 
538  setIsGeometryModified(true);
539 
540  // L'alti n'est plus a jour non plus...
542 
543  return true;
544 }
545 
547 {
548  return addPlanEau(new TYPlanEauGeoNode((LPTYElement)pPlanEau));
549 }
550 
552 {
553  assert(pPlanEauGeoNode);
554  bool ret = false;
555  TYTabPlanEauGeoNode::iterator ite;
556 
557  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
558  {
559  if ((*ite) == pPlanEauGeoNode)
560  {
561  // #if TY_USE_IHM
562  // (*ite)->remFromAllRenderer();
563  // #endif
564  _listPlanEau.erase(ite);
565  ret = true;
566  break;
567  }
568  }
569 
570  setIsGeometryModified(true);
571 
572  // L'alti n'est plus a jour non plus...
574 
575  return ret;
576 }
577 
579 {
580  assert(pPlanEau);
581  bool ret = false;
582  TYTabPlanEauGeoNode::iterator ite;
583 
584  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
585  {
586  if (dynamic_cast<TYPlanEau*>((*ite)->getElement()) == pPlanEau)
587  {
588  // #if TY_USE_IHM
589  // (*ite)->remFromAllRenderer();
590  // #endif
591  _listPlanEau.erase(ite);
592  ret = true;
593  break;
594  }
595  }
596 
597  setIsGeometryModified(true);
598 
599  // L'alti n'est plus a jour non plus...
601 
602  return ret;
603 }
604 
605 bool TYTopographie::remPlanEau(QString idPlanEau)
606 {
607  bool ret = false;
608  TYTabPlanEauGeoNode::iterator ite;
609 
610  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
611  {
612  if ((*ite)->getElement()->getID().toString() == idPlanEau)
613  {
614  // #if TY_USE_IHM
615  // (*ite)->remFromAllRenderer();
616  // #endif
617  _listPlanEau.erase(ite);
618  ret = true;
619  break;
620  }
621  }
622 
623  setIsGeometryModified(true);
624 
625  // L'alti n'est plus a jour non plus...
627 
628  return ret;
629 }
630 
632 {
633  _listPlanEau.clear();
634 
635  setIsGeometryModified(true);
636 
637  // L'alti n'est plus a jour non plus...
639 }
640 
642 {
643  assert(pPlanEau);
644  TYTabPlanEauGeoNode::iterator ite;
645 
646  for (ite = _listPlanEau.begin(); ite != _listPlanEau.end(); ite++)
647  {
648  if (dynamic_cast<TYPlanEau*>((*ite)->getElement()) == pPlanEau)
649  {
650  return (*ite);
651  }
652  }
653 
654  return NULL;
655 }
656 
658 {
659  assert(pCoursEauGeoNode);
660 
661  LPTYCoursEau pCoursEau = dynamic_cast<TYCoursEau*>(pCoursEauGeoNode->getElement());
662 
663  assert(pCoursEau);
664 
665  pCoursEauGeoNode->setParent(this);
666  pCoursEau->setParent(this);
667 
668  _listCrsEau.push_back(pCoursEauGeoNode);
669 
670  setIsGeometryModified(true);
671 
672  return true;
673 }
674 
676 {
677  return addCrsEau(new TYCoursEauGeoNode((LPTYElement)pCoursEau));
678 }
679 
680 bool TYTopographie::remCrsEau(const LPTYCoursEauGeoNode pCoursEauGeoNode)
681 {
682  assert(pCoursEauGeoNode);
683  bool ret = false;
684  TYTabCoursEauGeoNode::iterator ite;
685 
686  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
687  {
688  if ((*ite) == pCoursEauGeoNode)
689  {
690  // #if TY_USE_IHM
691  // (*ite)->remFromAllRenderer();
692  // #endif
693  _listCrsEau.erase(ite);
694  ret = true;
695  break;
696  }
697  }
698 
699  setIsGeometryModified(true);
700 
701  return ret;
702 }
703 
705 {
706  assert(pCoursEau);
707  bool ret = false;
708  TYTabCoursEauGeoNode::iterator ite;
709 
710  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
711  {
712  if (dynamic_cast<TYCoursEau*>((*ite)->getElement()) == pCoursEau)
713  {
714  // #if TY_USE_IHM
715  // (*ite)->remFromAllRenderer();
716  // #endif
717  _listCrsEau.erase(ite);
718  ret = true;
719  break;
720  }
721  }
722 
723  setIsGeometryModified(true);
724 
725  return ret;
726 }
727 
728 bool TYTopographie::remCrsEau(QString idCrsEau)
729 {
730  bool ret = false;
731  TYTabCoursEauGeoNode::iterator ite;
732 
733  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
734  {
735  if (dynamic_cast<TYCoursEau*>((*ite)->getElement())->getID().toString() == idCrsEau)
736  {
737  // #if TY_USE_IHM
738  // (*ite)->remFromAllRenderer();
739  // #endif
740  _listCrsEau.erase(ite);
741  ret = true;
742  break;
743  }
744  }
745 
746  setIsGeometryModified(true);
747 
748  return ret;
749 }
750 
752 {
753  _listCrsEau.clear();
754  setIsGeometryModified(true);
755 }
756 
758 {
759  assert(pCrsEau);
760  TYTabCoursEauGeoNode::iterator ite;
761 
762  for (ite = _listCrsEau.begin(); ite != _listCrsEau.end(); ite++)
763  {
764  if (dynamic_cast<TYCoursEau*>((*ite)->getElement()) == pCrsEau)
765  {
766  return (*ite);
767  }
768  }
769 
770  return NULL;
771 }
772 
774 {
775  assert(pTerGeoNode);
776 
777  TYTerrain* pTerrain = dynamic_cast<TYTerrain*>(pTerGeoNode->getElement());
778 
779  assert(pTerrain);
780 
781  pTerGeoNode->setParent(this);
782  pTerrain->setParent(this);
783 
784  _listTerrain.push_back(pTerGeoNode);
785 
786  setIsGeometryModified(true);
787 
788  return true;
789 }
790 
792 {
793  return addTerrain(new TYTerrainGeoNode((LPTYElement)pTer));
794 }
795 
797 {
798  assert(pTerGeoNode);
799  // On efface pas le terrain par defaut
800  if (pTerGeoNode == _listTerrain[_DefTerrainIdx])
801  {
802  return false;
803  }
804 
805  bool ret = false;
806  unsigned int terrainNbr = 0;
807 
808  TYTabTerrainGeoNode::iterator ite;
809 
810  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
811  {
812  if ((*ite) == pTerGeoNode)
813  {
814 
815  // #if TY_USE_IHM
816  // (*ite)->remFromAllRenderer();
817  // #endif
818  _listTerrain.erase(ite);
819 
820  if (terrainNbr < _DefTerrainIdx)
821  {
822  _DefTerrainIdx--;
823  } // Dans ce cas, on decremente l'indice du terrain par defaut
824 
825  ret = true;
826  break;
827  }
828 
829  terrainNbr++;
830  }
831 
832  setIsGeometryModified(true);
833 
834  return ret;
835 }
836 
838 {
839  assert(pTer);
840  bool ret = false;
841  unsigned int terrainNbr = 0;
842  TYTabTerrainGeoNode::iterator ite;
843 
844  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
845  {
846  if (dynamic_cast<TYTerrain*>((*ite)->getElement()) == pTer)
847  {
848  if ((*ite) == _listTerrain[_DefTerrainIdx])
849  {
850  return false;
851  }
852 
853  // #if TY_USE_IHM
854  // (*ite)->remFromAllRenderer();
855  // #endif
856  _listTerrain.erase(ite);
857 
858  if (terrainNbr < _DefTerrainIdx)
859  {
860  _DefTerrainIdx--;
861  } // Dans ce cas, on decremente l'indice du terrain par defaut
862 
863  ret = true;
864  break;
865  }
866 
867  terrainNbr++;
868  }
869 
870  setIsGeometryModified(true);
871 
872  return ret;
873 }
874 
875 bool TYTopographie::remTerrain(QString idTerrain)
876 {
877  bool ret = false;
878  unsigned int terrainNbr = 0;
879  TYTabTerrainGeoNode::iterator ite;
880 
881  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
882  {
883  if ((*ite)->getElement()->getID().toString() == idTerrain)
884  {
885  // #if TY_USE_IHM
886  // (*ite)->remFromAllRenderer();
887  // #endif
888  _listTerrain.erase(ite);
889 
890  if (terrainNbr < _DefTerrainIdx)
891  {
892  _DefTerrainIdx--;
893  } // Dans ce cas, on decremente l'indice du terrain par defaut
894 
895  ret = true;
896  break;
897  }
898 
899  terrainNbr++;
900  }
901 
902  setIsGeometryModified(true);
903 
904  return ret;
905 }
906 
908 {
909  _listTerrain.clear();
910  setIsGeometryModified(true);
911 }
912 
914 {
915  assert(pTerrain);
916  TYTabTerrainGeoNode::iterator ite;
917 
918  for (ite = _listTerrain.begin(); ite != _listTerrain.end(); ite++)
919  {
920  if (dynamic_cast<TYTerrain*>((*ite)->getElement()) == pTerrain)
921  {
922  return (*ite);
923  }
924  }
925 
926  return NULL;
927 }
928 
930 {
931  assert(pCrbNivGeoNode);
932 
933  TYCourbeNiveau* pCourbeNiv = dynamic_cast<TYCourbeNiveau*>(pCrbNivGeoNode->getElement());
934 
935  assert(pCourbeNiv);
936 
937  pCrbNivGeoNode->setParent(this);
938  pCourbeNiv->setParent(this);
939 
940  _listCrbNiv.push_back(pCrbNivGeoNode);
941 
942  setIsGeometryModified(true);
943 
944  // L'alti n'est plus a jour non plus...
946 
947  return true;
948 }
949 
951 {
952  return addCrbNiv(new TYCourbeNiveauGeoNode((LPTYElement)pCrbNiv));
953 }
954 
956 {
957  assert(pCrbNivGeoNode);
958  bool ret = false;
959  TYTabCourbeNiveauGeoNode::iterator ite;
960 
961  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
962  {
963  if ((*ite) == pCrbNivGeoNode)
964  {
965  // #if TY_USE_IHM
966  // (*ite)->remFromAllRenderer();
967  // #endif
968  _listCrbNiv.erase(ite);
969  ret = true;
970  break;
971  }
972  }
973 
974  setIsGeometryModified(true);
975 
976  // L'alti n'est plus a jour non plus...
978 
979  return ret;
980 }
981 
983 {
984  assert(pCrbNiv);
985  bool ret = false;
986  TYTabCourbeNiveauGeoNode::iterator ite;
987 
988  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
989  {
990  if (dynamic_cast<TYCourbeNiveau*>((*ite)->getElement()) == pCrbNiv.getRealPointer())
991  {
992  // #if TY_USE_IHM
993  // (*ite)->remFromAllRenderer();
994  // #endif
995  _listCrbNiv.erase(ite);
996  ret = true;
997  break;
998  }
999  }
1000 
1001  setIsGeometryModified(true);
1002 
1003  // L'alti n'est plus a jour non plus...
1005 
1006  return ret;
1007 }
1008 
1009 bool TYTopographie::remCrbNiv(QString idCrbNiv)
1010 {
1011  bool ret = false;
1012  TYTabCourbeNiveauGeoNode::iterator ite;
1013 
1014  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1015  {
1016  if ((*ite)->getElement()->getID().toString() == idCrbNiv)
1017  {
1018  // #if TY_USE_IHM
1019  // (*ite)->remFromAllRenderer();
1020  // #endif
1021  _listCrbNiv.erase(ite);
1022  ret = true;
1023  break;
1024  }
1025  }
1026 
1027  setIsGeometryModified(true);
1028 
1029  // L'alti n'est plus a jour non plus...
1031 
1032  return ret;
1033 }
1034 
1036 {
1037  _listCrbNiv.clear();
1038 
1039  setIsGeometryModified(true);
1040 
1041  // L'alti n'est plus a jour non plus...
1043 }
1044 
1046 {
1047  assert(pCrbNiv);
1048  TYTabCourbeNiveauGeoNode::iterator ite;
1049 
1050  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1051  {
1052  if (dynamic_cast<TYCourbeNiveau*>((*ite)->getElement()) == pCrbNiv.getRealPointer())
1053  {
1054  return (*ite);
1055  }
1056  }
1057 
1058  return NULL;
1059 }
1060 
1062 {
1063  double longueur = 0;
1064 
1065  double minX = +20000;
1066  double maxX = -20000;
1067  double minY = +20000;
1068  double maxY = -20000;
1069 
1070  // On calcule la dimension caracteristique definie par les courbes de niveau
1071  TYTabCourbeNiveauGeoNode::iterator ite;
1072  for (ite = _listCrbNiv.begin(); ite != _listCrbNiv.end(); ite++)
1073  {
1074  TYCourbeNiveau* pCourbe = dynamic_cast<TYCourbeNiveau*>((*ite)->getElement());
1075  TYTabPoint tabPoint = pCourbe->getListPoints();
1076 
1077  for (unsigned int i = 0; i < tabPoint.size(); i++)
1078  {
1079  if (tabPoint[i]._x < minX)
1080  {
1081  minX = tabPoint[i]._x;
1082  }
1083  if (tabPoint[i]._y < minY)
1084  {
1085  minY = tabPoint[i]._y;
1086  }
1087 
1088  if (tabPoint[i]._x > maxX)
1089  {
1090  maxX = tabPoint[i]._x;
1091  }
1092  if (tabPoint[i]._y > maxY)
1093  {
1094  maxY = tabPoint[i]._y;
1095  }
1096  }
1097  }
1098 
1099  OPoint3D ptMinCourbNiv(minX, minY, 0.0);
1100  OPoint3D ptMaxCourbNiv(maxX, maxY, 0.0);
1101  OSegment3D segCrbNiv(ptMinCourbNiv, ptMaxCourbNiv);
1102  double longueurCrb = segCrbNiv.longueur();
1103 
1104  // On calcule la dimension carateristique definie par l'emprise
1105 
1106  minX = +20000;
1107  maxX = -20000;
1108  minY = +20000;
1109  maxY = -20000;
1110  for (unsigned int i = 0; i < _emprise.size(); i++)
1111  {
1112  if (_emprise[i]._x < minX)
1113  {
1114  minX = _emprise[i]._x;
1115  }
1116  if (_emprise[i]._y < minY)
1117  {
1118  minY = _emprise[i]._y;
1119  }
1120 
1121  if (_emprise[i]._x > maxX)
1122  {
1123  maxX = _emprise[i]._x;
1124  }
1125  if (_emprise[i]._y > maxY)
1126  {
1127  maxY = _emprise[i]._y;
1128  }
1129  }
1130 
1131  OPoint3D ptMinEmprise = OPoint3D(minX, minY, 0.0);
1132  OPoint3D ptMaxEmprise = OPoint3D(maxX, maxY, 0.0);
1133  OSegment3D segEmprise(ptMinEmprise, ptMaxEmprise);
1134  double longueurEmprise = segEmprise.longueur();
1135 
1136  // On compare les deux et on prend le plus grand
1137 
1138  if (longueurCrb > longueurEmprise)
1139  {
1140  segDiagonale = segCrbNiv;
1141  return longueurCrb;
1142  }
1143  else
1144  {
1145  segDiagonale = segEmprise;
1146  return longueurEmprise;
1147  }
1148 
1149  return longueur;
1150 }
1151 
1152 void TYTopographie::setEmprise(const TYTabPoint& pts, const bool& defTerrain)
1153 {
1154  _emprise = pts;
1155 
1156  // On affecte au terrain par defaut le contour de l'emprise
1157  // getDefTerrain()->setListPoints(_emprise);
1158 
1159  // if (defTerrain) setDefTerrain(_DefTerrainIdx);
1160 
1161  setIsGeometryModified(true);
1162 }
1163 
1164 void TYTopographie::setDefTerrain(int defTerrainIdx)
1165 {
1166  if (_listTerrain.size() == 0)
1167  {
1168  return;
1169  }
1170  // assert( _listTerrain.size());
1171  TYTerrain* pTerrain = getDefTerrain();
1172 
1173  LPTYSol pSol = getTerrain(defTerrainIdx)->getSol();
1174  if ((defTerrainIdx > 0) && (defTerrainIdx < _listTerrain.size()))
1175  {
1176  _DefTerrainIdx = defTerrainIdx;
1177  }
1178  else
1179  {
1180  _DefTerrainIdx = 0;
1181  }
1182 
1183  // On affecte le sol du terrain choisi par defaut le perimetre defini par l'emprise
1184  if (pTerrain)
1185  {
1186  pTerrain->setSol(pSol);
1187  }
1188 }
1189 
1191 {
1192  assert(_DefTerrainIdx < _listTerrain.size()); // Securite
1193  return dynamic_cast<TYTerrain*>(_listTerrain[_DefTerrainIdx]._pObj->getElement());
1194 }
1195 
1197 {
1198  // 1. Nettoyage du tableau des terrains si non vide
1199  if (_pSortedTerrains)
1200  {
1201  delete[] _pSortedTerrains;
1202  _pSortedTerrains = NULL;
1203  }
1204  // 2. Generation du tableau des terrains
1205  size_t nbTerrains = _listTerrain.size();
1206  _pSortedTerrains = new TYTerrainGeoNode*[nbTerrains];
1207 
1208  for (size_t i = 0; i < nbTerrains; i++)
1209  {
1210  _pSortedTerrains[i] = _listTerrain[i]._pObj;
1211  }
1212 
1213  // 3. Tri du tableau
1214  qsort(_pSortedTerrains, nbTerrains, sizeof(TYTerrainGeoNode*), compareSurfaceTerrains);
1215 }
1216 
1217 int compareSurfaceTerrains(const void* elem1, const void* elem2)
1218 {
1219  TYTerrainGeoNode* pTerrainNode = *((TYTerrainGeoNode**)elem1);
1220  TYTerrain* Terrain1 = dynamic_cast<TYTerrain*>(pTerrainNode->getElement());
1221 
1222  pTerrainNode = *((TYTerrainGeoNode**)elem2);
1223  TYTerrain* Terrain2 = dynamic_cast<TYTerrain*>(pTerrainNode->getElement());
1224 
1225  // TODO return cmp(Terrain1->surface(), Terrain2->surface()) ?
1226  double res = Terrain1->surface() - Terrain2->surface();
1227  int sgn = int(res / fabs(res));
1228  return (sgn);
1229 }
1230 
1231 void TYTopographie::exportMesh(std::deque<OPoint3D>& points, std::deque<OTriangle>& triangles,
1232  std::deque<LPTYSol>& materials)
1233 {
1234  _pAltimetrie->exportMesh(points, triangles, materials);
1235 }
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:52
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:249
Class to define a segment.
Definition: 3d.h:1089
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)
TYTabPoint & getListPoints()
virtual bool deepCopy(const TYElement *pOther, bool copyId=true, bool pUseCopyTag=false)
Definition: TYElement.cpp:307
virtual DOM_Element toXML(DOM_Element &domElement)
Definition: TYElement.cpp:368
QString _name
Nom courant de l'element.
Definition: TYElement.h:966
TYElement & operator=(const TYElement &other)
Definition: TYElement.cpp:265
bool callFromXMLIfEqual(DOM_Element &domElement, int *pRetVal=NULL)
Definition: TYElement.cpp:544
const TYUUID & getID() const
Definition: TYElement.cpp:176
TYElement * _pParent
Reference sur l'element parent.
Definition: TYElement.h:969
virtual void updateCurrentCalcul(TYListID &listID, bool recursif=true)
Definition: TYElement.cpp:460
void setParent(TYElement *pParent)
Definition: TYElement.h:692
virtual int fromXML(DOM_Element domElement)
Definition: TYElement.cpp:381
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)
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