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