From 1b85763fcab64da300e89a0ed5ec26a89b947d12 Mon Sep 17 00:00:00 2001
From: Sergi Hernandez Juan <shernand@iri.upc.edu>
Date: Thu, 23 Jul 2020 09:17:18 +0200
Subject: [PATCH] Removed the subtype field from the Object class. Solved a bug
 when writing the object heading and other object float values to the XML
 file: they where treated as integers.

---
 OpenRoadEd/OpenDrive/ObjectSignal.cpp               | 13 -------------
 OpenRoadEd/OpenDrive/ObjectSignal.h                 |  3 ---
 OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp         |  2 --
 OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp         | 13 +++++++++----
 .../Qt/SettingsWidgets/SettingsRoadObject.cpp       | 11 -----------
 OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h  |  2 --
 6 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/OpenRoadEd/OpenDrive/ObjectSignal.cpp b/OpenRoadEd/OpenDrive/ObjectSignal.cpp
index 43c59a6..b71539b 100644
--- a/OpenRoadEd/OpenDrive/ObjectSignal.cpp
+++ b/OpenRoadEd/OpenDrive/ObjectSignal.cpp
@@ -12,7 +12,6 @@ Object::Object()
   mZOffset=0.0;
   mValidLength=0.0;
   mType="none";
-  mSubType="-1";
   mHeading=0.0;
   mPitch=0.0;
   mRoll=0.0;
@@ -31,7 +30,6 @@ Object::Object(std::string &name,std::string &id)
   mZOffset=0.0;
   mValidLength=0.0;
   mType="none";
-  mSubType="-1";
   mHeading=0.0;
   mPitch=0.0;
   mRoll=0.0;
@@ -50,7 +48,6 @@ Object::Object(const Object &object)
   mZOffset=object.mZOffset;
   mValidLength=object.mValidLength;
   mType=object.mType;
-  mSubType=object.mSubType;
   mHeading=object.mHeading;
   mPitch=object.mPitch;
   mRoll=object.mRoll;
@@ -120,11 +117,6 @@ std::string Object::GetType(void)
   return mType;
 }
 
-std::string Object::GetSubType(void)
-{
-  return mSubType;
-}
-
 double Object::GetHeading(void)
 {
   return mHeading;
@@ -239,11 +231,6 @@ void Object::SetType(const std::string &type)
   mType=type;
 }
 
