Browse Source

change tool/map_lanetoxodr. Add some Road Object Edit code.

yuchuli 3 years ago
parent
commit
a5aa3b908c

+ 388 - 8
src/tool/map_lanetoxodr/dialogroadobject.cpp

@@ -1,13 +1,63 @@
 #include "dialogroadobject.h"
 #include "ui_dialogroadobject.h"
 
-DialogRoadObject::DialogRoadObject(QWidget *parent) :
+#include <QMessageBox>
+
+static std::string strobjecttypelist[] ={"none","obstacle","car","pole",
+                                 "tree","vegetation","barrier","building","parkingSpace","patch",
+                                  "railing","trafficIsland","crosswalk","streetLamp","gantry",
+                                 "soundBarrier","van","bus","trailer","bike","motorbike",
+                                 "tram","train","pedestrian","wind","roadMark"};
+
+const static int objectlistcount = 26;
+
+DialogRoadObject::DialogRoadObject(Road * pRoad,QWidget *parent) :
     QDialog(parent),
     ui(new Ui::DialogRoadObject)
 {
     ui->setupUi(this);
 
+    mpRoad = pRoad;
+
+    if(pRoad == 0)
+    {
+        ui->pushButton_add->setEnabled(false);
+        ui->pushButton_change->setEnabled(false);
+        ui->pushButton_delete->setEnabled(false);
+    }
+    else
+    {
+        ui->lineEdit_RoadID->setText(pRoad->GetRoadId().data());
+        ui->lineEdit_RoadLen->setText(QString::number(pRoad->GetRoadLength()));
+    }
+
     CreateView();
+    int i;
+    for(i=0;i<objectlistcount;i++)
+    {
+        mpCBtype->addItem(strobjecttypelist[i].data());
+    }
+    mpCBtype->setCurrentIndex(8);
+
+    mpCBdynamic->addItem("no");
+    mpCBdynamic->addItem("yes");
+    mpCBdynamic->addItem("undefined");
+    mpCBdynamic->setCurrentIndex(2);
+
+    mpCBorientation->addItem("+");
+    mpCBorientation->addItem("-");
+    mpCBorientation->addItem("none");
+    mpCBorientation->addItem("undefined");
+    mpCBorientation->setCurrentIndex(3);
+
+
+    int nobjectcount = pRoad->GetObjectCount();
+    for(i=0;i<nobjectcount;i++)
+    {
+        Object * pObject = pRoad->GetObject(i);
+        ui->comboBox_Object->addItem("Object s:"+QString::number(pObject->Gets()));
+    }
+
     setWindowTitle("Edit Road Object");
 }
 
@@ -21,15 +71,12 @@ QLineEdit * DialogRoadObject::CreateLE(int pos_x, int pos_y, int nLabelWidth, in
 {
     QLineEdit * pLE;
     QLabel * pLabel;
-
     pLabel = new QLabel(this);
     pLabel->setGeometry(pos_x,pos_y,nLabelWidth,nHeight);
     pLabel->setText(strname.data());
     pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
-
     pLE = new QLineEdit(this);
     pLE->setGeometry(pos_x+nLabelWidth+10,pos_y,nLEWidth,nHeight);
-
     return pLE;
 }
 
@@ -37,15 +84,12 @@ QComboBox * DialogRoadObject::CreateCB(int pos_x, int pos_y, int nLabelWidth, in
 {
     QComboBox * pCB;
     QLabel * pLabel;
-
     pLabel = new QLabel(this);
     pLabel->setGeometry(pos_x,pos_y,nLabelWidth,nHeight);
     pLabel->setText(strname.data());
     pLabel->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
-
     pCB = new QComboBox(this);
     pCB->setGeometry(pos_x+nLabelWidth+10,pos_y,nLEWidth,nHeight);
-
     return pCB;
 }
 
@@ -58,7 +102,6 @@ void DialogRoadObject::CreateView()
     int nLEWidth = 150;
     int nHeight = 30;
     int nVSpace = 50;
-
     int nVIndex = 0;
     mpLEt = CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"t");
     mpLEzOffset = CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"zOffset");
@@ -82,6 +125,343 @@ void DialogRoadObject::CreateView()
     nVIndex++;
     mpLEwidth = CreateLE(startpos_x+0*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"width");
     mpLEradius = CreateLE(startpos_x+1*nSpace,startpos_y+nVIndex*nVSpace,nLabelWidth,nLEWidth,nHeight,"radius");
