Skip to content
Snippets Groups Projects
Commit 929f6c89 authored by Qiang Lu's avatar Qiang Lu Committed by Martins Mozeiko
Browse files

Add OpenDrive Map exporter in UI

parent b2c813e1
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ public class MapExport : EditorWindow
string[] exportFormats = new string[]
{
"Apollo HD Map", "Autoware Vector Map", "Lanelet2 Map"
"Apollo HD Map", "Autoware Vector Map", "Lanelet2 Map", "OpenDRIVE Map"
};
[MenuItem("Simulator/Export HD Map", false, 120)]
......@@ -104,6 +104,21 @@ public class MapExport : EditorWindow
}
GUILayout.EndHorizontal();
}
else if (Selected == 3)
{
EditorGUILayout.HelpBox("Save File As...", UnityEditor.MessageType.Info);
GUILayout.BeginHorizontal();
FileName = EditorGUILayout.TextField(FileName);
if (GUILayout.Button("...", GUILayout.ExpandWidth(false)))
{
var path = EditorUtility.SaveFilePanel("Save OpenDRIVE Map as xodr File", "", "OpenDRIVE.xodr", "xodr");
if (!string.IsNullOrEmpty(path))
{
FileName = path;
}
}
GUILayout.EndHorizontal();
}
if (GUILayout.Button(new GUIContent("Export", $"Export {exportFormats[Selected]}")))
{
......@@ -127,6 +142,11 @@ public class MapExport : EditorWindow
Lanelet2MapExporter lanelet2MapExporter = new Lanelet2MapExporter();
lanelet2MapExporter.ExportLanelet2Map(FileName);
}
else if (exportFormats[Selected] == "OpenDRIVE Map")
{
OpenDriveMapExporter openDriveMapExporter = new OpenDriveMapExporter();
openDriveMapExporter.ExportOpenDRIVEMap(FileName);
}
}
}
......
/**
* Copyright (c) 2019 LG Electronics, Inc.
*
* This software contains code licensed as described in LICENSE.
*
*/
using UnityEngine;
using Simulator.Map;
using System.IO;
using System.Xml.Serialization;
using Schemas;
namespace Simulator.Editor
{
public class OpenDriveMapExporter
{
MapOrigin MapOrigin;
MapManagerData MapAnnotationData;
OpenDRIVE Map;
public void ExportOpenDRIVEMap(string filePath)
{
if (Calculate())
{
Export(filePath);
Debug.Log("Successfully generated and exported OpenDRIVE Map!");
}
else
{
Debug.LogError("Failed to export OpenDRIVE Map!");
}
}
public bool Calculate()
{
var mapOrigin = MapOrigin.Find();
if (mapOrigin == null)
{
return false;
}
MapAnnotationData = new MapManagerData();
MapAnnotationData.GetIntersections();
MapAnnotationData.GetTrafficLanes();
Map = new OpenDRIVE()
{
header = new OpenDRIVEHeader()
{
revMajor = (ushort)1,
revMinor = (ushort)4,
name = "",
version = 1.00f,
date = System.DateTime.Now.ToString("ddd, MMM dd HH':'mm':'ss yyy"),
vendor = "LGSVL"
}
};
return true;
}
void Export(string filePath)
{
var serializer = new XmlSerializer(typeof(OpenDRIVE));
StreamWriter writer = new StreamWriter(filePath);
serializer.Serialize(writer, Map);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: e906bc06d2ab473968255f0953c50832
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment