123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include "dialogroadrotate.h"
- #include "ui_dialogroadrotate.h"
- #include <math.h>
- #include <mainwindow.h>
- extern MainWindow * gw;
- DialogRoadRotate::DialogRoadRotate(OpenDrive * pxodr,Road * pRoad, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::DialogRoadRotate)
- {
- ui->setupUi(this);
- mpxodr = pxodr;
- mpRoad = pRoad;
- if(pRoad != 0)
- {
- setWindowTitle(QString(pRoad->GetRoadId().data()));
- }
- }
- DialogRoadRotate::~DialogRoadRotate()
- {
- delete ui;
- }
- void DialogRoadRotate::on_pushButton_Rotate_clicked()
- {
- if(mpRoad == 0)
- {
- QMessageBox::warning(this,"Warning","Not have road.",QMessageBox::YesAll);
- return;
- }
- double frotate = ui->lineEdit_rotatedegree->text().toDouble() *M_PI/180.0;
- if(frotate == 0)
- {
- QMessageBox::StandardButton button;
- button=QMessageBox::question(this,tr("生成道路"),QString(tr("是否在原来位置生成道路")),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- return;
- }
- else if(button==QMessageBox::Yes)
- {
- }
- }
- Road newroad = *mpRoad;
- double hdg0 = 0;
- double x0 = 0;
- double y0 = 0;
- if(mpRoad->GetGeometryBlockCount()>0)
- {
- hdg0 = mpRoad->GetGeometryBlock(0)->GetGeometryAt(0)->GetHdg();
- x0 = mpRoad->GetGeometryBlock(0)->GetGeometryAt(0)->GetX();
- y0 = mpRoad->GetGeometryBlock(0)->GetGeometryAt(0)->GetY();
- }
- int i;
- int ngeobcount = mpRoad->GetGeometryBlockCount();
- for(i=0;i<ngeobcount;i++)
- {
- double x,y,hdg;
- x = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetX();
- y = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetY();
- hdg = newroad.GetGeometryBlock(i)->GetGeometryAt(0)->GetHdg();
- double s,t;
- s = (x-x0)*cos(frotate) -(y-y0)*sin(frotate) + x0;
- t = (x-x0)*sin(frotate) +(y-y0)*cos(frotate) + y0;
- hdg = hdg + frotate;
- while(hdg<0)hdg = hdg + 2.0*M_PI;
- while(hdg>=2.0*M_PI)hdg = hdg - 2.0*M_PI;
- newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetX(s);
- newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetY(t);
- newroad.GetGeometryBlock(i)->GetGeometryAt(0)->SetHdg(hdg);
- }
- int nnewroadid = gw->CreateRoadID();
- newroad.SetRoadId(QString::number(nnewroadid).toStdString());
- mpxodr->GetRoadVector()->push_back(newroad);
- bool bSaveOldRoad = true;
- QMessageBox::StandardButton button;
- char strout[256];
- snprintf(strout,256,"New Road id is %d. Keep the old road.",nnewroadid);
- button=QMessageBox::question(this,tr("Quest"),QString(strout),QMessageBox::Yes|QMessageBox::No);
- if(button==QMessageBox::No)
- {
- bSaveOldRoad = false;
- }
- else if(button==QMessageBox::Yes)
- {
- bSaveOldRoad = true;
- }
- if(bSaveOldRoad == false)
- {
- int nroadindex = xodrfunc::GetRoadIndex(mpxodr,mpRoad);
- if(nroadindex >= 0)
- {
- mpxodr->DeleteRoad(nroadindex);
- }
- }
- this->accept();
- }
|