+}
+
+bool DialogRoadObject::CheckLE(QLineEdit *pLE, QString stritemname,bool bWarning)
+{
+    QString str = pLE->text();
+    if(str == "")
+    {
+        if(bWarning)QMessageBox::warning(this,"Warning",stritemname + " is not set",QMessageBox::YesAll);
+        return false;
+    }
+    return true;
+}
+
+void DialogRoadObject::on_pushButton_add_clicked()
+{
+    Road * pRoad = mpRoad;
+    if(CheckLE(mpLEid,"id") == false)return;
+    string id = mpLEid->text().toStdString();
+
+    if(CheckLE(mpLEt,"t") == false)return;
+    double t = mpLEt->text().toDouble();
+
+    if(CheckLE(mpLEs,"s") == false)return;
+    double s = mpLEs->text().toDouble();
+
+    if(CheckLE(mpLEzOffset,"zOffset") == false)return;
+    double zOffset = mpLEzOffset->text().toDouble();
+
+    double length,width,hdg;
+    if(mpCBtype->currentText() == "parkingSpace")
+    {
+        if(CheckLE(mpLElength,"length") == false)return;
+        length = mpLElength->text().toDouble();
+
+        if(CheckLE(mpLEwidth,"width") == false)return;
+        width = mpLEwidth->text().toDouble();
+
+        if(CheckLE(mpLEhdg,"hdg") == false)return;
+        hdg = mpLEhdg->text().toDouble();
+    }
+
+    pRoad->AddObject(id,s,t,zOffset);
+
+    Object * pObject = pRoad->GetLastAddedObject();
+
+    pObject->Settype(mpCBtype->currentText().toStdString());
+
+    if(CheckLE(mpLEvalidLength,"validLength",false))
+    {
+        pObject->SetvalidLength(mpLEvalidLength->text().toDouble());
+    }
+
+    if(mpCBorientation->currentIndex() != 3)
+    {
+        pObject->Setorientation(mpCBorientation->currentText().toStdString());
+    }
+
+    if(CheckLE(mpLEsubtype,"subtype",false))
+    {
+        pObject->Setsubtype(mpLEsubtype->text().toStdString());
+    }
+
+    if(mpCBdynamic->currentIndex()!= 2)
+    {
+        pObject->Setdynamic(mpCBdynamic->currentText().toStdString());
+    }
+
+    if(CheckLE(mpLEname,"name",false))
+    {
+        pObject->Setname(mpLEname->text().toStdString());
+    }
+
+    if(CheckLE(mpLEhdg,"hdg",false))
+    {
+        pObject->Sethdg(mpLEhdg->text().toDouble());
+    }
+
+    if(CheckLE(mpLEpitch,"pitch",false))
+    {
+        pObject->Setpitch(mpLEpitch->text().toDouble());
+    }
+
+    if(CheckLE(mpLEroll,"roll",false))
+    {
+        pObject->Setroll(mpLEroll->text().toDouble());
+    }
+
+    if(CheckLE(mpLEheight,"height",false))
+    {
+        pObject->Setheight(mpLEheight->text().toDouble());
+    }
+
+    if(CheckLE(mpLElength,"length",false))
+    {
+        pObject->Setlength(mpLElength->text().toDouble());
+    }
+
+    if(CheckLE(mpLEwidth,"width",false))
+    {
+        pObject->Setwidth(mpLEwidth->text().toDouble());
+    }
+
+    if(CheckLE(mpLEradius,"radius",false))
+    {
+        pObject->Setradius(mpLEradius->text().toDouble());
+    }
+
+    ui->comboBox_Object->addItem("Object s:"+QString::number(pObject->Gets()));
+
+}
+
+void DialogRoadObject::on_comboBox_Object_currentIndexChanged(int index)
+{
+    Road * pRoad = mpRoad;
+    if(pRoad == 0)return;
+    if(index < 0)return;
+    if(index >= mpRoad->GetObjectCount())
+    {
+        return;
+    }
+    Object * pObject = mpRoad->GetObject(index);
+    if(pObject == 0)return;
+
+    mpLEt->setText(QString::number(pObject->Gett()));
+    mpLEzOffset->setText(QString::number(pObject->GetzOffset()));
+    string type = pObject->Gettype();
+    int i;
+    for(i=0;i<objectlistcount;i++)
+    {
+        if(strobjecttypelist[i] == type)break;
+    }
+    if(i<objectlistcount)mpCBtype->setCurrentIndex(i);
+
+    double validLength;
+    if(pObject->GetvalidLength(validLength) == 1)
+    {
+        mpLEvalidLength->setText(QString::number(validLength));
+    }
+    else
+        mpLEvalidLength->setText("");
+
+    string strorientation = pObject->Getorientation();
+    if(strorientation == "")
+    {
+        mpCBorientation->setCurrentIndex(3);
+    }
+    else
+    {
+        if(strorientation == "+")mpCBorientation->setCurrentIndex(0);
+        else
+        {
+            if(strorientation == "-")mpCBorientation->setCurrentIndex(1);
+            else mpCBorientation->setCurrentIndex(2);
+        }
+    }
+
+    string strtype = pObject->Getsubtype();
+    if(strtype != "")pObject->Setsubtype(strtype);
+
+    string strdynamic = pObject->Getdynamic();
+    if(strdynamic == "")
+    {
+        mpCBdynamic->setCurrentIndex(2);
+    }
+    else
+    {
+        if(strdynamic == "no")mpCBdynamic->setCurrentIndex(0);
+        else mpCBdynamic->setCurrentIndex(1);
+    }
+
+    double hdg;
+    if(pObject->Gethdg(hdg) == 1)mpLEhdg->setText(QString::number(hdg));
+    else    mpLEhdg->setText("");
+
+    mpLEname->setText(pObject->Getname().data());
+
+    double pitch;
+    if(pObject->Getpitch(pitch) == 1)mpLEpitch->setText(QString::number(pitch));
+    else mpLEpitch->setText("");
+
+    mpLEid->setText(pObject->Getid().data());
+
+    double roll;
+    if(pObject->Getroll(roll) == 1)mpLEroll->setText(QString::number(roll));
+    else mpLEroll->setText("");
+
+    double height;
+    if(pObject->Getheight(height) == 1)mpLEheight->setText(QString::number(height));
+    else mpLEheight->setText("");
+
+    mpLEs->setText(QString::number(pObject->Gets()));
+
+    double length;
+    if(pObject->Getlength(length) == 1)mpLElength->setText(QString::number(length));
+    else mpLElength->setText("");
+
+    double width;
+    if(pObject->Getwidth(width) == 1)mpLEwidth->setText(QString::number(width));
+    else mpLEwidth->setText("");
+
+    double radius;
+    if(pObject->Getradius(radius) == 1)mpLEradius->setText(QString::number(radius));
+    else mpLEradius->setText("");
+}
+
+void DialogRoadObject::on_pushButton_delete_clicked()
+{
+    if(mpRoad == 0)return;
+    Road * pRoad = mpRoad;
+    if(pRoad->GetObjectCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
+        return;
+    }
+
+    int index = ui->comboBox_Object->currentIndex();
+    if(index<0)return;
+    if(index >= mpRoad->GetObjectCount())return;
+
+    pRoad->DeleteObject(index);
+    ui->comboBox_Object->removeItem(index);
+}
+
+void DialogRoadObject::on_pushButton_change_clicked()
+{
+    if(mpRoad == 0)return;
+    Road * pRoad = mpRoad;
+    if(pRoad->GetObjectCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No Object.",QMessageBox::YesAll);
+        return;
+    }
 
+    int index = ui->comboBox_Object->currentIndex();
+    if(index<0)return;
+    if(index >= mpRoad->GetObjectCount())return;
 
+    Object * pObject = mpRoad->GetObject(index);
+    if(pObject == 0)
+    {
+        QMessageBox::warning(this,"Warning","Can't found Object.",QMessageBox::YesAll);
+        return;
+    }
+
+    if(CheckLE(mpLEid,"id") == false)return;
+    string id = mpLEid->text().toStdString();
+
+    if(CheckLE(mpLEt,"t") == false)return;
+    double t = mpLEt->text().toDouble();
+
+    if(CheckLE(mpLEs,"s") == false)return;
+    double s = mpLEs->text().toDouble();
+
+    if(CheckLE(mpLEzOffset,"zOffset") == false)return;
+    double zOffset = mpLEzOffset->text().toDouble();
+
+
+    double length,width,hdg;
+    if(mpCBtype->currentText() == "parkingSpace")
+    {
+        if(CheckLE(mpLElength,"length") == false)return;
+        length = mpLElength->text().toDouble();
+
+        if(CheckLE(mpLEwidth,"width") == false)return;
+        width = mpLEwidth->text().toDouble();
+
+        if(CheckLE(mpLEhdg,"hdg") == false)return;
+        hdg = mpLEhdg->text().toDouble();
+    }
+
+    pObject->Setid(id);
+    pObject->Sets(s);
+    pObject->Sett(t);
+    pObject->SetzOffset(zOffset);
+
+    pObject->Settype(mpCBtype->currentText().toStdString());
+
+    if(CheckLE(mpLEvalidLength,"validLength",false))
+    {
+        pObject->SetvalidLength(mpLEvalidLength->text().toDouble());
+    }
+
+    if(mpCBorientation->currentIndex() != 3)
+    {
+        pObject->Setorientation(mpCBorientation->currentText().toStdString());
+    }
+
+    if(CheckLE(mpLEsubtype,"subtype",false))
+    {
+        pObject->Setsubtype(mpLEsubtype->text().toStdString());
+    }
+
+    if(mpCBdynamic->currentIndex()!= 2)
+    {
+        pObject->Setdynamic(mpCBdynamic->currentText().toStdString());
+    }
+
+    if(CheckLE(mpLEhdg,"hdg",false))
+    {
+        pObject->Sethdg(mpLEhdg->text().toDouble());
+    }
+
+    if(CheckLE(mpLEname,"name",false))
+    {
+        pObject->Setname(mpLEname->text().toStdString());
+    }
+
+    if(CheckLE(mpLEpitch,"pitch",false))
+    {
+        pObject->Setpitch(mpLEpitch->text().toDouble());
+    }
+
+    if(CheckLE(mpLEroll,"roll",false))
+    {
+        pObject->Setroll(mpLEroll->text().toDouble());
+    }
+
+    if(CheckLE(mpLEheight,"height",false))
+    {
+        pObject->Setheight(mpLEheight->text().toDouble());
+    }
+
+    if(CheckLE(mpLElength,"length",false))
+    {
+        pObject->Setlength(mpLElength->text().toDouble());
+    }
+
+    if(CheckLE(mpLEwidth,"width",false))
+    {
+        pObject->Setwidth(mpLEwidth->text().toDouble());
+    }
+
+    if(CheckLE(mpLEradius,"radius",false))
+    {
+        pObject->Setradius(mpLEradius->text().toDouble());
+    }
+
+    QMessageBox::information(this,"Info","Change Object Successfull.",QMessageBox::YesAll);
 }
