Explorar el Código

change tool/map_lanetoxodr. add traffic light edit.

yuchuli hace 4 años
padre
commit
a40d470308

+ 1 - 0
src/tool/map_lanetoxodr/OpenDrive/OpenDriveXmlWriter.cpp

@@ -937,6 +937,7 @@ bool OpenDriveXmlWriter::WriteSignal(TiXmlElement *node, Signal * pSignal)
     nodeSignal->SetAttribute("s",pSignal->Gets());
     nodeSignal->SetAttribute("t",pSignal->Gett());
     nodeSignal->SetAttribute("id",pSignal->Getid());
+    nodeSignal->SetAttribute("name",pSignal->Getname());
     if(pSignal->Getdynamic() == true)
     nodeSignal->SetAttribute("dynamic","yes");
     else

+ 157 - 0
src/tool/map_lanetoxodr/trafficlightdialog.cpp

@@ -4,6 +4,8 @@
 #include "trafficlightlanevaliditydialog.h"
 #include "trafficlightpositiondialog.h"
 
+#include <QMessageBox>
+
 TrafficLightDialog::TrafficLightDialog(OpenDrive * pxodr,QWidget *parent) :
     QDialog(parent),
     ui(new Ui::TrafficLightDialog)
@@ -14,6 +16,8 @@ TrafficLightDialog::TrafficLightDialog(OpenDrive * pxodr,QWidget *parent) :
     ui->comboBox_dynamic->addItem("yes");
     ui->comboBox_dynamic->addItem("no");
 
+    ui->lineEdit_id->setReadOnly(true);
+
     int i;
     int nroadcount = mpxodr->GetRoadCount();
     for(i=0;i<nroadcount;i++)
@@ -146,3 +150,156 @@ void TrafficLightDialog::on_pushButton_EditlaneValidity_clicked()
     int res = td.exec();
     (void)&res;
 }
+
+void TrafficLightDialog::on_pushButton_Add_clicked()
+{
+    Road * pRoad =mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)return;
+
+    double s;
+    double t;
+    string id;
+    string name;
+    bool dynamic;
+    string orientation;
+    double zOffset;
+    string type;
+    string country;
+    string countryRevision;
+    string subtype;
+    double hOffset;
+    double pitch;
+    double roll;
+    double height;
+    double width;
+
+    int nid = getnewsignalid();
+    string strid = QString::number(nid).toStdString();
+
+    geteditvalue(s,t,name,dynamic,orientation,zOffset,type,country,countryRevision,
+                 subtype,hOffset,pitch,roll,height,width);
+
+    pRoad->AddSignal(s,t,strid,name,dynamic,orientation,zOffset,type,country,countryRevision,
+                     subtype,hOffset,pitch,roll,height,width);
+
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+    ui->comboBox_TrafficLIght->setCurrentIndex(pRoad->GetSignalCount()-1);
+
+
+
+}
+
+void TrafficLightDialog::on_pushButton_Delete_clicked()
+{
+    Road * pRoad =mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)return;
+
+    if(pRoad->GetSignalCount() == 0)
+    {
+        QMessageBox::warning(this,"warning","No Signal Delete.");
+        return;
+    }
+
+    pRoad->DeleteSignal(ui->comboBox_TrafficLIght->currentIndex());
+
+    on_comboBox_Road_currentIndexChanged(ui->comboBox_Road->currentIndex());
+    ui->comboBox_TrafficLIght->setCurrentIndex(pRoad->GetSignalCount()-1);
+
+}
+
+void TrafficLightDialog::on_pushButton_Update_clicked()
+{
+    Road * pRoad =mpxodr->GetRoad(ui->comboBox_Road->currentIndex());
+    if(pRoad == 0)return;
+
+    if(pRoad->GetSignalCount() == 0)return;
+    Signal * pSignal =pRoad->GetSignal(ui->comboBox_TrafficLIght->currentIndex());
+    if(pSignal == 0)return;
+
+    double s;
+    double t;
+    string name;
+    bool dynamic;
+    string orientation;
+    double zOffset;
+    string type;
+    string country;
+    string countryRevision;
+    string subtype;
+    double hOffset;
+    double pitch;
+    double roll;
+    double height;
+    double width;
+
+    geteditvalue(s,t,name,dynamic,orientation,zOffset,type,country,countryRevision,
+                 subtype,hOffset,pitch,roll,height,width);
+
+    pSignal->Sets(s);
+    pSignal->Sett(t);
+    pSignal->Setname(name);
+    pSignal->Setdynamic(dynamic);
+    pSignal->Setorientation(orientation);
+    pSignal->SetzOffset(zOffset);
+    pSignal->Settype(type);
+    pSignal->Setcountry(country);
+    pSignal->SetcountryRevision(countryRevision);
+    pSignal->Setsubtype(subtype);
+    pSignal->SethOffset(hOffset);
+    pSignal->Setpitch(pitch);
+    pSignal->Setroll(roll);
+    pSignal->Setheight(height);
+    pSignal->Setwidth(width);
+}
+
+int TrafficLightDialog::geteditvalue(double &s, double &t, std::string &name, bool &dynamic,
+                                     std::string &orientation, double &zOffset, std::string &type,
+                                     std::string &country, std::string &countryRevision, std::string &subtype,
+                                     double &hOffset, double &pitch, double &roll, double &height, double &width)
+{
+    s = ui->lineEdit_s->text().toDouble();
+    t = ui->lineEdit_t->text().toDouble();
+    name = ui->lineEdit_name->text().toStdString();
+    if(ui->comboBox_dynamic->currentIndex() == 0)dynamic = true;
+    else dynamic = false;
+    orientation = ui->lineEdit_orientation->text().toStdString();
+    zOffset = ui->lineEdit_zOffset->text().toDouble();
+    type = ui->lineEdit_type->text().toStdString();
+    country = ui->lineEdit_country->text().toStdString();
+    countryRevision = ui->lineEdit_countryRevision->text().toStdString();
+    subtype = ui->lineEdit_subtype->text().toStdString();
+    hOffset = ui->lineEdit_hOffset->text().toDouble();
+    pitch = ui->lineEdit_pitch->text().toDouble();
+    roll = ui->lineEdit_roll->text().toDouble();
+    height = ui->lineEdit_height->text().toDouble();
+    width = ui->lineEdit_width->text().toDouble();
+    return 0;
+}
+
+int TrafficLightDialog::getnewsignalid()
+{
+    int id = -1;
+    bool bHaveExist = false;
+    do
+    {
+        bHaveExist = false;
+        id = id + 1;
+        int nroadcount = mpxodr->GetRoadCount();
+        int i,j;
+        for(i=0;i<nroadcount;i++)
+        {
+            Road * pRoad = mpxodr->GetRoad(i);
+            int nsignalcount = pRoad->GetSignalCount();
+            for(j=0;j<nsignalcount;j++)
+            {
+                if(id == atoi(pRoad->GetSignal(j)->Getid().data()))
+                {
+                    bHaveExist = true;
+                    break;
+                }
+            }
+            if(bHaveExist)break;
+        }
+    }while(bHaveExist == true);
+    return id;
+}

