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