123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- #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;i<nroadcount;i++)
- {
- const char * strname = mpxodr->GetRoad(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<iv::GPSData> 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;j<pRoad->GetGeometryBlockCount();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;k<ncount;k++)
- {
- pSpiral->GetCoords(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<ncount;k++)
- {
- double x_draw,y_draw;
- if(curv > 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)
- {
- }
- 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;i<nsize;i++)
- {
- scene->removeItem(mvectorroadview.at(i));
- delete mvectorroadview.at(i);
- }
- mvectorroadview.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;i<nsize;i++)
- {
- ui->comboBox_Geo->addItem(QString("Geo ")+QString::number(i));
- }
- 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;i<nroadcount;i++)
- {
- const char * strname = mpxodr->GetRoad(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;i<nroadcount;i++)
- {
- const char * strname = mpxodr->GetRoad(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;i<nroadcount;i++)
- {
- const char * strname = mpxodr->GetRoad(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;i<nroadcount;i++)
- {
- const char * strname = mpxodr->GetRoad(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;i<nroadcount;i++)
- {
- const char * strname = mpxodr->GetRoad(i)->GetRoadId().data();
- ui->comboBox_Road->addItem(strname);
- }
- on_comboBox_Road_currentIndexChanged(ncurindex);
- }
|