-void Object::SetSubType(const std::string &subType)
-{
-  mSubType=subType;
-}
-
 void Object::SetHeading(const double heading)
 {
   mHeading=heading;
diff --git a/OpenRoadEd/OpenDrive/ObjectSignal.h b/OpenRoadEd/OpenDrive/ObjectSignal.h
index a382e02..762873f 100644
--- a/OpenRoadEd/OpenDrive/ObjectSignal.h
+++ b/OpenRoadEd/OpenDrive/ObjectSignal.h
@@ -38,7 +38,6 @@ class Object
     double mZOffset;
     double mValidLength;
     std::string mType;
-    std::string mSubType;
     double mHeading;
     double mPitch;
     double mRoll;
@@ -60,7 +59,6 @@ class Object
     double GetZOffset(void);
     double GetValidLength(void);
     std::string GetType(void);
-    std::string GetSubType(void);
     double GetHeading(void);
     double GetPitch(void);
     double GetRoll(void);
@@ -80,7 +78,6 @@ class Object
     void SetZOffset(const double zOffset);
     void SetValidLength(const double length);
     void SetType(const std::string &type);
-    void SetSubType(const std::string &subType);
     void SetHeading(const double heading);
     void SetPitch(const double pitch);
     void SetRoll(const double roll);
diff --git a/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp b/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp
index d725165..b3785a2 100644
--- a/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp
+++ b/OpenRoadEd/OpenDrive/OpenDriveXmlParser.cpp
@@ -945,7 +945,6 @@ bool OpenDriveXmlParser::ReadObjects (Road* road, TiXmlElement *node)
   	checker+=object_node->QueryDoubleAttribute("zOffset",&zOffset);
   	checker+=object_node->QueryDoubleAttribute("validLength",&validLength);
     checker+=object_node->QueryStringAttribute("type",&type);
-    checker+=object_node->QueryStringAttribute("subtype",&subType);
   	checker+=object_node->QueryDoubleAttribute("hdg",&heading);
 	  checker+=object_node->QueryDoubleAttribute("pitch",&pitch);
    	checker+=object_node->QueryDoubleAttribute("roll",&roll);
@@ -988,7 +987,6 @@ bool OpenDriveXmlParser::ReadObjects (Road* road, TiXmlElement *node)
     object->SetZOffset(zOffset);
     object->SetValidLength(validLength);
     object->SetType(type);
-    object->SetSubType(subType);
     object->SetHeading(heading);
     object->SetPitch(pitch);
     object->SetRoll(roll);
diff --git a/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp b/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp
index 1902202..e6fbb95 100644
--- a/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp
+++ b/OpenRoadEd/OpenDrive/OpenDriveXmlWriter.cpp
@@ -873,10 +873,15 @@ bool OpenDriveXmlWriter::WriteObjects (TiXmlElement *node, Road* road)
     text << setprecision(16) << setiosflags (ios_base::scientific) << object->GetValidLength();
     object_node->SetAttribute("validLength",text.str());
     object_node->SetAttribute("type",object->GetType());
-    object_node->SetAttribute("subtype",object->GetSubType());
-    object_node->SetAttribute("hdg",object->GetHeading());
-    object_node->SetAttribute("pitch",object->GetPitch());
-    object_node->SetAttribute("roll",object->GetRoll());
+    text.str("");
+    text << setprecision(16) << setiosflags (ios_base::scientific) << object->GetHeading();
+    object_node->SetAttribute("hdg",text.str());
+    text.str("");
+    text << setprecision(16) << setiosflags (ios_base::scientific) << object->GetPitch();
+    object_node->SetAttribute("pitch",text.str());
+    text.str("");
+    text << setprecision(16) << setiosflags (ios_base::scientific) << object->GetRoll();
+    object_node->SetAttribute("roll",text.str());
     if(object->GetBoundingBox(length,width,height))
     {
       text.str("");
diff --git a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp
index 0da70de..71ab21a 100644
--- a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp
+++ b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.cpp
@@ -67,7 +67,6 @@ SettingsRoadObject::SettingsRoadObject(OpenDrive *openDrive)
   mTypeMap["soundBarrier"]="13";
 	mType->insertItem(15,tr("unkown"));
   mTypeMap["unknown"]="14";
-	mSubType = new QLineEdit;
 	mHeading = new QLineEdit;
 
   mBoundingBox = new QGroupBox;
@@ -112,7 +111,6 @@ SettingsRoadObject::SettingsRoadObject(OpenDrive *openDrive)
 	settingsFormLayout->addRow(tr("zOffset:"),mZOffset);
 	settingsFormLayout->addRow(tr("validLength:"),mValidLength);
 	settingsFormLayout->addRow(tr("Type:"),mType);
-	settingsFormLayout->addRow(tr("SubType:"),mSubType);
 	settingsFormLayout->addRow(tr("Heading:"),mHeading);
 
 	QVBoxLayout *settingsGroupLayout = new QVBoxLayout;
@@ -139,7 +137,6 @@ SettingsRoadObject::SettingsRoadObject(OpenDrive *openDrive)
 						"<p><b>zOffset</b> - z offset from track level to bottom edge of the object [meter]</p>"
 						"<p><b>validLength</b> - extent of object's validity along s-axis (0.0 for point object) [meter]</p>"
 						"<p><b>Type</b> - type identifier according to country code. -1 or none for unspecified type</p>"
-						"<p><b>SubType</b> - sub type identifier according to country code. -1 or none for unspecified sub type</p>"
 						"<p><b>heading</b> - heading angle of the object relative to road direction</p>"
             "<p><b>BoundingBox</b> - check if this road has a bounding box</p>"
             "<p><b>Box length</b> - length of the bounding box</p>"
@@ -181,7 +178,6 @@ void SettingsRoadObject::LoadData(Object *object)
 		disconnect(mZOffset, SIGNAL(editingFinished()), this, SLOT(ZOffsetChanged()));
 		disconnect(mValidLength, SIGNAL(editingFinished()), this, SLOT(ValidLengthChanged()));
 		disconnect(mType, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(TypeChanged(const QString &)));
-		disconnect(mSubType,SIGNAL(editingFinished()), this, SLOT(SubTypeChanged()));
 		disconnect(mHeading, SIGNAL(editingFinished()), this, SLOT(HeadingChanged()));
     disconnect(mBoundingBox, SIGNAL(clicked(bool)), this, SLOT(BoundingBoxChanged(bool)));
     disconnect(mBoxLength, SIGNAL(editingFinished()), this, SLOT(BoxLengthChanged()));
@@ -242,7 +238,6 @@ void SettingsRoadObject::LoadData(Object *object)
       mType->setCurrentIndex(14);
     else 
       mType->setCurrentIndex(15);
-		mSubType->setText(object->GetSubType().c_str());
 		mHeading->setText(QString("%1").arg(object->GetHeading()));
 
     if(object->GetBoundingBox(length,width,height))
@@ -275,7 +270,6 @@ void SettingsRoadObject::LoadData(Object *object)
 		connect(mZOffset, SIGNAL(editingFinished()), this, SLOT(ZOffsetChanged()));
 		connect(mValidLength, SIGNAL(editingFinished()), this, SLOT(ValidLengthChanged()));
 		connect(mType, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(TypeChanged(const QString &)));
-		connect(mSubType,SIGNAL(editingFinished()), this, SLOT(SubTypeChanged()));
 		connect(mHeading, SIGNAL(editingFinished()), this, SLOT(HeadingChanged()));
     connect(mBoundingBox, SIGNAL(clicked(bool)), this, SLOT(BoundingBoxChanged(bool)));
     connect(mBoxLength, SIGNAL(editingFinished()), this, SLOT(BoxLengthChanged()));
@@ -341,11 +335,6 @@ void SettingsRoadObject::TypeChanged(const QString & text)
   emit RoadGeometryChanged(true);
 }
 
-void SettingsRoadObject::SubTypeChanged()
-{
-	mObject->SetSubType(mSubType->text().toStdString());
-}
-
 void SettingsRoadObject::HeadingChanged()
 {
 	mObject->SetHeading(mHeading->text().toDouble());
diff --git a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h
index 5aa9a02..393e7df 100644
--- a/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h
+++ b/OpenRoadEd/Qt/SettingsWidgets/SettingsRoadObject.h
@@ -55,7 +55,6 @@ private:
 	QLineEdit *mZOffset;
 	QLineEdit *mValidLength;
 	QComboBox *mType;
-  QLineEdit *mSubType;
   QLineEdit *mHeading;
   QGroupBox *mBoundingBox;
   QLineEdit *mBoxLength;
@@ -79,7 +78,6 @@ public slots:
   void ZOffsetChanged();
   void ValidLengthChanged();
 	void TypeChanged(const QString & text);
-  void SubTypeChanged();
   void HeadingChanged();
   void BoundingBoxChanged(bool on);
   void BoxLengthChanged();
-- 
GitLab