Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYRouteWidget.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 
21 #include <QMessageBox>
22 
23 #include "RoadEmissionNMPB08.h"
24 
27 #include "TYRouteWidget.h"
28 
29 #define TR(id) OLocalizator::getString("TYRouteWidget", (id))
30 
31 static struct
32 {
33  const char* name;
34  int id;
35 } RoadSurfaceFormulationMap[] = {{"BBUM 0/6", BBUM_0_6},
36  {"BBDr 0/10", BBDR_0_10},
37  {"BBTM 0/6 - type 2", BBTM_0_6_type2},
38  {"BBTM 0/6 - type 1", BBTM_0_6_type1},
39  {"BBTM 0/10 - type 2", BBTM_0_10_type2},
40  {"BBSG 0/10", BBSG_0_10},
41  {"BBTM 0/10 - type 1", BBTM_0_10_type1},
42  {"BBUM 0/10", BBUM_0_10},
43  {"ECF", ECF},
44  {"BBSG 0/14", BBSG_0_14},
45  {"BBTM 0/14", BBTM_0_14},
46  {"ES 6/10", ES_6_10},
47  {"BC", BC},
48  {"ES 10/14", ES_10_14}};
49 
50 TYRouteWidget::TYRouteWidget(TYRoute* pElement, QWidget* _pParent /*=NULL*/) : TYWidget(pElement, _pParent)
51 {
52  // Initialise the QT Designer generated UI base
53  setupUi(this);
54  bool connect_ok = false;
55 
56  // Display the widget for pElement as an AcousticSource in an additional tab
57  _elmW = new TYAcousticLineWidget(pElement, this);
58  QTabWidget* qTabW = findChild<QTabWidget*>("tabWidget");
59  assert(qTabW && "Check name consistency with the UI file");
60  qTabW->insertTab(0, _elmW, "Source");
61  qTabW->setCurrentIndex(0);
62 
63  // Find the widget by name so that it is easy to access them
64  q_RoadSurfaceType_Combo = findChild<QComboBox*>("route_classe_revetement");
66  q_RoadSurfaceFormulation_Combo = findChild<QComboBox*>("route_formule_revetement");
68  q_RoadSurfaceDraining_Check = findChild<QCheckBox*>("route_drainant");
70  q_RoadSurfaceAge_Spin = findChild<QSpinBox*>("route_age");
71  assert(q_RoadSurfaceAge_Spin);
72  q_RoadFlowType_Combo = findChild<QComboBox*>("route_ecoulement");
73  assert(q_RoadFlowType_Combo);
74 
75  // Get he widget for the traffic speed
76  q_RoadSpeed_Spin[TYRoute::Day][TYTrafic::LV] = findChild<QSpinBox*>("vitesse_vl_jour");
78  q_RoadSpeed_Spin[TYRoute::Evening][TYTrafic::LV] = findChild<QSpinBox*>("vitesse_vl_soir");
80  q_RoadSpeed_Spin[TYRoute::Night][TYTrafic::LV] = findChild<QSpinBox*>("vitesse_vl_nuit");
82  q_RoadSpeed_Spin[TYRoute::Day][TYTrafic::HGV] = findChild<QSpinBox*>("vitesse_pl_jour");
84  q_RoadSpeed_Spin[TYRoute::Evening][TYTrafic::HGV] = findChild<QSpinBox*>("vitesse_pl_soir");
86  q_RoadSpeed_Spin[TYRoute::Night][TYTrafic::HGV] = findChild<QSpinBox*>("vitesse_pl_nuit");
88  // Get he widget for the traffic flow
89  q_RoadFlow_Spin[TYRoute::Day][TYTrafic::LV] = findChild<QSpinBox*>("periode_debit_vl_jour");
91  q_RoadFlow_Spin[TYRoute::Evening][TYTrafic::LV] = findChild<QSpinBox*>("periode_debit_vl_soir");
93  q_RoadFlow_Spin[TYRoute::Night][TYTrafic::LV] = findChild<QSpinBox*>("periode_debit_vl_nuit");
95  q_RoadFlow_Spin[TYRoute::Day][TYTrafic::HGV] = findChild<QSpinBox*>("periode_debit_pl_jour");
97  q_RoadFlow_Spin[TYRoute::Evening][TYTrafic::HGV] = findChild<QSpinBox*>("periode_debit_pl_soir");
99  q_RoadFlow_Spin[TYRoute::Night][TYTrafic::HGV] = findChild<QSpinBox*>("periode_debit_pl_nuit");
101 
102  // Disambiguate the overloaded signals
103  void (QComboBox::*_qComboBox_RoadSurfaceType_currentIndexChanged)(int) = &QComboBox::currentIndexChanged;
104  void (QComboBox::*_qComboBox_RoadSurfaceFormulation_activated)(int) = &QComboBox::activated;
105 
106  void (QButtonGroup::*_qButtonGroup_clicked)(int) = &QButtonGroup::idClicked;
107 
108  connect_ok = QObject::connect(q_RoadSurfaceType_Combo, _qComboBox_RoadSurfaceType_currentIndexChanged,
110  assert(connect_ok && "Qt signal connection failed");
111 
112  connect_ok = QObject::connect(q_RoadSurfaceFormulation_Combo, _qComboBox_RoadSurfaceFormulation_activated,
114  assert(connect_ok && "Qt signal connection failed");
115 
116  q_AADT_Push = findChild<QPushButton*>("bouton_tmja");
117  assert(q_AADT_Push);
118  connect_ok =
119  QObject::connect(q_AADT_Push, &QPushButton::clicked, this, &TYRouteWidget::display_AADT_dialog);
120  assert(connect_ok && "Qt signal connection failed");
121  p_ModeCalcul_ButtonGroup = findChild<QButtonGroup*>("groupe_boutons_mode_calcul");
122  assert(p_ModeCalcul_ButtonGroup);
123  QRadioButton* q_check_box = nullptr;
124  q_check_box = findChild<QRadioButton*>("radio_spectres");
125  assert(q_check_box);
126  p_ModeCalcul_ButtonGroup->setId(q_check_box, 0);
127  q_check_box = findChild<QRadioButton*>("radio_debits");
128  assert(q_check_box);
129  p_ModeCalcul_ButtonGroup->setId(q_check_box, 1);
130  q_check_box = findChild<QRadioButton*>("radio_tmja");
131  assert(q_check_box);
132  p_ModeCalcul_ButtonGroup->setId(q_check_box, 2);
133 
134  q_EditSpectre_Button[TYRoute::Day] = findChild<QPushButton*>("bouton_spectre_jour");
136  connect_ok = QObject::connect(q_EditSpectre_Button[TYRoute::Day], &QPushButton::clicked, this,
138  assert(connect_ok && "Qt signal connection failed");
139  q_EditSpectre_Button[TYRoute::Evening] = findChild<QPushButton*>("bouton_spectre_soir");
141  connect_ok = QObject::connect(q_EditSpectre_Button[TYRoute::Evening], &QPushButton::clicked, this,
143  assert(connect_ok && "Qt signal connection failed");
144  q_EditSpectre_Button[TYRoute::Night] = findChild<QPushButton*>("bouton_spectre_nuit");
146  connect_ok = QObject::connect(q_EditSpectre_Button[TYRoute::Night], &QPushButton::clicked, this,
148  assert(connect_ok && "Qt signal connection failed");
149 
151  connect_ok = QObject::connect(p_ModeCalcul_ButtonGroup, _qButtonGroup_clicked, this,
153  assert(connect_ok && "Qt signal connection failed");
154 
155  // Update the GUI from the data in the TYRoute instance.
156  updateContent();
157 }
158 
160 
162 {
163  _elmW->updateContent();
166  QWidget::update();
167 }
168 
170 {
171  _elmW->apply();
174 
175  emit modified();
176 }
177 
179 {
180  TYRoute& road = *getElement();
181  int index = 0;
182 
183  index = q_RoadSurfaceType_Combo->currentIndex();
184  if (index != 0 && q_RoadSurfaceDraining_Check->isChecked())
185  {
186  index += RoadSurface_DR1 - 1;
187  }
188  assert(index >= 0 && index < RoadSurface_UserDefined);
189  RoadSurfaceType surf_type = static_cast<RoadSurfaceType>(index);
190  road.setSurfaceType(surf_type);
191 
192  int age = q_RoadSurfaceAge_Spin->value();
193  road.setSurfaceAge(age);
194 }
195 
197 {
198  TYRoute& road = *getElement();
199  int index = 0;
200 
201  index = road.surfaceType();
202  assert(index >= 0 && index < RoadSurface_UserDefined);
203  if (index >= RoadSurface_DR1)
204  {
205  q_RoadSurfaceDraining_Check->setChecked(true);
206  index -= RoadSurface_DR1 - 1;
207  }
208  else
209  {
210  q_RoadSurfaceDraining_Check->setChecked(false);
211  }
212  q_RoadSurfaceType_Combo->setCurrentIndex(index);
213 
214  q_RoadSurfaceAge_Spin->setValue(road.surfaceAge());
215 
216  RoadFlowType flow_type = road.getNMPB08RoadTrafficComponent(TYRoute::Day, TYTrafic::LV).flowType;
217 
218  for (unsigned j = 0; j < TYRoute::NB_TRAFFIC_REGIMES; ++j)
219  {
220  enum TYRoute::TrafficRegimes regime = static_cast<TYRoute::TrafficRegimes>(j);
221  for (unsigned i = 0; i < TYTrafic::NB_VEHICLE_TYPES; ++i)
222  {
223  enum TYTrafic::VehicleTypes vehicle_type = static_cast<TYTrafic::VehicleTypes>(i);
224  assert(road.getNMPB08RoadTrafficComponent(regime, vehicle_type).flowType == flow_type &&
225  "The traffic flow type for all componenets are expected to be the same for now.");
226  }
227  }
228  q_RoadFlowType_Combo->setCurrentIndex(flow_type);
229 }
230 
232 {
233  TYRoute& road = *getElement();
234 
235  for (unsigned j = 0; j < TYRoute::NB_TRAFFIC_REGIMES; ++j)
236  {
237  enum TYRoute::TrafficRegimes regime = static_cast<TYRoute::TrafficRegimes>(j);
238  for (unsigned i = 0; i < TYTrafic::NB_VEHICLE_TYPES; ++i)
239  {
240  enum TYTrafic::VehicleTypes vehicle_type = static_cast<TYTrafic::VehicleTypes>(i);
241 
242  int speed = q_RoadSpeed_Spin[regime][vehicle_type]->value();
243  int flow = q_RoadFlow_Spin[regime][vehicle_type]->value();
244  // NB : For now there is only one flow type for all traffic componenet in the GUI
245  int index = q_RoadFlowType_Combo->currentIndex();
246  RoadFlowType flow_type = static_cast<RoadFlowType>(index);
247  road.setRoadTrafficComponent(regime, vehicle_type, flow, speed, flow_type);
248  }
249  }
250 }
251 
253 {
254  TYRoute& road = *getElement();
255 
256  for (unsigned j = 0; j < TYRoute::NB_TRAFFIC_REGIMES; ++j)
257  {
258  enum TYRoute::TrafficRegimes regime = static_cast<TYRoute::TrafficRegimes>(j);
259  for (unsigned i = 0; i < TYTrafic::NB_VEHICLE_TYPES; ++i)
260  {
261  enum TYTrafic::VehicleTypes vehicle_type = static_cast<TYTrafic::VehicleTypes>(i);
262 
263  const RoadTrafficComponent& rtc = road.getNMPB08RoadTrafficComponent(regime, vehicle_type);
264  q_RoadSpeed_Spin[regime][vehicle_type]->setValue(rtc.trafficSpeed);
265  q_RoadFlow_Spin[regime][vehicle_type]->setValue(rtc.trafficFlow);
266  /* TODO Handle rtc.flowType */
267  }
268  }
269 }
270 
271 TYRouteWidget_AADT_Dialog::TYRouteWidget_AADT_Dialog(QWidget* _pParent) : QDialog(_pParent)
272 {
273  setupUi(this);
274 }
275 
277 {
278  TYRouteWidget_AADT_Dialog dlg(this);
279  bool ok = false;
280  while (!ok)
281  {
282  int status = dlg.exec();
283  if (status == QDialog::Accepted)
284  {
285  QSpinBox* q_lv_Spin = findChild<QSpinBox*>("tmja_debit_vl");
286  assert(q_lv_Spin);
287  QSpinBox* q_hgv_Spin = findChild<QSpinBox*>("tmja_debit_pl");
288  assert(q_hgv_Spin);
289  QComboBox* q_RoadType_Combo = findChild<QComboBox*>("tmja_type_route");
290  assert(q_RoadType_Combo);
291  QComboBox* q_RoadFunction_Combo = findChild<QComboBox*>("tmja_fonction_route");
292  assert(q_RoadFunction_Combo);
293 
294  double lv_aadt = q_lv_Spin->value();
295  double hgv_aadt = q_hgv_Spin->value();
296  TYRoute::RoadType road_type = static_cast<TYRoute::RoadType>(q_RoadType_Combo->currentIndex());
297  TYRoute::RoadFunction road_function =
298  static_cast<TYRoute::RoadFunction>(q_RoadFunction_Combo->currentIndex());
299 
300  TYRoute& road = *getElement();
301  QString msg;
302  ok = road.setFromAADT(hgv_aadt, lv_aadt, road_type, road_function, &msg);
303 
304  if (ok)
305  {
306  // Do not forget to update the traffic to reflect the computed parameters
307  updateContent();
308  }
309  else
310  {
311  // TODO i18n when serious i18n based on Qt will be in place
312  msg.replace("\n", "<br/>");
313  QString text =
314  QString::fromUtf8("<p>Les valeurs du TMJA spécifiées sont hors du domaine "
315  "de validité de la <i>Note 77</i>. Merci de les rectifier :</p>");
316  QMessageBox::information(this, "TMJA invalide !", text + msg,
317  QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton,
318  QMessageBox::NoButton);
319  }
320  }
321  else
322  {
323  break; // Dialog canceled
324  }
325  } // while(!ok)
326 }
327 
329 {
330  for (unsigned j = 0; j < TYRoute::NB_TRAFFIC_REGIMES; ++j)
331  for (unsigned i = 0; i < TYTrafic::NB_VEHICLE_TYPES; ++i)
332  {
333  q_RoadSpeed_Spin[j][i]->setEnabled(enabled);
334  }
335 }
336 
338 {
339  for (unsigned j = 0; j < TYRoute::NB_TRAFFIC_REGIMES; ++j)
340  for (unsigned i = 0; i < TYTrafic::NB_VEHICLE_TYPES; ++i)
341  {
342  q_RoadFlow_Spin[j][i]->setEnabled(enabled);
343  }
344 }
345 
347 {
348  TYRoute& road = *getElement();
349  spectrum_read_only = !enabled;
350  for (unsigned j = 0; j < TYRoute::NB_TRAFFIC_REGIMES; ++j)
351  {
352  q_EditSpectre_Button[j]->setEnabled(enabled);
353  road.setCurRegime(j);
354  if (enabled)
355  {
357  }
358  else
359  {
361  }
362  road.updateCurrentRegime();
363  }
364 }
365 
367 {
368  switch (mode)
369  {
370  case 0: // Directly input spectrums
371  setSpeedBoxEnabled(false);
372  setFlowBoxEnabled(false);
373  setSpectresEditable(true);
374  q_AADT_Push->setEnabled(false);
375  break;
376  case 1: // Input flows and speeds
377  setSpeedBoxEnabled(true);
378  setFlowBoxEnabled(true);
379  setSpectresEditable(false);
380  q_AADT_Push->setEnabled(false);
381  break;
382  case 2: // Use note 77 to estimate traffic from the TMJA
383  setSpeedBoxEnabled(true);
384  setFlowBoxEnabled(false);
385  setSpectresEditable(false);
386  q_AADT_Push->setEnabled(true);
387  break;
388  default:
389  assert(false && "mode should be in 0..2");
390  }
391 
392  _elmW->updateContent();
393 }
394 
396 {
397  TYRoute& road = *getElement();
398 
399  assert(road.getNbRegimes() == 3);
400  road.setCurRegime(regime);
401  TYSpectre* spectre = road.getCurrentSpectre();
402  spectre->edit(this);
403 }
404 
406 {
407  int index = q_RoadSurfaceType_Combo->currentIndex();
408  assert(index >= 0 && index < RoadSurface_UserDefined);
409  q_RoadSurfaceDraining_Check->setEnabled(index != RoadSurface_Default);
410  q_RoadSurfaceFormulation_Combo->setCurrentIndex(0);
411 }
412 
414 {
415  if (index > 0)
416  {
417  TYRoute& road = *getElement();
418  int surf_type_no = RoadSurfaceFormulationMap[index - 1].id;
419  RoadSurfaceType surf_type = static_cast<RoadSurfaceType>(surf_type_no);
420  road.setSurfaceType(surf_type);
422  q_RoadSurfaceFormulation_Combo->setCurrentIndex(index);
423  QWidget::update();
424  }
425 }
Outil IHM pour une ligne acoustique (fichier header)
int id
const char * name
outil IHM pour une route (fichier header)
classe de l'objet IHM pour une ligne acoustique
virtual void setCurRegime(int regimeNumber)
size_t getNbRegimes() const
virtual void updateCurrentRegime()
void setTypeDistribution(int typeDistri)
TYRouteWidget_AADT_Dialog(QWidget *_pParent=NULL)
void apply_road_traffic()
bool spectrum_read_only
void setSpectresEditable(bool enabled=true)
void onRoadSurfaceChange(int)
void displaySpectrumEvening()
void displaySpectrumDay()
Definition: TYRouteWidget.h:96
void setSpeedBoxEnabled(bool enabled=true)
QComboBox * q_RoadFlowType_Combo
Definition: TYRouteWidget.h:82
void update_road_traffic()
QButtonGroup * p_ModeCalcul_ButtonGroup
Definition: TYRouteWidget.h:87
void displaySpectrumNight()
QComboBox * q_RoadSurfaceType_Combo
Definition: TYRouteWidget.h:78
TYRouteWidget(TYRoute *pElement, QWidget *_pParent=NULL)
QSpinBox * q_RoadFlow_Spin[TYRoute::NB_TRAFFIC_REGIMES][TYTrafic::NB_VEHICLE_TYPES]
Definition: TYRouteWidget.h:84
virtual ~TYRouteWidget()
virtual void updateContent()
QPushButton * q_AADT_Push
Definition: TYRouteWidget.h:85
void apply_road_surface()
QSpinBox * q_RoadSpeed_Spin[TYRoute::NB_TRAFFIC_REGIMES][TYTrafic::NB_VEHICLE_TYPES]
Definition: TYRouteWidget.h:83
TYAcousticLineWidget * _elmW
Definition: TYRouteWidget.h:76
QComboBox * q_RoadSurfaceFormulation_Combo
Definition: TYRouteWidget.h:79
QSpinBox * q_RoadSurfaceAge_Spin
Definition: TYRouteWidget.h:81
virtual void apply()
void display_AADT_dialog()
QCheckBox * q_RoadSurfaceDraining_Check
Definition: TYRouteWidget.h:80
void setFlowBoxEnabled(bool enabled=true)
void checkComputationMode(int)
void onRoadSurfaceFormulationChange(int)
QPushButton * q_EditSpectre_Button[TYRoute::NB_TRAFFIC_REGIMES]
Definition: TYRouteWidget.h:88
void displaySpectrum(TYRoute::TrafficRegimes)
void update_road_surface()
TrafficRegimes
Definition: TYRoute.h:56
@ Day
Definition: TYRoute.h:57
@ Evening
Definition: TYRoute.h:58
@ Night
Definition: TYRoute.h:59
@ NB_TRAFFIC_REGIMES
Definition: TYRoute.h:60
void setSurfaceAge(double age)
Setter for the surface age.
Definition: TYRoute.cpp:690
bool setFromAADT(double aadt_hgv, double aadt_lv, RoadType road_type, RoadFunction road_function, QString *out_msg=NULL)
Apply Note77 from Setra to estimate trafic from AADT and road kind.
Definition: TYRoute.cpp:630
RoadType
Definition: TYRoute.h:152
const RoadTrafficComponent & getNMPB08RoadTrafficComponent(enum TrafficRegimes regime, enum TYTrafic::VehicleTypes vehic_type) const
Definition: TYRoute.cpp:497
void setSurfaceType(RoadSurfaceType type)
Setter for the road surface type.
Definition: TYRoute.cpp:685
double surfaceAge() const
Getter for the surface age.
Definition: TYRoute.h:225
RoadSurfaceType surfaceType() const
Getter for the road surface type.
Definition: TYRoute.h:218
void setRoadTrafficComponent(enum TrafficRegimes regime, enum TYTrafic::VehicleTypes vehic_type, double flow, double speed, RoadFlowType type=FlowType_CONST)
Set the traffic parameter for a given regime and type of vehicles.
Definition: TYRoute.cpp:700
RoadFunction
Definition: TYRoute.h:157
virtual TYSpectre * getCurrentSpectre() const
Definition: TYSource.h:84
VehicleTypes
Definition: TYTrafic.h:38
@ NB_VEHICLE_TYPES
Definition: TYTrafic.h:41
classe de l'objet IHM pour un objet metier de type TYElement
Definition: TYWidget.h:43
void modified()