+

+ 15 - 1
src/tool/map_lanetoxodr/dialogroadobject.h

@@ -6,6 +6,8 @@
 #include <QLabel>
 #include <QComboBox>
 
+#include <OpenDrive/OpenDrive.h>
+
 namespace Ui {
 class DialogRoadObject;
 }
@@ -15,9 +17,18 @@ class DialogRoadObject : public QDialog
     Q_OBJECT
 
 public:
-    explicit DialogRoadObject(QWidget *parent = nullptr);
+    explicit DialogRoadObject(Road * pRoad,QWidget *parent = nullptr);
     ~DialogRoadObject();
 
+private slots:
+    void on_pushButton_add_clicked();
+
+    void on_comboBox_Object_currentIndexChanged(int index);
+
+    void on_pushButton_delete_clicked();
+
+    void on_pushButton_change_clicked();
+
 private:
     Ui::DialogRoadObject *ui;
 
@@ -46,6 +57,9 @@ private:
 private:
     QLineEdit * CreateLE(int pos_x,int pos_y,int nLabelWidth,int nLEWidth,int nHeight,std::string strname);
     QComboBox * CreateCB(int pos_x,int pos_y,int nLabelWidth,int nLEWidth,int nHeight,std::string strname);
+    bool CheckLE(QLineEdit * pLE,QString stritemname,bool bWarning = true);
+private:
+    Road * mpRoad;
 };
 
 #endif // DIALOGROADOBJECT_H

