Browse Source

change tool/map_lanetoxodr. Complete parking space show.

yuchuli 3 years ago
parent
commit
06123f1a78

+ 20 - 1
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -5311,7 +5311,10 @@ void MainWindow::UpdateScene()
 
 
     for(i=0;i<nsize;i++)
     for(i=0;i<nsize;i++)
     {
     {
-        std::vector<QGraphicsPathItem *> xvectorparkpath = xodrscenfunc::GetRoadParkingItem(&(xvectorrd[i]));
+        std::vector<QGraphicsTextItem *> xvectortext;
+        std::vector<QGraphicsPathItem *> xvectorparkmark;
+        std::vector<QGraphicsPathItem *> xvectorparkpath = xodrscenfunc::GetRoadParkingItem(&(xvectorrd[i]),xvectortext,
+                                                                                            xvectorparkmark);
         int j;
         int j;
         int ncount = xvectorparkpath.size();
         int ncount = xvectorparkpath.size();
         for(j=0;j<ncount;j++)
         for(j=0;j<ncount;j++)
@@ -5321,6 +5324,22 @@ void MainWindow::UpdateScene()
             mpscene->addItem(pitem);
             mpscene->addItem(pitem);
             mvectorviewitem.push_back(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);
+        }
     }
     }
     mbRefresh = false;
     mbRefresh = false;
 }
 }

+ 50 - 1
src/tool/map_lanetoxodr/roaddigit.cpp

@@ -386,7 +386,7 @@ void RoadDigit::CalcParkingPoint()
             double s = pObject->Gets();
             double s = pObject->Gets();
             double t = pObject->Gett();
             double t = pObject->Gett();
             double length,width,hdg;
             double length,width,hdg;
-            if((pObject->Getwidth(width) == 1)&&(pObject->Getlength(length)==1)&&(pObject->Gethdg(hdg)== 1))
+            if((pObject->Getwidth(length) == 1)&&(pObject->Getlength(width)==1)&&(pObject->Gethdg(hdg)== 1))
             {
             {
                 double roadx,roady,roadhdg;
                 double roadx,roady,roadhdg;
                 mpRoad->GetGeometryCoords(s,roadx,roady,roadhdg);
                 mpRoad->GetGeometryCoords(s,roadx,roady,roadhdg);
@@ -414,6 +414,55 @@ void RoadDigit::CalcParkingPoint()
                 xP.mX = x2;xP.mY = y2;xPP.mParkingXY.push_back(xP);
                 xP.mX = x2;xP.mY = y2;xPP.mParkingXY.push_back(xP);
                 xP.mX = x3;xP.mY = y3;xPP.mParkingXY.push_back(xP);
                 xP.mX = x3;xP.mY = y3;xPP.mParkingXY.push_back(xP);
                 xP.mX = x4;xP.mY = y4;xPP.mParkingXY.push_back(xP);
                 xP.mX = x4;xP.mY = y4;xPP.mParkingXY.push_back(xP);
+                xPP.strtext = pObject->Getid();
+                xPP.mParkingCenterXY.mX = centerx;
+                xPP.mParkingCenterXY.mY = centery;
+                xPP.mfHdg = hdgpark;
+
+
+                double fMarkWidth = 0.15;
+
+                vector<iv::ParkingXY> border;
+                iv::ParkingXY temxy;
+
+                double tem_x1,tem_x2,tem_y1,tem_y2,tem_hdg;
+                unsigned int j;
+                for(j=0;j<4;j++)
+                {
+                    border.clear();
+                    if(j ==0)
+                    {
+                        tem_x1 = x2;tem_x2 = x1;tem_y1 = y2;tem_y2 = y1;tem_hdg = hdgpark;
+                    }
+                    if(j ==1)
+                    {
+                        tem_x1 = x1;tem_x2 = x4;tem_y1 = y1;tem_y2 = y4;tem_hdg = hdgpark - M_PI/2.0;
+                    }
+                    if(j ==2)
+                    {
+                        tem_x1 = x4;tem_x2 = x3;tem_y1 = y4;tem_y2 = y3;tem_hdg = hdgpark -M_PI;;
+                    }
+                    if(j ==3)
+                    {
+                        tem_x1 = x3;tem_x2 = x2;tem_y1 = y3;tem_y2 = y2;tem_hdg = hdgpark +M_PI/2.0;
+                    }
+                    temxy.mX = tem_x1 + ((0-fMarkWidth*0.5)*cos(tem_hdg) - (0+fMarkWidth*0.5)*sin(tem_hdg));
+                    temxy.mY = tem_y1 + ((0-fMarkWidth*0.5)*sin(tem_hdg) + (0+fMarkWidth*0.5)*cos(tem_hdg));
+                    border.push_back(temxy);
+                    temxy.mX = tem_x2 + ((0+fMarkWidth*0.5)*cos(tem_hdg) - (0+fMarkWidth*0.5)*sin(tem_hdg));
+                    temxy.mY = tem_y2 + ((0+fMarkWidth*0.5)*sin(tem_hdg) + (0+fMarkWidth*0.5)*cos(tem_hdg));
+                    border.push_back(temxy);
+                    temxy.mX = tem_x2 + ((0+fMarkWidth*0.5)*cos(tem_hdg) - (0-fMarkWidth*0.5)*sin(tem_hdg));
+                    temxy.mY = tem_y2 + ((0+fMarkWidth*0.5)*sin(tem_hdg) + (0-fMarkWidth*0.5)*cos(tem_hdg));
+                    border.push_back(temxy);
+                    temxy.mX = tem_x1 + ((0-fMarkWidth*0.5)*cos(tem_hdg) - (0-fMarkWidth*0.5)*sin(tem_hdg));
+                    temxy.mY = tem_y1 + ((0-fMarkWidth*0.5)*sin(tem_hdg) + (0-fMarkWidth*0.5)*cos(tem_hdg));
+                    border.push_back(temxy);
+                    xPP.mParkingMark.push_back(border);
+                }
+
+
+
                 mvectorParkingPoint.push_back(xPP);
                 mvectorParkingPoint.push_back(xPP);
             }
             }
         }
         }

