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