瀏覽代碼

change map_lanetoxodr. add some cda code.

yuchuli 2 年之前
父節點
當前提交
3a2e319480

+ 3 - 2
src/common/ivxlnt/ivxlnt.cpp

@@ -54,10 +54,11 @@ void * Openxlsx(std::string strfilepath)
     return p;
 }
 
-std::string getcellvalue(void * pxlsxhanle,unsigned int column,unsigned int row)
+int  getcellvalue(void * pxlsxhanle,unsigned int column,unsigned int row,std::string & strvalue)
 {
     Ivxlnt * p = (Ivxlnt * )pxlsxhanle;
-    return p->getcellvalue(column,row);
+    strvalue =  p->getcellvalue(column,row);
+    return 0;
 }
 
 void Closexlsx(void * pxlsxhanle)

+ 6 - 6
src/common/ivxlnt/ivxlnt.h

@@ -4,11 +4,11 @@
 #include <string>
 
 
-
-
-
-void * Openxlsx(std::string strfilepath);
-std::string getcellvalue(void * pxlsxhanle,unsigned int column,unsigned int row);
-void Closexlsx(void * pxlsxhanle);
+extern "C"
+{
+void *   Openxlsx(std::string strfilepath);
+int getcellvalue(void * pxlsxhanle,unsigned int column,unsigned int row,std::string & strvalue);
+void  Closexlsx(void * pxlsxhanle);
+}
 
 #endif // IVXLNT_H

+ 0 - 12
src/tool/map_lanetoxodr/dialogaddroadfromcda.cpp

@@ -10,18 +10,6 @@ DialogAddRoadFromCDA::DialogAddRoadFromCDA(QWidget *parent) :
 {
     ui->setupUi(this);
 
-    QLibrary xlib("./libxlnt.so.1.5.0");
-    xlib.load();
-
-    QLibrary qlib("./libivxlnt.so");
-    if(qlib.load())
-    {
-        std::cout<<" lib load."<<std::endl;
-    }
-    else
-    {
-        std::cout<<" load libivxlnt fail."<<qlib.errorString().toStdString()<< std::endl;
-    }
 }
 
 DialogAddRoadFromCDA::~DialogAddRoadFromCDA()

+ 59 - 0
src/tool/map_lanetoxodr/excelapi.cpp

@@ -0,0 +1,59 @@
+#include "excelapi.h"
+
+#include <QLibrary>
+#include <iostream>
+
+ExcelAPI::ExcelAPI()
+{
+    std::cout<<"Load Excel API"<<std::endl;
+    QLibrary xlib("./plugin/libxlnt.so.1.5.0");
+    if(!xlib.load())
+    {
+        std::cout<<" load libxlnt fail."<<xlib.errorString().toStdString()<< std::endl;
+        return ;
+    }
+
+    QLibrary qlib("./plugin/libivxlnt.so");
+    if(qlib.load())
+    {
+        std::cout<<" lib load."<<std::endl;
+    }
+    else
+    {
+        std::cout<<" load libivxlnt fail."<<qlib.errorString().toStdString()<< std::endl;
+        return;
+    }
+    mOpenxlsx=(OpenxlsxFunction)qlib.resolve("Openxlsx");
+    mgetcellvalue = (getcellvalueFunction)qlib.resolve("getcellvalue");
+    mClosexlsx = (ClosexlsxFunction)qlib.resolve("Closexlsx");
+    if((mOpenxlsx != NULL)&&(mgetcellvalue!=NULL)&&(mClosexlsx != NULL))
+    {
+        mbLoad = true;
+    }
+
+
+}
+
+ExcelAPI & ExcelAPI::Inst()
+{
+    static ExcelAPI xAPI;
+    return xAPI;
+}
+
+bool ExcelAPI::IsLoad()
+{
+    return mbLoad;
+}
+
+void *   ExcelAPI::Openxlsx(std::string strfilepath)
+{
+    return mOpenxlsx(strfilepath);
+}
+int ExcelAPI::getcellvalue(void * pxlsxhanle,unsigned int column,unsigned int row,std::string & strvalue)
+{
+    return mgetcellvalue(pxlsxhanle,column,row,strvalue);
+}
+void  ExcelAPI::Closexlsx(void * pxlsxhanle)
+{
+    mClosexlsx(pxlsxhanle);
+}

+ 34 - 0
src/tool/map_lanetoxodr/excelapi.h

