|
@@ -0,0 +1,296 @@
|
|
|
+#include "xvmainwindow.h"
|
|
|
+#include "ui_xvmainwindow.h"
|
|
|
+
|
|
|
+#include <QMessageBox>
|
|
|
+#include <QFileDialog>
|
|
|
+
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+#include "xodrfunc.h"
|
|
|
+#include "roaddigit.h"
|
|
|
+#include "xodrscenfunc.h"
|
|
|
+
|
|
|
+#define VIEW_WIDTH 2000
|
|
|
+#define VIEW_HEIGHT 2000
|
|
|
+
|
|
|
+static bool IsNaN(double dat)
|
|
|
+{
|
|
|
+ qint64 & ref=*(qint64 *)&dat;
|
|
|
+ return (ref&0x7FF0000000000000) == 0x7FF0000000000000 && (ref&0xfffffffffffff)!=0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+XVMainWindow::XVMainWindow(QWidget *parent) :
|
|
|
+ QMainWindow(parent),
|
|
|
+ ui(new Ui::XVMainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ myview = new MyView(this);
|
|
|
+ myview->setObjectName(QStringLiteral("graphicsView"));
|
|
|
+ myview->setGeometry(QRect(30, 30, 600, 600));
|
|
|
+
|
|
|
+ connect(myview,SIGNAL(dbclickxy(double,double)),this,SLOT(onClickXY(double,double)));
|
|
|
+
|
|
|
+
|
|
|
+ myview->setCacheMode(myview->CacheBackground);
|
|
|
+
|
|
|
+ mpscene = new QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
|
|
|
+ mpscene->setBackgroundBrush(Qt::darkGreen);
|
|
|
+
|
|
|
+ myview->setScene(mpscene);
|
|
|
+
|
|
|
+ setWindowTitle("ADC OpenDrive Viewer");
|
|
|
+}
|
|
|
+
|
|
|
+XVMainWindow::~XVMainWindow()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::resizeEvent(QResizeEvent *event)
|
|
|
+{
|
|
|
+ qDebug("resize");
|
|
|
+ QSize sizemain = ui->centralwidget->size();
|
|
|
+ qDebug("size x = %d y=%d",sizemain.width(),sizemain.height());
|
|
|
+ myview->setGeometry(0,30,sizemain.width(),sizemain.height()-30);
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::on_actionLoad_triggered()
|
|
|
+{
|
|
|
+
|
|
|
+ if(mxodr.GetRoadCount() > 0)
|
|
|
+ {
|
|
|
+ QMessageBox::StandardButton button;
|
|
|
+ char strquest[256];
|
|
|
+ snprintf(strquest,256,"Do you Want to Load New File ?");
|
|
|
+ button=QMessageBox::question(this,"Move",strquest,QMessageBox::Yes|QMessageBox::No);
|
|
|
+ if(button==QMessageBox::No)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if(button==QMessageBox::Yes)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+#ifndef Android
|
|
|
+ QString strpath = QFileDialog::getOpenFileName(this,"Load XODR",".","*.xodr");
|
|
|
+ if(strpath.isEmpty())return;
|
|
|
+#else
|
|
|
+// QMessageBox::warning(this,"warning","no file dialog.",QMessageBox::YesAll);
|
|
|
+ QString strpath = "/storage/emulated/0/map.xodr";
|
|
|
+
|
|
|
+
|
|
|
+#endif
|
|
|
+ LoadXODR(strpath);
|
|
|
+ UpdateScene();
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::LoadXODR(QString strpath)
|
|
|
+{
|
|
|
+ mxodr.Clear();
|
|
|
+ OpenDrive * pxodr = &mxodr; //because add to xodr,so don't delete
|
|
|
+ OpenDriveXmlParser x(pxodr);
|
|
|
+ if(!x.ReadFile(strpath.toStdString()))
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"warn","Can't load xodr file.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nroadnum = pxodr->GetRoadCount();
|
|
|
+ int i;
|
|
|
+ double froadlen = 0;
|
|
|
+ for(i=0;i<nroadnum;i++)
|
|
|
+ {
|
|
|
+ Road * pRoad = pxodr->GetRoad(i);
|
|
|
+ if(IsNaN(pRoad->GetRoadLength()))
|
|
|
+ {
|
|
|
+ pxodr->DeleteRoad(i);
|
|
|
+ i--;
|
|
|
+ nroadnum--;
|
|
|
+ qDebug("delete road %s because length is NaN",pRoad->GetRoadId().data());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ froadlen = froadlen + pRoad->GetRoadLength();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ char strout[256];
|
|
|
+ snprintf(strout,256,"Road count is %d. Total Len is %f",mxodr.GetRoadCount(),froadlen);
|
|
|
+ QMessageBox::information(this,"Info",strout,QMessageBox::YesAll);
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::UpdateScene()
|
|
|
+{
|
|
|
+ int i;
|
|
|
+ int nsize = mvectorviewitem.size();
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mpscene->removeItem(mvectorviewitem.at(i));
|
|
|
+ delete mvectorviewitem.at(i);
|
|
|
+ }
|
|
|
+ mvectorviewitem.clear();
|
|
|
+
|
|
|
+ nsize = mxodr.GetRoadCount();
|
|
|
+
|
|
|
+ std::vector<RoadDigit> xvectorrd;
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ RoadDigit xrd(mxodr.GetRoad(i),10.0);
|
|
|
+ xvectorrd.push_back(xrd);
|
|
|
+ }
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ std::vector<QGraphicsPathItem *> xvectorlanepath = xodrscenfunc::GetRoadLaneItem(&(xvectorrd[i]));
|
|
|
+ int j;
|
|
|
+ int ncount = xvectorlanepath.size();
|
|
|
+ for(j=0;j<ncount;j++)
|
|
|
+ {
|
|
|
+ QGraphicsPathItem * pitem = xvectorlanepath[j];
|
|
|
+ pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
|
|
|
+ mpscene->addItem(pitem);
|
|
|
+ mvectorviewitem.push_back(pitem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ std::vector<QGraphicsPathItem *> xvectormarkpath = xodrscenfunc::GetRoadMarkItem(&(xvectorrd[i]));
|
|
|
+ int j;
|
|
|
+ int ncount = xvectormarkpath.size();
|
|
|
+ for(j=0;j<ncount;j++)
|
|
|
+ {
|
|
|
+ QGraphicsPathItem * pitem = xvectormarkpath[j];
|
|
|
+ pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
|
|
|
+ mpscene->addItem(pitem);
|
|
|
+ mvectorviewitem.push_back(pitem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void XVMainWindow::on_actionZoom_In_triggered()
|
|
|
+{
|
|
|
+ myview->zoomIn();
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::on_actionZoom_Out_triggered()
|
|
|
+{
|
|
|
+ myview->zoomOut();
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::on_actionZoom_One_triggered()
|
|
|
+{
|
|
|
+ myview->zoomone();
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::onClickXY(double x, double y)
|
|
|
+{
|
|
|
+ double selx,sely;
|
|
|
+ double lon,lat;
|
|
|
+ selx = (x - VIEW_WIDTH/2);
|
|
|
+ sely = (y - VIEW_HEIGHT/2) * (-1);
|
|
|
+
|
|
|
+ mfselx = selx;
|
|
|
+ mfsely = sely;
|
|
|
+
|
|
|
+// double x0,y0;
|
|
|
+// GaussProjCal(glon0,glat0,&x0,&y0);
|
|
|
+// GaussProjInvCal(x0+selx,y0+sely,&lon,&lat);
|
|
|
+
|
|
|
+ double rel_x,rel_y;
|
|
|
+ rel_x = selx - mfViewMoveX;
|
|
|
+ rel_y = sely - mfViewMoveY;
|
|
|
+
|
|
|
+ Road * pRoad = 0;
|
|
|
+ GeometryBlock * pgeob;
|
|
|
+ double fdis,nearx,neary,hdg;
|
|
|
+ double fs;
|
|
|
+ int nlane;
|
|
|
+ if(xodrfunc::GetNearPoint(rel_x,rel_y,&mxodr,&pRoad,&pgeob,fdis,nearx,neary,hdg,50,&fs,&nlane) == 0)
|
|
|
+ {
|
|
|
+ qDebug("s:%f dis is %f nlane is %d",fs,fdis,nlane);
|
|
|
+ char strout[1000];
|
|
|
+ snprintf(strout,1000,"Road:%s s:%f dis:%f nlane:%d",pRoad->GetRoadId().data(),fs,fdis,nlane);
|
|
|
+ // mpLabel_Status->setText(strout);
|
|
|
+ ui->statusbar->showMessage(strout,10000);
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ char strout[1000];
|
|
|
+ snprintf(strout,1000,"Click x:%f y:%f",rel_x,rel_y);
|
|
|
+ ui->statusbar->showMessage(strout,10000);
|
|
|
+ qDebug("not found near road.");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::on_actionSet_Move_triggered()
|
|
|
+{
|
|
|
+ QMessageBox::StandardButton button;
|
|
|
+ char strquest[256];
|
|
|
+ snprintf(strquest,256,"Want to Move Center to x:%f y:%f ?",-(mfViewMoveX - mfselx),-(mfViewMoveY-mfsely));
|
|
|
+ button=QMessageBox::question(this,"Move",strquest,QMessageBox::Yes|QMessageBox::No);
|
|
|
+ if(button==QMessageBox::No)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if(button==QMessageBox::Yes)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ mfViewMoveX = mfViewMoveX - mfselx;
|
|
|
+ mfViewMoveY = mfViewMoveY - mfsely;
|
|
|
+
|
|
|
+ int nsize = mvectorviewitem.size();
|
|
|
+ int i;
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mpscene->removeItem(mvectorviewitem.at(i));
|
|
|
+ }
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mvectorviewitem.at(i)->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
|
|
|
+ mpscene->addItem(mvectorviewitem.at(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ myview->zoomIn();
|
|
|
+ myview->zoomOut();
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::on_actionReset_Move_triggered()
|
|
|
+{
|
|
|
+ mfViewMoveX = 0;
|
|
|
+ mfViewMoveY = 0;
|
|
|
+ int nsize = mvectorviewitem.size();
|
|
|
+ int i;
|
|
|
+
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mpscene->removeItem(mvectorviewitem.at(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mvectorviewitem.at(i)->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
|
|
|
+ mpscene->addItem(mvectorviewitem.at(i));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ myview->zoomIn();
|
|
|
+ myview->zoomOut();
|
|
|
+}
|
|
|
+
|
|
|
+void XVMainWindow::paintEvent(QPaintEvent * event)
|
|
|
+{
|
|
|
+ if(mbRefresh)
|
|
|
+ {
|
|
|
+ myview->setScene(mpscene);
|
|
|
+ mbRefresh = false;
|
|
|
+ }
|
|
|
+}
|