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