From 11d811e93d549d5944ad80c89ebd9cde42852225 Mon Sep 17 00:00:00 2001
From: Stuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Date: Tue, 30 Jan 2018 20:59:16 +0000
Subject: [PATCH] Set a default DTO target on AirportInfo page.

---
 .../Nasal/AirportInfo/AirportInfoController.nas    |  3 +++
 .../FG1000/Nasal/Interfaces/NavDataInterface.nas   | 12 ++++++++----
 .../FG1000/Nasal/MFDPageController.nas             | 14 +++++++++++++-
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas
index f4612af95..abfa94994 100644
--- a/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas
+++ b/Aircraft/Instruments-3d/FG1000/Nasal/AirportInfo/AirportInfoController.nas
@@ -72,6 +72,9 @@ var AirportInfoController =
 
     if (apt != nil)  {
       me.airport = id;
+
+      # Set up the default ID if the user presses DTO.
+      me.setDefaultDTOWayPoint(id);
       me.info = apt;
     }
 
diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/NavDataInterface.nas b/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/NavDataInterface.nas
index ff2ecaef3..721747a98 100644
--- a/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/NavDataInterface.nas
+++ b/Aircraft/Instruments-3d/FG1000/Nasal/Interfaces/NavDataInterface.nas
@@ -13,7 +13,7 @@ new : func (device)
   obj._transmitter = emesary.GlobalTransmitter;
   obj._registered = 0;
   obj._device = device;
-  obj._currentDTO = "";
+  obj._defaultDTO = "";
 
   # List of recently use waypoints
   obj._recentWaypoints = std.Vector.new();
@@ -173,13 +173,13 @@ setDirectTo : func(param)
 # Return the current DTO location to use
 getCurrentDTO : func()
 {
-  return me._currentDTO;
+  return me._defaultDTO;
 },
 
 # Set the current DTO location to use
-setCurrentDTO : func(id)
+setDefaultDTO : func(id)
 {
-  me._currentDTO = id;
+  me._defaultDTO = id;
 },
 
 RegisterWithEmesary : func()
@@ -237,6 +237,10 @@ RegisterWithEmesary : func()
             controller.setDirectTo(notification.EventParameter.Value);
             return emesary.Transmitter.ReceiptStatus_Finished;
           }
+          if (id == "SetDefaultDTO") {
+            controller.setDefaultDTO(notification.EventParameter.Value);
+            return emesary.Transmitter.ReceiptStatus_Finished;
+          }
         }
       }
       return emesary.Transmitter.ReceiptStatus_NotProcessed;
diff --git a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
index eaf52aa52..006048e35 100644
--- a/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
+++ b/Aircraft/Instruments-3d/FG1000/Nasal/MFDPageController.nas
@@ -15,7 +15,6 @@ new : func (page)
   obj._transmitter = emesary.GlobalTransmitter;
   obj._registered = 0;
 
-
   return obj;
 },
 
@@ -175,6 +174,19 @@ DeRegisterWithEmesary : func()
     me._registered = 0;
 },
 
+# Set up the default waypoint to use if the DirectTo button is pressed
+setDefaultDTOWayPoint : func(id)
+{
+  # Use Emesary to set the default DTO waypoint
+  var notification = notifications.PFDEventNotification.new(
+    "MFD",
+    1,
+    notifications.PFDEventNotification.NavData,
+    {Id: "SetDefaultDTO", Value: id});
+
+  var response = me._transmitter.NotifyAll(notification);
+  if (me._transmitter.IsFailed(response)) print("Failed to set Default DTO waypoint");
+},
 
 
 };