Browse Source

change tool/map_lanetoxodr. Add RoadNoavoid. but xml save and parse not write.

yuchuli 3 years ago
parent
commit
69ddf44819

+ 71 - 0
src/common/common/xodr/OpenDrive/Road.cpp

@@ -358,6 +358,21 @@ RoadBorrow * Road::GetRoadBorrow(unsigned int i)
     else
         return NULL;
 }
+vector<RoadNoavoid> *Road::GetRoadNoavoidVector()
+{
+    return &mRoadNoavoidVector;
+}
+RoadNoavoid*	Road::GetRoadNoavoid(unsigned int i)
+{
+    if((mRoadNoavoidVector.size()>0)&&(i<mRoadNoavoidVector.size()))
+        return &mRoadNoavoidVector.at(i);
+    else
+        return NULL;
+}
+unsigned int Road::GetRoadNoavoidCount()
+{
+    return mRoadNoavoidVector.size();
+}
 //-------------------------------------------------
 
 /**
@@ -429,6 +444,14 @@ RoadBorrow* Road::GetLastRoadBorrow()
         return NULL;
 }
 
+RoadNoavoid* Road::GetLastRoadNoavoid()
+{
+    if(mRoadNoavoidVector.size()>0)
+        return &mRoadNoavoidVector.at(mRoadNoavoidVector.size()-1);
+    else
+        return NULL;
+}
+
 
 /**
  * Getters for the last added child records in their respective vectors
@@ -496,6 +519,13 @@ RoadBorrow* Road::GetLastAddedRoadBorrow()
     else
         return NULL;
 }
+RoadNoavoid* Road::GetLastAddedRoadNoavoid()
+{
+    if(mLastAddedRoadNoavoid<mRoadNoavoidVector.size())
+        return &mRoadNoavoidVector.at(mLastAddedRoadNoavoid);
+    else
+        return NULL;
+}
 //-------------------------------------------------
 
 /**
@@ -686,6 +716,15 @@ unsigned int Road::AddRoadBorrow(double s,double length,string mode)
     return index;
 }
 
+unsigned int Road::AddRoadNoavoid(double s, double length)
+{
+    unsigned int index = CheckRoadNoavoidInterval(s)+1;
+    if(index>=GetRoadNoavoidCount()) mRoadNoavoidVector.push_back(RoadNoavoid(s,length));
+    else mRoadNoavoidVector.insert(mRoadNoavoidVector.begin()+index, RoadNoavoid(s,length));
+    mLastAddedRoadNoavoid=index;
+    return index;
+}
+
 //-------------
 unsigned int Road::AddObject(string id,double s,double t,double zOffset)
 {	
@@ -898,6 +937,16 @@ unsigned int Road::CloneRoadBorrow(unsigned int index)
     return mLastAddedRoadBorrow;
 }
 
+unsigned int Road::CloneRoadNoavoid(unsigned int index)
+{
+    if(index<mRoadNoavoidVector.size()-1)
+        mRoadNoavoidVector.insert(mRoadNoavoidVector.begin()+index+1, mRoadNoavoidVector[index]);
+    else if(index==mRoadNoavoidVector.size()-1)
+        mRoadNoavoidVector.push_back(mRoadNoavoidVector[index]);
+    mLastAddedRoadNoavoid=index+1;
+    return mLastAddedRoadNoavoid;
+}
+
 
 /**
  * Methods used to delete child records from the respective vectors
@@ -945,6 +994,12 @@ void Road::DeleteRoadBorrow(unsigned int index)
     mRoadBorrowVector.erase(mRoadBorrowVector.begin()+index);
 }
 
+void Road::DeleteRoadNoavoid(unsigned int index)
+{
+    if(mRoadNoavoidVector.size() == 0)return;
+    mRoadNoavoidVector.erase(mRoadNoavoidVector.begin()+index);
+}
+
 //-------------------------------------------------
 // EVALUATION METHODS
 
@@ -1178,6 +1233,22 @@ int Road::CheckRoadBorrowInterval(double s_check)
     }
     return res;		//return the result: 0 to MaxInt as the index to the record containing s_check or -1 if nothing found
 
+}
+//-----------
+int Road::CheckRoadNoavoidInterval(double s_check)
+{
+    int res=-1;
+    //Go through all the lane section records
+    for (unsigned int i=0;i<mRoadNoavoidVector.size();i++)
+    {
+        //check if the s_check belongs to the current record
+        if (mRoadNoavoidVector.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
+
 }
 //-----------
 int Road::CheckLaneOffsetInterval(double s_check)

+ 14 - 0
src/common/common/xodr/OpenDrive/Road.h

@@ -84,6 +84,8 @@ private:
 
     vector<RoadBorrow> mRoadBorrowVector;
 
+    vector<RoadNoavoid> mRoadNoavoidVector;
+
 	/**
 	 * Indices of the last added child records
 	 */
