#include "dialogroadrotate.h" #include "ui_dialogroadrotate.h" #include #include 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;iGetGeometryAt(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(); }