dialogroadrotate.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "dialogroadrotate.h"
  2. #include "ui_dialogroadrotate.h"
  3. #include <math.h>
  4. #include <mainwindow.h>
  5. extern MainWindow * gw;
  6. DialogRoadRotate::DialogRoadRotate(OpenDrive * pxodr,Road * pRoad, QWidget *parent) :
  7. QDialog(parent),
  8. ui(new Ui::DialogRoadRotate)
  9. {
  10. ui->setupUi(this);
  11. mpxodr = pxodr;
  12. mpRoad = pRoad;
  13. if(pRoad != 0)
  14. {
  15. setWindowTitle(QString(pRoad->GetRoadId().data()));
  16. }
  17. }
  18. DialogRoadRotate::~DialogRoadRotate()
  19. {
  20. delete ui;
  21. }
  22. void DialogRoadRotate::on_pushButton_Rotate_clicked()
  23. {
  24. if(mpRoad == 0)
  25. {
  26. QMessageBox::warning(this,"Warning","Not have road.",QMessageBox::YesAll);
  27. return;
  28. }
  29. double frotate = ui->lineEdit_rotatedegree->text().toDouble() *M_PI/180.0;
  30. if(frotate == 0)
  31. {
  32. QMessageBox::StandardButton button;
  33. button=QMessageBox::question(this,tr("生成道路"),QString(tr("是否在原来位置生成道路")),QMessageBox::Yes|QMessageBox::No);
  34. if(button==QMessageBox::No)
  35. {
  36. return;
  37. }
  38. else if(button==QMessageBox::Yes)
  39. {
  40. }
  41. }
  42. Road newroad = *mpRoad;
  43. double hdg0 = 0;
  44. double x0 = 0;
  45. double y0 = 0;
  46. if(mpRoad->GetGeometryBlockCount()>0)
  47. {
  48. hdg0 = mpRoad->GetGeometryBlock(0)->GetGeometryAt(0)->GetHdg();
  49. x0 = mpRoad->GetGeometryBlock(0)->GetGeometryAt(0)->GetX();
  50. y0 = mpRoad->GetGeometryBlock(0)->GetGeometryAt(0)->GetY();
  51. }
  52. int i;
  53. int ngeobcount = mpRoad->GetGeometryBlockCount();
  54. for(i=0;i<ngeobcount;i++)
  55. {
  56. double x,y,hdg;
  57. x = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetX();
  58. y = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetY();
  59. hdg = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetHdg();
  60. double s,t;
  61. s = (x-x0)*cos(frotate) -(y-y0)*sin(frotate) + x0;
  62. t = (x-x0)*sin(frotate) +(y-y0)*cos(frotate) + y0;
  63. hdg = hdg + frotate;
  64. while(hdg<0)hdg = hdg + 2.0*M_PI;
  65. while(hdg>=2.0*M_PI)hdg = hdg - 2.0*M_PI;
  66. newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetX(s);
  67. newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetY(t);
  68. newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetHdg(hdg);
  69. }
  70. int nnewroadid = gw->CreateRoadID();
  71. newroad.SetRoadId(QString::number(nnewroadid).toStdString());
  72. mpxodr->GetRoadVector()->push_back(newroad);
  73. bool bSaveOldRoad = true;
  74. QMessageBox::StandardButton button;
  75. char strout[256];
  76. snprintf(strout,256,"New Road id is %d. Keep the old road.",nnewroadid);
  77. button=QMessageBox::question(this,tr("Quest"),QString(strout),QMessageBox::Yes|QMessageBox::No);
  78. if(button==QMessageBox::No)
  79. {
  80. bSaveOldRoad = false;
  81. }
  82. else if(button==QMessageBox::Yes)
  83. {
  84. bSaveOldRoad = true;
  85. }
  86. if(bSaveOldRoad == false)
  87. {
  88. int nroadindex = xodrfunc::GetRoadIndex(mpxodr,mpRoad);
  89. if(nroadindex >= 0)
  90. {
  91. mpxodr->DeleteRoad(nroadindex);
  92. }
  93. }
  94. this->accept();
  95. }