@@ -97,6 +99,7 @@ private:
 	unsigned int mLastAddedObject;
 	unsigned int mLastAddedSignal;
     unsigned int mLastAddedRoadBorrow;
+    unsigned int mLastAddedRoadNoavoid;
 
 public:
 	/**
@@ -186,6 +189,10 @@ public:
     RoadBorrow*	GetRoadBorrow(unsigned int i);
     unsigned int GetRoadBorrowCount();
 
+    vector<RoadNoavoid> *GetRoadNoavoidVector();
+    RoadNoavoid*	GetRoadNoavoid(unsigned int i);
+    unsigned int GetRoadNoavoidCount();
+
 
     vector<string> * GetUserData();
 	//-------------------------------------------------
@@ -202,6 +209,7 @@ public:
 	Object*			GetLastObject();
 	Signal*			GetLastSignal();
     RoadBorrow *    GetLastRoadBorrow();
+    RoadNoavoid *   GetLastRoadNoavoid();
 
 	/**
 	 * Getters for the last added child records in their respective vectors
@@ -215,6 +223,7 @@ public:
 	Object*			GetLastAddedObject();
 	Signal*			GetLastAddedSignal();
     RoadBorrow*     GetLastAddedRoadBorrow();
+    RoadNoavoid*    GetLastAddedRoadNoavoid();
 
 	//-------------------------------------------------
 
@@ -261,6 +270,7 @@ public:
                            string subtype,double hOffset,double pitch,double roll ,double height,double width);
 
     unsigned int AddRoadBorrow(double s,double length,string mode);
+    unsigned int AddRoadNoavoid(double s,double length);
 	/**
 	 * Methods used to clone child records in the respective vectors
 	 */
@@ -273,6 +283,7 @@ public:
 	unsigned int CloneObject(unsigned int index);
 	unsigned int CloneSignal(unsigned int index);
     unsigned int CloneRoadBorrow(unsigned int index);
