Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYAcousticInterfaceWidget.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 
27 
28 #include <qradiobutton.h>
29 #include <qbuttongroup.h>
30 #include <qcombobox.h>
31 // Added by qt3to4:
32 #include <QGridLayout>
33 #include <QLabel>
34 #include <QtWidgets>
35 
37 
38 #define TR(id) OLocalizator::getString("TYAcousticInterfaceWidget", (id))
39 #define IMG(id) OLocalizator::getPicture("TYAcousticInterfaceWidget", (id))
40 
42  QWidget* _pParent /*=NULL*/)
43  : QWidget(_pParent), _pElement(pElement)
44 {
45  _bAddRemRegimeOk = false;
46  _modified = false;
47 
48  resize(300, 375);
49  setWindowTitle(TR("id_caption"));
50  _acousticInterfaceLayout = new QGridLayout();
51  setLayout(_acousticInterfaceLayout);
52 
53  _groupBox = new QGroupBox(this);
54  _groupBox->setTitle(TR(""));
55  _groupBoxLayout = new QGridLayout();
56  _groupBox->setLayout(_groupBoxLayout);
57 
58  // Gestion des densites de sources
59 
60  // Densite Horizontale
61  _groupBoxDensiteH = new QGroupBox(_groupBox);
62  _groupBoxDensiteH->setTitle(TR("id_densitessrcsH_label"));
63  _groupBoxDensiteHLayout = new QGridLayout();
65 
68  QLabel* pUnitDensiteH = new QLabel(_groupBoxDensiteH);
69  pUnitDensiteH->setText(TR("id_unite_densite_srcs"));
70  _groupBoxDensiteHLayout->addWidget(pUnitDensiteH, 0, 1);
71 
72  _groupBoxLayout->addWidget(_groupBoxDensiteH, 0, 0);
73 
74  // Densite verticale
75  _groupBoxDensiteV = new QGroupBox(_groupBox);
76  _groupBoxDensiteV->setTitle(TR("id_densitessrcsV_label"));
77  _groupBoxDensiteVLayout = new QGridLayout();
79 
82  QLabel* pUnitDensiteV = new QLabel(_groupBoxDensiteV);
83  pUnitDensiteV->setText(TR("id_unite_densite_srcs"));
84  _groupBoxDensiteVLayout->addWidget(pUnitDensiteV, 0, 1);
85 
86  _groupBoxLayout->addWidget(_groupBoxDensiteV, 0, 1);
87 
88  // Proprietes acoustiques
89  QGroupBox* pgroupBoxPropriete = new QGroupBox(_groupBox);
90  QGridLayout* pgroupBoxProprieteLayout = new QGridLayout();
91  pgroupBoxPropriete->setLayout(pgroupBoxProprieteLayout);
92 
93  _labeUseAtt = new QLabel(pgroupBoxPropriete);
94  _labeUseAtt->setText(TR("id_useatt_label"));
95  _checkBoxUseAtt = new QCheckBox(pgroupBoxPropriete);
96  _checkBoxUseAtt->setText(TR(""));
97 
98  _labelIsRayonnant = new QLabel(pgroupBoxPropriete);
99  _labelIsRayonnant->setText(TR("id_israyonnant_label"));
100  _checkBoxIsRayonnant = new QCheckBox(pgroupBoxPropriete);
101  _checkBoxIsRayonnant->setText(TR(""));
102 
103  pgroupBoxProprieteLayout->addWidget(_labeUseAtt, 0, 1);
104  pgroupBoxProprieteLayout->addWidget(_checkBoxUseAtt, 0, 2);
105  pgroupBoxProprieteLayout->addWidget(_labelIsRayonnant, 0, 3);
106  pgroupBoxProprieteLayout->addWidget(_checkBoxIsRayonnant, 0, 4);
107 
108  _groupBoxLayout->addWidget(pgroupBoxPropriete, 1, 0);
109 
110  // Creation du bouton d'affichage du spectre
111  _groupBoxSpectre = new QGroupBox(_groupBox);
112  _groupBoxSpectreLayout = new QGridLayout();
114 
115  _pushButtonShowSpectre = new QPushButton(_groupBoxSpectre);
116  _pushButtonShowSpectre->setText(TR("id_button_spectre"));
117 
119 
120  _groupBoxLayout->addWidget(_groupBoxSpectre, 1, 1);
121 
122  _buttonGroupTypeDistrib = new QButtonGroup();
123  _buttonGroupTypeDistrib->setExclusive(true);
124  _pRadioButtonCalculee = new QRadioButton(TR("id_puissance_calculee"));
126  _pRadioButtonImposee = new QRadioButton(TR("id_puissance_imposee"));
128 
129  QGridLayout* groupBoxTypeDistribLayout = new QGridLayout();
130  groupBoxTypeDistribLayout->addWidget(_pRadioButtonCalculee, 0, 0);
131  groupBoxTypeDistribLayout->addWidget(_pRadioButtonImposee, 0, 1);
132 
133  QGroupBox* groupBoxTypeDistrib = new QGroupBox();
134  groupBoxTypeDistrib->setTitle(TR("id_type_distribution"));
135  groupBoxTypeDistrib->setLayout(groupBoxTypeDistribLayout);
136 
137  _groupBoxLayout->addWidget(groupBoxTypeDistrib, 2, 0);
138 
139  _groupBoxAtt = new QGroupBox(_groupBox);
140  _groupBoxAtt->setTitle(TR("id_att"));
141  _groupBoxAttLayout = new QGridLayout();
142  _groupBoxAtt->setLayout(_groupBoxAttLayout);
143 
144  _lineEditNomAtt = new QLineEdit(_groupBoxAtt);
145  _lineEditNomAtt->setEnabled(false);
146  _groupBoxAttLayout->addWidget(_lineEditNomAtt, 0, 0);
147 
148  _pushButtonSpectreAtt = new QPushButton(_groupBoxAtt);
149  _pushButtonSpectreAtt->setText(TR("id_proprietes_button"));
150  _groupBoxAttLayout->addWidget(_pushButtonSpectreAtt, 0, 1);
151 
152  _groupBoxLayout->addWidget(_groupBoxAtt, 2, 1);
153 
154  _acousticInterfaceLayout->addWidget(_groupBox, 0, 0);
155 
156  // Gestion du choix du regime
157  QGroupBox* _buttonGroupBox = new QGroupBox(this);
158  _buttonGroupBox->setTitle(TR("id_select_regime"));
159  QGridLayout* _buttonGroupBoxLayout = new QGridLayout();
161 
162  _pushButtonRemRegime = new QPushButton(_buttonGroupBox);
163  _pushButtonRemRegime->setText(TR("id_supprimer"));
165 
166  _comboBoxSelectRegime = new QComboBox(_buttonGroupBox);
167  _comboBoxSelectRegime->setEditable(true);
169 
170  _pushButtonNewRegime = new QPushButton(_buttonGroupBox);
171  _pushButtonNewRegime->setText(TR("id_nouveau"));
173 
174  _acousticInterfaceLayout->addWidget(_buttonGroupBox, 3, 0);
175  updateContent();
176 
177  // Disambiguate the overloaded QComboBox::activated signal
178  void (QComboBox::*_qComboBox_activated)(int) = &QComboBox::activated;
179 
180  connect(_pushButtonNewRegime, &QPushButton::clicked, this, &TYAcousticInterfaceWidget::createNewRegime);
181  connect(_pushButtonRemRegime, &QPushButton::clicked, this, &TYAcousticInterfaceWidget::deleteRegime);
182  connect(_comboBoxSelectRegime, _qComboBox_activated, this, &TYAcousticInterfaceWidget::changeRegime);
183  connect(_lineEditDensiteSrcsH, &QLineEdit::textChanged, this, &TYAcousticInterfaceWidget::updateDensite);
184  connect(_lineEditDensiteSrcsV, &QLineEdit::textChanged, this, &TYAcousticInterfaceWidget::updateDensite);
185  connect(_pushButtonShowSpectre, &QPushButton::clicked, this, &TYAcousticInterfaceWidget::showSpectre);
186  connect(_checkBoxIsRayonnant, &QCheckBox::clicked, this, &TYAcousticInterfaceWidget::updateRayonnant);
187  connect(_checkBoxUseAtt, &QCheckBox::clicked, this, &TYAcousticInterfaceWidget::useAttenuateur);
188  connect(_pushButtonSpectreAtt, &QPushButton::clicked, this, &TYAcousticInterfaceWidget::editAtt);
189  connect(_pRadioButtonImposee, &QRadioButton::clicked, this, &TYAcousticInterfaceWidget::showSpectre);
190 
191  _comboBoxSelectRegime->installEventFilter(this);
192 }
193 
195 
197 {
198  _pRadioButtonCalculee->setEnabled(false);
199  _pRadioButtonImposee->setEnabled(false);
200 }
201 
203 {
204  QString num;
205 
206  _lineEditDensiteSrcsH->setText(num.setNum(getElement()->getDensiteSrcsH(), 'f', 2));
207  _lineEditDensiteSrcsV->setText(num.setNum(getElement()->getDensiteSrcsV(), 'f', 2));
208 
209  // Mise a jour a partir du regime courant
211 
212  // Mise a jour du combo des regimes
214 
215  // Inactivation de la possibilite de changer de regime
216  _pushButtonRemRegime->setEnabled(getElement()->getIsRegimeChangeAble());
217  _comboBoxSelectRegime->setEnabled(getElement()->getIsRegimeChangeAble());
218  _pushButtonNewRegime->setEnabled(getElement()->getIsRegimeChangeAble());
219 }
220 
222 {
223  if (_checkBoxUseAtt->isChecked())
224  {
225  getElement()->setUseAtt(true);
226  // Va associer le meme atténuateur aux éléments
227  // acoustiques composant celui-ci
228  getElement()->propagateAtt(getElement()->getAtt());
229  }
230  else
231  {
232  getElement()->setUseAtt(false);
233  // Si un atténuateur était présent, il s'agit d'une suppression
234  if (getElement()->getAtt())
235  {
236  getElement()->setAtt(NULL);
237  // alors on propage la suppression aux sous-éléments
238  getElement()->propagateAtt(NULL);
239  }
240  }
241 
242  if (_pRadioButtonCalculee->isChecked())
243  {
245  }
246  else
247  {
249  }
250 
252 
253  if (_modified)
254  {
255  getElement()->setDensiteSrcsH(_lineEditDensiteSrcsH->text().toDouble());
256  getElement()->setDensiteSrcsV(_lineEditDensiteSrcsV->text().toDouble());
257  }
258 
260 
262  // emit modified();
263 }
264 
266 {
267  _modified = true;
268 }
269 
271 
273 {
274  // Si l'utilisateur annule, on restitue l'etat du regime courant
275  getElement()->setCurRegime(getElement()->getCurRegime());
276 }
277 
279 {
280  getElement()->setUseAtt(_checkBoxUseAtt->isChecked());
281  _groupBoxAtt->setEnabled(_checkBoxUseAtt->isChecked());
282 
283  // Si on selectionne un attenuateur on ouvre immediatement la boite de dialogue de saisie
284  if (_checkBoxUseAtt->isChecked())
285  {
286  editAtt();
287  }
288 }
289 
291 {
292  if (getElement()->getAtt() == NULL) // Si l'attenuateur n'existe pas, on le cree
293  {
294  LPTYAttenuateur pAtt = new TYAttenuateur();
295  getElement()->setAtt(pAtt);
296  }
297 
298  int ret = getElement()->getAtt()->edit(this);
299 
300  if (ret == QDialog::Accepted)
301  {
302  _lineEditNomAtt->setText(getElement()->getAtt()->getName());
303  }
304 }
305 
307 {
308  TYSpectre& spectre = getElement()->getCurrentSpectre();
309 
310  if (_pRadioButtonCalculee->isChecked())
311  {
312  spectre.setIsReadOnly(true);
313  }
314 
315  spectre.edit(this);
316 
317  spectre.setIsReadOnly(false);
318 }
319 
321 {
322  // On sauve l'etat du regime courant avant d'en rajouter un autre
324 
325  // Creation du nouveau regime
326  getElement()->addRegime();
327 
328  // Choix du nouveau regime comme regime courant
329  getElement()->setCurRegime(-1);
330 
331  // Mise a jour depuis le regime courant
333 
334  // Mise a jour du combo des regimes
336 }
337 
339 {
340  bool status = true;
341  TYRegime& regime = getElement()->getRegimeNb(getElement()->getCurRegime(), status);
342 
343  regime._isRayonnant = _checkBoxIsRayonnant->isChecked();
344  regime._useAtt = _checkBoxUseAtt->isChecked();
345 
346  if (_pRadioButtonCalculee->isChecked())
347  {
349  }
350  else
351  {
353  }
354 
355  regime._spectre = getElement()->getCurrentSpectre();
356 
357  if (regime._useAtt)
358  {
359  regime._pAtt = getElement()->getAtt();
360  }
361 }
362 
364 {
365  getElement()->remRegime(_comboBoxSelectRegime->currentIndex());
366 
368 
369  // Mise a jour du combo box
371 }
372 
374 {
375  // Sauvegarde du regime courant
377 
378  // Changement de regime
379  getElement()->setCurRegime(regime);
380 
382 
383  emit regimeChanged(regime);
384 }
385 
387 {
388  bool status = true;
389 
390  TYRegime& regime = getElement()->getRegimeNb(getElement()->getCurRegime(), status);
391  QString actualName = regime.getName();
392 
393  QLineEdit* LE = _comboBoxSelectRegime->lineEdit();
394  QString nomRegime = LE->text();
395 
396  // Si le nom n'a pas change, on ne fait rien.
397  if (actualName == nomRegime)
398  {
399  return;
400  }
401 
402  // Actualisation du nom du regime pour les sous-elements
403  getElement()->setRegimeName(nomRegime);
404 
406 }
407 
409 {
410  _comboBoxSelectRegime->clear();
411 
412  // Remplissage du comboBox des regimes
413  QString nom;
414  bool status = true;
415  for (short i = 0; i < getElement()->getNbRegimes(); i++)
416  {
417  nom = getElement()->getRegimeNb(i, status).getName();
418  _comboBoxSelectRegime->insertItem(i, nom);
419  }
420 
421  // On affiche le regime courant
422  _comboBoxSelectRegime->setCurrentIndex(getElement()->getCurRegime());
423 }
424 
426 {
427  _checkBoxIsRayonnant->setChecked(getElement()->getIsRayonnant());
428 
429  _groupBoxAtt->setEnabled(getElement()->getUseAtt());
430 
431  if (getElement()->getTypeDistribution() == TYAcousticInterface::TY_PUISSANCE_CALCULEE)
432  {
433  _pRadioButtonCalculee->setChecked(true);
434  }
435  else
436  {
437  _pRadioButtonImposee->setChecked(true);
438  }
439 
440  if (getElement()->getUseAtt() && getElement()->getAtt())
441  {
442  _checkBoxUseAtt->setChecked(true); // Attenuateur ou pas
443  _lineEditNomAtt->setText(getElement()->getAtt()->getName());
444  }
445  else
446  {
447  _checkBoxUseAtt->setChecked(false); // Attenuateur ou pas
448  _lineEditNomAtt->setText("");
449  }
450 }
451 
453 {
454  _checkBoxIsRayonnant->setEnabled(active);
455 }
456 
458 {
459  return _checkBoxIsRayonnant->isEnabled();
460 }
461 
462 bool TYAcousticInterfaceWidget::eventFilter(QObject* obj, QEvent* event)
463 {
464  if (obj == _comboBoxSelectRegime)
465  {
466  if (event->type() == QEvent::FocusOut)
467  {
468  renameRegime();
469  }
470  else
471  {
472  return false;
473  }
474  }
475  else
476  {
477  // pass the event on to the parent class
478  return QWidget::eventFilter(obj, event);
479  }
480 
481  return true;
482 }
#define TR(id)
Outil IHM pour une interface acoustique (fichier header)
outil IHM pour une entrée utilisateur (fichier header)
bool eventFilter(QObject *obj, QEvent *ev)
bool _modified
Signale une modification des parametres.
bool _bAddRemRegimeOk
Autorise ou non l'ajout et la suppression de regime.
TYAcousticInterfaceWidget(TYAcousticInterface *pElement, QWidget *_pParent=NULL)
TYAcousticInterface * getElement()
void setCheckBoxRayonnantState(const bool &active)
void updateDensite()
Note que la densite de source a ete modifiee.
virtual void updateCurrentRegime()
virtual void setDensiteSrcsH(double densite, bool recursif=true)
LPTYAttenuateur getAtt()
TYRegime & getRegimeNb(const int &nb, bool &status)
size_t getNbRegimes() const
TYSpectre & getCurrentSpectre()
void setAtt(LPTYAttenuateur pAtt)
void setTypeDistribution(int typeDistri)
virtual int addRegime(const TYRegime &regime)
virtual void setUseAtt(bool state)
virtual void setDensiteSrcsV(double densite, bool recursif=true)
virtual void setIsRayonnant(bool rayonnant=true, bool recursif=true)
virtual void setCurRegime(int regimeNumber)
virtual void propagateAtt(LPTYAttenuateur pAtt)
virtual bool remRegime(int regime)
virtual void setRegimeName(const QString &name)
static void setIsSavedOk(const bool &toSave)
Definition: TYElement.h:914
virtual QString getName() const
Definition: TYElement.h:691
bool _useAtt
Definition: TYRegime.h:197
bool _isRayonnant
Definition: TYRegime.h:196
TYSpectre _spectre
Definition: TYRegime.h:199
LPTYAttenuateur _pAtt
Definition: TYRegime.h:200
virtual void setIsReadOnly(bool flag)
Set/Get du flag _isReadOnly.
Definition: TYSpectre.h:141