@@ -0,0 +1,34 @@
+#ifndef EXCELAPI_H
+#define EXCELAPI_H
+
+
+#include <string>
+
+typedef void * (*OpenxlsxFunction)(std::string strfilepath);
+typedef int (*getcellvalueFunction)(void * pxlsxhanle,unsigned int column,unsigned int row,std::string & strvalue);
+typedef void  (*ClosexlsxFunction)(void * pxlsxhanle);
+
+class ExcelAPI
+{
+public:
+    ExcelAPI();
+
+    static ExcelAPI & Inst();
+
+    bool IsLoad();
+
+public:
+    void *   Openxlsx(std::string strfilepath);
+    int getcellvalue(void * pxlsxhanle,unsigned int column,unsigned int row,std::string & strvalue);
+    void  Closexlsx(void * pxlsxhanle);
+
+private:
+    bool mbLoad = false;
+    OpenxlsxFunction mOpenxlsx;
+    getcellvalueFunction mgetcellvalue;
+    ClosexlsxFunction mClosexlsx;
+};
+
+#define ServiceExcelAPI ExcelAPI::Inst()
+
+#endif // EXCELAPI_H

+ 72 - 0
src/tool/map_lanetoxodr/function/cdaproc.cpp

@@ -0,0 +1,72 @@
+#include "cdaproc.h"
+
+#include <iostream>
+
+CDAProc::CDAProc()
+{
+
+}
+
+int CDAProc::ProcLineRoad(OpenDrive * pxodr,  std::string strtype,std::string strradius,std::string strroadlen,std::string strlanewidth,
+    std::string strlannecount,std::string strlanetype,std::string strlanemarkcolor,std::string strlanemarktype)
+{
+
+    pxodr->AddRoad("zl",atof(strroadlen.data()),"1","-1");
+    Road * pRoad = pxodr->GetLastAddedRoad();
+    pRoad->AddGeometryBlock();
+    GeometryBlock * pgeob = pRoad->GetLastAddedGeometryBlock();
+    pgeob->AddGeometryLine(0,0,0,0,atof(strroadlen.data()));
+    pRoad->AddLaneSection(0);
+    LaneSection * pLS = pRoad->GetLaneSection(0);
+    pLS->AddLane(0,0,"none",false);
+    Lane * pcenterlane = pLS->GetLastAddedLane();
+    pcenterlane->AddRoadMarkRecord(0,"solid solid","standard","yellow",0.15,"none");
+
+    int nlanecount = atoi(strlannecount.data());
+    double flanewidth = atof(strlanewidth.data());
+    int i;
+    for(i=0;i<nlanecount;i++)
+    {
+        pLS->AddLane(-1,(i+1)*(-1),"driving",false,true);
+        Lane * pnewlane = pLS->GetLastAddedLane();
+        pnewlane->AddWidthRecord(0,flanewidth,0,0,0);
+        if(i == (nlanecount -1))
+        {
+            pnewlane->AddRoadMarkRecord(0,"solid","standard","standard",0.15,"none");
+        }
+        else
+            pnewlane->AddRoadMarkRecord(0,"broken","standard","standard",0.15,"none");
+    }
+    return 0;
+}
+
+int CDAProc::Proc(std::string strxlsxpath,OpenDrive * pxodr)
+{
+    void * pexcel = ServiceExcelAPI.Openxlsx(strxlsxpath);
+
+    std::string strtype;
+    std::string strradius;
+    std::string strroadlen;
+    std::string strlanewidth;
+    std::string strlannecount;
+    std::string strlanetype;
+    std::string strlanemarkcolor;
+    std::string strlanemarktype;
+    ServiceExcelAPI.getcellvalue(pexcel,119,4,strtype);
+    ServiceExcelAPI.getcellvalue(pexcel,129,4,strradius);
+    ServiceExcelAPI.getcellvalue(pexcel,121,4,strroadlen);
+    ServiceExcelAPI.getcellvalue(pexcel,122,4,strlanewidth);
+    ServiceExcelAPI.getcellvalue(pexcel,123,4,strlannecount);
+    ServiceExcelAPI.getcellvalue(pexcel,124,4,strlanetype);
+    ServiceExcelAPI.getcellvalue(pexcel,125,4,strlanemarkcolor);
+    ServiceExcelAPI.getcellvalue(pexcel,126,4,strlanemarktype);
+    std::cout<<"type : "<<strtype<<std::endl;
+    ServiceExcelAPI.Closexlsx(pexcel);
+
+    if(strtype == "直路" )
+    {
+        std::cout<<" is zl . "<<std::endl;
+        return ProcLineRoad(pxodr,strtype,strradius,strroadlen,strlanewidth,strlannecount,strlanetype,strlanemarkcolor,strlanemarktype);
+    }
+    return 0;
+}

