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