diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 5e955a78..37eaa4e3 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -784,7 +784,6 @@ var canvas_MCDU_base = { me["Simple_R6S"].setText("SOFTWARE "); me["Simple_R4S"].setText("PILOT STORED "); me["Simple_R4"].setText("00RTES 00RWYS "); - me["Simple_R5"].setText("DELETE ALL "); pageSwitch[i].setBoolValue(1); } @@ -809,6 +808,14 @@ var canvas_MCDU_base = { me["arrow5R"].hide(); } + if (fmgc.WaypointDatabase.confirm) { + me["Simple_R5"].setText("CONFIRM DELETE ALL "); + me["Simple_R5"].setColor(getprop("/MCDUC/colors/amb/r"),getprop("/MCDUC/colors/amb/g"),getprop("/MCDUC/colors/amb/b")); + } else { + me["Simple_R5"].setText("DELETE ALL "); + me["Simple_R5"].setColor(getprop("/MCDUC/colors/blu/r"),getprop("/MCDUC/colors/blu/g"),getprop("/MCDUC/colors/blu/b")); + } + if (getprop("/FMGC/status/phase") == 0 or getprop("/FMGC/status/phase") == 7) { me["Simple_L5"].show(); me["Simple_L5S"].show(); diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index 88c35c04..46e7b41f 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -119,7 +119,7 @@ setprop("gear/gear[0]/wow-fmgc", 1); var FMGCinit = func { setprop("/FMGC/status/to-state", 0); - setprop("/FMGC/status/phase", "0"); # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done + setprop("/FMGC/status/phase", 0); # 0 is Preflight 1 is Takeoff 2 is Climb 3 is Cruise 4 is Descent 5 is Decel/Approach 6 is Go Around 7 is Done setprop("/FMGC/internal/maxspeed", 338); setprop("/FMGC/internal/mng-spd", 157); setprop("/FMGC/internal/mng-spd-cmd", 157); @@ -519,7 +519,7 @@ var masterFMGC = maketimer(0.2, func { }); var reset_FMGC = func { - setprop("/FMGC/status/phase", "0"); + setprop("/FMGC/status/phase", 0); fd1 = getprop("/it-autoflight/input/fd1"); fd2 = getprop("/it-autoflight/input/fd2"); spd = getprop("/it-autoflight/input/spd-kts"); diff --git a/Nasal/FMGC/flightplan-waypoints.nas b/Nasal/FMGC/flightplan-waypoints.nas index d6318c91..5126f9a9 100644 --- a/Nasal/FMGC/flightplan-waypoints.nas +++ b/Nasal/FMGC/flightplan-waypoints.nas @@ -9,6 +9,7 @@ var nilTree = { var WaypointDatabase = { waypointsVec: [], + confirm: 0, # addWP - adds pilot waypoint to waypoints vector # arg: wpObj - passed pilot waypoint object # return: @@ -40,6 +41,8 @@ var WaypointDatabase = { append(me.waypointsVec, wpObj); return 2; } + + me.write(); }, # delete - empties waypoints vector delete: func() { @@ -96,9 +99,9 @@ var WaypointDatabase = { } return nil; }, - # write - write to file, as a delimited string + # write - write to file, as a hash structure write: func() { - var path = getprop("/sim/fg-home") ~ "/Export/savedWaypoints.xml"; + var path = getprop("/sim/fg-home") ~ "/Export/A320SavedWaypoints.xml"; var tree = { waypoints: { @@ -108,13 +111,48 @@ var WaypointDatabase = { for (var i = 0; i < me.getSize(); i = i + 1) { if (me.waypointsVec[i] != nil) { tree.waypoints["waypoint" ~ i] = me.waypointsVec[i].tree; - } else { - tree.waypoints["waypoint" ~ i] = nilTree; } } io.writexml(path, props.Node.new(tree)); # write the data }, + # read - read from a file, extract using props interface + read: func() { + me.delete(); + var path = getprop("/sim/fg-home") ~ "/Export/A320SavedWaypoints.xml"; + var data = io.readxml(path).getChild("waypoints"); + var pilotWP = nil; + for (var i = 0; i < 20; i = i + 1) { + pilotWP = nil; + var childNode = data.getChild("waypoint" ~ i); + if (childNode == nil) { + continue; + } + + var wpt = createWP({lat: num(childNode.getChild("latitude").getValue()), lon: num(childNode.getChild("longitude").getValue())},childNode.getChild("ident").getValue()); + + if (left(childNode.getChild("ident").getValue(), 3) == "PBD") { + pilotWP = pilotWaypoint.newAtPosition(wpt, "PBD", right(childNode.getChild("ident").getValue(), 1)); + } else { + pilotWP = pilotWaypoint.newAtPosition(wpt, "LL", right(childNode.getChild("ident").getValue(), 1)); + } + me.addWPToPos(pilotWP, right(childNode.getChild("ident").getValue(), 1)); + } + }, + # addWPToPos - helper for reading - inserts at specific index + # will create nil for intermediates + addWPToPos: func(wpObj, position) { + if (me.getSize() >= position) { + me.waypointsVec[position - 1] = wpObj; + } else { + var numToIns = position - me.getSize(); + while (numToIns >= 1) { + append(me.waypointsVec, nil); + numToIns -= 1; + } + me.waypointsVec[position - 1] = wpObj; + } + }, }; var pilotWaypoint = { @@ -145,6 +183,23 @@ var pilotWaypoint = { return pilotWp; }, + newAtPosition: func(positioned, typeStr, position) { + var pilotWp = { parents:[pilotWaypoint] }; + + pilotWp.setId(typeStr ~ sprintf("%s", position)); + pilotWp.index = position - 1; + + # set ghost to created waypoint + pilotWp.wpGhost = positioned; + + pilotWp.tree = { + "latitude": pilotWp.wpGhost.wp_lat, + "longitude": pilotWp.wpGhost.wp_lon, + "ident": pilotWp.id, + }; + + return pilotWp; + }, setId: func(id) { if (typeof(id) == "scalar") { me.id = id; } }, diff --git a/Nasal/Libraries/libraries.nas b/Nasal/Libraries/libraries.nas index fb6c7614..ef1740f2 100644 --- a/Nasal/Libraries/libraries.nas +++ b/Nasal/Libraries/libraries.nas @@ -227,6 +227,7 @@ var systemsInit = func { setlistener("/sim/signals/fdm-initialized", func { systemsInit(); fmgc.flightPlanTimer.start(); + fmgc.WaypointDatabase.read(); }); var systemsLoop = maketimer(0.1, func { diff --git a/Nasal/MCDU/STATUS.nas b/Nasal/MCDU/STATUS.nas index afe40e20..335a1d65 100644 --- a/Nasal/MCDU/STATUS.nas +++ b/Nasal/MCDU/STATUS.nas @@ -6,6 +6,11 @@ var statusInput = func(key, i) { if (key == "L3") { fmgc.switchDatabase(); } elsif (key == "R5") { - fmgc.WaypointDatabase.delete(); + if (fmgc.WaypointDatabase.confirm) { + fmgc.WaypointDatabase.delete(); + fmgc.WaypointDatabase.confirm = 0; + } else { + fmgc.WaypointDatabase.confirm = 1; + } } }