+ 13 - 13
src/tool/map_lanetoxodr/dialogroadobject.ui

@@ -13,16 +13,6 @@
   <property name="windowTitle">
    <string>Dialog</string>
   </property>
-  <widget class="QComboBox" name="comboBox_Road">
-   <property name="geometry">
-    <rect>
-     <x>180</x>
-     <y>30</y>
-     <width>231</width>
-     <height>31</height>
-    </rect>
-   </property>
-  </widget>
   <widget class="QComboBox" name="comboBox_Object">
    <property name="geometry">
     <rect>
@@ -76,9 +66,9 @@
    <property name="geometry">
     <rect>
      <x>570</x>
-     <y>40</y>
-     <width>113</width>
-     <height>25</height>
+     <y>34</y>
+     <width>131</width>
+     <height>31</height>
     </rect>
    </property>
   </widget>
@@ -121,6 +111,16 @@
     <string>Object</string>
    </property>
   </widget>
+  <widget class="QLineEdit" name="lineEdit_RoadID">
+   <property name="geometry">
+    <rect>
+     <x>180</x>
+     <y>30</y>
+     <width>171</width>
+     <height>31</height>
+    </rect>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>

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

@@ -654,7 +654,7 @@ void RoadEditDialog::on_pushButton_EditRoadObjects_clicked()
     return;
 #endif
 
-    DialogRoadObject roadobject(this);
+    DialogRoadObject roadobject(mpCurRoad,this);
     roadobject.exec();
 
 }