|
@@ -0,0 +1,273 @@
|
|
|
+#include "mainwindow.h"
|
|
|
+#include "ui_mainwindow.h"
|
|
|
+
|
|
|
+#include "roaddigit.h"
|
|
|
+#include "xodrscenfunc.h"
|
|
|
+
|
|
|
+
|
|
|
+#include <QFileDialog>
|
|
|
+#include <QMessageBox>
|
|
|
+
|
|
|
+#define VIEW_WIDTH 1000
|
|
|
+#define VIEW_HEIGHT 1000
|
|
|
+
|
|
|
+
|
|
|
+double glon0 = 117.0866293;
|
|
|
+double glat0 = 39.1364713;
|
|
|
+
|
|
|
+MainWindow::MainWindow(QWidget *parent)
|
|
|
+ : QMainWindow(parent)
|
|
|
+ , ui(new Ui::MainWindow)
|
|
|
+{
|
|
|
+ ui->setupUi(this);
|
|
|
+
|
|
|
+ myview = new MyView(ui->centralwidget);
|
|
|
+ myview->setObjectName(QStringLiteral("graphicsView"));
|
|
|
+ myview->setGeometry(QRect(30, 30, 600, 600));
|
|
|
+
|
|
|
+ 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;
|
|
|
+
|
|
|
+ // mpscene = new QGraphicsScene;//(-300, -300, 600, 600);
|
|
|
+ mpscene = new QGraphicsScene(0,0,VIEW_WIDTH,VIEW_HEIGHT);
|
|
|
+ mpscene->setBackgroundBrush(Qt::darkGreen);
|
|
|
+
|
|
|
+ mnFontHeight = ui->centralwidget->fontMetrics().height();
|
|
|
+
|
|
|
+ QTabWidget * p = new QTabWidget(ui->centralwidget);
|
|
|
+ p->setGeometry(30,30,300,300);
|
|
|
+
|
|
|
+ // CreateTab1View(p);
|
|
|
+
|
|
|
+ mpLabel_Status = new QLabel(this);
|
|
|
+ ui->statusbar->addPermanentWidget(mpLabel_Status);
|
|
|
+
|
|
|
+ mTabMain = p;
|
|
|
+
|
|
|
+ CreateCar();
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+MainWindow::~MainWindow()
|
|
|
+{
|
|
|
+ delete ui;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::resizeEvent(QResizeEvent *event)
|
|
|
+{
|
|
|
+ (void)event;
|
|
|
+ QSize sizemain = ui->centralwidget->size();
|
|
|
+ myview->setGeometry(0,30,sizemain.width()-mnFontHeight * 22 - 30,sizemain.height());
|
|
|
+ mTabMain->setGeometry(sizemain.width()-mnFontHeight * 22,30,mnFontHeight * 22,sizemain.height()-50);
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::paintEvent(QPaintEvent *)
|
|
|
+{
|
|
|
+ myview->setScene(mpscene);
|
|
|
+ myview->show();
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onClickXY(double x,double y)
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::on_actionLoad_triggered()
|
|
|
+{
|
|
|
+ QString str = QFileDialog::getOpenFileName(this,"Load XODR",".","*.xodr");
|
|
|
+ if(str.isEmpty())return;
|
|
|
+
|
|
|
+ OpenDrive * pxodr = new OpenDrive(); //because add to xodr,so don't delete
|
|
|
+ OpenDriveXmlParser x(pxodr);
|
|
|
+ if(!x.ReadFile(str.toStdString()))
|
|
|
+ {
|
|
|
+ QMessageBox::warning(this,"warn","Can't load xodr file.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ unsigned short int revMajor,revMinor;
|
|
|
+ std::string name,date;
|
|
|
+ float version;
|
|
|
+ double north,south,east,west,lat0,lon0,hdg0;
|
|
|
+ if(pxodr->GetHeader() != 0)
|
|
|
+ {
|
|
|
+ pxodr->GetHeader()->GetAllParams(revMajor,revMinor,name,version,date,north,south,east,west,lat0,lon0,hdg0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ lat0 = 39.0;
|
|
|
+ lon0 = 119.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ glat0 = lat0;
|
|
|
+ glon0 = lon0;
|
|
|
+
|
|
|
+ mxodr = *pxodr;
|
|
|
+
|
|
|
+ UpdateScene();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#include <QtGui>
|
|
|
+
|
|
|
+void MainWindow::UpdateScene()
|
|
|
+{
|
|
|
+
|
|
|
+ int i;
|
|
|
+ int nsize = mvectorviewitem.size();
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mpscene->removeItem(mvectorviewitem.at(i));
|
|
|
+ delete mvectorviewitem.at(i);
|
|
|
+ }
|
|
|
+ nsize = mvectorgeoitem.size();
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ mpscene->removeItem(mvectorgeoitem.at(i));
|
|
|
+ delete mvectorgeoitem.at(i);
|
|
|
+ }
|
|
|
+ mvectorviewitem.clear();
|
|
|
+ mvectorgeoitem.clear();
|
|
|
+
|
|
|
+ nsize = mxodr.GetRoadCount();
|
|
|
+
|
|
|
+ std::vector<RoadDigit> xvectorrd;
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+ RoadDigit xrd(mxodr.GetRoad(i),5.0);
|
|
|
+ xvectorrd.push_back(xrd);
|
|
|
+ // UpdateSceneRoad(mxodr.GetRoad(i));
|
|
|
+ // qDebug("update road %d",i);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=0;i<nsize;i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ std::vector<QGraphicsTextItem *> xvectortext;
|
|
|
+ std::vector<QGraphicsPathItem *> xvectorparkmark;
|
|
|
+ std::vector<QGraphicsPathItem *> xvectorparkpath = xodrscenfunc::GetRoadParkingItem(&(xvectorrd[i]),xvectortext,
|
|
|
+ xvectorparkmark);
|
|
|
+ int j;
|
|
|
+ int ncount = xvectorparkpath.size();
|
|
|
+ for(j=0;j<ncount;j++)
|
|
|
+ {
|
|
|
+ QGraphicsPathItem * pitem = xvectorparkpath[j];
|
|
|
+ pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
|
|
|
+ mpscene->addItem(pitem);
|
|
|
+ mvectorviewitem.push_back(pitem);
|
|
|
+ }
|
|
|
+ ncount = xvectortext.size();
|
|
|
+ for(j=0;j<ncount;j++)
|
|
|
+ {
|
|
|
+ QGraphicsTextItem * pitem = xvectortext[j];
|
|
|
+ // pitem->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + (-24.0),-mfViewMoveY+VIEW_HEIGHT/2.0+(-102.0));
|
|
|
+ pitem->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + pitem->pos().x(),-mfViewMoveY+VIEW_HEIGHT/2.0+pitem->pos().y());
|
|
|
+ mpscene->addItem(pitem);
|
|
|
+ }
|
|
|
+ ncount = xvectorparkmark.size();
|
|
|
+ for(j=0;j<ncount;j++)
|
|
|
+ {
|
|
|
+ QGraphicsPathItem * pitem = xvectorparkmark[j];
|
|
|
+ pitem->setPos(mfViewMoveX +VIEW_WIDTH/2,-mfViewMoveY+VIEW_HEIGHT/2);
|
|
|
+ mpscene->addItem(pitem);
|
|
|
+ mvectorviewitem.push_back(pitem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ SetCarPos(30,10,M_PI/2.0);
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::CreateCar()
|
|
|
+{
|
|
|
+ QGraphicsPixmapItem * ppix;
|
|
|
+ ppix = new QGraphicsPixmapItem();
|
|
|
+ ppix->setPixmap(QPixmap(":/car.png"));
|
|
|
+ QRectF xr = ppix->boundingRect();
|
|
|
+ double fvehwidth = 2.0;
|
|
|
+ double fvehlen = fvehwidth*(xr.width()/xr.height());
|
|
|
+ double fhdg = 0;
|
|
|
+ double fhead = fhdg * 180.0/M_PI *(-1.0);
|
|
|
+ double fscale = 2.0/xr.height();
|
|
|
+
|
|
|
+ mfvehwidth = fvehwidth;
|
|
|
+ mfvehlen = fvehlen;
|
|
|
+
|
|
|
+ double x0,y0;
|
|
|
+ x0 = fvehlen/2.0;
|
|
|
+ y0 = fvehwidth/2.0 *(-1.0);
|
|
|
+ double x1,y1;
|
|
|
+ double hdgrt = fhdg;//法 fhead *M_PI/180.0;
|
|
|
+ x1 = x0 * cos(hdgrt) - y0 * sin(hdgrt);
|
|
|
+ y1 = x0 * sin(hdgrt) + y0 * cos(hdgrt);
|
|
|
+
|
|
|
+ ppix->setRotation(fhead);
|
|
|
+ ppix->setScale(fscale);
|
|
|
+ ppix->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + 0 - x1 ,-mfViewMoveY+VIEW_HEIGHT/2.0 + y1);
|
|
|
+ mpscene->addItem(ppix);
|
|
|
+ ppix->setZValue(100.0);
|
|
|
+ mppixcar = ppix;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::SetCarPos(double x,double y, double fhdg)
|
|
|
+{
|
|
|
+ double fhead = fhdg * 180.0/M_PI *(-1.0);
|
|
|
+
|
|
|
+ double x0,y0;
|
|
|
+ x0 = mfvehlen/2.0;
|
|
|
+ y0 = mfvehwidth/2.0 *(-1.0);
|
|
|
+ double x1,y1;
|
|
|
+ double hdgrt = fhdg;//法 fhead *M_PI/180.0;
|
|
|
+ x1 = x0 * cos(hdgrt) - y0 * sin(hdgrt);
|
|
|
+ y1 = x0 * sin(hdgrt) + y0 * cos(hdgrt);
|
|
|
+
|
|
|
+ mppixcar->setRotation(fhead);
|
|
|
+
|
|
|
+
|
|
|
+ mppixcar->setPos(mfViewMoveX +VIEW_WIDTH/2.0 + x - x1 ,-mfViewMoveY+VIEW_HEIGHT/2.0 - y + y1);
|
|
|
+
|
|
|
+}
|
|
|
+
|