speeddialog.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. int nspeedcount = pLane->GetLaneSpeedCount();
  57. for(i=0;i<nspeedcount;i++)
  58. {
  59. LaneSpeed * pSpeed = pLane->GetLaneSpeed(i);
  60. char strout[255];
  61. snprintf(strout,255,"S:%f Speed:%f",pSpeed->GetS(),pSpeed->GetMax());
  62. ui->comboBox_Speed->addItem(strout);
  63. }
  64. }
  65. void SpeedDialog::on_comboBox_Speed_currentIndexChanged(int index)
  66. {
  67. }
  68. void SpeedDialog::on_pushButton_add_clicked()
  69. {
  70. double s = ui->lineEdit_s->text().toDouble();
  71. double speedlim = ui->lineEdit_speedlim->text().toDouble();
  72. Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
  73. if(pRoad == 0)
  74. {
  75. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  76. return;
  77. }
  78. int i;
  79. LaneSection * pLS = pRoad->GetLaneSection(0);
  80. if(pLS == 0)return;
  81. Lane * pLane = pLS->GetLane(ui->comboBox_Lane->currentIndex());
  82. pLane->AddSpeedRecord(s,speedlim);
  83. on_comboBox_Lane_currentIndexChanged(ui->comboBox_Lane->currentIndex());
  84. }
  85. void SpeedDialog::on_pushButton_del_clicked()
  86. {
  87. Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
  88. if(pRoad == 0)
  89. {
  90. // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL");
  91. return;
  92. }
  93. int i;
  94. LaneSection * pLS = pRoad->GetLaneSection(0);
  95. if(pLS == 0)return;
  96. Lane * pLane = pLS->GetLane(ui->comboBox_Lane->currentIndex());
  97. pLane->DeleteLaneSpeed(ui->comboBox_Speed->currentIndex());
  98. on_comboBox_Lane_currentIndexChanged(ui->comboBox_Lane->currentIndex());
  99. }