speeddialog.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #include "speeddialog.h"
  2. #include "ui_speeddialog.h"
  3. SpeedDialog::SpeedDialog(OpenDrive * pxodr,QWidget *parent) :
  4. QDialog(parent),
  5. ui(new Ui::SpeedDialog)
  6. {
  7. ui->setupUi(this);
  8. mpxodr = pxodr;
  9. int i;
  10. int nroadcount = mpxodr->GetRoadCount();
  11. for(i=0;i<nroadcount;i++)
  12. {
  13. const char * strname = mpxodr->GetRoad(i)->GetRoadId().data();
  14. ui->comboBox_Road->addItem(strname);
  15. }
  16. }
  17. SpeedDialog::~SpeedDialog()
  18. {
  19. delete ui;
  20. }
  21. void SpeedDialog::on_comboBox_Road_currentIndexChanged(int index)
  22. {
  23. Road * pRoad = mpxodr->GetRoad(index);
  24. if(pRoad == 0)
  25. {
  26. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  27. return;
  28. }
  29. ui->lineEdit_RoadLen->setText(QString::number(pRoad->GetRoadLength(),'f',3));
  30. int i;
  31. LaneSection * pLS = pRoad->GetLaneSection(0);
  32. if(pLS == 0)return;
  33. int nlanecount = pLS->GetLaneCount();
  34. ui->comboBox_Lane->clear();
  35. for(i=0;i<nlanecount;i++)
  36. {
  37. char strout[255];
  38. Lane * pLane = pLS->GetLane(i);
  39. snprintf(strout,255,"%d",pLane->GetId());
  40. ui->comboBox_Lane->addItem(strout);
  41. }
  42. }
  43. void SpeedDialog::on_comboBox_Lane_currentIndexChanged(int index)
  44. {
  45. Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
  46. if(pRoad == 0)
  47. {
  48. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  49. return;
  50. }
  51. int i;
  52. LaneSection * pLS = pRoad->GetLaneSection(0);
  53. if(pLS == 0)return;
  54. Lane * pLane = pLS->GetLane(ui->comboBox_Lane->currentIndex());
  55. ui->comboBox_Speed->clear();
  56. if(pLane == 0)return;
  57. int nspeedcount = pLane->GetLaneSpeedCount();
  58. for(i=0;i<nspeedcount;i++)
  59. {
  60. LaneSpeed * pSpeed = pLane->GetLaneSpeed(i);
  61. char strout[255];
  62. snprintf(strout,255,"S:%f Speed:%f",pSpeed->GetS(),pSpeed->GetMax());
  63. ui->comboBox_Speed->addItem(strout);
  64. }
  65. }
  66. void SpeedDialog::on_comboBox_Speed_currentIndexChanged(int index)
  67. {
  68. }
  69. void SpeedDialog::on_pushButton_add_clicked()
  70. {
  71. double s = ui->lineEdit_s->text().toDouble();
  72. double speedlim = ui->lineEdit_speedlim->text().toDouble();
  73. Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
  74. if(pRoad == 0)
  75. {
  76. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  77. return;
  78. }
  79. int i;
  80. LaneSection * pLS = pRoad->GetLaneSection(0);
  81. if(pLS == 0)return;
  82. Lane * pLane = pLS->GetLane(ui->comboBox_Lane->currentIndex());
  83. pLane->AddSpeedRecord(s,speedlim);
  84. on_comboBox_Lane_currentIndexChanged(ui->comboBox_Lane->currentIndex());
  85. }
  86. void SpeedDialog::on_pushButton_del_clicked()
  87. {
  88. Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
  89. if(pRoad == 0)
  90. {
  91. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  92. return;
  93. }
  94. int i;
  95. LaneSection * pLS = pRoad->GetLaneSection(0);
  96. if(pLS == 0)return;
  97. Lane * pLane = pLS->GetLane(ui->comboBox_Lane->currentIndex());
  98. pLane->DeleteLaneSpeed(ui->comboBox_Speed->currentIndex());
  99. on_comboBox_Lane_currentIndexChanged(ui->comboBox_Lane->currentIndex());
  100. }