+ 18 - 0
src/tool/map_lanetoxodr/function/cdaproc.h

@@ -0,0 +1,18 @@
+#ifndef CDAPROC_H
+#define CDAPROC_H
+
+#include <string>
+#include "excelapi.h"
+
+#include <OpenDrive/OpenDrive.h>
+
+class CDAProc
+{
+public:
+    CDAProc();
+    static int Proc(std::string strxlsxpath,OpenDrive * pxodr);
+    static int ProcLineRoad(OpenDrive * pxodr,  std::string strtype,std::string strradius,std::string strroadlen,std::string strlanewidth,
+        std::string strlannecount,std::string strlanetype,std::string strlanemarkcolor,std::string strlanemarktype);
+};
+
+#endif // CDAPROC_H

+ 12 - 0
src/tool/map_lanetoxodr/function/ndsdataproc.cpp

@@ -312,6 +312,11 @@ int NDSDataProc::ProcNDSData(std::string strlinepath,std::string strvehiclepath,
             y_veh[j] = xvectorvehicle[xvectorvl[j+ncurpos].mvehindex].fy;//mvectorrtkdata.at(j+ncurpos).mfrely;
         }
 
+        if(nrange<1)
+        {
+            break;
+        }
+
         bool bArcOk = false;
         bool bLineOk = false;
         double dismax = 0;
@@ -492,6 +497,13 @@ int NDSDataProc::ProcNDSData(std::string strlinepath,std::string strvehiclepath,
     ncurpos = 0;
     nrange = xvectorvl.size();
     double flanewidtherror = 0.1; //1cm
+
+    if(nrange <2)
+    {
+        mstrState = " No Valid Data. Complete.";
+        mnProc = 100;
+        return 0;
+    }
     while(bComplete == false)
     {
         double ele_coff[4];

+ 1 - 1
src/tool/map_lanetoxodr/main.cpp

@@ -59,9 +59,9 @@ bool requestPermission() {
 iv::Ivlog *givlog;
 #endif
 
+#include "excelapi.h"
 int main(int argc, char *argv[])
 {
-
     //Call License
     //Wait
 #ifndef ANDROID

+ 12 - 2
src/tool/map_lanetoxodr/mainwindow.cpp

@@ -5984,6 +5984,16 @@ void MainWindow::on_CreateAfter_triggered()
 
 void MainWindow::on_actionAdd_Road_From_CDA_triggered()
 {
-    DialogAddRoadFromCDA cda;//(&mxodr,strroadid,this);
-    cda.exec();
+    if(ServiceExcelAPI.IsLoad() == false)
+    {
+        QMessageBox::warning(this,tr("Waring"),tr("Can't load ivxlnt plugin."),QMessageBox::YesAll);
+        return;
+    }
+//    QString str = QFileDialog::getOpenFileName(this,"Load xlsx",".","*.xlsx");
+//    if(str.isEmpty())return;
+
+    QString str = "/home/yuchuli/1.xlsx";
+    int nrtn = CDAProc::Proc(str.toStdString(),&mxodr);
+
+
 }

+ 3 - 0
src/tool/map_lanetoxodr/mainwindow.h

@@ -87,6 +87,9 @@ using namespace Eigen;
 
 #include "createextendroad.h"
 
+#include "excelapi.h"
+#include "cdaproc.h"
+
 namespace Ui {
 class MainWindow;
 }

+ 6 - 2
src/tool/map_lanetoxodr/map_lanetoxodr.pro

@@ -92,7 +92,9 @@ SOURCES += \
     view/xodrscenfunc.cpp \
     function/createextendroad.cpp \
     function/autoconnect.cpp \
-    dialogaddroadfromcda.cpp
+    dialogaddroadfromcda.cpp \
+    excelapi.cpp \
+    function/cdaproc.cpp
 
 HEADERS += \
     function/autoroadcontact.h \
@@ -155,7 +157,9 @@ HEADERS += \
     view/xodrscenfunc.h \
     function/createextendroad.h \
     function/autoconnect.h \
-    dialogaddroadfromcda.h
+    dialogaddroadfromcda.h \
+    excelapi.h \
+    function/cdaproc.h
 
 FORMS += \
         ui/dialogaddroadfromnds.ui \