Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticBoxWidget.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 
21 #include <math.h>
22 #include <qmenu.h>
23 #include <qtablewidget.h>
24 // Added by qt3to4:
25 #include <QGridLayout>
26 #include <QHeaderView>
27 #include <QtWidgets>
28 
32 #include "TYAcousticBoxWidget.h"
34 
35 #define TR(id) OLocalizator::getString("TYAcousticBoxWidget", (id))
36 
37 TYAcousticBoxWidget::TYAcousticBoxWidget(TYAcousticBox* pElement, QWidget* _pParent /*=NULL*/)
38  : TYWidget(pElement, _pParent), _isColorModified(false)
39 {
40 
41  _elmW = new TYAcousticVolumeWidget(pElement, this);
42 
43  resize(300, 500);
44  setWindowTitle(TR("id_caption"));
45  _acousticBoxLayout = new QGridLayout();
46  setLayout(_acousticBoxLayout);
47 
48  _acousticBoxLayout->addWidget(_elmW, 0, 0);
49 
50  _groupBox = new QGroupBox(this);
51  _groupBox->setTitle(TR(""));
52  _groupBoxLayout = new QGridLayout();
53  _groupBox->setLayout(_groupBoxLayout);
54 
55  _tableFaces = new QTableWidget();
56  _tableFaces->setColumnCount(2);
57  _tableFaces->setHorizontalHeaderItem(0, new QTableWidgetItem(TR("id_nom")));
58  _tableFaces->setHorizontalHeaderItem(1, new QTableWidgetItem(TR("id_emission")));
59 
60  _groupBoxLayout->addWidget(_tableFaces, 0, 0);
61  _acousticBoxLayout->addWidget(_groupBox, 1, 0);
62 
63  _groupBoxDimensions = new QGroupBox(this);
64  _groupBoxDimensions->setTitle(TR("id_title_dimensions"));
65  _groupBoxDimensionsLayout = new QGridLayout();
67 
68  _dimensionsXLabel = new QLabel("labelName");
69  _dimensionsXLabel->setText("X : ");
71 
72  _dimensionsYLabel = new QLabel("labelName");
73  _dimensionsYLabel->setText("Y : ");
75 
76  _dimensionsZLabel = new QLabel("labelName");
77  _dimensionsZLabel->setText("Z : ");
79 
86 
87  _acousticBoxLayout->addWidget(_groupBoxDimensions, 2, 0);
88 
89  updateContent();
90 
92 }
93 
95 
97 {
99 
100  for (int i = 0, row = 0; i < 6; i++, row++)
101  {
102  LPTYAcousticRectangleNode pRectNode =
103  TYAcousticRectangleNode::safeDownCast(getElement()->getFace(i)->getElement());
104  _tableFaces->setRowCount(i + 1);
105  QTableWidgetItem* pItem = new QTableWidgetItem(pRectNode->getName());
106  QTableWidgetItem* pCheckItemEmit = new QTableWidgetItem(" ");
107  pCheckItemEmit->setCheckState(pRectNode->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
108  _tableFaces->setItem(row, 0, pItem);
109  _tableFaces->setItem(row, 1, pCheckItemEmit);
110  }
111 
112  float sizeX = NAN, sizeY = NAN, sizeZ = NAN;
113  ((TYAcousticBox*)_pElement)->getDimension(sizeX, sizeY, sizeZ);
114  _dimensionsXLineEdit->setText(QString().setNum(sizeX, 'f', 2));
115  _dimensionsYLineEdit->setText(QString().setNum(sizeY, 'f', 2));
116  _dimensionsZLineEdit->setText(QString().setNum(sizeZ, 'f', 2));
117 }
118 
120 {
121  _elmW->apply();
122  unsigned int i = 0;
123  if (_isColorModified)
124  {
125  for (i = 0; i < 6; ++i)
126  {
127  TYAcousticRectangleNode::safeDownCast(getElement()->getFace(i)->getElement())
128  ->setColor(getElement()->getColor());
129  }
130 
131  _isColorModified = false;
132  }
133 
134  for (i = 0; i < _tableFaces->rowCount(); i++)
135  {
136  LPTYAcousticRectangleNode pRectNode =
137  TYAcousticRectangleNode::safeDownCast(getElement()->getFace(i)->getElement());
138  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(i, 1);
139  pRectNode->setIsRayonnant(pCheck->checkState() == Qt::Checked);
140  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(i, 0);
141  pRectNode->setName(pText->text());
142  }
143 
144  _elmW->apply();
145  float sizeX = _dimensionsXLineEdit->text().toDouble();
146  float sizeY = _dimensionsYLineEdit->text().toDouble();
147  float sizeZ = _dimensionsZLineEdit->text().toDouble();
148  ((TYAcousticBox*)_pElement)->setDimension(sizeX, sizeY, sizeZ);
149 
150  emit modified();
151 }
152 
154 {
155  _elmW->reject();
156 
157  _isColorModified = false;
158 }
159 
160 void TYAcousticBoxWidget::editFace(const int& item)
161 {
162  LPTYAcousticRectangleNode pRectNode =
163  TYAcousticRectangleNode::safeDownCast(getElement()->getFace(item)->getElement());
164  QTableWidgetItem* pCheck = (QTableWidgetItem*)_tableFaces->item(item, 1);
165  pRectNode->setIsRayonnant(pCheck->checkState() == Qt::Checked);
166  QTableWidgetItem* pText = (QTableWidgetItem*)_tableFaces->item(item, 0);
167  pRectNode->setName(pText->text());
168 
169  int ret = pRectNode->edit(this);
170 
171  if (ret == QDialog::Accepted)
172  {
173  pCheck->setCheckState(pRectNode->getIsRayonnant() ? Qt::Checked : Qt::Unchecked);
174  pText->setText(pRectNode->getName());
175  }
176 }
177 
178 void TYAcousticBoxWidget::contextMenuEvent(QContextMenuEvent* e)
179 {
180  QPoint point = _tableFaces->mapFrom(this, e->pos());
181 
182  if ((point.x() >= 0) && (point.y() >= 0) && (point.x() <= _tableFaces->width()) &&
183  (point.y() <= _tableFaces->height()))
184  {
185  // It is not very explicit in Qt's QTableView documentation, but coordinates given to itemAt must be
186  // in the viewport's coordinate system (viewport = cells displayed on screen -- headers excluded)
187  QPoint resPoint = _tableFaces->viewport()->mapFrom(_tableFaces, point);
188  QTableWidgetItem* item = _tableFaces->itemAt(resPoint);
189  if (item)
190  {
191  QMenu* pMenu = new QMenu(this);
192 
193  QAction* prop = pMenu->addAction(TR("id_proprietes_button"));
194  QAction* ret = pMenu->exec(_tableFaces->mapToGlobal(point));
195 
196  if ((ret) && (ret == prop))
197  {
198  editFace(_tableFaces->indexAt(resPoint).row());
199  }
200  }
201  }
202 }
203 
205 {
206  _isColorModified = true;
207 }
QColor getColor
#define TR(id)
outil IHM pour une boite acoustique (fichier header)
outil IHM pour un volume acoustique (fichier header)
outil IHM pour une entrée utilisateur (fichier header)
static OPrototype * safeDownCast(OPrototype *pObject)
Definition: TYElement.cpp:71
void editFace(const int &item)
QGridLayout * _acousticBoxLayout
QGroupBox * _groupBoxDimensions
virtual void updateContent()
TYLineEdit * _dimensionsXLineEdit
QGridLayout * _groupBoxLayout
TYAcousticBoxWidget(TYAcousticBox *pElement, QWidget *_pParent=NULL)
QGridLayout * _groupBoxDimensionsLayout
QTableWidget * _tableFaces
TYLineEdit * _dimensionsYLineEdit
TYLineEdit * _dimensionsZLineEdit
virtual void contextMenuEvent(QContextMenuEvent *e)
TYAcousticVolumeWidget * _elmW
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
classe de l'objet IHM pour un volume acoustique
void setName(QString name)
Definition: TYElement.h:678
virtual QString getName() const
Definition: TYElement.h:691
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
TYElement * _pElement
Definition: TYWidget.h:114
void modified()