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