Forráskód Böngészése

change tool/map_lanetoxodr. complete road borrow.

yuchuli 3 éve
szülő
commit
ab14b10d6d

+ 42 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlWriter.cpp

@@ -169,6 +169,21 @@ bool OpenDriveXmlWriter::WriteRoad(TiXmlElement *node, Road *road)
 	//Proceed to Signals
 	WriteSignals(nodeRoad, road);
 
+
+    vector<string> * puserDataVector = road->GetUserData();
+    unsigned int luserDataCount = puserDataVector->size();
+    for(unsigned int i=0;i<luserDataCount;i++)
+    {
+        TiXmlElement * nodeuserData = new TiXmlElement("userData");
+        nodeuserData->Parse(puserDataVector->at(i).data(),0,TIXML_ENCODING_UTF8);
+        nodeRoad->LinkEndChild(nodeuserData);
+    }
+
+    if(road->GetRoadBorrowCount()>0)
+    {
+        WriteRoadBorrows(nodeRoad,road);
+    }
+
 	/*
 	//Proceed to Surface
 	subNode=node->FirstChildElement("surface");
@@ -1318,6 +1333,33 @@ bool OpenDriveXmlWriter::WriteObjectParkingSpace(TiXmlElement *node, Object_park
 }
 //--------------
 
+bool OpenDriveXmlWriter::WriteRoadBorrow(TiXmlElement *node, RoadBorrow *pRoadBorrow)
+{
+    TiXmlElement* nodeRoadBorrow = new TiXmlElement("roadborrow");
+    node->LinkEndChild(nodeRoadBorrow);
+
+    nodeRoadBorrow->SetDoubleAttribute("sOffset",pRoadBorrow->GetS());
+    nodeRoadBorrow->SetDoubleAttribute("length",pRoadBorrow->GetLength());
+    nodeRoadBorrow->SetAttribute("mode",pRoadBorrow->GetMode());
+    return true;
+}
+//--------------
+bool OpenDriveXmlWriter::WriteRoadBorrows(TiXmlElement *node, Road *road)
+{
+    TiXmlElement* nodeRoadBorrows = new TiXmlElement("userData");
+    nodeRoadBorrows->SetAttribute("code","roadborrow");
+    node->LinkEndChild(nodeRoadBorrows);
+
+    unsigned int lRoadBorrowCount = road->GetRoadBorrowCount();
+    for(unsigned int i=0; i<lRoadBorrowCount; i++)
+    {
+        WriteRoadBorrow(nodeRoadBorrows, road->GetRoadBorrow(i));
+    }
+
+    return true;
+}
+//--------------
+
 bool OpenDriveXmlWriter::WriteSignals (TiXmlElement *node, Road* road)
 {
 	TiXmlElement* nodeSignals = new TiXmlElement("signals");

+ 2 - 0
src/common/common/xodr/OpenDrive/OpenDriveXmlWriter.h

@@ -67,6 +67,8 @@ public:
     bool WriteLaneBorder(TiXmlElement *node, LaneBorder* laneWidth);
 	//--------------
 
+    bool WriteRoadBorrows(TiXmlElement *node, Road* road);
+    bool WriteRoadBorrow(TiXmlElement *node,RoadBorrow * pRoadBorrow);
 	bool WriteObjects (TiXmlElement *node, Road* road);
     bool WriteObject(TiXmlElement * node, Object * pObject);
     bool WriteObjectParkingSpace(TiXmlElement * node,Object_parkingSpace * pObject_parkingSpace);

+ 16 - 1
src/common/common/xodr/OpenDrive/Road.cpp

@@ -62,6 +62,8 @@ Road::Road (const Road& road)
 	mObjectsVector=road.mObjectsVector;
 	mSignalsVector=road.mSignalsVector;
     mLaneOffsetVector=road.mLaneOffsetVector;
+    mRoadBorrowVector = road.mRoadBorrowVector;
+
 }
 
 /**
@@ -104,6 +106,7 @@ const Road& Road::operator=(const Road& otherRoad)
 		mObjectsVector=otherRoad.mObjectsVector;
 		mSignalsVector=otherRoad.mSignalsVector;
         mLaneOffsetVector=otherRoad.mLaneOffsetVector;
+        mRoadBorrowVector = otherRoad.mRoadBorrowVector;
 	}
 	return *this;
 }
@@ -938,6 +941,7 @@ void Road::DeleteSignal(unsigned int index)
 
 void Road::DeleteRoadBorrow(unsigned int index)
 {
+    if(mRoadBorrowVector.size() == 0)return;
     mRoadBorrowVector.erase(mRoadBorrowVector.begin()+index);
 }
 
@@ -1134,6 +1138,17 @@ int  Road::CheckLaneSectionInterval(double s_check)
 //-----------
 int Road::CheckRoadBorrowInterval(double s_check)
 {
+    int res=-1;
+    //Go through all the lane section records
+    for (unsigned int i=0;i<mRoadBorrowVector.size();i++)
+    {
+        //check if the s_check belongs to the current record
+        if (mRoadBorrowVector.at(i).CheckInterval(s_check))
+            res=i;	//assign it to the result id
+        else
+            break;	//if not, break;
+    }
+    return res;		//return the result: 0 to MaxInt as the index to the record containing s_check or -1 if nothing found
 
 }
 //-----------
@@ -1144,7 +1159,7 @@ int Road::CheckLaneOffsetInterval(double s_check)
     for (unsigned int i=0;i<mLaneOffsetVector.size();i++)
     {
         //check if the s_check belongs to the current record
-        if (mRoadBorrowVector.at(i).CheckInterval(s_check))
+        if (mLaneOffsetVector.at(i).CheckInterval(s_check))
             res=i;	//assign it to the result id
         else
             break;	//if not, break;

+ 118 - 0
src/tool/map_lanetoxodr/dialogroadborrow.cpp

@@ -35,3 +35,121 @@ DialogRoadBorrow::~DialogRoadBorrow()
 {
     delete ui;
 }
+
+void DialogRoadBorrow::on_comboBox_Road_currentIndexChanged(int index)
+{
+    Road * pRoad = mpxodr->GetRoad(index);
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    ui->lineEdit_RoadLen->setText(QString::number(pRoad->GetRoadLength(),'f',3));
+
+    ui->lineEdit_s->setText("");
+    ui->lineEdit_t->setText("");
+
+    unsigned int nBorrowCount = pRoad->GetRoadBorrowCount();
+    ui->comboBox_Borrow->clear();
+    unsigned int i;
+    for(i=0;i<nBorrowCount;i++)
+    {
+        ui->comboBox_Borrow->addItem(QString::number(pRoad->GetRoadBorrow(i)->GetS(),'g'));
+    }
+}
+
+
+void DialogRoadBorrow::on_comboBox_Borrow_currentIndexChanged(int index)
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    if(pRoad->GetRoadBorrowCount() == 0)
+    {
+        ui->lineEdit_s->setText("");
+        ui->lineEdit_t->setText("");
+        return;
+    }
+
+    if(index<0)return;
+    if(index>=pRoad->GetRoadBorrowCount())return;
+    RoadBorrow * pRoadBorrow = pRoad->GetRoadBorrow(index);
+    if(pRoadBorrow == NULL)
+    {
+        return;
+    }
+    ui->lineEdit_s->setText(QString::number(pRoadBorrow->GetS()));
+    ui->lineEdit_t->setText(QString::number(pRoadBorrow->GetLength()));
+    std::string strmode = pRoadBorrow->GetMode();
+    ui->comboBox_borrowmode->setCurrentIndex(0);
+    if(strmode == "R2L")
+    {
+        ui->comboBox_borrowmode->setCurrentIndex(1);
+    }
+    if(strmode == "L2R")
+    {
+        ui->comboBox_borrowmode->setCurrentIndex(2);
+    }
+
+}
+
+void DialogRoadBorrow::on_pushButton_Add_clicked()
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    if(ui->lineEdit_s->text().toStdString() == "")
+    {
+        QMessageBox::warning(this,"Warning","s is empty.",QMessageBox::YesAll);
+        return;
+    }
+
+    if(ui->lineEdit_t->text().toStdString() == "")
+    {
+        QMessageBox::warning(this,"Warning","length is empty.",QMessageBox::YesAll);
+        return;
+    }
+
+    double s = ui->lineEdit_s->text().toDouble();
+    double length = ui->lineEdit_t->text().toDouble();
+    string strmode = ui->comboBox_borrowmode->currentText().toStdString();
+
+    pRoad->AddRoadBorrow(s,length,strmode);
+
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+
+}
+
+void DialogRoadBorrow::on_pushButton_Delete_clicked()
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    pRoad->DeleteRoadBorrow(ui->comboBox_Borrow->currentIndex());
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+}
+
+void DialogRoadBorrow::on_pushButton_Change_clicked()
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    RoadBorrow * pRoadBorrow = pRoad->GetRoadBorrow(ui->comboBox_Borrow->currentIndex());
+    pRoadBorrow->SetS(ui->lineEdit_s->text().toDouble());
+    pRoadBorrow->SetLength(ui->lineEdit_t->text().toDouble());
+    pRoadBorrow->SetMode(ui->comboBox_borrowmode->currentText().toStdString());
+
+    QMessageBox::information(this,"Info","Change RoadBorrow Successfully.",QMessageBox::YesAll);
+}

+ 16 - 0
src/tool/map_lanetoxodr/dialogroadborrow.h

@@ -20,6 +20,17 @@ public:
     explicit DialogRoadBorrow(OpenDrive * pxodr,std::string strdefroad,QWidget *parent = nullptr);
     ~DialogRoadBorrow();
 
+private slots:
+    void on_comboBox_Road_currentIndexChanged(int index);
+
+    void on_comboBox_Borrow_currentIndexChanged(int index);
+
+    void on_pushButton_Add_clicked();
+
+    void on_pushButton_Delete_clicked();
+
+    void on_pushButton_Change_clicked();
+
 private:
     Ui::DialogRoadBorrow *ui;
 
@@ -27,3 +38,8 @@ private:
 };
 
 #endif // DIALOGROADBORROW_H
+
+
+
+
+

+ 14 - 1
src/tool/map_lanetoxodr/dialogroadborrow.ui

@@ -16,7 +16,7 @@
   <widget class="QPushButton" name="pushButton_Delete">
    <property name="geometry">
     <rect>
-     <x>715</x>
+     <x>680</x>
      <y>165</y>
      <width>89</width>
      <height>25</height>
@@ -177,6 +177,19 @@
     </rect>
    </property>
   </widget>
+  <widget class="QPushButton" name="pushButton_Change">
+   <property name="geometry">
+    <rect>
+     <x>817</x>
+     <y>165</y>
+     <width>71</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Change</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>