+    unsigned int CloneRoadNoavoid(unsigned int index);
 
 	/**
 	 * Methods used to delete child records from the respective vectors
@@ -287,6 +298,7 @@ public:
 	void DeleteObject(unsigned int index);
 	void DeleteSignal(unsigned int index);
     void DeleteRoadBorrow(unsigned int index);
+    void DeleteRoadNoavoid(unsigned int index);
 	
 	//-------------------------------------------------
 
@@ -329,6 +341,8 @@ public:
     int CheckLaneOffsetInterval(double s_check);
 
     int CheckRoadBorrowInterval(double s_check);
+
+    int CheckRoadNoavoidInterval(double s_check);
 	
 	//-------------------------------------------------
 

+ 35 - 0
src/common/common/xodr/OpenDrive/userData.cpp

@@ -45,3 +45,38 @@ bool RoadBorrow::CheckInterval(double s_check)
         return false;
 }
 
+////////////////////////////////////////////
+
+RoadNoavoid::RoadNoavoid(double s,double length)
+{
+    mS = s;
+    mlength = length;
+}
+
+void RoadNoavoid::SetS(double s)
+{
+    mS = s;
+}
+
+void RoadNoavoid::SetLength(double length)
+{
+    mlength = length;
+}
+
+double RoadNoavoid::GetS()
+{
+    return mS;
+}
+
+double RoadNoavoid::GetLength()
+{
+    return mlength;
+}
+
+bool RoadNoavoid::CheckInterval(double s_check)
+{
+    if (s_check>=mS)
+        return true;
+    else
+        return false;
+}

+ 17 - 0
src/common/common/xodr/OpenDrive/userData.h

@@ -26,4 +26,21 @@ public:
     bool CheckInterval(double s_check);
 };
 
+class RoadNoavoid
+{
+private:
+    double mS;
+    double mlength;
+public:
+    RoadNoavoid(double s,double length);
+
+    void SetS(double s);
+    void SetLength(double length);
+
+    double GetS();
+    double GetLength();
+
+    bool CheckInterval(double s_check);
+};
+
 #endif // USERDATA_H

+ 135 - 0
src/tool/map_lanetoxodr/dialogroadnoavoid.cpp

@@ -0,0 +1,135 @@
+#include "dialogroadnoavoid.h"
+#include "ui_dialogroadnoavoid.h"
+
+#include "mainwindow.h"
+
+#include <QMessageBox>
+
+DialogRoadNoavoid::DialogRoadNoavoid(OpenDrive * pxodr,std::string strdefroad,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogRoadNoavoid)
+{
+    ui->setupUi(this);
+
+    mpxodr = pxodr;
+
+    int i;
+    int nroadcount = mpxodr->GetRoadCount();
+    for(i=0;i<nroadcount;i++)
+    {
+        const char * strname = mpxodr->GetRoad(i)->GetRoadId().data();
+        ui->comboBox_Road->addItem(strname);
+
+    }
+
+    MainWindow::ComboToString(strdefroad,ui->comboBox_Road);
+}
+
+DialogRoadNoavoid::~DialogRoadNoavoid()
+{
+    delete ui;
+}
+
+void DialogRoadNoavoid::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 nNoavoidCount = pRoad->GetRoadNoavoidCount();
+    ui->comboBox_Noavoid->clear();
+    unsigned int i;
+    for(i=0;i<nNoavoidCount;i++)
+    {
+        ui->comboBox_Noavoid->addItem(QString::number(pRoad->GetRoadNoavoid(i)->GetS(),'g'));
+    }
+}
+
+void DialogRoadNoavoid::on_comboBox_Noavoid_currentIndexChanged(int index)
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    if(pRoad->GetRoadNoavoidCount() == 0)
+    {
+        ui->lineEdit_s->setText("");
+        ui->lineEdit_t->setText("");
+        return;
+    }
+
+    if(index<0)return;
+    if(index>=pRoad->GetRoadNoavoidCount())return;
+    RoadNoavoid * pRoadNoavoid = pRoad->GetRoadNoavoid(index);
+    if(pRoadNoavoid == NULL)
+    {
+        return;
+    }
+    ui->lineEdit_s->setText(QString::number(pRoadNoavoid->GetS()));
+    ui->lineEdit_t->setText(QString::number(pRoadNoavoid->GetLength()));
+}
+
+void DialogRoadNoavoid::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();
+
+    pRoad->AddRoadNoavoid(s,length);
+
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+
+}
+
+void DialogRoadNoavoid::on_pushButton_Delete_clicked()
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    pRoad->DeleteRoadNoavoid(ui->comboBox_Noavoid->currentIndex());
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+}
+
+void DialogRoadNoavoid::on_pushButton_Change_clicked()
+{
+    Road * pRoad = mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)
+    {
+        return;
+    }
+
+    RoadNoavoid * pRoadNoavoid = pRoad->GetRoadNoavoid(ui->comboBox_Noavoid->currentIndex());
+    pRoadNoavoid->SetS(ui->lineEdit_s->text().toDouble());
+    pRoadNoavoid->SetLength(ui->lineEdit_t->text().toDouble());
+
+    QMessageBox::information(this,"Info","Change RoadNoavoid Successfully.",QMessageBox::YesAll);
+}

+ 37 - 0
src/tool/map_lanetoxodr/dialogroadnoavoid.h

@@ -0,0 +1,37 @@
+#ifndef DIALOGROADNOAVOID_H
+#define DIALOGROADNOAVOID_H
+
+#include <QDialog>
+
+#include "OpenDrive/OpenDrive.h"
+
+namespace Ui {
+class DialogRoadNoavoid;
+}
+
+class DialogRoadNoavoid : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogRoadNoavoid(OpenDrive * pxodr,std::string strdefroad,QWidget *parent = nullptr);
+    ~DialogRoadNoavoid();
+
+private slots:
+    void on_comboBox_Road_currentIndexChanged(int index);
+
+    void on_comboBox_Noavoid_currentIndexChanged(int index);
+
+    void on_pushButton_Add_clicked();
+
+    void on_pushButton_Delete_clicked();
+
+    void on_pushButton_Change_clicked();
+
+private:
+    Ui::DialogRoadNoavoid *ui;
+
+    OpenDrive * mpxodr;
+};
+
+#endif // DIALOGROADNOAVOID_H

+ 173 - 0
src/tool/map_lanetoxodr/dialogroadnoavoid.ui

@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogRoadNoavoid</class>
+ <widget class="QDialog" name="DialogRoadNoavoid">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>993</width>
+    <height>578</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>60</y>
+     <width>67</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Road</string>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox_Noavoid">
+   <property name="geometry">
+    <rect>
+     <x>200</x>
+     <y>160</y>
+     <width>261</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_s">
+   <property name="geometry">
+    <rect>
+     <x>150</x>
+     <y>244</y>
+     <width>113</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Add">
+   <property name="geometry">
+    <rect>
+     <x>570</x>
+     <y>165</y>
+     <width>89</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Add</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_4">
+   <property name="geometry">
+    <rect>
+     <x>62</x>
+     <y>250</y>
+     <width>67</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>s</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_RoadLen">
+   <property name="geometry">
+    <rect>
+     <x>300</x>
+     <y>94</y>
+     <width>113</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>170</y>
+     <width>101</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Noavoid</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_5">
+   <property name="geometry">
+    <rect>
+     <x>280</x>
+     <y>250</y>
+     <width>67</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>length</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Change">
+   <property name="geometry">
+    <rect>
+     <x>847</x>
+     <y>165</y>
+     <width>71</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Change</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Delete">
+   <property name="geometry">
+    <rect>
+     <x>710</x>
+     <y>165</y>
+     <width>89</width>
+     <height>25</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Delete</string>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>202</x>
+     <y>100</y>
+     <width>70</width>
+     <height>17</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Length</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_t">
+   <property name="geometry">
+    <rect>
+     <x>380</x>
+     <y>244</y>
+     <width>113</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox_Road">
+   <property name="geometry">
+    <rect>
+     <x>200</x>
+     <y>50</y>
+     <width>231</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

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

@@ -5828,3 +5828,16 @@ void MainWindow::onDrawNewRoad()
         UpdateScene();
     }
 }
+
+void MainWindow::on_actionEdit_Road_Noavoid_triggered()
+{
+#ifdef OPENDRIVE_EDITONLY
+    QMessageBox::warning(this,"Warning","This Release is Only for Edit OpenDrive. Other Function Need Change conf.",QMessageBox::YesAll);
+    return;
+#endif
+    std::string strroadid = mpCBRoad->currentText().toStdString();
+    DialogRoadNoavoid rbd(&mxodr,strroadid,this);
+    rbd.exec();
+
+    mpfb->SetOpenDrive(mxodr);
+}

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

@@ -49,6 +49,7 @@
 #include "dialogroadborrow.h"
 #include "dialoghideroad.h"
 #include "dialogdrawroad.h"
+#include "dialogroadnoavoid.h"
 
 #include "filebackup.h"
 
@@ -222,6 +223,8 @@ private slots:
 
     void onDrawNewRoad();
 
+    void on_actionEdit_Road_Noavoid_triggered();
+
 private:
 
 

+ 6 - 0
src/tool/map_lanetoxodr/mainwindow.ui

@@ -43,6 +43,7 @@
     <addaction name="actionSet_Traffic_Light"/>
     <addaction name="actionCalc_Road_S"/>
     <addaction name="actionEdit_Road_Borrow"/>
+    <addaction name="actionEdit_Road_Noavoid"/>
     <addaction name="separator"/>
     <addaction name="actionBack"/>
     <addaction name="separator"/>
@@ -176,6 +177,11 @@
     <string>Draw Road</string>
    </property>
   </action>
+  <action name="actionEdit_Road_Noavoid">
+   <property name="text">
+    <string>Edit Road Noavoid</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <resources>

+ 3 - 0
src/tool/map_lanetoxodr/map_lanetoxodr.pro

@@ -44,6 +44,7 @@ SOURCES += \
     dialogroadmerge.cpp \
     dialogroadmirror.cpp \
     dialogroadmove.cpp \
+    dialogroadnoavoid.cpp \
     dialogroadobject.cpp \
     dialogroadobject_material.cpp \
     dialogroadobject_outline.cpp \
@@ -103,6 +104,7 @@ HEADERS += \
     dialogroadmerge.h \
     dialogroadmirror.h \
     dialogroadmove.h \
+    dialogroadnoavoid.h \
     dialogroadobject.h \
     dialogroadobject_material.h \
     dialogroadobject_outline.h \
@@ -156,6 +158,7 @@ FORMS += \
         dialogroadmerge.ui \
         dialogroadmirror.ui \
         dialogroadmove.ui \
+        dialogroadnoavoid.ui \
         dialogroadobject.ui \
         dialogroadobject_material.ui \
         dialogroadobject_outline.ui \