Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYSpectreWidget.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 
23 #include <qtablewidget.h>
24 #include <qtabwidget.h>
25 #include <qpainter.h>
26 #include <QtPrintSupport/QPrinter>
27 #include <QtPrintSupport/QPrintDialog>
28 #include <qfile.h>
29 #include <qtextstream.h>
30 #include <qfiledialog.h>
31 #include <qradiobutton.h>
32 #include <qpixmap.h>
33 #include <qbuttongroup.h>
34 #include <qmessagebox.h>
35 #include <qheaderview.h>
36 #include <QtWidgets>
37 
38 #include "TYSpectreWidget.h"
42 #include "TYHistoWidget.h"
43 #include "TYCourbeWidget.h"
44 #include "TYElementWidget.h"
45 
46 // Added by qt3to4:
47 #include <QHBoxLayout>
48 #include <QLabel>
49 #include <QGridLayout>
50 #include <QFrame>
51 #include <QBoxLayout>
52 
53 // using namespace Qt;
54 
55 #define TR(id) OLocalizator::getString("TYSpectreWidget", (id))
56 
57 // --------------------------------------
58 // Fournisseur global de forme du spectre
59 // --------------------------------------
61 
63 {
64  s_formProvider = p;
66 }
68 {
69  return s_formProvider;
70 }
71 
72 // --------------------------------------------
73 // Fournisseur global de pondération du spectre
74 // --------------------------------------------
76 
78 {
79  s_pondProvider = p;
80 }
82 {
83  return s_pondProvider;
84 }
85 
87 
88 TYSpectreWidget::TYSpectreWidget(TYSpectre* pElement, QWidget* _pParent /*=NULL*/)
89  : TYWidget(pElement, _pParent)
90 {
91  // Par defaut precision prend la valeur affectee a la classe TYSpectre pour le stockage en XML
93 
94  // On utilise une copie du spectre associe a ce widget
95 
96  // Et on conserve ce spectre par ailleurs
97  _pTmpSpectre = pElement;
98 
100 
101  _etatSpectre = "tiersOctave";
102  _pondSpectre = "dB(Z)";
103 
104  resize(450, 700);
105  setWindowTitle(TR("id_caption"));
106 
107  _elmW = new TYElementWidget(getElement(), this);
108 
109  _spectreLayout = new QGridLayout();
110 
111  _spectreLayout->addWidget(_elmW, 0, 0);
112 
113  _groupBox = new QGroupBox(this);
114  _groupBox->setTitle(TR(""));
115  _groupBoxLayout = new QGridLayout();
116  _groupBoxLayout->setAlignment(Qt::AlignTop);
117  _groupBox->setLayout(_groupBoxLayout);
118 
119  _formButtonGroup = new QButtonGroup();
120  _formButtonGroup->setExclusive(true);
121  _pondButtonGroup = new QButtonGroup();
122  _pondButtonGroup->setExclusive(true);
123 
124  _radioButtonTiers = new QRadioButton();
125  _radioButtonTiers->setText(TR("id_radiobutton_tiers"));
126  _radioButtonTiers->setChecked(true);
128 
129  _radioButtonOctave = new QRadioButton();
130  _radioButtonOctave->setText(TR("id_radiobutton_octave"));
132 
133  _radioButtonPondZ = new QRadioButton();
134  _radioButtonPondZ->setText(TR("id_radiobutton_pond_z"));
135  _radioButtonPondZ->setChecked(true);
137 
138  _radioButtonPondA = new QRadioButton();
139  _radioButtonPondA->setText(TR("id_radiobutton_pond_a"));
141 
142  QGridLayout* groupBoxRadioLayout = new QGridLayout();
143  groupBoxRadioLayout->addWidget(_radioButtonTiers, 0, 0);
144  groupBoxRadioLayout->addWidget(_radioButtonOctave, 0, 1);
145  groupBoxRadioLayout->addWidget(_radioButtonPondZ, 1, 0);
146  groupBoxRadioLayout->addWidget(_radioButtonPondA, 1, 1);
147 
148  QGroupBox* groupBoxRadio = new QGroupBox();
149  groupBoxRadio->setTitle("");
150  groupBoxRadio->setLayout(groupBoxRadioLayout);
151 
152  _groupBoxLayout->addWidget(groupBoxRadio, 0, 0, 1, 2);
153 
154  _lineEditRq = new QLineEdit(_groupBox);
155  _lineEditRq->setText(getElement()->getRemarque());
156  _groupBoxLayout->addWidget(_lineEditRq, 2, 1);
157 
158  _labeRq = new QLabel(_groupBox);
159  _labeRq->setText(TR("id_rq_label"));
160  _groupBoxLayout->addWidget(_labeRq, 2, 0);
161 
162  _comboBoxType = new QComboBox(_groupBox);
163  _comboBoxType->insertItem(0, TR("id_spectre_type_att"));
164  _comboBoxType->insertItem(1, TR("id_spectre_type_abso"));
165  _comboBoxType->insertItem(2, TR("id_spectre_type_lw"));
166  _comboBoxType->insertItem(3, TR("id_spectre_type_lp"));
167  _comboBoxType->insertItem(4, TR("id_spectre_type_autre"));
168  _comboBoxType->setCurrentIndex(getElement()->getType());
169  _groupBoxLayout->addWidget(_comboBoxType, 1, 1);
170 
171  _labelType = new QLabel(_groupBox);
172  _labelType->setText(TR("id_type_label"));
173  _groupBoxLayout->addWidget(_labelType, 1, 0);
174 
175  _spectreLayout->addWidget(_groupBox, 1, 0);
176 
177  // Tableau
178  _tableau = new QTableWidget();
179  QStringList stringList;
180  stringList.append(TR("id_freq"));
181  stringList.append("");
182  _tableau->setHorizontalHeaderLabels(stringList);
183  _tableau->setColumnCount(2);
184  _nbFreq = pElement->getNbValues();
185 
186  // histo
187  _histoWidget = new TYHistoWidget(this, false);
188  // courbe
189  _courbeWidget = new TYCourbeWidget(this, false);
190 
191  _tabWidget = new QTabWidget(this);
192  _tabWidget->insertTab(0, _tableau, TR("id_tableau"));
193  _tabWidget->insertTab(1, _histoWidget, TR("id_histogramme"));
194  _tabWidget->insertTab(2, _courbeWidget, TR("id_courbe"));
195 
196  _spectreLayout->addWidget(_tabWidget, 2, 0);
197 
198  QGroupBox* buttonGroupBox = new QGroupBox(this);
199  buttonGroupBox->setTitle(TR(""));
200  QGridLayout* buttonGroupBoxLayout = new QGridLayout();
201  buttonGroupBox->setLayout(buttonGroupBoxLayout);
202  buttonGroupBoxLayout->setAlignment(Qt::AlignTop);
203 
204  _pushButtonImport = new QPushButton(buttonGroupBox);
205  _pushButtonImport->setText(TR("id_import_csv"));
206  buttonGroupBoxLayout->addWidget(_pushButtonImport, 0, 0);
207 
208  _pushButtonExport = new QPushButton(buttonGroupBox);
209  _pushButtonExport->setText(TR("id_export_csv"));
210  buttonGroupBoxLayout->addWidget(_pushButtonExport, 0, 1);
211 
212  _spectreLayout->addWidget(buttonGroupBox, 3, 0);
213 
214  update();
215 
216  _printer = new QPrinter();
217 
218  connect(_radioButtonTiers, &QRadioButton::clicked, this, &TYSpectreWidget::changeOctave);
219  connect(_radioButtonOctave, &QRadioButton::clicked, this, &TYSpectreWidget::changeOctave);
220  connect(_radioButtonPondZ, &QRadioButton::clicked, this, &TYSpectreWidget::changePonderation);
221  connect(_radioButtonPondA, &QRadioButton::clicked, this, &TYSpectreWidget::changePonderation);
222  connect(_pushButtonExport, &QPushButton::clicked, this, &TYSpectreWidget::exportCsv);
223  connect(_pushButtonImport, &QPushButton::clicked, this, &TYSpectreWidget::importCsv);
224  connect(_tableau, &QTableWidget::cellChanged, this, &TYSpectreWidget::tabValueChanged);
225 
226  setLayout(_spectreLayout);
227  updateContent();
228 
229  // Initialisation octave/tiers via provider app (si défini)
231  // Initialisation dB(A)/dB(Z) via provider app (si défini)
233 }
234 
236 {
237  delete _printer;
238 }
239 
241 {
242  _elmW->updateContent();
243 
244  _lineEditRq->setText(_pTmpSpectre->getRemarque());
245  _comboBoxType->setCurrentIndex(_pTmpSpectre->getType());
246 
247  _comboBoxType->setEnabled(false);
248 
249  // Affichage de l'unite
250  QString unite = "dB";
253  {
254  unite = "";
255  _radioButtonPondZ->setEnabled(false);
256  _radioButtonPondA->setEnabled(false);
257  _radioButtonPondZ->setChecked(true);
258  _radioButtonPondA->setChecked(false);
259  }
260  else if (_pondSpectre == "dB(A)")
261  {
262  unite = "dBA";
263  }
264 
266 
267  QStringList stringList;
268  stringList.append(TR("id_freq"));
269  stringList.append(unite);
270  _tableau->setHorizontalHeaderLabels(stringList);
271 
272  // Mise a jour du tableau
274 
275  // Inactivation de la colonne des frequences (toujours !)
276  for (int i = 0; i < _tableau->rowCount(); i++)
277  {
278  _tableau->item(i, 0)->setFlags(QFlag(0));
279  }
280 
281  // Spectre en read only si le mode de calcul est "Calcule"
283  {
284  setContentEnabled(false);
285  }
286 }
287 
289 {
290  _elmW->apply();
291 
292  getElement()->setRemarque(_lineEditRq->text());
293  getElement()->setType((TYSpectreType)_comboBoxType->currentIndex());
294 
295  // On repasse le spectre en Tiers d'octave si necessaire
296  if (!_radioButtonTiers->isChecked())
297  {
298  _radioButtonTiers->setChecked(true);
299  changeOctave();
300  }
301 
302  // Mis a jour du spectre a partir du tableau
304 
305  emit modified();
306 }
307 
308 void TYSpectreWidget::tabValueChanged(int row, int col)
309 {
310  if (col == 1 && _tableau->item(row, col) != nullptr)
311  {
312  // Translate input value to double to see if it's a correct number
313  bool ok = false;
314  QString txt = _tableau->item(row, col)->text();
315  int index = txt.indexOf(',');
316  if (index > 0)
317  {
318  txt.replace(index, 1, '.');
319  _tableau->item(row, col)->setText(txt);
320  }
321  _tableau->item(row, col)->text().toDouble(&ok);
322 
323  // If value is not a valid number, get the original value in the spectrum and return
324  if (!ok)
325  {
326  _tableau->item(row, 1)->setText(
327  QString().setNum(_pTmpSpectre->getTabValReel()[row], 'f', _precision));
328  return;
329  }
330 
331  // Else, we copy value to all the selected cells
332  for (int i = 0; i < _nbFreq; i++)
333  {
334  if ((_tableau->item(i, col)) && ((_tableau->item(i, col))->isSelected()))
335  {
336  _tableau->item(i, col)->setText(_tableau->item(row, col)->text());
337  }
338  }
339 
340  _isModified = true;
341  }
342 }
343 
345 {
346  for (int i = 0; i < _nbFreq; i++)
347  {
348  if (state)
349  {
350  _tableau->item(i, 1)->setFlags(Qt::ItemIsEditable);
351  }
352  else
353  {
354  _tableau->item(i, 1)->setFlags(QFlag(0));
355  }
356  }
357 
358  _pushButtonImport->setEnabled(state);
359 }
360 
362 {
363  std::vector<QString> tmp;
364 
365  QString qFileName = QFileDialog::getOpenFileName(this, "Choose a file", "", "CSV (*.csv)");
366 
367  if (!qFileName.isEmpty())
368  {
369  // On charge les donnees
370  if (!qFileName.endsWith("csv"))
371  {
372  qFileName += ".csv";
373  }
374 
375  std::ifstream file(
376 #ifdef _WIN32
377  std::filesystem::path(qFileName.toStdWString())
378 #else
379  std::filesystem::path(qFileName.toUtf8().constData())
380 #endif
381  );
382 
383  if (!file.is_open())
384  {
385  const QString title = TR("id_error_loading_title");
386  const QString text = TR("id_error_loading_spectrum").arg(QDir::toNativeSeparators(qFileName));
387 
388  QMessageBox::critical(this, title, text);
389 
390  std::cerr << "Failed to open file: " << qFileName.toUtf8().constData() << std::endl;
391  return;
392  }
393  std::string line;
394  int i = 0;
395  while (std::getline(file, line))
396  {
397  switch (i)
398  {
399  case 0:
400  break;
401  case 1: // On saute la ligne des labels
402  break;
403  default:
404  tmp.push_back(QString::fromStdString(line));
405  break;
406  }
407 
408  i++;
409  }
410 
411  bool bOctave = true;
412 
413  // récupère la liste des fréquence en fonction du type de spectre
414  std::vector<double> freqListeOctave;
415  std::vector<double> freqListeTiersOctave;
418 
419  // On teste si la forme du spectre est en Octave
420  for (int i = 0; i < tmp.size(); i++)
421  {
422  for (int j = 0; j < freqListeOctave.size(); j++)
423  {
424  if (tmp[i].section(";", 0, 0).toDouble() == freqListeOctave[j])
425  break;
426  else if (j == freqListeOctave.size() - 1)
427  {
428  bOctave = false;
429  }
430  }
431  }
432 
433  // Si la forme n'est pas en octave alors on vérifie que les fréquences correspondent bien à une forme
434  // tiers d'octave
435  if (!bOctave)
436  {
437  for (int i = 0; i < tmp.size(); i++)
438  {
439  for (int j = 0; j < freqListeTiersOctave.size(); j++)
440  {
441  if (tmp[i].section(";", 0, 0).toDouble() == freqListeTiersOctave[j])
442  break;
443  // Si une fréquence est invalide pour la forme tiers d'octave alors on sort sans importer
444  // le spectre
445  else if (j == freqListeTiersOctave.size() - 1)
446  {
447  QMessageBox::warning(this, "Tympan", TR("id_warning_freq_invalid"), QMessageBox::Yes);
448  return;
449  }
450  }
451  }
452  }
453 
454  if (bOctave) // si spectre en octave
455  {
456  // On modifie le checkBox indiquant l'etat octave-1/3 d'octave ce qui convertit le spectre en
457  // octave
458  _radioButtonOctave->setChecked(true);
459  _etatSpectre = "octave";
460  }
461  else // Spectre en (1/3)
462  {
463  // On modifie le checkBox indiquant l'etat octave-1/3 d'octave ce qui convertit le spectre en
464  // tiers d'octave
465  _radioButtonTiers->setChecked(true);
466  _etatSpectre = "tiersOctave";
467  }
468 
469  if ((bOctave && (tmp.size() < 9)) ||
470  (!bOctave && (tmp.size() < 31))) // nb valeurs incorrect (9 en 1/1, 31 en 1/3)
471  {
472  int ret = QMessageBox::warning(this, "Tympan", TR("id_warning_file_not_ok"), QMessageBox::Yes,
473  QMessageBox::No);
474  if (ret == QMessageBox::No)
475  {
476  return;
477  }
478  }
479 
480  std::vector<double> freqListe = freqListeTiersOctave;
481  if (bOctave)
482  freqListe = freqListeOctave;
483 
484  // Réinitialisation du tableau
485  resetTab();
486 
487  // On remplit le tableau avec les valeurs
488  _tableau->setRowCount(static_cast<int>(freqListe.size()));
489  for (int i = 0; i < freqListe.size(); i++)
490  {
491  // On écrit 1 ligne par fréquence qui sera dans le spectre final
492  _tableau->setItem(i, 0, new QTableWidgetItem(QString::number(freqListe[i])));
493 
494  for (int j = 0; j < tmp.size(); j++)
495  {
496  double test1 = freqListe[i];
497  double test2 = tmp[j].section(";", 0, 0).toDouble();
498  // On regarde chaque fréquence importée jusqu'à avoir trouvé celle correspondant à la ligne en
499  // cours. Puis on ajoute le niveau correspondant
500  if (tmp[j].section(";", 0, 0).toDouble() == freqListe[i])
501  {
502  _tableau->setItem(i, 1, new QTableWidgetItem(tmp[j].section(";", 1, 1)));
503  break;
504  }
505  else if (j == tmp.size() - 1)
506  {
507  // Si la fréquence n'est pas présente dans le fichier importé, on utilise la valeur par
508  // défaut
509  int defVal = TY_SPECTRE_DEFAULT_VALUE;
510  if (bOctave)
511  defVal = TY_SPECTRE_OCT_DEFAULT_VALUE;
512 
513  _tableau->setItem(i, 1, new QTableWidgetItem(QString::number(defVal)));
514  }
515  }
516  }
517  }
518 }
519 
521 {
522  QString qFileName = QFileDialog::getSaveFileName(this, "Choose a file", "", "CSV (*.csv)");
523 
524  if (!qFileName.isEmpty())
525  {
526  if (!qFileName.endsWith(".csv"))
527  {
528  qFileName += ".csv";
529  }
530 
531  QFile f(qFileName);
532 
533  if (f.open(QIODevice::WriteOnly))
534  {
535  QTextStream s(&f);
536 
537  // Ajout du type de spectre 1/1 ou 1/3
538  int type = _radioButtonOctave->isChecked() ? 1 : 3;
539  s << type << '\n';
540 
541  // Ajout entete de colonne
542  s << TR("id_freq") << ";";
543  if (_pondSpectre == "dB(A)")
544  {
545 
546  s << "dB(A)\n";
547  }
548  else
549  {
550  s << "dB(Z)\n";
551  }
552 
553  // Ecriture contenu du spectre
554  int nbFreq = _tableau->rowCount();
555  for (int i = 0; i < nbFreq; i++)
556  {
557  s << _tableau->item(i, 0)->text() << ";" << _tableau->item(i, 1)->text() << "\n";
558  }
559 
560  f.close();
561  }
562  }
563 }
564 
565 static void processEvents();
566 
567 void processEvents()
568 {
569  qApp->processEvents();
570 }
571 
573 {
574  LPTYSpectre pSpectre = new TYSpectre();
575  pSpectre->setType(_pTmpSpectre->getType()); // Recopie du type du spectre edite
576  bool isChanged = false;
577 
578  // Effectue la conversion
579  if (_radioButtonTiers->isChecked() && _etatSpectre != "tiersOctave") // Passage de 1/1 en 1/3
580  {
581  pSpectre->setForm(SPECTRE_FORM_OCT);
582 
583  // Creation des valeurs du spectre depuis le tableau
584  tableauToSpectre(pSpectre.getRealPointer());
585 
586  // Passage du spectre en 1/3
587  *pSpectre = pSpectre->toTOct();
588 
589  _etatSpectre = "tiersOctave";
590  isChanged = true;
591  }
592  else if (_radioButtonOctave->isChecked() && _etatSpectre != "octave") // Passage de 1/3 en 1/1
593  {
595  {
596  int ret = QMessageBox::warning(this, "Tympan", TR("id_warning_converting_TO_to_Oct"),
597  QMessageBox::Yes, QMessageBox::No);
599  if (ret == QMessageBox::No)
600  {
601  _radioButtonTiers->setChecked(true);
602  return;
603  }
604  }
605 
606  pSpectre->setForm(SPECTRE_FORM_TIERS);
607 
608  // Creation des valeurs du spectre depuis le tableau
609  tableauToSpectre(pSpectre.getRealPointer());
610 
611  // Passage du spectre en 1/1
612  *pSpectre = pSpectre->toOct();
613 
614  _etatSpectre = "octave";
615  isChanged = true;
616  }
617 
618  // Remplissage du tableau
619  if (isChanged)
620  {
621  spectreToTableau(pSpectre);
622  _histoWidget->update();
623  _courbeWidget->update();
624  }
625 
626  _nbFreq = pSpectre->getNbValues();
627  // Grise la colonne des frequences
628  for (int i = 0; i < _tableau->rowCount(); i++)
629  {
630  _tableau->item(i, 0)->setFlags(QFlag(0));
631  }
632 
634  {
635  // Grise la colonne des dB
636  setContentEnabled(false);
637  }
638 }
639 
641 {
642  LPTYSpectre pSpectre = new TYSpectre();
643  pSpectre->setType(_pTmpSpectre->getType()); // Recopie du type du spectre edite
644  if (_etatSpectre == "octave")
645  {
646  pSpectre->setForm(SPECTRE_FORM_OCT);
647  }
648  bool isChanged = false;
649 
650  // Effectue la conversion
651  if (_radioButtonPondZ->isChecked() && _pondSpectre != "dB(Z)") // Passage de dB(A) à dB(Z)
652  {
653  // Creation des valeurs du spectre depuis le tableau
654  tableauToSpectre(pSpectre.getRealPointer());
655 
656  _pondSpectre = "dB(Z)";
657  isChanged = true;
658  }
659  else if (_radioButtonPondA->isChecked() && _pondSpectre != "dB(A)") // Passage de dB(Z) à dB(A)
660  {
661  // Creation des valeurs du spectre depuis le tableau
662  tableauToSpectre(pSpectre.getRealPointer());
663 
664  _pondSpectre = "dB(A)";
665  isChanged = true;
666  }
667 
668  // code ci-dessous à factoriser
669  // Remplissage du tableau
670  if (isChanged)
671  {
672  spectreToTableau(pSpectre);
673  _histoWidget->update();
674  _courbeWidget->update();
675  }
676 
677  _nbFreq = pSpectre->getNbValues();
678  // Grise la colonne des frequences
679  for (int i = 0; i < _tableau->rowCount(); i++)
680  {
681  _tableau->item(i, 0)->setFlags(QFlag(0));
682  }
683 
685  {
686  // Grise la colonne des dB
687  setContentEnabled(false);
688  }
689 }
690 
692 {
693  if (_comboBoxType->currentIndex() == 1)
694  {
695  _histoWidget->setDbType(true);
696  _courbeWidget->setDbType(true);
697  }
698  else
699  {
700  _histoWidget->setDbType(false);
701  _courbeWidget->setDbType(false);
702  }
703 }
704 
706 {
707  // Reset tab
708  for (int i = 0; i < _tableau->rowCount(); i++)
709  {
710  _tableau->takeItem(i, 0);
711  _tableau->takeItem(i, 1);
712  }
713 
714  _tableau->setRowCount(0);
715 }
716 
718 {
719  assert(pSpectre);
720 
721  // Initialisation du tableau
722  resetTab();
723 
724  // Recuperation du tableau des frequences (octave ou 1/3 d'octaves)
726  if (_pondSpectre == "dB(A)")
727  {
728  // Créer operateur + et - sur TYSpectre
729  TYSpectre pondASpectre{};
730  if (pSpectre->getForm() == SPECTRE_FORM_TIERS)
731  {
732  pondASpectre = TYSpectre{*pSpectre->downcast_ospectre() + OSpectre::pondA()};
733  }
734  else if (pSpectre->getForm() == SPECTRE_FORM_OCT)
735  {
736  pondASpectre = TYSpectre{*pSpectre->downcast_ospectre() + OSpectreOctave::pondA()};
737  }
738  pondASpectre.setForm(pSpectre->getForm());
739  pondASpectre.setType(pSpectre->getType());
740  pSpectre = &pondASpectre;
741  }
742 
743  int nbFreq = pSpectre->getNbValues();
744 
745  _tableau->setColumnCount(2);
746  _tableau->setRowCount(nbFreq);
747  for (int i = 0; i < nbFreq; i++)
748  {
749  _tableau->setItem(i, 0, new QTableWidgetItem((QString().setNum(tabFreq[i], 'f', 2))));
750  _tableau->setItem(
751  i, 1, new QTableWidgetItem((QString().setNum(pSpectre->getTabValReel()[i], 'f', _precision))));
752  }
753 }
754 
756 {
757  assert(pSpectre);
758 
759  bool ok = false;
760  double val = -200.0;
761  int indexDepart = 0;
762 
763  int nbFreq = _tableau->rowCount();
764 
765  // Pour toutes les frequences
766  for (int i = indexDepart; i < nbFreq; i++)
767  {
768  val = _tableau->item(i, 1)->text().toDouble(
769  &ok); // Suppose que la valeur a freq donnee stockee en colonne 1
770  if (ok)
771  {
772  pSpectre->getTabValReel()[i] = val;
773  }
774  }
775  if (_pondSpectre == "dB(A)")
776  {
777  // Créer operateur + et - sur TYSpectre
778  TYSpectre pondZSpectre{};
779  if (pSpectre->getForm() == SPECTRE_FORM_TIERS)
780  {
781  pondZSpectre = TYSpectre{*pSpectre->downcast_ospectre() - OSpectre::pondA()};
782  }
783  else if (pSpectre->getForm() == SPECTRE_FORM_OCT)
784  {
785  pondZSpectre = TYSpectre{*pSpectre->downcast_ospectre() - OSpectreOctave::pondA()};
786  }
787  pondZSpectre.setForm(pSpectre->getForm());
788  pondZSpectre.setType(pSpectre->getType());
789  *pSpectre = pondZSpectre;
790  }
791 }
792 
794 {
795  assert(pSpectre);
796 
797  if (_radioButtonOctave->isChecked())
798  {
799  *pSpectre = pSpectre->toOct();
800  }
801 
802  tableauToSpectre(pSpectre);
803 }
804 
805 // ----------------------------------------------------------
806 // Applique la forme initiale en utilisant le provider global
807 // ----------------------------------------------------------
809 {
810  if (!s_formProvider)
811  return;
812 
813  const TYSpectreForm form = s_formProvider();
814 
815  switch (form)
816  {
817  case SPECTRE_FORM_OCT:
818  if (!_radioButtonOctave->isChecked())
819  {
820  _radioButtonOctave->setChecked(true);
821  changeOctave();
822  }
823  break;
824  case SPECTRE_FORM_TIERS:
825  default:
826  // Par défaut, on reste en 1/3 d’octave (déjà coché)
827  break;
828  }
829 }
830 
831 // ----------------------------------------------------------------
832 // Applique la pondération initiale en utilisant le provider global
833 // ----------------------------------------------------------------
835 {
836  if (!s_pondProvider)
837  return;
838 
839  const QString pond = s_pondProvider();
840 
841  if (pond == "dB(A)" && !_radioButtonPondA->isChecked())
842  {
843  _radioButtonPondA->setChecked(true);
845  }
846 }
NxReal s
Definition: NxVec3.cpp:317
outil IHM pour une courbe (fichier header)
outil IHM pour un element (fichier header)
outil IHM pour un histogramme (fichier header)
Boite de dialogue des parametres d'impression (fichier header)
const std::vector< double > tabFreq
#define TR(id)
outil IHM pour un spectre (fichier header)
OTabFreq TYTabFreq
Collection des frequences.
Definition: TYSpectre.h:27
void setForm(TYSpectreForm form)
Force the spectrum state (to use carefully ...)
Definition: spectre.h:181
unsigned int getNbValues() const
Number of values in the spectrum.
Definition: spectre.cpp:187
void setType(TYSpectreType type)
Set the spectrum type.
Definition: spectre.h:153
TYSpectreType getType() const
Get the spectrum type.
Definition: spectre.h:148
OSpectreAbstract & toTOct() const
Converts to one-third Octave.
Definition: spectre.cpp:709
OSpectreAbstract & toOct() const
Converts to Octave.
Definition: spectre.cpp:783
static OSpectreOctave pondA()
Build a weighted spectrum A.
Definition: spectre.cpp:1601
double * getTabValReel() override
Definition: spectre.h:357
static OSpectre pondA()
Build a weighted spectrum A.
Definition: spectre.cpp:1014
T * getRealPointer()
Definition: smartptr.h:291
classe de l'objet IHM pour une courbe
void setDbType(bool dbType)
classe de l'objet IHM pour un element
virtual void apply()
virtual void updateContent()
TYElement * getParent() const
Definition: TYElement.h:706
classe de l'outil IHM pour un histogramme
Definition: TYHistoWidget.h:39
void setDbType(bool dbType)
Definition: TYHistoWidget.h:57
void applyInitialPondFromProvider()
Applique la pondération initiale du spectre fournie par le provider.
virtual void apply()
QLineEdit * _lineEditRq
QString(*)() TYSpectrePondProvider
QGridLayout * _groupBoxLayout
virtual ~TYSpectreWidget()
QPrinter * _printer
void spectre(TYSpectre *pSpectre)
Construit un spectre a partir du contenu du widget.
int _precision
Precision d'affichage des spectres.
void resetTab()
Initialisation du tableau.
void tabValueChanged(int row, int col)
TYCourbeWidget * _courbeWidget
QRadioButton * _radioButtonOctave
QGroupBox * _groupBox
void tableauToSpectre(TYSpectre *pSpectre)
Mise a jour d'un spectre depuis le tableau.
static bool _warningConvertingTOtoOctShown
QRadioButton * _radioButtonPondA
TYElementWidget * _elmW
static TYSpectreFormProvider s_formProvider
QRadioButton * _radioButtonPondZ
void setContentEnabled(bool state)
QGridLayout * _spectreLayout
static void setSpectrePondProvider(TYSpectrePondProvider p)
TYHistoWidget * _histoWidget
void spectreToTableau(TYSpectre *pSpectre)
Mise a jour du tableau depuis un spectre.
QPushButton * _pushButtonImport
void applyInitialFormFromProvider()
Applique la forme initiale du spectre fournie par le provider.
static void setSpectreFormProvider(TYSpectreFormProvider p)
virtual void updateContent()
QPushButton * _pushButtonExport
TYSpectreForm(*)() TYSpectreFormProvider
static TYSpectrePondProvider spectrePondProvider()
TYSpectreWidget(TYSpectre *pElement, QWidget *_pParent=NULL)
QButtonGroup * _formButtonGroup
static TYSpectrePondProvider s_pondProvider
QComboBox * _comboBoxType
static TYSpectreFormProvider spectreFormProvider()
QButtonGroup * _pondButtonGroup
TYSpectre * _pTmpSpectre
QRadioButton * _radioButtonTiers
QTabWidget * _tabWidget
QTableWidget * _tableau
virtual void setForm(const TYSpectreForm &form)
Definition: TYSpectre.h:111
static int getXMLPrecision()
Get/Set de la precision de stockage des resultats (XML)
Definition: TYSpectre.h:180
virtual TYSpectreForm getForm()
Set/Get de la forme du spectre.
Definition: TYSpectre.h:107
virtual bool getIsReadOnly()
Set/Get du flag de conservation en BDD.
Definition: TYSpectre.h:135
virtual QString getRemarque() const
Set/Get des remarques.
Definition: TYSpectre.h:117
OSpectre * downcast_ospectre()
: return spectrum casted as OSpectre
Definition: TYSpectre.h:202
static const TYTabFreq getTabFreqNorm(TYSpectreForm form=SPECTRE_FORM_TIERS)
Definition: TYSpectre.cpp:419
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
void modified()
TYSpectreForm
Spectrum representation.
Definition: spectre.h:36
@ SPECTRE_FORM_TIERS
Definition: spectre.h:37
@ SPECTRE_FORM_OCT
Definition: spectre.h:38
TYSpectreType
Spectrum type.
Definition: spectre.h:27
@ SPECTRE_TYPE_AUTRE
Definition: spectre.h:32
@ SPECTRE_TYPE_ATT
Definition: spectre.h:28
@ SPECTRE_TYPE_ABSO
Definition: spectre.h:29