Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYDimensionDialog.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 
22 // Added by qt3to4:
23 #include <QGridLayout>
24 #include <QBoxLayout>
25 #include <QHBoxLayout>
26 #include <QLabel>
27 
37 
38 #include "TYDimensionDialog.h"
39 
40 #include <math.h>
41 
42 #define TR(id) OLocalizator::getString("TYDimensionDialog", (id))
43 
44 TYDimensionDialog::TYDimensionDialog(TYAcousticVolume* pElement, QWidget* _pParent /*=NULL*/)
45  : TYFormDialog(_pParent)
46 {
47  Q_ASSERT(pElement);
48  _pElement = pElement;
49 
50  resize(300, 174);
51  setWindowTitle(TR("id_caption"));
52 
53  QGridLayout* pLayout = new QGridLayout();
54  setLayout(pLayout);
55 
56  QBoxLayout* pEditLayout = new QHBoxLayout();
57  pEditLayout->setContentsMargins(10, 10, 10, 10);
58  pLayout->addLayout(pEditLayout, 0, 1);
59 
60  _pXLineEdit = nullptr;
61  _pYLineEdit = nullptr;
62  _pZLineEdit = nullptr;
63  _pDiamLineEdit = nullptr;
64  _pHauteurLineEdit = nullptr;
65 
66  if (_pElement->isA("TYAcousticBox"))
67  {
68  // Size X
69  QLabel* pXLabelName = new QLabel(this);
70  pXLabelName->setText(TR("id_x_label"));
71  pEditLayout->addWidget(pXLabelName);
72  _pXLineEdit = new TYLineEdit(QString(), false, false, this);
73  _pXLineEdit->setFixedWidth(60);
74  pEditLayout->addWidget(_pXLineEdit);
75 
76  // Size Y
77  pEditLayout->addSpacing(10);
78  QLabel* pYLabelName = new QLabel(this);
79  pYLabelName->setText(TR("id_y_label"));
80  pEditLayout->addWidget(pYLabelName);
81  _pYLineEdit = new TYLineEdit(QString(), false, false, this);
82  _pYLineEdit->setFixedWidth(60);
83  pEditLayout->addWidget(_pYLineEdit);
84 
85  // Size Z
86  pEditLayout->addSpacing(10);
87  QLabel* pZLabelName = new QLabel(this);
88  pZLabelName->setText(TR("id_z_label"));
89  pEditLayout->addWidget(pZLabelName);
90  _pZLineEdit = new TYLineEdit(QString(), false, false, this);
91  _pZLineEdit->setFixedWidth(60);
92  pEditLayout->addWidget(_pZLineEdit);
93  }
94  else if (_pElement->isA("TYAcousticCylinder") || _pElement->isA("TYAcousticSemiCylinder"))
95  {
96  // Diametre
97  QLabel* pDiamLabelName = new QLabel(this);
98  pDiamLabelName->setText(TR("id_diameter_label"));
99  pEditLayout->addWidget(pDiamLabelName);
100  _pDiamLineEdit = new TYLineEdit(QString(), false, false, this);
101  _pDiamLineEdit->setFixedWidth(60);
102  pEditLayout->addWidget(_pDiamLineEdit);
103 
104  // Hauteur
105  pEditLayout->addSpacing(10);
106  QLabel* pHauteurLabelName = new QLabel(this);
107  pHauteurLabelName->setText(TR("id_hauteur_label"));
108  pEditLayout->addWidget(pHauteurLabelName);
109  _pHauteurLineEdit = new TYLineEdit(QString(), false, false, this);
110  _pHauteurLineEdit->setFixedWidth(60);
111  pEditLayout->addWidget(_pHauteurLineEdit);
112  }
113 
114  QBoxLayout* pBtnLayout = new QHBoxLayout();
115  pLayout->addLayout(pBtnLayout, 1, 1);
116 
117  pBtnLayout->addStretch(1);
118 
119  QPushButton* pButtonOK = new QPushButton(TR("id_ok_btn"), this);
120  pButtonOK->setDefault(true);
121  QObject::connect(pButtonOK, &QPushButton::clicked, this, &TYDimensionDialog::apply);
122  pBtnLayout->addWidget(pButtonOK);
123 
124  QPushButton* pButtonCancel = new QPushButton(TR("id_cancel_btn"), this);
125  pButtonCancel->setShortcut(Qt::Key_Escape);
126  QObject::connect(pButtonCancel, &QPushButton::clicked, this, &TYDimensionDialog::reject);
127  pBtnLayout->addWidget(pButtonCancel);
128 
129  updateContent();
130 }
131 
133 
135 {
136  if (_pElement->isA("TYAcousticBox"))
137  {
138  TYAcousticBox* pAccBox = dynamic_cast<TYAcousticBox*>(_pElement);
139  float sizeX = NAN, sizeY = NAN, sizeZ = NAN;
140  pAccBox->getDimension(sizeX, sizeY, sizeZ);
141 
142  _pXLineEdit->setText(QString().setNum(sizeX, 'f', 2));
143  _pYLineEdit->setText(QString().setNum(sizeY, 'f', 2));
144  _pZLineEdit->setText(QString().setNum(sizeZ, 'f', 2));
145  }
146  else if (_pElement->isA("TYAcousticCylinder"))
147  {
148  float diameter = dynamic_cast<TYAcousticCylinder*>(_pElement)->getDiameter();
149  float hauteur = dynamic_cast<TYAcousticCylinder*>(_pElement)->getHauteur();
150  _pDiamLineEdit->setText(QString().setNum(diameter, 'f', 2));
151  _pHauteurLineEdit->setText(QString().setNum(hauteur, 'f', 2));
152  }
153  else if (_pElement->isA("TYAcousticSemiCylinder"))
154  {
155  float diameter = dynamic_cast<TYAcousticSemiCylinder*>(_pElement)->getDiameter();
156  float hauteur = dynamic_cast<TYAcousticSemiCylinder*>(_pElement)->getHauteur();
157  _pDiamLineEdit->setText(QString().setNum(diameter, 'f', 2));
158  _pHauteurLineEdit->setText(QString().setNum(hauteur, 'f', 2));
159  }
160 }
161 
163 {
164  if (_pElement->isA("TYAcousticBox"))
165  {
166  float sizeX = _pXLineEdit->text().toDouble();
167  float sizeY = _pYLineEdit->text().toDouble();
168  float sizeZ = _pZLineEdit->text().toDouble();
169 
170  dynamic_cast<TYAcousticBox*>(_pElement)->setDimension(sizeX, sizeY, sizeZ);
171  }
172  else if (_pElement->isA("TYAcousticCylinder"))
173  {
174  double diameter = _pDiamLineEdit->text().toDouble();
175  double hauteur = _pHauteurLineEdit->text().toDouble();
176 
177  dynamic_cast<TYAcousticCylinder*>(_pElement)->setDiameter(diameter);
178  dynamic_cast<TYAcousticCylinder*>(_pElement)->setHauteur(hauteur);
179  }
180  else if (_pElement->isA("TYAcousticSemiCylinder"))
181  {
182  double diameter = _pDiamLineEdit->text().toDouble();
183  double hauteur = _pHauteurLineEdit->text().toDouble();
184 
185  dynamic_cast<TYAcousticSemiCylinder*>(_pElement)->setDiameter(diameter);
186  dynamic_cast<TYAcousticSemiCylinder*>(_pElement)->setHauteur(hauteur);
187  }
188 
189  QDialog::accept();
190 }
All base classes related to 3D manipulation.
#define TR(id)
boite de dialogue pour la gestion des dimensions des volumes (fichier header)
outil IHM pour un element (fichier header)
outil IHM pour une entrée utilisateur (fichier header)
bool isA(const char *className) const
Definition: TYElement.cpp:65
void getDimension(float &larg, float &lon, float &haut)
TYLineEdit * _pYLineEdit
TYLineEdit * _pDiamLineEdit
TYAcousticVolume * _pElement
virtual void updateContent()
TYDimensionDialog(TYAcousticVolume *pElement, QWidget *_pParent=NULL)
TYLineEdit * _pHauteurLineEdit
TYLineEdit * _pZLineEdit
TYLineEdit * _pXLineEdit