Browse Source

change tool/map_lanetoxodr. fix geofit::CalcHdg when y1 = y0 x1!= x0 calulate error. and test draw ok.

yuchuli 3 years ago
parent
commit
4ab1c31ee5

+ 6 - 0
src/tool/map_lanetoxodr/dialogdrawroad.cpp

@@ -384,6 +384,7 @@ int DialogDrawRoad::CreateLineRoad(double startx, double starty, double hdg, dou
     {
         return -1;
     }
+    gw->SaveBack();
     pRoad->AddGeometryBlock();
     GeometryBlock * pgb = pRoad->GetLastAddedGeometryBlock();
     pgb->AddGeometryLine(0,startx,starty,hdg,len);
@@ -421,6 +422,7 @@ int DialogDrawRoad::CreateArcRoad(double startx, double starty, double hdg, doub
     {
         return -1;
     }
+    gw->SaveBack();
     pRoad->AddGeometryBlock();
     GeometryBlock * pgb = pRoad->GetLastAddedGeometryBlock();
     pgb->AddGeometryArc(0,startx,starty,hdg,len,curv);
@@ -530,6 +532,8 @@ void DialogDrawRoad::on_pushButton_Draw_clicked()
         QMessageBox::warning(this,"Warnig","Can't find this road.",QMessageBox::YesAll);
         return;
     }
+    gw->SaveBack();
+
     double point_x,point_y;
     point_x = ui->lineEdit_newpointx->text().toDouble();
     point_y = ui->lineEdit_newpointy->text().toDouble();
@@ -557,6 +561,7 @@ void DialogDrawRoad::on_pushButton_Draw_clicked()
     {
         newhdg = calchdg;
     }
+    std::cout<<"end hdg is "<<newhdg<<std::endl;
     std::vector<geobase> xvectorgeo = geofit::CreateBezierGeo(endx,endy,endhdg,
                                                               point_x,point_y,newhdg);
 
@@ -603,4 +608,5 @@ void DialogDrawRoad::on_pushButton_Draw_clicked()
     emit drawnewroad();
 
 
+
 }

+ 10 - 0
src/tool/map_lanetoxodr/geofit.cpp

@@ -817,9 +817,18 @@ double geofit::CalcHdg(double x0,double y0,double x1,double y1)
             return M_PI*3.0/2.0;
     }
 
+    if(y1 == y0)
+    {
+        if(x1>x0)return 0;
+        else return M_PI;
+    }
+
     double ratio = (y1-y0)/(x1-x0);
 
+
+
     double hdg = atan(ratio);
+//    qDebug("ratio: %f hdg:%f  y1:%f y0:%f x1:%f x0:%f",ratio,hdg,y1,y0,x1,x0);
 
     if(ratio > 0)
     {
@@ -844,6 +853,7 @@ double geofit::CalcHdg(double x0,double y0,double x1,double y1)
         }
     }
 
+//    std::cout<<" hdg : "<<hdg<<std::endl;
     return hdg;
 }
 

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

@@ -3677,7 +3677,7 @@ void MainWindow::onClickCreateRoad()
                 pgb->AddGeometryParamPoly3(s,pbez->mfX,pbez->mfY,
                                            pbez->mfHdg,pbez->mfLen,pbez->mfu[0],
                         pbez->mfu[1],pbez->mfu[2],pbez->mfu[3],pbez->mfv[0],
-                        pbez->mfv[1],pbez->mfv[2],pbez->mfv[3]);
+                        pbez->mfv[1],pbez->mfv[2],pbez->mfv[3],false);
                 break;
             }
             s = s + xvectorgeo1[j].mfLen;
@@ -4800,6 +4800,10 @@ void MainWindow::onClickCBRoadChange(int index)
    }
 
    LaneSection * pLS = pRoad->GetLaneSection(0);
+   if(pLS == 0)
+   {
+       return;
+   }
    int nlanecount = pLS->GetLaneCount();
    for(i=0;i<nlanecount;i++)
    {
@@ -4946,6 +4950,10 @@ void MainWindow::onClickCBJunctionIncommingChange(int index)
     {
         pLS = pRoad->GetLaneSection(pRoad->GetLaneSectionCount()-1);
     }
+    if(pLS == 0)
+    {
+        return;
+    }
     int nlanecount = pLS->GetLaneCount();
     mpCBJunctionFromLane->clear();
     for(i=0;i<nlanecount;i++)
@@ -4973,6 +4981,10 @@ void MainWindow::onClickCBJunctionConnectionroadChange(int index)
     }
     LaneSection * pLS;
         pLS = pRoad->GetLaneSection(0);
+    if(pLS == 0)
+    {
+        return;
+    }
     int nlanecount = pLS->GetLaneCount();
     mpCBJunctionToLane->clear();
     for(i=0;i<nlanecount;i++)

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

@@ -386,6 +386,7 @@ public:
     std::string getlanetype(Road * p,int nlane,bool bstart = true);
 
     bool IsHidenRoad(int nroadid);
+    void SaveBack();
 
 private:
     void UpdateMap(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname);
@@ -443,7 +444,7 @@ private:
 
     std::vector<OpenDrive> mvectorxodrback;
 
-    void SaveBack();
+
 
     FileBackup * mpfb;