dialogroadmirror.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "dialogroadmirror.h"
  2. #include "ui_dialogroadmirror.h"
  3. #include "gnss_coordinate_convert.h"
  4. #include <math.h>
  5. #include <mainwindow.h>
  6. extern MainWindow * gw;
  7. extern double glon0 ;
  8. extern double glat0 ;
  9. DialogRoadMirror::DialogRoadMirror(OpenDrive * pxodr,Road * pRoad,QWidget *parent) :
  10. QDialog(parent),
  11. ui(new Ui::DialogRoadMirror)
  12. {
  13. ui->setupUi(this);
  14. mpxodr = pxodr;
  15. mpRoad = pRoad;
  16. if(pRoad != 0)
  17. {
  18. setWindowTitle(QString(pRoad->GetRoadId().data()));
  19. }
  20. }
  21. DialogRoadMirror::~DialogRoadMirror()
  22. {
  23. delete ui;
  24. }
  25. void DialogRoadMirror::on_pushButton_Mirror_clicked()
  26. {
  27. double x0,y0;
  28. double rel_x,rel_y;
  29. double x,y;
  30. double flon,flat;
  31. flon = ui->lineEdit_Lon->text().toDouble();
  32. flat = ui->lineEdit_Lat->text().toDouble();
  33. GaussProjCal(glon0,glat0,&x0,&y0);
  34. GaussProjCal(flon,flat,&x,&y);
  35. rel_x = x - x0;
  36. rel_y = y - y0;
  37. double hdg = (90 - ui->lineEdit_Heading->text().toDouble())*M_PI/180.0;
  38. while(hdg < 0)hdg = hdg + 2.0*M_PI;
  39. while(hdg >= 2.0*M_PI)hdg = hdg - 2.0*M_PI;
  40. x0 = rel_x;
  41. y0 = rel_y;
  42. double hdg0 = hdg;
  43. Road newroad = *mpRoad;
  44. int i;
  45. int ngeobcount = mpRoad->GetGeometryBlockCount();
  46. for(i=0;i<ngeobcount;i++)
  47. {
  48. double x,y,hdg;
  49. RoadGeometry * pgeo = newroad.GetGeometryBlock(i)->GetGeometryAt(0);
  50. if(pgeo == 0)continue;
  51. x = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetX();
  52. y = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetY();
  53. hdg = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetHdg();
  54. x = x-x0;
  55. y = y- y0;
  56. double s,t;
  57. double frotate = hdg0*(-1);
  58. s = x*cos(frotate) -y*sin(frotate) ;
  59. t = x*sin(frotate) +y*cos(frotate);
  60. hdg = hdg + frotate;
  61. while(hdg<0)hdg = hdg + 2.0*M_PI;
  62. while(hdg>=2.0*M_PI)hdg = hdg - 2.0*M_PI;
  63. x = s;
  64. y = t*(-1);
  65. hdg = hdg*(-1);
  66. while(hdg<0)hdg = hdg + 2.0*M_PI;
  67. while(hdg>=2.0*M_PI)hdg = hdg - 2.0*M_PI;
  68. frotate = hdg0;
  69. s = x*cos(frotate) -y*sin(frotate) ;
  70. t = x*sin(frotate) +y*cos(frotate);
  71. hdg = hdg + frotate;
  72. while(hdg<0)hdg = hdg + 2.0*M_PI;
  73. while(hdg>=2.0*M_PI)hdg = hdg - 2.0*M_PI;
  74. newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetX(s + x0);
  75. newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetY(t + y0);
  76. newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetHdg(hdg);
  77. if(pgeo->GetGeomType() == 1)
  78. {
  79. GeometrySpiral * pSpiral = (GeometrySpiral *)pgeo;
  80. double startcurv = pSpiral->GetCurvatureStart() *(-1);
  81. double endcurv = pSpiral->GetCurvatureEnd() *(-1);
  82. pSpiral->SetCurvatureStart(startcurv);
  83. pSpiral->SetCurvatureEnd(endcurv);
  84. }
  85. if(pgeo->GetGeomType() == 2)
  86. {
  87. GeometryArc * pArc = (GeometryArc *)pgeo;
  88. double curv = pArc->GetCurvature();
  89. pArc->SetCurvature(curv*(-1));
  90. }
  91. }
  92. int nnewroadid = gw->CreateRoadID();
  93. newroad.SetRoadId(QString::number(nnewroadid).toStdString());
  94. mpxodr->GetRoadVector()->push_back(newroad);
  95. bool bSaveOldRoad = true;
  96. QMessageBox::StandardButton button;
  97. char strout[256];
  98. snprintf(strout,256,"New Road id is %d. Keep the old road.",nnewroadid);
  99. button=QMessageBox::question(this,tr("Quest"),QString(strout),QMessageBox::Yes|QMessageBox::No);
  100. if(button==QMessageBox::No)
  101. {
  102. bSaveOldRoad = false;
  103. }
  104. else if(button==QMessageBox::Yes)
  105. {
  106. bSaveOldRoad = true;
  107. }
  108. if(bSaveOldRoad == false)
  109. {
  110. int nroadindex = xodrfunc::GetRoadIndex(mpxodr,mpRoad);
  111. if(nroadindex >= 0)
  112. {
  113. mpxodr->DeleteRoad(nroadindex);
  114. }
  115. }
  116. this->accept();
  117. }