#include "roadeditdialog.h" #include "ui_roadeditdialog.h" #include "mainwindow.h" #include "math.h" #define VIEW_WIDTH 850 #define VIEW_HEIGHT 450 RoadEditDialog::RoadEditDialog(OpenDrive * pxodr,std::string strdefroad,QWidget *parent) : QDialog(parent), ui(new Ui::RoadEditDialog) { mpxodr = pxodr; ui->setupUi(this); myview = new MyView(this); myview->setObjectName(QStringLiteral("graphicsView")); myview->setGeometry(QRect(30, 300, 900, 500)); // connect(myview,SIGNAL(dbclickxy(double,double)),this,SLOT(onClickXY(double,double))); image = new QImage(VIEW_WIDTH, VIEW_HEIGHT, QImage::Format_RGB32);//画布的初始化大小设为300*300,使用32位颜色 myview->setCacheMode(myview->CacheBackground); painter = new QPainter(image); painter->end(); // scene = new QGraphicsScene; scene = new QGraphicsScene(-VIEW_WIDTH/2, -VIEW_HEIGHT/2, VIEW_WIDTH, VIEW_HEIGHT); myview->setScene(scene); scene->setBackgroundBrush(Qt::darkGreen); ui->comboBox_geotype->addItem("Line"); ui->comboBox_geotype->addItem("Spiral"); ui->comboBox_geotype->addItem("Arc"); ui->comboBox_geotype->addItem("Poly"); ui->comboBox_geotype->addItem("Param Poly"); int i; int nroadcount = mpxodr->GetRoadCount(); for(i=0;iGetRoad(i)->GetRoadId().data(); ui->comboBox_Road->addItem(strname); } MainWindow::ComboToString(strdefroad,ui->comboBox_Road); } RoadEditDialog::~RoadEditDialog() { delete ui; } void RoadEditDialog::ExecPainter() { painter->begin(image); int nkeep = 30; Road * pRoad = mpCurRoad; // qDebug("time is %d",x.elapsed()); image->fill(QColor(255, 255, 255));//对画布进行填充 // std::vector navigation_data = brain->navigation_data; painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点 // painter->translate(mnMoveX,mnMoveY); // painter->translate(VIEW_WIDTH/2,VIEW_HEIGHT/2); double froad_xmin,froad_ymin,froad_xmax,froad_ymax; int nfac = 1; ServiceXODRTool.GetRoadMaxMin(pRoad,froad_xmin,froad_ymin,froad_xmax,froad_ymax); double fac_x,fac_y; fac_x = 100000; fac_y = 100000; if(froad_xmax > froad_xmin) { fac_x = (VIEW_WIDTH-nkeep*2)/(froad_xmax - froad_xmin); } if(froad_ymax > froad_ymin) { fac_y = (VIEW_HEIGHT - nkeep*2)/(froad_ymax - froad_ymin); } nfac = fac_x; if(fac_y < nfac)nfac = fac_y; painter->translate(nkeep,VIEW_HEIGHT-nkeep); painter->setPen(Qt::black); // painter->drawLine(VIEW_WIDTH/(-2),0,VIEW_WIDTH/2,0); // painter->drawLine(0,VIEW_HEIGHT/(-2),0,VIEW_HEIGHT/2); int i; // int nfac = 5;; painter->setPen(Qt::blue); // if(mbClick) // { // painter->setPen(Qt::red); // painter->drawEllipse(QPoint(mClickX ,mClickY),mnMarkSize,mnMarkSize); // painter->setPen(Qt::black); // } // if(mbSetObj) // { // painter->setPen(Qt::green); // painter->drawRect(mfObjX*nfac-mnMarkSize,mfObjY*nfac*(-1)-mnMarkSize,mnMarkSize*2,mnMarkSize*2); // painter->setPen(Qt::black); // } painter->setPen(Qt::green); double x0,y0; // GaussProjCal(glon0,glat0,&x0,&y0); painter->setPen(Qt::blue); // int nfac = nfac; // int selid = mpCBRoad->currentText().toInt(); // continue; int j; painter->setPen(Qt::blue); for(j=0;jGetGeometryBlockCount();j++) { GeometryBlock * pgeob = pRoad->GetGeometryBlock(j); double x,y; double x_center,y_center; double R; RoadGeometry * pg; GeometryArc * parc; GeometryParamPoly3 * ppp3; GeometrySpiral *pSpiral; double rel_x,rel_y,rel_hdg; pg = pgeob->GetGeometryAt(0); x = pg->GetX(); y = pg->GetY(); painter->setPen(Qt::blue); if(j == mnSelGeo) { painter->setPen(Qt::green); } // if(j== 0) // { // if(selid == atoi(pRoad->GetRoadId().data())) // { // painter->setPen(Qt::green); // painter->drawEllipse(x*nfac-5,y*nfac*(-1)-5,10,10); // painter->setPen(Qt::red); // } // } switch (pg->GetGeomType()) { case 0: painter->drawLine(QPoint((x-froad_xmin)*nfac,(y-froad_ymin)*nfac*(-1)), QPoint(((x-froad_xmin) + pg->GetLength() * cos(pg->GetHdg()))*nfac,((y-froad_ymin) + pg->GetLength() * sin(pg->GetHdg()))*nfac*(-1))); break; case 1: pSpiral = (GeometrySpiral * )pg; { int ncount = pSpiral->GetLength() * nfac; double sstep = pSpiral->GetLength()/((double)ncount); int k; double x0,y0,hdg0,s0; x0 = pSpiral->GetX(); y0 = pSpiral->GetY(); s0 = pSpiral->GetS(); hdg0 = pSpiral->GetHdg() ; painter->setPen(Qt::red); for(k=0;kGetCoords(s0+sstep*k,rel_x,rel_y,rel_hdg); x = rel_x - froad_xmin; y = rel_y - froad_ymin; painter->drawPoint((int)(x*nfac),(int)(y*(-1.0*nfac))); } painter->setPen(Qt::blue); } // qDebug("spi"); break; case 2: { parc = (GeometryArc *)pg; R = abs(1.0/parc->GetCurvature()); if(parc->GetCurvature() > 0) { x_center = pg->GetX() + R *cos(pg->GetHdg() + M_PI/2.0); y_center = pg->GetY() + R * sin(pg->GetHdg() + M_PI/2.0); } else { x_center = pg->GetX() + R *cos(pg->GetHdg() -M_PI/2.0); y_center = pg->GetY() + R * sin(pg->GetHdg() - M_PI/2.0); } int k; int ncount = parc->GetLength() * nfac ; double curv = parc->GetCurvature(); double hdgstep; double hdg0 = parc->GetHdg(); double hdgnow = parc->GetHdg(); if(ncount > 0) hdgstep= (parc->GetLength()/R)/ncount; for(k=0;k 0) { hdgnow = hdg0 + k*hdgstep; x_draw = x_center + R *cos(hdgnow - M_PI/2.0); y_draw = y_center + R * sin(hdgnow - M_PI/2.0); } else { hdgnow = hdg0 - k * hdgstep; x_draw = x_center + R *cos(hdgnow + M_PI/2.0); y_draw = y_center + R * sin(hdgnow + M_PI/2.0); } x_draw = x_draw - froad_xmin; y_draw = y_draw - froad_ymin; painter->drawPoint(x_draw * nfac ,y_draw * nfac *(-1)); } } break; case 4: { ppp3 = (GeometryParamPoly3 * )pg; int ncount = ppp3->GetLength()* nfac; double sstep; if(ncount > 0)sstep = ppp3->GetLength()/ncount; else sstep = 10000.0; double s = 0; while(s < ppp3->GetLength()) { double xtem,ytem; xtem = ppp3->GetuA() + ppp3->GetuB() * s + ppp3->GetuC() * s*s + ppp3->GetuD() * s*s*s; ytem = ppp3->GetvA() + ppp3->GetvB() * s + ppp3->GetvC() * s*s + ppp3->GetvD() * s*s*s; x = xtem*cos(ppp3->GetHdg()) - ytem * sin(ppp3->GetHdg()) + ppp3->GetX(); y = xtem*sin(ppp3->GetHdg()) + ytem * cos(ppp3->GetHdg()) + ppp3->GetY(); x = x - froad_xmin; y = y- froad_ymin; painter->drawPoint((int)(x*nfac),(int)(y*(-1.0*nfac))); s = s+ sstep; } } break; default: break; } // painter->drawPoint((int)(x*nfac),(int)(y*(-1.0*nfac))); } painter->setPen(Qt::green); painter->end(); } void RoadEditDialog::paintEvent(QPaintEvent * painter) { scene->update(); return; if(mpCurRoad != 0) { ExecPainter(); scene->clear(); scene->addPixmap(QPixmap::fromImage(*image)); myview->setScene(scene); myview->show(); } } void RoadEditDialog::on_comboBox_Road_activated(const QString &arg1) { } bool RoadEditDialog::IsDrawMark(double s) { const double dotdis = 10.0; const double dotlen = 5.0; double y = fmod(s,dotdis); if(y>dotlen)return true; else { return false; } } void RoadEditDialog::on_comboBox_Road_currentIndexChanged(int index) { Road * pRoad = mpxodr->GetRoad(index); if(pRoad == 0) { // QMessageBox::warning(this,"WARN","MainWindow::onClickCBRoadChange road is NULL"); return; } mpCurRoad = pRoad; int i; int nsize = mvectorroadview.size(); for(i=0;iremoveItem(mvectorroadview.at(i)); delete mvectorroadview.at(i); } mvectorroadview.clear(); nsize = mvectorviewitem.size(); for(i=0;iremoveItem(mvectorviewitem.at(i)); delete mvectorviewitem.at(i); } mvectorviewitem.clear(); double froad_xmin,froad_ymin,froad_xmax,froad_ymax; ServiceXODRTool.GetRoadMaxMin(pRoad,froad_xmin,froad_ymin,froad_xmax,froad_ymax); // roadviewitem * prvw = new roadviewitem(pRoad); int nfac; int nkeep = 30; double fac_x,fac_y; fac_x = 100000; fac_y = 100000; if(froad_xmax > froad_xmin) { fac_x = (VIEW_WIDTH-nkeep*2)/(froad_xmax - froad_xmin); } if(froad_ymax > froad_ymin) { fac_y = (VIEW_HEIGHT - nkeep*2)/(froad_ymax - froad_ymin); } nfac = fac_x; if(fac_y < nfac)nfac = fac_y; mfViewMoveX = VIEW_WIDTH/2.0 ; mfViewMoveY = VIEW_HEIGHT/2.0; mfViewMoveX = 0 - froad_xmin - (froad_xmax - froad_xmin)/2.0; mfViewMoveY = 0 + froad_ymin + (froad_ymax-froad_ymin)/2.0; // prvw->setPos(mfViewMoveX,mfViewMoveY); // prvw->setPos((froad_xmax - froad_xmin)/2.0, (froad_ymax-froad_ymin)/2.0); // mvectorroadview.push_back(prvw); // prvw->setratio(1.0); // scene->addItem(prvw); mnSelGeo = -1; ui->lineEdit_roadlen->setText(QString::number(pRoad->GetRoadLength())); ui->comboBox_Geo->clear(); nsize = pRoad->GetGeometryBlockCount(); // int i; for(i=0;icomboBox_Geo->addItem(QString("Geo ")+QString::number(i)); } RoadDigit xrd(mpCurRoad,0.1); std::vector xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&xrd); int j; int ncount = xvectorlanepath.size(); for(j=0;jsetPos(mfViewMoveX,mfViewMoveY); scene->addItem(pitem); mvectorviewitem.push_back(pitem); } std::vector xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&xrd); ncount = xvectormarkpath.size(); for(j=0;jsetPos(mfViewMoveX,mfViewMoveY); scene->addItem(pitem); mvectorviewitem.push_back(pitem); } update(); } void RoadEditDialog::on_comboBox_Geo_currentIndexChanged(int index) { if(mpCurRoad == 0 )return; if(index<0)return; mnSelGeo = index; if(index>= mpCurRoad->GetGeometryBlockCount())return; GeometryBlock * pgb = mpCurRoad->GetGeometryBlock(index); RoadGeometry * pg = pgb->GetGeometryAt(0); ui->lineEdit_s->setText(QString::number(pg->GetS())); ui->lineEdit_x->setText(QString::number(pg->GetX())); ui->lineEdit_y->setText(QString::number(pg->GetY())); ui->lineEdit_hdg->setText(QString::number(pg->GetHdg())); ui->lineEdit_len->setText(QString::number(pg->GetLength())); if((pg->GetGeomType()>=0)&&(pg->GetGeomType()<5)) { ui->comboBox_geotype->setCurrentIndex(pg->GetGeomType()); } } void RoadEditDialog::on_pushButton_EditLane_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogEditLane laned(mpCurRoad,this); int res = laned.exec(); on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex()); } void RoadEditDialog::on_pushButton_EditRoadMark_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogEditRoadMark roadmarkd(mpCurRoad,this); roadmarkd.exec(); on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex()); } void RoadEditDialog::on_pushButton_LaneFromRTK_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogLaneFromRTK lanertk(mpCurRoad,mpxodr,this); lanertk.exec(); on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex()); } void RoadEditDialog::on_pushButton_RoadSplit_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogRoadSplit roadsplit(mpCurRoad,mpxodr,this); roadsplit.exec(); unsigned int ncurindex = ui->comboBox_Road->currentIndex(); ui->comboBox_Road->clear(); int i; int nroadcount = mpxodr->GetRoadCount(); for(i=0;iGetRoad(i)->GetRoadId().data(); ui->comboBox_Road->addItem(strname); } on_comboBox_Road_currentIndexChanged(ncurindex); } void RoadEditDialog::on_pushButton_RoadMerge_clicked() { DialogRoadMerge roadmerge(mpxodr,this); roadmerge.exec(); unsigned int ncurindex = ui->comboBox_Road->currentIndex(); ui->comboBox_Road->clear(); int i; int nroadcount = mpxodr->GetRoadCount(); for(i=0;iGetRoad(i)->GetRoadId().data(); ui->comboBox_Road->addItem(strname); } on_comboBox_Road_currentIndexChanged(ncurindex); } void RoadEditDialog::on_pushButton_MoveRoad_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogRoadMove roadmove(mpxodr,mpCurRoad,this); roadmove.exec(); unsigned int ncurindex = ui->comboBox_Road->currentIndex(); ui->comboBox_Road->clear(); int i; int nroadcount = mpxodr->GetRoadCount(); for(i=0;iGetRoad(i)->GetRoadId().data(); ui->comboBox_Road->addItem(strname); } on_comboBox_Road_currentIndexChanged(ncurindex); } void RoadEditDialog::on_pushButton_RotateRoad_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogRoadRotate roadrotate(mpxodr,mpCurRoad,this); roadrotate.exec(); unsigned int ncurindex = ui->comboBox_Road->currentIndex(); ui->comboBox_Road->clear(); int i; int nroadcount = mpxodr->GetRoadCount(); for(i=0;iGetRoad(i)->GetRoadId().data(); ui->comboBox_Road->addItem(strname); } on_comboBox_Road_currentIndexChanged(ncurindex); } void RoadEditDialog::on_pushButton_MirrorRoad_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogRoadMirror roadmirror(mpxodr,mpCurRoad,this); roadmirror.exec(); unsigned int ncurindex = ui->comboBox_Road->currentIndex(); ui->comboBox_Road->clear(); int i; int nroadcount = mpxodr->GetRoadCount(); for(i=0;iGetRoad(i)->GetRoadId().data(); ui->comboBox_Road->addItem(strname); } on_comboBox_Road_currentIndexChanged(ncurindex); } void RoadEditDialog::on_pushButton_EditLaneOffset_clicked() { if(mpCurRoad == 0) { QMessageBox::warning(this,"Warning","Not Select Road"); return; } DialogLaneOffset dlglaneoffset(mpCurRoad,this); dlglaneoffset.exec(); }