Browse Source

change tool/map_lanetoxodr. add Road Type Edit.

yuchuli 3 years ago
parent
commit
cd4cc6b111

+ 242 - 0
src/tool/map_lanetoxodr/dialogroadtype.cpp

@@ -0,0 +1,242 @@
+#include "dialogroadtype.h"
+#include "ui_dialogroadtype.h"
+
+static std::string strroadtypelist[] = {"unknown","rural","motorway","town","lowSpeed","pedestrian","bicycle","townExpressway",
+                                     "townCollector","townArterial","townPrivate","townLocal","townPlayStreet"};
+static const int strroadtypecount = 13;
+
+DialogRoadType::DialogRoadType(Road * pCurRoad,QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::DialogRoadType)
+{
+    ui->setupUi(this);
+    mpRoad = pCurRoad;
+
+    unsigned int i;
+    for(i=0;i<strroadtypecount;i++)
+    {
+        ui->comboBox_Type->addItem(strroadtypelist[i].data());
+    }
+    ui->comboBox_Type->setCurrentIndex(3);
+
+    UpdateCombo();
+
+}
+
+DialogRoadType::~DialogRoadType()
+{
+    delete ui;
+}
+
+void DialogRoadType::UpdateCombo()
+{
+    ui->comboBox_RoadTypeList->clear();
+
+    if(mpRoad == 0)return;
+
+    Road * pRoad = mpRoad;
+    unsigned int lRoadTypeCount = pRoad->GetRoadTypeCount();
+    unsigned int i;
+    for(i=0;i<lRoadTypeCount;i++)
+    {
+        RoadType * pRoadType = pRoad->GetRoadType(i);
+        ui->comboBox_RoadTypeList->addItem("s = "+ QString::number(pRoadType->GetS()));
+    }
+}
+
+void DialogRoadType::on_pushButton_Add_clicked()
+{
+    if(mpRoad == 0)return;
+
+    if(ui->lineEdit_s->text() == "")
+    {
+        QMessageBox::warning(this,"Warning","s is not set.",QMessageBox::YesAll);
+        return;
+    }
+    double s = ui->lineEdit_s->text().toDouble();
+    string type = ui->comboBox_Type->currentText().toStdString();
+    mpRoad->AddRoadType(s,type);
+
+    UpdateCombo();
+}
+
+void DialogRoadType::on_comboBox_RoadTypeList_currentIndexChanged(int index)
+{
+    ui->lineEdit_s->setText("");
+    ui->lineEdit_SpeedMax->setText("");
+
+    if(index == -1)return;
+
+    if((index<0) ||((int)index >= mpRoad->GetRoadTypeCount()))
+    {
+        return;
+    }
+
+    RoadType * pRoadType = mpRoad->GetRoadType(index);
+    ui->lineEdit_s->setText(QString::number(pRoadType->GetS()));
+
+    int ntypeindex = 0;
+    int i;
+    for(i=0;i<strroadtypecount;i++)
+    {
+        if(strroadtypelist[i] == pRoadType->GetType())
+        {
+            ntypeindex = i;
+            break;
+        }
+    }
+    ui->comboBox_Type->setCurrentIndex(ntypeindex);
+
+    if(pRoadType->GetRoadTypeSpeedCount()>0)
+    {
+        RoadTypeSpeed * pRoadTypeSpeed = pRoadType->GetRoadTypeSpeed(0);
+        double fratio = 1.0;
+        string strunit = pRoadTypeSpeed->Getunit();
+        if(strunit == "km/h")fratio = fratio/3.6;
+        if(strunit == "mph")fratio = fratio*1.609344 /3.6;
+        double fspeedmax = pRoadTypeSpeed->GetmaxSpeed() * fratio;
+        ui->lineEdit_SpeedMax->setText(QString::number(fspeedmax,'f',3));
+    }
+    else
+    {
+        ui->lineEdit_SpeedMax->setText("");
+    }
+}
+
+void DialogRoadType::on_pushButton_ClearSpeed_clicked()
+{
+    if(mpRoad == 0)return;
+
+    if(mpRoad->GetRoadTypeCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    RoadType * pRoadType = mpRoad->GetRoadType(ui->comboBox_RoadTypeList->currentIndex());
+
+    if(pRoadType == 0)
+    {
+        QMessageBox::warning(this,"Warning","Can't Get RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    if(pRoadType->GetRoadTypeSpeedCount() == 0)
+    {
+        QMessageBox::information(this,"Info","This RoadType Don't have Road Type Speed.",QMessageBox::YesAll);
+        return;
+    }
+
+    pRoadType->GetRoadTypeSpeedVector()->clear();
+
+    QMessageBox::information(this,"Info","Clear Road Type Speed Successfully.",QMessageBox::YesAll);
+    return;
+}
+
+void DialogRoadType::on_pushButton_ChangeSpeed_clicked()
+{
+    if(mpRoad == 0)return;
+
+    if(mpRoad->GetRoadTypeCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    RoadType * pRoadType = mpRoad->GetRoadType(ui->comboBox_RoadTypeList->currentIndex());
+
+    if(pRoadType == 0)
+    {
+        QMessageBox::warning(this,"Warning","Can't Get RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    if(pRoadType->GetRoadTypeSpeedCount() == 0)
+    {
+        QMessageBox::warning(this,"Info","This RoadType Don't have Road Type Speed.",QMessageBox::YesAll);
+        return;
+    }
+
+    double fratio = 1.0;
+    RoadTypeSpeed * pRoadTypeSpeed = pRoadType->GetRoadTypeSpeed(0);
+    string strunit = pRoadTypeSpeed->Getunit();
+    if(strunit == "km/h")fratio = fratio/3.6;
+    if(strunit == "mph")fratio = fratio*1.609344 /3.6;
+    pRoadTypeSpeed->SetmaxSpeed(ui->lineEdit_SpeedMax->text().toDouble()/fratio);
+
+    QMessageBox::information(this,"Info","Change Road Type Speed Successfully.",QMessageBox::YesAll);
+    return;
+}
+
+void DialogRoadType::on_pushButton_SetSpeed_clicked()
+{
+    if(ui->lineEdit_SpeedMax->text() == "")
+    {
+        QMessageBox::warning(this,"Warning","Speed Not Set",QMessageBox::YesAll);
+        return;
+    }
+
+    if(mpRoad == 0)return;
+
+    if(mpRoad->GetRoadTypeCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    RoadType * pRoadType = mpRoad->GetRoadType(ui->comboBox_RoadTypeList->currentIndex());
+
+    if(pRoadType == 0)
+    {
+        QMessageBox::warning(this,"Warning","Can't Get RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    while(pRoadType->GetRoadTypeSpeedCount()>0)pRoadType->DeleteRoadTypeSpeed(0);
+
+    pRoadType->AddRoadTypeSpeed(ui->lineEdit_SpeedMax->text().toDouble(),"m/s");
+    QMessageBox::information(this,"Info","Add Road Type Speed Successfully.",QMessageBox::YesAll);
+    return;
+}
+
+void DialogRoadType::on_pushButton_Delete_clicked()
+{
+    if(mpRoad == 0)return;
+
+    if(mpRoad->GetRoadTypeCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No Road Type.",QMessageBox::YesAll);
+        return;
+    }
+    mpRoad->DeleteRoadType(ui->comboBox_RoadTypeList->currentIndex());
+
+    QMessageBox::information(this,"Info","Delete Road Type Successfully,",QMessageBox::YesAll);
+    UpdateCombo();
+    return;
+}
+
+void DialogRoadType::on_pushButton_Change_clicked()
+{
+    if(mpRoad == 0)return;
+
+    if(mpRoad->GetRoadTypeCount() == 0)
+    {
+        QMessageBox::warning(this,"Warning","No Road Type.",QMessageBox::YesAll);
+        return;
+    }
+
+    RoadType * pRoadType = mpRoad->GetRoadType(ui->comboBox_RoadTypeList->currentIndex());
+
+    if(pRoadType == 0)
+    {
+        QMessageBox::warning(this,"Warning","Can't Get RoadType",QMessageBox::YesAll);
+        return;
+    }
+
+    pRoadType->SetS(ui->lineEdit_s->text().toDouble());
+    pRoadType->SetType(ui->comboBox_Type->currentText().toStdString());
+
+    QMessageBox::information(this,"Info","Change Road Type Successfully,",QMessageBox::YesAll);
+    UpdateCombo();
+    return;
+}

+ 45 - 0
src/tool/map_lanetoxodr/dialogroadtype.h

@@ -0,0 +1,45 @@
+#ifndef DIALOGROADTYPE_H
+#define DIALOGROADTYPE_H
+
+#include <QDialog>
+
+#include "OpenDrive/OpenDrive.h"
+#include <QMessageBox>
+
+namespace Ui {
+class DialogRoadType;
+}
+
+class DialogRoadType : public QDialog
+{
+    Q_OBJECT
+
+public:
+    explicit DialogRoadType(Road * pCurRoad,QWidget *parent = nullptr);
+    ~DialogRoadType();
+
+private slots:
+    void on_pushButton_Add_clicked();
+
+    void on_comboBox_RoadTypeList_currentIndexChanged(int index);
+
+    void on_pushButton_ClearSpeed_clicked();
+
+    void on_pushButton_ChangeSpeed_clicked();
+
+    void on_pushButton_SetSpeed_clicked();
+
+    void on_pushButton_Delete_clicked();
+
+    void on_pushButton_Change_clicked();
+
+private:
+    Ui::DialogRoadType *ui;
+
+    Road * mpRoad;
+
+private:
+    void UpdateCombo();
+};
+
+#endif // DIALOGROADTYPE_H

+ 201 - 0
src/tool/map_lanetoxodr/dialogroadtype.ui

@@ -0,0 +1,201 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DialogRoadType</class>
+ <widget class="QDialog" name="DialogRoadType">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>682</width>
+    <height>517</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <widget class="QLabel" name="label">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>50</y>
+     <width>101</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Road Type</string>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox_RoadTypeList">
+   <property name="geometry">
+    <rect>
+     <x>140</x>
+     <y>50</y>
+     <width>201</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_2">
+   <property name="geometry">
+    <rect>
+     <x>30</x>
+     <y>130</y>
+     <width>101</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>S</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_s">
+   <property name="geometry">
+    <rect>
+     <x>130</x>
+     <y>128</y>
+     <width>171</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_3">
+   <property name="geometry">
+    <rect>
+     <x>380</x>
+     <y>130</y>
+     <width>101</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Type</string>
+   </property>
+  </widget>
+  <widget class="QComboBox" name="comboBox_Type">
+   <property name="geometry">
+    <rect>
+     <x>470</x>
+     <y>127</y>
+     <width>181</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Add">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>220</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Add</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Change">
+   <property name="geometry">
+    <rect>
+     <x>260</x>
+     <y>220</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Change</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_Delete">
+   <property name="geometry">
+    <rect>
+     <x>450</x>
+     <y>220</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Delete</string>
+   </property>
+  </widget>
+  <widget class="QLineEdit" name="lineEdit_SpeedMax">
+   <property name="geometry">
+    <rect>
+     <x>280</x>
+     <y>340</y>
+     <width>171</width>
+     <height>41</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QLabel" name="label_4">
+   <property name="geometry">
+    <rect>
+     <x>100</x>
+     <y>350</y>
+     <width>141</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Speed Max (m/s)</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_SetSpeed">
+   <property name="geometry">
+    <rect>
+     <x>60</x>
+     <y>410</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Set</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_ChangeSpeed">
+   <property name="geometry">
+    <rect>
+     <x>270</x>
+     <y>410</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Change</string>
+   </property>
+  </widget>
+  <widget class="QPushButton" name="pushButton_ClearSpeed">
+   <property name="geometry">
+    <rect>
+     <x>460</x>
+     <y>410</y>
+     <width>111</width>
+     <height>41</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Clear</string>
+   </property>
+  </widget>
+ </widget>
+ <tabstops>
+  <tabstop>comboBox_RoadTypeList</tabstop>
+  <tabstop>lineEdit_s</tabstop>
+  <tabstop>comboBox_Type</tabstop>
+  <tabstop>pushButton_Add</tabstop>
+  <tabstop>pushButton_Change</tabstop>
+  <tabstop>pushButton_Delete</tabstop>
+  <tabstop>lineEdit_SpeedMax</tabstop>
+  <tabstop>pushButton_SetSpeed</tabstop>
+  <tabstop>pushButton_ChangeSpeed</tabstop>
+  <tabstop>pushButton_ClearSpeed</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>

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

@@ -47,6 +47,7 @@ SOURCES += \
     dialogroadoptimize.cpp \
     dialogroadrotate.cpp \
     dialogroadsplit.cpp \
+    dialogroadtype.cpp \
     filebackup.cpp \
     ivxodrtool.cpp \
         main.cpp \
@@ -97,6 +98,7 @@ HEADERS += \
     dialogroadoptimize.h \
     dialogroadrotate.h \
     dialogroadsplit.h \
+    dialogroadtype.h \
     filebackup.h \
     ivxodrtool.h \
         mainwindow.h \
@@ -141,6 +143,7 @@ FORMS += \
         dialogroadoptimize.ui \
         dialogroadrotate.ui \
         dialogroadsplit.ui \
+        dialogroadtype.ui \
         mainwindow.ui \
         roadeditdialog.ui \
         speeddialog.ui \

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

@@ -670,3 +670,15 @@ void RoadEditDialog::on_pushButton_RoadOptimize_clicked()
     DialogRoadOptimize dlgroadopt(mpCurRoad,mpxodr, this);
     dlgroadopt.exec();
 }
+
+void RoadEditDialog::on_pushButton_EditRoadType_clicked()
+{
+    if(mpCurRoad == 0)
+    {
+        QMessageBox::warning(this,"Warning","Not Select Road");
+        return;
+    }
+
+    DialogRoadType dlgroadtype(mpCurRoad,this);
+    dlgroadtype.exec();
+}

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

@@ -22,6 +22,7 @@
 #include "dialoglaneoffset.h"
 #include "dialogroadobject.h"
 #include "dialogroadoptimize.h"
+#include "dialogroadtype.h"
 
 #include "roaddigit.h"
 #include "xodrscenfunc.h"
@@ -72,6 +73,8 @@ private slots:
 
     void on_pushButton_RoadOptimize_clicked();
 
+    void on_pushButton_EditRoadType_clicked();
+
 private:
     bool IsDrawMark(double s);
 

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

@@ -354,7 +354,7 @@
    <property name="geometry">
     <rect>
      <x>1010</x>
-     <y>280</y>
+     <y>345</y>
      <width>181</width>
      <height>31</height>
     </rect>
@@ -363,6 +363,19 @@
     <string>Road Optimize</string>
    </property>
   </widget>
+  <widget class="QPushButton" name="pushButton_EditRoadType">
+   <property name="geometry">
+    <rect>
+     <x>1010</x>
+     <y>278</y>
+     <width>181</width>
+     <height>31</height>
+    </rect>
+   </property>
+   <property name="text">
+    <string>Edit Road Type</string>
+   </property>
+  </widget>
  </widget>
  <resources/>
  <connections/>