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  QPoint resPoint = QPoint(point.x(), point.y() - _tableFaces->horizontalHeader()->height());
206  QTableWidgetItem* item = _tableFaces->itemAt(resPoint);
207  if (item)
208  {
209  QMenu* pMenu = new QMenu(this);
210 
211  QAction* prop = pMenu->addAction(TR("id_property"));
212  QAction* del = pMenu->addAction(TR("id_delete"));
213 
214  QAction* ret = pMenu->exec(_tableFaces->mapToGlobal(point));
215 
216  if (ret)
217  {
218  if (ret == prop)
219  {
220  editAccVol(_tableFaces->indexAt(resPoint).row());
221  }
222  else if (ret == del)
223  {
224  remAccVol(_tableFaces->indexAt(resPoint).row());
225  }
226  }
227  }
228  }
229 }
230 
232 {
233  // On met a jour la boite de dialogue des volumes
235 
236  emit regimeChanged(regime);
237 }
238 
240 {
241  // On met a jour les sous volumes qui ont pu etre modifies
242  applyToSubVol();
243 
244  _pAccVolsWidget->hide();
245 }
246 
248 {
249  for (int i = 0; i < _tableFaces->rowCount(); i++)
250  {
251  LPTYAcousticVolume pVol = getElement()->getAcousticVol(i);
252  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(i, 1);
253  pVol->setIsRayonnant(pCheck->checkState() == Qt::Checked, false);
254  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(i, 0);
255  pVol->setName(pText->text());
256 
257  // Color propagation
258  if (_isColorModified)
259  {
260  // Volumes color set
261  pVol->setColor(getElement()->getColor());
262 
263  // Surfaces color set
264  // TYAcousticSurfaceNodes color set
265  LPTYElementArray childs;
266  pVol->getChilds(childs, false);
267 
268  LPTYGeometryNode pNode = nullptr;
269  LPTYAcousticSurfaceNode pSurfNode = nullptr;
270  for (size_t i = 0; i < childs.size(); i++)
271  {
272  pNode = TYGeometryNode::safeDownCast(childs[i]);
273  if (pNode == nullptr)
274  {
275  continue;
276  }
277 
278  pSurfNode = TYAcousticSurfaceNode::safeDownCast(pNode->getElement());
279  if (pSurfNode != nullptr)
280  {
281  pSurfNode->setColor(getElement()->getColor());
282  }
283  }
284 
285  // TYAcousticSurfaces color set
286  TYTabAcousticSurfaceGeoNode tab = pVol->acousticFaces();
287  for (unsigned int i = 0; i < tab.size(); ++i)
288  {
289  LPTYAcousticSurface pAccSurf = TYAcousticSurface::safeDownCast(tab[i]->getElement());
290  if (!pAccSurf->getIsSub())
291  {
292  pAccSurf->setColor(getElement()->getColor());
293  }
294  }
295  }
296  }
297 }
298 
300 {
301  for (unsigned int i = 0, row = 0; i < getElement()->getTabAcousticVol().size(); i++, row++)
302  {
303  LPTYAcousticVolume pVol = getElement()->getAcousticVol(i);
304  _tableFaces->setRowCount(i + 1);
305  QTableWidgetItem* pItem = new QTableWidgetItem(pVol->getName());
306  _tableFaces->setItem(row, 0, pItem);
307  QTableWidgetItem* pCheckItemEmit = new QTableWidgetItem(" ");
308  pCheckItemEmit->setCheckState(pVol->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
309  _tableFaces->setItem(row, 1, pCheckItemEmit);
310  }
311 }
312 
314 {
315  _isColorModified = true;
316 }
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()