+ 4 - 0
src/tool/map_lanetoxodr/roaddigit.h

@@ -42,6 +42,10 @@ struct ParkingXY
 struct ParkingPoint
 struct ParkingPoint
 {
 {
     vector<ParkingXY> mParkingXY;
     vector<ParkingXY> mParkingXY;
+    vector<vector<ParkingXY>> mParkingMark;
+    string strtext;
+    ParkingXY mParkingCenterXY;
+    double mfHdg;
 };
 };
 
 
 }
 }

+ 61 - 1
src/tool/map_lanetoxodr/xodrscenfunc.cpp

@@ -5,7 +5,8 @@ xodrscenfunc::xodrscenfunc()
 
 
 }
 }
 
 
-std::vector<QGraphicsPathItem *> xodrscenfunc::GetRoadParkingItem(RoadDigit *prd)
+std::vector<QGraphicsPathItem *> xodrscenfunc::GetRoadParkingItem(RoadDigit *prd,std::vector<QGraphicsTextItem *> & xvectortext,
+                                                                  std::vector<QGraphicsPathItem *>  & xvectormarkgraph)
 {
 {
     std::vector<QGraphicsPathItem *> xvectorgrapath;
     std::vector<QGraphicsPathItem *> xvectorgrapath;
     std::vector<iv::ParkingPoint> * pvectorpark = prd->GetParkingPoint();
     std::vector<iv::ParkingPoint> * pvectorpark = prd->GetParkingPoint();
@@ -26,7 +27,66 @@ std::vector<QGraphicsPathItem *> xodrscenfunc::GetRoadParkingItem(RoadDigit *prd
         pitem->setPen(QPen(Qt::darkGray,0.001));
         pitem->setPen(QPen(Qt::darkGray,0.001));
         xvectorgrapath.push_back(pitem);
         xvectorgrapath.push_back(pitem);
 
 
+        QGraphicsTextItem * pitemtext = new QGraphicsTextItem;
 
 
+        pitemtext->setPlainText(pvectorpark->at(i).strtext.data());
+        QRectF xrect =  pitemtext->boundingRect();
+        QFont font = pitemtext->font();
+        font.setPixelSize(100.0);
+//                font.setPixelSize(1);  // 像素大小
+        //        font.setItalic(false);  // 斜体
+        //        font.setUnderline(false);  // 下划线
+        pitemtext->setFont(font);
+  //      pitemtext->setFont(QFont("华文琥珀",10));
+        pitemtext->setDefaultTextColor(QColor(255,255,255));
+        pitemtext->setFlags(QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsSelectable);
+        double fScale = 0.01;
+        pitemtext->setScale(fScale);
+        xrect =  pitemtext->boundingRect();
+        qDebug("rect height:  %f",xrect.height());
+        double fwidth = xrect.width() * fScale;
+        double fheight = xrect.height()*fScale;
+        double ftemx = fwidth * (-0.5);
+        double ftemy = fheight * 0.5;
+
+        double fparkhdg = pvectorpark->at(i).mfHdg;
+        double fposx = ftemx*cos(fparkhdg)-ftemy*sin(fparkhdg);
+        double fposy = ftemx*sin(fparkhdg)+ftemy*cos(fparkhdg);
+
+
+//        pitemtext->setDefaultTextColor(QColor(0, 160, 230));  // 文本色
+        pitemtext->setDefaultTextColor(Qt::white);
+        pitemtext->setRotation(pvectorpark->at(i).mfHdg *(-1.0)*180.0/M_PI);
+        pitemtext->setPos(pvectorpark->at(i).mParkingCenterXY.mX + fposx,(pvectorpark->at(i).mParkingCenterXY.mY+fposy)*(-1));
+        xvectortext.push_back(pitemtext);
+
+
+
+    }
+
+    for(i=0;i<lsize;i++)
+    {
+        std::vector<std::vector<iv::ParkingXY>> xvectormark = pvectorpark->at(i).mParkingMark;
+        unsigned int j;
+        for(j=0;j<xvectormark.size();j++)
+        {
+        QPainterPath xpath;
+        if(xvectormark.at(j).size()<4)
+        {
+            std::cout<<"Park Mark size < 4"<<std::endl;
+            continue;
+        }
+        xpath.moveTo(xvectormark.at(j).at(0).mX,xvectormark.at(j).at(0).mY*(-1));
+        xpath.lineTo(xvectormark.at(j).at(1).mX,xvectormark.at(j).at(1).mY*(-1));
+        xpath.lineTo(xvectormark.at(j).at(2).mX,xvectormark.at(j).at(2).mY*(-1));
+        xpath.lineTo(xvectormark.at(j).at(3).mX,xvectormark.at(j).at(3).mY*(-1));
+        xpath.closeSubpath();
+        QGraphicsPathItem * pitem = new QGraphicsPathItem;
+        pitem->setPath(xpath);
+        pitem->setBrush(Qt::yellow);
+        pitem->setPen(QPen(Qt::white,0.001));
+        xvectormarkgraph.push_back(pitem);
+        }
     }
     }
     return xvectorgrapath;
     return xvectorgrapath;
 }
 }

+ 2 - 1
src/tool/map_lanetoxodr/xodrscenfunc.h

@@ -18,7 +18,8 @@ public:
 public:
 public:
     static std::vector<QGraphicsPathItem *> GetRoadLaneItem(RoadDigit * prd);
     static std::vector<QGraphicsPathItem *> GetRoadLaneItem(RoadDigit * prd);
     static std::vector<QGraphicsPathItem *> GetRoadMarkItem(RoadDigit * prd);
     static std::vector<QGraphicsPathItem *> GetRoadMarkItem(RoadDigit * prd);
-    static std::vector<QGraphicsPathItem *> GetRoadParkingItem(RoadDigit * prd);
+    static std::vector<QGraphicsPathItem *> GetRoadParkingItem(RoadDigit * prd,std::vector<QGraphicsTextItem *> & xvectortext,
+                                                               std::vector<QGraphicsPathItem *>  & xvectormark);
 
 
 public:
 public:
     static bool IsDrawMark(double s);
     static bool IsDrawMark(double s);