Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYResultatTreeDialog.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 
23 #include <qmap.h>
24 #include <qpushbutton.h>
25 // #include <qtreeWidget.h>
26 
32 // Added by qt3to4:
33 #include <QGridLayout>
34 #include <QShowEvent>
35 #include <QCloseEvent>
36 #include <QTreeWidget>
37 
38 #include "TYResultatTreeDialog.h"
39 #include "TYElementWidget.h"
40 
41 #define TR(id) OLocalizator::getString("TYResultatTreeDialog", (id))
42 
43 TYResultatTreeDialog::TYResultatTreeDialog(QWidget* parent, const char* name, Qt::WindowFlags f)
44  : QDialog(parent, f), _pPtCalcul(NULL)
45 {
46  setObjectName(name);
47  setWindowTitle(TR("id_caption"));
48  resize(400, 300);
49 
50  QGridLayout* pLayout = new QGridLayout();
51  setLayout(pLayout);
52 
53  _pListView = new QTreeWidget();
54  QStringList stringList;
55  stringList.append(TR("id_column_element_type"));
56  stringList.append(TR("id_column_element_name"));
57  stringList.append(TR("id_column_puissance_dba"));
58  stringList.append(TR("id_column_puissance_dblin"));
59  _pListView->setColumnCount(4);
60  _pListView->setHeaderLabels(stringList);
61  _pListView->setSelectionMode(QTreeWidget::NoSelection);
62  _pListView->setRootIsDecorated(true);
63  _pListView->sortItems(2, Qt::DescendingOrder); // Tri decroissant sur les valeurs en dB(A)
64  pLayout->addWidget(_pListView, 0, 0);
65 
66  _pCloseButton = new QPushButton(TR("id_close_button"), this);
67  pLayout->addWidget(_pCloseButton, 1, 0);
68  QObject::connect(_pCloseButton, &QPushButton::clicked, this, &TYResultatTreeDialog::close);
69 }
70 
72 
74 {
75  Q_ASSERT(pResultat);
76  Q_ASSERT(pPtCalcul);
77 
78  _pResultat = pResultat;
79  _pPtCalcul = pPtCalcul;
80 
81  updateContent();
82 }
83 
85 {
86  if (!_pPtCalcul)
87  {
88  _pListView->clear();
89  return;
90  }
91 
92  // On travaille d'abord sur une arborescence temporaire
93  QMap<TYElement*, childTreeItem*> mapElementChilds;
94 
95  int nbSources = static_cast<int>(_pResultat->getInitialNbOfSources());
96  int indexRecepteur = static_cast<int>(_pResultat->getIndexRecepteur(_pPtCalcul));
97  TYElement* pParent = NULL;
98  TYElement* pChild = NULL;
99 
100  // Pour chaque source (couple)
101  for (int i = 0; i < nbSources; i++)
102  {
104 
105  pParent = pSrc->getParent();
106  pChild = NULL;
107 
108  if (!pParent)
109  {
110  return;
111  } // Securite
112 
113  OSpectre spectre = _pResultat->getElementSpectre(indexRecepteur, i);
114 
115  // La source ponctuelle utilisateur necessite une entree meme si elle n'a pas de descendant
116  if (pSrc->isA("TYUserSourcePonctuelle"))
117  {
118  // On cree l'entree manquante
119  childTreeItem* pChildItem = new childTreeItem();
120  pChildItem->spectre = spectre.toDB();
121  pChildItem->pChildsList[pChild] = pChild;
122  mapElementChilds.insert(pSrc, pChildItem);
123  }
124 
125  while (pParent)
126  {
127  // On teste si le parent est present dans le tab de parents
128  if (mapElementChilds.contains(pParent))
129  {
130  // On ajoute le spectre au spectre du parent
131  mapElementChilds[pParent]->spectre = mapElementChilds[pParent]->spectre.sumdB(spectre.toDB());
132  // On ajoute "l'enfant" a la liste des enfants
133  mapElementChilds[pParent]->pChildsList[pChild] = pChild;
134  }
135  else
136  {
137  // On cree l'entree manquante
138  childTreeItem* pChildItem = new childTreeItem();
139  pChildItem->spectre = spectre.toDB();
140  pChildItem->pChildsList[pChild] = pChild;
141  mapElementChilds.insert(pParent, pChildItem);
142  }
143 
144  pChild = pParent;
145  pParent = pParent->getParent();
146  }
147  }
148 
149  // On parcours ensuite la map pour construire l'arboresecnce dans le bon sens (inch allah)
150 
151  QMap<TYElement*, QTreeWidgetItem*> mapParentItem;
152  QStringList stringList;
153  stringList.append(TYElementWidget::getDisplayName(_pPtCalcul));
154  stringList.append(_pPtCalcul->getName());
155  QTreeWidgetItem* pRootItem = new QTreeWidgetItem(_pListView, stringList);
156  // pRootItem->setExpanded(true);
157  QTreeWidgetItem* pCurItem = NULL;
158  QMap<TYElement*, childTreeItem*>::iterator it;
159 
160  for (it = mapElementChilds.begin(); it != mapElementChilds.end(); it++)
161  {
162  pParent = it.key();
163  pCurItem = pRootItem;
164 
165  if (pParent->isA("TYUserSourcePonctuelle"))
166  {
167  // Spectre de l'element racine
168  OSpectre spectre = it.value()->spectre;
169  QStringList stringList;
170  stringList.append(TYElementWidget::getDisplayName(pParent));
171  stringList.append(pParent->getName());
172  pCurItem = new QTreeWidgetItem(pCurItem, stringList);
173  pCurItem->setText(2, QString().setNum(spectre.valGlobDBA(), 'f', 2));
174  pCurItem->setText(3, QString().setNum(spectre.valGlobDBLin(), 'f', 2));
175 
176  // Ajout a la collection de parents
177  mapParentItem.insert(pParent, pCurItem);
178  }
179  else if (dynamic_cast<TYAcousticLine*>(pParent) != nullptr)
180  {
181  // Spectre de l'element racine
182  OSpectre spectre = it.value()->spectre;
183  QStringList stringList;
184  stringList.append(TYElementWidget::getDisplayName(pParent));
185  stringList.append(pParent->getName());
186  pCurItem = new QTreeWidgetItem(pCurItem, stringList);
187  pCurItem->setText(2, QString().setNum(spectre.valGlobDBA(), 'f', 2));
188  pCurItem->setText(3, QString().setNum(spectre.valGlobDBLin(), 'f', 2));
189 
190  // Ajout a la collection de parents
191  mapParentItem.insert(pParent, pCurItem);
192  }
193  else if (dynamic_cast<TYAcousticVolumeNode*>(pParent) != nullptr)
194  {
195  QMap<TYElement*, childTreeItem*>::iterator it2 = mapElementChilds.find(pParent);
196  followChilds(mapElementChilds, it2, mapParentItem, pCurItem);
197  }
198 
199  pCurItem = pRootItem;
200  }
201 
202  // On detruit l'arborescence utilisee pour la construction
203  QMap<TYElement*, childTreeItem*>::iterator itdel;
204 
205  for (itdel = mapElementChilds.begin(); itdel != mapElementChilds.end(); itdel++)
206  {
207  delete itdel.value();
208  itdel.value() = NULL;
209  }
210 }
211 
212 void TYResultatTreeDialog::followChilds(QMap<TYElement*, childTreeItem*>& mapElementChilds,
213  QMap<TYElement*, childTreeItem*>::iterator it,
214  QMap<TYElement*, QTreeWidgetItem*>& mapParentItem,
215  QTreeWidgetItem* pCurItem)
216 {
217  TYElement* pParent = it.key();
218 
219  if (dynamic_cast<TYSourceSurfacic*>(pParent) != nullptr)
220  {
221  return;
222  }
223 
224  OSpectre spectre = it.value()->spectre;
225  QStringList stringList;
226  stringList.append(TYElementWidget::getDisplayName(pParent));
227  stringList.append(pParent->getName());
228  pCurItem = new QTreeWidgetItem(pCurItem, stringList);
229  pCurItem->setText(2, QString().setNum(spectre.valGlobDBA(), 'f', 2));
230  pCurItem->setText(3, QString().setNum(spectre.valGlobDBLin(), 'f', 2));
231 
232  // Ajout a la collection de parents
233  std::map<TYElement*, TYElement*>::iterator itmap;
234 
235  for (itmap = it.value()->pChildsList.begin(); itmap != it.value()->pChildsList.end(); itmap++)
236  {
237  QMap<TYElement*, childTreeItem*>::iterator it2 = mapElementChilds.find((*itmap).first);
238 
239  followChilds(mapElementChilds, it2, mapParentItem, pCurItem);
240  }
241 }
242 
243 /*
244 void TYResultatTreeDialog::updateContent()
245 {
246  if (!_pPtCalcul)
247  {
248  _pListView->clear();
249  return;
250  }
251 
252  QMap<TYElement*, QListViewItem*> mapParentItem;
253 
254  // Le point de calcul est le root
255  QListViewItem * pRootItem = new QListViewItem(_pListView, TYElementWidget::getDisplayName(_pPtCalcul),
256 _pPtCalcul->getName()); pRootItem->setOpen(true);
257 
258  int nbSources = _pResultat->getInitialNbOfSources();
259  int indexRecepteur = _pResultat->getIndexRecepteur(_pPtCalcul);
260 
261  // Pour chaque source (couple)
262  for (int i = 0; i < nbSources; i++)
263  {
264  LPTYElement pSrc = _pResultat->getElementSource(i);
265 
266  TYElement * pParent = NULL;
267  QListViewItem * pCurItem = pRootItem;
268 
269  pParent = pSrc->getParent();
270 
271  double correct ;
272  while (pParent)
273  {
274  // On teste si le parent est present dans le tab de parents
275  if (mapParentItem.contains(pParent)) {
276  QString tmp;
277  // Ajout de la contribution de ce couple a ce parent
278  OSpectre spectre = _pResultat->getElementSpectre(indexRecepteur, i);
279 
280  // dBA
281  tmp = mapParentItem[pParent]->text(2);
282  correct = 10 * log10(pow(10, tmp.toDouble()/10) + pow(10, spectre.valGlobDBA()/10));
283  tmp = QString().setNum(correct, 'f', 2);
284  mapParentItem[pParent]->setText(2, tmp);
285 
286  // dBLin
287  tmp = mapParentItem[pParent]->text(3);
288  correct = 10 * log10(pow(10, tmp.toDouble()/10) + pow(10, spectre.valGlobDBLin()/10));
289  tmp = QString().setNum(correct, 'f', 2);
290  mapParentItem[pParent]->setText(3, tmp);
291  }
292  else
293  {
294  // Le spectre de ce couple
295  OSpectre spectre = _pResultat->getElementSpectre(indexRecepteur, i);
296 
297  // Ajout d'un item pour ce parent
298  pCurItem = new QListViewItem(pCurItem, TYElementWidget::getDisplayName(pParent),
299 pParent->getName()); pCurItem->setText(2, QString().setNum(spectre.valGlobDBA(), 'f', 2));
300  pCurItem->setText(3, QString().setNum(spectre.valGlobDBLin(), 'f', 2));
301 
302  // Ajout a la collection de parents
303  mapParentItem.insert(pParent, pCurItem);
304  }
305 
306  // Parent du parent
307  pParent = pParent->getParent();
308  }
309  }
310 
311 }
312 */
313 
314 void TYResultatTreeDialog::showEvent(QShowEvent* pEvent)
315 {
316  // On charge les settings
317  TYPreferenceManager::loadGeometryFromPreferences(metaObject()->className(), this);
318 }
319 
320 void TYResultatTreeDialog::closeEvent(QCloseEvent* pEvent)
321 {
322  // On sauve les settings
323  TYPreferenceManager::saveGeometryToPreferences(metaObject()->className(), this);
324 
325  QDialog::closeEvent(pEvent);
326 }
outil IHM pour un element (fichier header)
#define TR(id)
Boite de dialogue pour la representation par une arborescence des elements contribuant au resultat d'...
const char * name
bool isA(const char *className) const
Definition: TYElement.cpp:65
double valGlobDBA() const
Compute the global value dB[A] of a one-third Octave spectrum.
Definition: spectre.cpp:690
double valGlobDBLin() const
Compute the global value dB[Lin] of a one-third Octave spectrum.
Definition: spectre.cpp:678
OSpectreAbstract & toDB() const
Converts to dB.
Definition: spectre.cpp:595
TYElement * getParent() const
Definition: TYElement.h:697
virtual QString getName() const
Definition: TYElement.h:682
QTreeWidget * _pListView
La liste pour la representation de l'arborescence.
LPTYResultat _pResultat
Le resultat associe.
TYResultatTreeDialog(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=QFlag(0))
void set(LPTYResultat pResultat, LPTYPointCalcul pPtCalcul)
void followChilds(QMap< TYElement *, childTreeItem * > &mapElementChilds, QMap< TYElement *, childTreeItem * >::iterator it, QMap< TYElement *, QTreeWidgetItem * > &mapParentItem, QTreeWidgetItem *pCurItem)
QPushButton * _pCloseButton
Bouton pour fermer la boite de dialogue.
virtual void closeEvent(QCloseEvent *pEvent)
LPTYPointCalcul _pPtCalcul
Le point de calcul associe.
virtual void showEvent(QShowEvent *pEvent)
int getIndexRecepteur(TYPointCalcul *pRecepteur)
Retourne l'index d'un recepteur.
Definition: TYResultat.h:168
size_t getInitialNbOfSources() const
Retourne le nombre de sources initialement utilisees par le calcul.
Definition: TYResultat.h:112
LPTYElement getElementSource(const int &indexSource)
Retourne la source elementaire correspondant a l'indice passe.
Definition: TYResultat.cpp:525
const OSpectre & getElementSpectre(int indexRecepteur, int indexSource) const
Retourne le spectre de la matrice brute (avant condensation)pour un couple S-R (S = Source elementair...
Definition: TYResultat.cpp:480
static QString getDisplayName(TYElement *pElt)
Definition: TYWidget.cpp:125
std::map< TYElement *, TYElement * > pChildsList