Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticVolumeNodeWidget.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 
24 
28 
30 #include "TYElementWidget.h"
31 
32 #include <qmenu.h>
33 #include <qtablewidget.h>
34 #include <qmessagebox.h>
35 // Added by qt3to4:
36 #include <QHBoxLayout>
37 #include <QBoxLayout>
38 #include <QGridLayout>
39 #include <QFrame>
40 #include <QVBoxLayout>
41 #include <QHeaderView>
42 #include <QtWidgets>
43 
44 #define TR(id) OLocalizator::getString("TYAcousticVolumeNodeWidget", (id))
45 
47  QWidget* _pParent /*=NULL*/)
48  : TYWidget(pElement, _pParent), _isColorModified(false)
49 {
50 
51  _elmW = new TYElementWidget(pElement, this);
52  _colorW = new TYColorInterfaceWidget(dynamic_cast<TYColorInterface*>(pElement), this);
53 
54  _interW = new TYAcousticInterfaceWidget(dynamic_cast<TYAcousticInterface*>(pElement), this);
55 
56  // Pour les element principaux, on desactive la possibilite de changer l'etat
57  // (cette propriete est pilotee directement par le calcul)
59 
60  resize(300, 140);
61  setWindowTitle(TR("id_caption"));
62  _acousticVolumeNodeLayout = new QGridLayout();
63  setLayout(_acousticVolumeNodeLayout);
64 
65  unsigned int iln = 0;
66 
67  _acousticVolumeNodeLayout->addWidget(_elmW, iln, 0);
68  _acousticVolumeNodeLayout->addWidget(_colorW, ++iln, 0);
69  _acousticVolumeNodeLayout->addWidget(_interW, ++iln, 0);
70 
71  QGroupBox* pGroupBoxAccVols = new QGroupBox(this);
72  pGroupBoxAccVols->setTitle(TR("id_tabaccvol_box"));
73  QGridLayout* pGroupBoxAccVolsLayout = new QGridLayout();
74  pGroupBoxAccVols->setLayout(pGroupBoxAccVolsLayout);
75 
76  QLineEdit* pLineEditNomAccVols = new QLineEdit(pGroupBoxAccVols);
77  pLineEditNomAccVols->setEnabled(false);
78  pGroupBoxAccVolsLayout->addWidget(pLineEditNomAccVols, 0, 0);
79 
80  QPushButton* pPushButtonAccVols = new QPushButton(pGroupBoxAccVols);
81  pPushButtonAccVols->setText(TR("id_proprietes_button"));
82  pGroupBoxAccVolsLayout->addWidget(pPushButtonAccVols, 0, 1);
83 
84  _acousticVolumeNodeLayout->addWidget(pGroupBoxAccVols, ++iln, 0);
85 
86  // CREATION DE LA BOITE DE DIALOGUE DE SELECTION DES VOLUMES ACOUSTIQUES
87 
88  _pAccVolsWidget = new QWidget(this, Qt::Dialog);
89  _pAccVolsWidget->setWindowModality(Qt::WindowModal);
90  _pAccVolsWidget->setContextMenuPolicy(Qt::CustomContextMenu);
91  QBoxLayout* pLayoutAccVols = new QVBoxLayout(_pAccVolsWidget);
92  _pAccVolsWidget->setLayout(pLayoutAccVols);
93  _pAccVolsWidget->setWindowTitle(TR("id_tabaccvol_box"));
94 
95  _groupBox = new QGroupBox(_pAccVolsWidget);
96  _groupBoxLayout = new QGridLayout();
97  _groupBox->setLayout(_groupBoxLayout);
98 
99  _tableFaces = new QTableWidget();
100  _tableFaces->setColumnCount(2);
101  _tableFaces->setHorizontalHeaderItem(0, new QTableWidgetItem(TR("id_nom")));
102  _tableFaces->setHorizontalHeaderItem(1, new QTableWidgetItem(TR("id_emission")));
103 
104  _groupBoxLayout->addWidget(_tableFaces, 0, 0);
105  pLayoutAccVols->addWidget(_groupBox);
106 
107  pLayoutAccVols->addSpacing(5);
108  QBoxLayout* pBtnLayoutAccVols = new QHBoxLayout();
109  pBtnLayoutAccVols->setContentsMargins(10, 10, 10, 10);
110  pLayoutAccVols->addLayout(pBtnLayoutAccVols);
111 
112  pBtnLayoutAccVols->addStretch();
113 
114  QPushButton* pButtonOKAccVols = new QPushButton(TR("id_ok_btn"), _pAccVolsWidget);
115  pButtonOKAccVols->setDefault(true);
116  connect(pButtonOKAccVols, &QPushButton::clicked, this, &TYAcousticVolumeNodeWidget::hideAccVolWidget);
117  pBtnLayoutAccVols->addWidget(pButtonOKAccVols);
118 
119  // FIN DE CREATION DE LA BOITE DE DIALOGUE DES VOLUMES ACOUSTIQUES
120 
121  updateContent();
122 
123  connect(pPushButtonAccVols, &QPushButton::clicked, _pAccVolsWidget, &TYAcousticVolumeNodeWidget::show);
127  connect(_pAccVolsWidget, &QWidget::customContextMenuRequested, this,
129 }
130 
132 
134 {
136 }
137 
139 {
140  _elmW->updateContent();
144 }
145 
147 {
148  _elmW->apply();
149  _colorW->apply();
150  _interW->apply();
151 
152  applyToSubVol();
153 
155 
156  emit modified();
157 }
158 
160 {
161  LPTYAcousticVolume pVol = getElement()->getAcousticVol(item);
162  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(item, 1);
163  pVol->setIsRayonnant(pCheck->checkState() == Qt::Checked, false);
164  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(item, 0);
165  pVol->setName(pText->text());
166 
167  int ret = pVol->edit(_pAccVolsWidget);
168 
169  if (ret == QDialog::Accepted)
170  {
171  pCheck->setCheckState(pVol->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
172  pText->setText(pVol->getName());
173  }
174 }
175 
177 {
178  int ret = QMessageBox::warning(this, TR("id_attention"), TR("id_are_you_sure"), TR("id_button_oui"),
179  TR("id_button_non"), QString(), 0, 1);
180 
181  if (ret == 0)
182  {
183  LPTYAcousticVolume pVol = getElement()->getAcousticVol(item);
184 
185  LPTYAcousticVolumeNode pVolNode = TYAcousticVolumeNode::safeDownCast(pVol->getParent());
186 
187  if (pVolNode)
188  {
189  pVolNode->remAcousticVol(pVol);
190  }
191 
192  updateContent();
193 
194  emit modified(); // Il y a eu modification
195  }
196 }
197 
199 {
200  QPoint point = _tableFaces->mapFrom(_pAccVolsWidget, pt);
201 
202  if ((point.x() >= 0) && (point.y() >= 0) && (point.x() <= _tableFaces->width()) &&
203  (point.y() <= _tableFaces->height()))
204  {
205  // It is not very explicit in Qt's QTableView documentation, but coordinates given to itemAt must be
206  // in the viewport's coordinate system (viewport = cells displayed on screen -- headers excluded)
207  QPoint resPoint = _tableFaces->viewport()->mapFrom(_tableFaces, point);
208  QTableWidgetItem* item = _tableFaces->itemAt(resPoint);
209  if (item)
210  {
211  QMenu* pMenu = new QMenu(this);
212 
213  QAction* prop = pMenu->addAction(TR("id_property"));
214  QAction* del = pMenu->addAction(TR("id_delete"));
215 
216  QAction* ret = pMenu->exec(_tableFaces->mapToGlobal(point));
217 
218  if (ret)
219  {
220  if (ret == prop)
221  {
222  editAccVol(_tableFaces->indexAt(resPoint).row());
223  }
224  else if (ret == del)
225  {
226  remAccVol(_tableFaces->indexAt(resPoint).row());
227  }
228  }
229  }
230  }
231 }
232 
234 {
235  // On met a jour la boite de dialogue des volumes
237 
238  emit regimeChanged(regime);
239 }
240 
242 {
243  // On met a jour les sous volumes qui ont pu etre modifies
244  applyToSubVol();
245 
246  _pAccVolsWidget->hide();
247 }
248 
250 {
251  for (int i = 0; i < _tableFaces->rowCount(); i++)
252  {
253  LPTYAcousticVolume pVol = getElement()->getAcousticVol(i);
254  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(i, 1);
255  pVol->setIsRayonnant(pCheck->checkState() == Qt::Checked, false);
256  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(i, 0);
257  pVol->setName(pText->text());
258 
259  // Color propagation
260  if (_isColorModified)
261  {
262  // Volumes color set
263  pVol->setColor(getElement()->getColor());
264 
265  // Surfaces color set
266  // TYAcousticSurfaceNodes color set
267  LPTYElementArray childs;
268  pVol->getChilds(childs, false);
269 
270  LPTYGeometryNode pNode = nullptr;
271  LPTYAcousticSurfaceNode pSurfNode = nullptr;
272  for (size_t i = 0; i < childs.size(); i++)
273  {
274  pNode = TYGeometryNode::safeDownCast(childs[i]);
275  if (pNode == nullptr)
276  {
277  continue;
278  }
279 
280  pSurfNode = TYAcousticSurfaceNode::safeDownCast(pNode->getElement());
281  if (pSurfNode != nullptr)
282  {
283  pSurfNode->setColor(getElement()->getColor());
284  }
285  }
286 
287  // TYAcousticSurfaces color set
288  TYTabAcousticSurfaceGeoNode tab = pVol->acousticFaces();
289  for (unsigned int i = 0; i < tab.size(); ++i)
290  {
291  LPTYAcousticSurface pAccSurf = TYAcousticSurface::safeDownCast(tab[i]->getElement());
292  if (!pAccSurf->getIsSub())
293  {
294  pAccSurf->setColor(getElement()->getColor());
295  }
296  }
297  }
298  }
299 }
300 
302 {
303  for (unsigned int i = 0, row = 0; i < getElement()->getTabAcousticVol().size(); i++, row++)
304  {
305  LPTYAcousticVolume pVol = getElement()->getAcousticVol(i);
306  _tableFaces->setRowCount(i + 1);
307  QTableWidgetItem* pItem = new QTableWidgetItem(pVol->getName());
308  _tableFaces->setItem(row, 0, pItem);
309  QTableWidgetItem* pCheckItemEmit = new QTableWidgetItem(" ");
310  pCheckItemEmit->setCheckState(pVol->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
311  _tableFaces->setItem(row, 1, pCheckItemEmit);
312  }
313 }
314 
316 {
317  _isColorModified = true;
318 }
QColor getColor
Outil IHM pour une interface acoustique (fichier header)
std::vector< LPTYAcousticSurfaceGeoNode > TYTabAcousticSurfaceGeoNode
Collection de noeuds geometriques de type TYAcousticSurface.
#define TR(id)
outil IHM pour un ensemble de volumes acoustiques (fichier header)
outil IHM pour l'objet ColorInterface (fichier header)
outil IHM pour un element (fichier header)
std::vector< LPTYElement > LPTYElementArray
Definition: TYElement.h:344
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
classe de l'objet IHM pour une interface acoustique
void setCheckBoxRayonnantState(const bool &active)
TYAcousticInterfaceWidget * _interW
TYAcousticVolumeNodeWidget(TYAcousticVolumeNode *pElement, QWidget *_pParent=NULL)
void hideAccVolWidget()
Action a engager lorsque l'on ferme/cacahe la boite de dialogue des acousticVol.
virtual void contextMenuRequested(const QPoint &point)
bool remAcousticVol(const LPTYAcousticVolumeGeoNode pAccVolGeoNode)
classe de l'objet IHM pour l'objet ColorInterface
virtual void setColor(const OColor &color)
classe de l'objet IHM pour un element
virtual void apply()
virtual void updateContent()
virtual void setIsAcousticModified(bool isModified)
Definition: TYElement.cpp:248
TYElement * getElement() const
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
TYElement * _pElement
Definition: TYWidget.h:114
void modified()