|
@@ -0,0 +1,345 @@
|
|
|
+#include "roadeditdialog.h"
|
|
|
+#include "ui_roadeditdialog.h"
|
|
|
+
|
|
|
+#include "math.h"
|
|
|
+
|
|
|
+#define VIEW_WIDTH 850
|
|
|
+#define VIEW_HEIGHT 350
|
|
|
+
|
|
|
+RoadEditDialog::RoadEditDialog(OpenDrive * pxodr,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, 400, 900, 400));
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
+{
|
|
|
+ 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;
|
|
|
+
|
|
|
+ mnSelGeo = -1;
|
|
|
+
|
|
|
+ ui->lineEdit_roadlen->setText(QString::number(pRoad->GetRoadLength()));
|
|
|
+
|
|
|
+ ui->comboBox_Geo->clear();
|
|
|
+ int 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());
|
|
|
+ }
|
|
|
+}
|