+ 12 - 0
src/tool/map_lanetoxodr/trafficlightdialog.h

@@ -25,12 +25,24 @@ private slots:
 
     void on_pushButton_EditlaneValidity_clicked();
 
+    void on_pushButton_Add_clicked();
+
+    void on_pushButton_Delete_clicked();
+
+    void on_pushButton_Update_clicked();
+
 private:
     Ui::TrafficLightDialog *ui;
     OpenDrive * mpxodr;
 
     void initlineedit();
     void showsignal(Signal * pSignal);
+
+    int geteditvalue(double & s,double & t, string & name, bool &dynamic, string & orientation, double & zOffset,
+                     string & type, string & country, string & countryRevision, string & subtype, double & hOffset,
+                     double & pitch, double & roll, double & height, double & width);
+
+    int getnewsignalid();
 };
 
 #endif // TRAFFICLIGHTDIALOG_H

+ 11 - 11
src/tool/map_lanetoxodr/trafficlightdialog.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>1009</width>
-    <height>598</height>
+    <width>1006</width>
+    <height>556</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -450,11 +450,11 @@
     </rect>
    </property>
   </widget>
-  <widget class="QPushButton" name="pushButton">
+  <widget class="QPushButton" name="pushButton_Add">
    <property name="geometry">
     <rect>
-     <x>170</x>
-     <y>500</y>
+     <x>540</x>
+     <y>135</y>
      <width>89</width>
      <height>25</height>
     </rect>
@@ -463,11 +463,11 @@
     <string>Add</string>
    </property>
   </widget>
-  <widget class="QPushButton" name="pushButton_2">
+  <widget class="QPushButton" name="pushButton_Delete">
    <property name="geometry">
     <rect>
-     <x>390</x>
-     <y>500</y>
+     <x>715</x>
+     <y>135</y>
      <width>89</width>
      <height>25</height>
     </rect>
@@ -476,10 +476,10 @@
     <string>Delete</string>
    </property>
   </widget>
-  <widget class="QPushButton" name="pushButton_3">
+  <widget class="QPushButton" name="pushButton_Update">
    <property name="geometry">
     <rect>
-     <x>630</x>
+     <x>400</x>
      <y>500</y>
      <width>89</width>
      <height>25</height>
@@ -505,7 +505,7 @@
   <widget class="QPushButton" name="pushButton_EditinertialPosition">
    <property name="geometry">
     <rect>
-     <x>460</x>
+     <x>620</x>
      <y>430</y>
      <width>221</width>
      <height>25</height>