2022-02-02 12:05:42 +00:00
# A3XX FMGC Flightplan Page
2022-12-31 17:56:08 +00:00
# Copyright (c) 2023 Josh Davidson (Octal450) and Jonathan Redpath (legoboyvdlp)
2022-02-02 12:05:42 +00:00
# Local vars
var decelIndex = 0;
var decelShow = 0;
2022-02-13 10:02:40 +00:00
var decelOffset = 0;
2022-02-02 12:05:42 +00:00
var destName = nil;
2022-01-26 12:38:56 +00:00
var getSubTextFunc = func(meRef) {
var subText = nil;
call(func {
subText = me.wp.wp_owner.id;
}, nil, meRef, nil,
var errs = []
);
return nil;
}
2020-01-05 20:21:28 +00:00
var fplnItem = {
2020-01-07 20:48:27 +00:00
new: func(wp, index, plan, computer, colour = "grn") {
2020-01-05 20:21:28 +00:00
var fI = {parents:[fplnItem]};
fI.wp = wp;
fI.index = index;
fI.plan = plan;
2020-01-07 20:48:27 +00:00
fI.computer = computer;
fI.colour = colour;
2020-04-28 14:16:08 +00:00
fI.assembledStr = [nil, nil, colour];
2020-06-12 16:14:02 +00:00
fI._colour = "wht";
2020-01-05 20:21:28 +00:00
return fI;
},
updateLeftText: func() {
2020-01-07 20:48:27 +00:00
if (me.wp != nil) {
2020-03-31 15:33:28 +00:00
if (me.wp.wp_name == "T-P") {
return ["T-P", nil, me.colour];
} elsif (me.wp.wp_name != "DISCONTINUITY") {
2020-01-07 20:48:27 +00:00
var wptName = split("-", me.wp.wp_name);
2020-01-11 13:30:08 +00:00
if (wptName[0] == "VECTORS") {
2020-05-15 22:42:40 +00:00
return ["MANUAL", me.getSubText(), me.colour];
2020-01-07 20:48:27 +00:00
} else {
2022-01-26 12:56:15 +00:00
if (me.wp.fly_type == "Hold") {
return ["HOLD " ~ (me.wp.hold_is_left_handed ? "L" : "R"), me.getSubText(), me.colour];
2020-01-11 13:30:08 +00:00
} else {
2022-01-26 12:38:56 +00:00
if (size(wptName) == 2) {
return[wptName[0] ~ wptName[1 ~ (me.wp.fly_type == "flyOver" ? "@" : "")], me.getSubText(), me.colour];
} else {
return [me.wp.wp_name ~ (me.wp.fly_type == "flyOver" ? "@" : ""), me.getSubText(), me.colour];
}
2020-01-11 13:30:08 +00:00
}
2020-01-07 20:48:27 +00:00
}
} else {
return [nil, nil, "ack"];
}
2020-01-05 20:21:28 +00:00
} else {
2020-01-07 20:48:27 +00:00
return ["problem", nil, "ack"];
2020-01-05 20:21:28 +00:00
}
},
2020-05-15 22:42:40 +00:00
getSubText: func() {
2022-01-26 12:38:56 +00:00
if (me.wp.wp_parent_name != nil) {
return " " ~ me.wp.wp_parent_name;
} else {
return nil;
}
2020-05-15 22:42:40 +00:00
},
2020-01-05 20:21:28 +00:00
updateCenterText: func() {
2020-01-07 20:48:27 +00:00
if (me.wp != nil) {
if (me.wp.wp_name != "DISCONTINUITY") {
2020-04-28 14:16:08 +00:00
if (me.index == fmgc.flightPlanController.currentToWptIndex.getValue() - 1 and fmgc.flightPlanController.fromWptTime != nil) {
2020-05-14 23:51:52 +00:00
me.assembledStr[0] = fmgc.flightPlanController.fromWptTime ~ " ";
2020-06-12 16:14:02 +00:00
me.assembledStr[2] = "grn";
2020-03-24 16:46:27 +00:00
} else {
2020-05-14 23:51:52 +00:00
me.assembledStr[0] = "---- ";
2020-06-12 16:14:02 +00:00
me.assembledStr[2] = "wht";
2020-03-24 16:46:27 +00:00
}
2020-04-28 14:16:08 +00:00
if (me.index == fmgc.flightPlanController.currentToWptIndex.getValue()) {
2022-01-18 12:46:08 +00:00
me.assembledStr[1] = "BRG" ~ me.getBrg() ~ "° ";
2020-05-14 23:51:52 +00:00
} elsif (me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() + 1) or me.index == (fmgc.flightPlanController.arrivalIndex[me.plan] + 1)) {
2022-01-18 12:46:08 +00:00
me.assembledStr[1] = "TRK" ~ me.getTrack() ~ "° ";
2020-04-28 14:16:08 +00:00
} else {
me.assembledStr[1] = nil;
}
return me.assembledStr;
2020-01-07 20:48:27 +00:00
} else {
return ["---F-PLN DISCONTINUITY--", nil, "wht"];
}
2020-01-05 20:21:28 +00:00
} else {
2020-01-07 20:48:27 +00:00
return ["problem", nil, "ack"];
2020-01-05 20:21:28 +00:00
}
},
updateRightText: func() {
2020-01-07 20:48:27 +00:00
if (me.wp != nil) {
if (me.wp.wp_name != "DISCONTINUITY") {
me.spd = me.getSpd();
me.alt = me.getAlt();
2020-12-31 20:03:47 +00:00
if (me.colour != "yel") { # not temporary flightplan
me._colour = "wht";
#if (me.spd[1] != "wht" or me.alt[1] != "wht") {
if (me.spd[1] == me.alt[1]) {
me._colour = me.spd[1];
}
else if (me.spd[1] == "mag" or me.alt[1] == "mag") {
me._colour = "mag";
}
else if (me.spd[1] == "grn" or me.alt[1] == "grn") {
me._colour = "grn";
}
} else { # temporary flightplan
me._colour = "yel";
2020-06-12 16:14:02 +00:00
}
2022-01-18 12:46:08 +00:00
return [me.spd[0] ~ "/" ~ me.alt[0], me.getDist() ~ "NM ", me._colour];
2020-01-07 20:48:27 +00:00
} else {
return [nil, nil, "ack"];
}
} else {
return ["problem", nil, "ack"];
}
2020-01-05 20:21:28 +00:00
},
getBrg: func() {
2022-01-17 11:43:31 +00:00
var wp = fmgc.flightPlanController.flightplans[me.plan].getWP(me.index);
2022-05-16 16:13:14 +00:00
if (wp.wp_type == "vectors") {
me.brg = pts.Orientation.heading.getValue();
} else {
var courseDistanceFrom = courseAndDistance(wp);
me.brg = courseDistanceFrom[0] - magvar();
if (me.brg < 0) { me.brg += 360; }
if (me.brg > 360) { me.brg -= 360; }
}
2020-04-28 14:33:28 +00:00
return sprintf("%03.0f", math.round(me.brg));
2020-01-05 20:21:28 +00:00
},
getTrack: func() {
2022-02-02 16:46:35 +00:00
me.trk = me.wp.leg_bearing - magvar(me.wp.lat, me.wp.lon);
2020-04-28 14:33:28 +00:00
if (me.trk < 0) { me.trk += 360; }
if (me.trk > 360) { me.trk -= 360; }
return sprintf("%03.0f", math.round(me.trk));
2020-01-05 20:21:28 +00:00
},
getSpd: func() {
2020-07-11 13:03:30 +00:00
if (me.index == 0 and left(me.wp.wp_name, 4) == fmgc.FMGCInternal.depApt and fmgc.FMGCInternal.v1set) {
2020-12-31 20:03:47 +00:00
return [sprintf("%3.0f", math.round(fmgc.FMGCInternal.v1)), "grn"]; # why "mag"? I think "grn"
} elsif (me.wp.speed_cstr != nil and me.wp.speed_cstr > 0) {
2022-05-13 15:50:24 +00:00
var tcol = (me.wp.speed_cstr_type == "computed" or me.wp.speed_cstr_type == "computed_mach") ? "grn" : "mag";
2020-12-31 20:03:47 +00:00
return [sprintf("%3.0f", me.wp.speed_cstr), tcol];
2020-05-14 23:51:52 +00:00
} else {
2020-06-12 16:14:02 +00:00
return ["---", "wht"];
2020-05-14 23:51:52 +00:00
}
2020-01-05 20:21:28 +00:00
},
getAlt: func() {
2020-07-10 20:28:53 +00:00
if (me.index == 0 and left(me.wp.wp_name, 4) == fmgc.FMGCInternal.depApt and fmgc.flightPlanController.flightplans[me.plan].departure != nil) {
2021-02-15 17:45:54 +00:00
return [" " ~ sprintf("%5.0f", math.round(fmgc.flightPlanController.flightplans[me.plan].departure.elevation * M2FT)), "grn"];
2020-05-14 23:51:52 +00:00
} elsif (me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1) and fmgc.flightPlanController.fromWptAlt != nil) {
2020-06-13 14:48:12 +00:00
return [" " ~ fmgc.flightPlanController.fromWptAlt, "mag"];
2020-12-31 20:03:47 +00:00
} elsif (me.wp.alt_cstr != nil and me.wp.alt_cstr > 0) {
2022-05-13 15:50:24 +00:00
var tcol = (me.wp.alt_cstr_type == "computed" or me.wp.alt_cstr_type == "computed_mach") ? "grn" : "mag";
2022-01-05 16:38:04 +00:00
var cstrAlt = "";
2020-06-12 16:14:02 +00:00
if (me.wp.alt_cstr > fmgc.FMGCInternal.transAlt) {
2022-01-05 16:38:04 +00:00
cstrAlt = "FL" ~ math.round(num(me.wp.alt_cstr) / 100);
2020-06-12 16:14:02 +00:00
} else {
2022-01-05 16:38:04 +00:00
cstrAlt = me.wp.alt_cstr;
2020-06-12 16:14:02 +00:00
}
2022-01-05 16:38:04 +00:00
cstrAlt = (me.wp.alt_cstr_type == "above") ? "+" ~ cstrAlt : cstrAlt;
cstrAlt = (me.wp.alt_cstr_type == "below") ? "-" ~ cstrAlt : cstrAlt;
return [sprintf("%6s", cstrAlt), tcol];
2020-03-24 16:46:27 +00:00
} else {
2020-06-12 16:14:02 +00:00
return ["------", "wht"];
2020-03-24 16:46:27 +00:00
}
2020-01-05 20:21:28 +00:00
},
getDist: func() {
2022-01-18 19:54:27 +00:00
decelIndex = getprop("/instrumentation/nd/symbols/decel/index");
decelShow = getprop("/instrumentation/nd/symbols/decel/show");
2022-01-18 12:46:08 +00:00
var prevwp = fmgc.flightPlanController.flightplans[me.plan].getWP(me.index -1);
2022-01-17 11:43:31 +00:00
if (me.index == fmgc.flightPlanController.currentToWptIndex.getValue()) {
2022-01-18 16:05:27 +00:00
return sprintf("%3.0f", math.round(courseAndDistance(me.wp)[1]));;
2020-04-28 14:16:08 +00:00
} else {
2022-01-21 13:44:25 +00:00
if (me.plan == 2 and decelShow and me.index == decelIndex and fmgc.flightPlanController.decelPoint != nil) {
2022-01-18 16:05:27 +00:00
return sprintf("%3.0f", courseAndDistance(fmgc.flightPlanController.decelPoint, me.wp)[1]);
2022-05-16 16:13:14 +00:00
} else if (prevwp != nil and (prevwp.wp_name != "DISCONTINUITY" or find(prevwp.wp_name, "VECTORS"))) {
2022-01-18 16:05:27 +00:00
return sprintf("%3.0f", math.round(me.wp.leg_distance));
2022-01-18 12:46:08 +00:00
} else {
return " --";
}
2020-04-28 14:16:08 +00:00
}
2020-01-07 20:48:27 +00:00
},
pushButtonLeft: func() {
if (canvas_mcdu.myLatRev[me.computer] != nil) {
canvas_mcdu.myLatRev[me.computer].del();
}
canvas_mcdu.myLatRev[me.computer] = nil;
2020-03-09 18:00:22 +00:00
2020-01-07 20:48:27 +00:00
if (me.wp.wp_name == "DISCONTINUITY") {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(4, me.wp, me.index, me.computer);
2020-01-07 20:48:27 +00:00
} elsif (fmgc.flightPlanController.temporaryFlag[me.computer]) {
2022-01-17 11:43:31 +00:00
if (me.wp.wp_name == "PPOS") {
2022-01-14 13:07:51 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(2, me.wp, me.index, me.computer);
} elsif (me.index == fmgc.flightPlanController.arrivalIndex[me.computer]) {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(1, me.wp, me.index, me.computer);
2022-01-14 13:07:51 +00:00
} elsif (fmgc.flightPlanController.flightplans[me.computer].departure != nil and left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[me.computer].departure.id) {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(0, me.wp, me.index, me.computer);
2020-01-07 20:48:27 +00:00
} else {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(3, me.wp, me.index, me.computer);
2020-01-07 20:48:27 +00:00
}
} else {
2022-01-17 11:43:31 +00:00
if (me.wp.wp_name == "PPOS") {
2022-01-14 13:07:51 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(2, me.wp, me.index, me.computer);
} elsif (me.index == fmgc.flightPlanController.arrivalIndex[2]) {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(1, me.wp, me.index, me.computer);
2022-01-14 13:07:51 +00:00
} elsif (fmgc.flightPlanController.flightplans[2].departure != nil and left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[2].departure.id) {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(0, me.wp, me.index, me.computer);
2020-01-07 20:48:27 +00:00
} else {
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(3, me.wp, me.index, me.computer);
2020-01-07 20:48:27 +00:00
}
}
2020-03-09 18:00:22 +00:00
setprop("MCDU[" ~ me.computer ~ "]/page", "LATREV");
2020-01-07 20:48:27 +00:00
},
pushButtonRight: func() {
2020-06-15 15:29:05 +00:00
if (size(mcdu_scratchpad.scratchpads[me.computer].scratchpad) == 0) {
if (canvas_mcdu.myVertRev[me.computer] != nil) {
canvas_mcdu.myVertRev[me.computer].del();
}
canvas_mcdu.myVertRev[me.computer] = nil;
if (fmgc.flightPlanController.temporaryFlag[me.computer]) {
2022-01-14 13:07:51 +00:00
if (me.wp.wp_name == "PPOS" or me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1)) {
canvas_mcdu.myVertRev[me.computer] = vertRev.new(3, me.wp.wp_name, me.index, me.computer, me.wp, me.plan);
} elsif (me.index == fmgc.flightPlanController.arrivalIndex[me.computer]) {
2020-06-15 15:29:05 +00:00
canvas_mcdu.myVertRev[me.computer] = vertRev.new(1, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan);
2022-01-14 13:07:51 +00:00
} if (fmgc.flightPlanController.flightplans[me.computer].departure != nil and left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[me.computer].departure.id) {
2020-06-15 15:29:05 +00:00
canvas_mcdu.myVertRev[me.computer] = vertRev.new(0, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan);
} else {
canvas_mcdu.myVertRev[me.computer] = vertRev.new(2, me.wp.wp_name, me.index, me.computer, me.wp, me.plan);
}
2020-03-09 18:00:22 +00:00
} else {
2022-01-14 13:07:51 +00:00
if (me.wp.wp_name == "PPOS" or me.index == (fmgc.flightPlanController.currentToWptIndex.getValue() - 1)) {
canvas_mcdu.myVertRev[me.computer] = vertRev.new(3, me.wp.wp_name, me.index, me.computer, me.wp, me.plan);
} elsif (me.index == fmgc.flightPlanController.arrivalIndex[2]) {
2020-06-15 15:29:05 +00:00
canvas_mcdu.myVertRev[me.computer] = vertRev.new(1, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan);
2022-01-14 13:07:51 +00:00
} elsif (fmgc.flightPlanController.flightplans[2].departure != nil and left(me.wp.wp_name, 4) == fmgc.flightPlanController.flightplans[2].departure.id) {
2020-06-15 15:29:05 +00:00
canvas_mcdu.myVertRev[me.computer] = vertRev.new(0, left(me.wp.wp_name, 4), me.index, me.computer, me.wp, me.plan);
} else {
canvas_mcdu.myVertRev[me.computer] = vertRev.new(2, me.wp.wp_name, me.index, me.computer, me.wp, me.plan);
}
2020-03-09 18:00:22 +00:00
}
2020-06-15 15:29:05 +00:00
setprop("MCDU[" ~ me.computer ~ "]/page", "VERTREV");
} elsif (me.index != 0) { # todo - only apply to climb, descent, or missed waypoints
var scratchpadStore = mcdu_scratchpad.scratchpads[me.computer].scratchpad;
if (scratchpadStore == "CLR") {
me.wp.setSpeed("delete");
me.wp.setAltitude("delete");
mcdu_scratchpad.scratchpads[me.computer].empty();
} elsif (find("/", scratchpadStore) != -1) {
var scratchpadSplit = split("/", scratchpadStore);
2022-01-05 16:38:04 +00:00
if (size(scratchpadSplit[0]) != 0) {
if (num(scratchpadSplit[0]) != nil and size(scratchpadSplit[0]) == 3 and scratchpadSplit[0] >= 100 and scratchpadSplit[0] <= 350) {
2020-06-15 15:29:05 +00:00
me.wp.setSpeed(scratchpadSplit[0], "at");
mcdu_scratchpad.scratchpads[me.computer].empty();
} else {
mcdu_message(me.computer, "FORMAT ERROR");
}
}
2022-01-05 16:38:04 +00:00
if (right(scratchpadSplit[1], 1) == "+") {
validateAltCstrFpln(left(scratchpadSplit[1], size(scratchpadSplit[1]) - 1), "above", me);
} elsif (right(scratchpadSplit[1], 1) == "-") {
validateAltCstrFpln(left(scratchpadSplit[1], size(scratchpadSplit[1]) - 1), "below", me);
} elsif (left(scratchpadSplit[1], 1) == "+") {
validateAltCstrFpln(right(scratchpadSplit[1], size(scratchpadSplit[1]) - 1), "above", me);
} elsif (left(scratchpadSplit[1], 1) == "-") {
validateAltCstrFpln(right(scratchpadSplit[1], size(scratchpadSplit[1]) - 1), "below", me);
} else {
validateAltCstrFpln(scratchpadSplit[1], "at", me);
}
2020-06-15 15:29:05 +00:00
} elsif (num(scratchpadStore) != nil and size(scratchpadStore) == 3 and scratchpadStore >= 100 and scratchpadStore <= 350) {
me.wp.setSpeed(scratchpadStore, "at");
mcdu_scratchpad.scratchpads[me.computer].empty();
2020-03-09 18:00:22 +00:00
} else {
2020-06-15 15:29:05 +00:00
mcdu_message(me.computer, "FORMAT ERROR");
2020-03-09 18:00:22 +00:00
}
2020-06-15 15:29:05 +00:00
} else {
mcdu_message(me.computer, "NOT ALLOWED");
2020-03-09 18:00:22 +00:00
}
2020-01-07 20:48:27 +00:00
},
};
2022-01-05 16:38:04 +00:00
var validateAltCstrFpln = func(scratchpadStore, type, self) {
if (num(scratchpadStore) != nil and (size(scratchpadStore) >= 3 and size(scratchpadStore) <= 5)) {
if (scratchpadStore >= 100 and scratchpadStore <= 39000) {
self.wp.setAltitude(math.round(scratchpadStore, 10), type);
mcdu_scratchpad.scratchpads[self.computer].empty();
} else {
mcdu_message(self.computer, "ENTRY OUT OF RANGE");
}
} else {
mcdu_message(self.computer, "FORMAT ERROR");
}
}
2020-01-07 20:48:27 +00:00
var staticText = {
new: func(computer, text) {
var sT = {parents:[staticText]};
sT.computer = computer;
sT.text = text;
2022-01-18 20:11:31 +00:00
sT.wp = "STATIC";
2020-01-07 20:48:27 +00:00
return sT;
},
updateLeftText: func() {
return [nil, nil, "ack"];
},
updateCenterText: func() {
return [me.text, nil, "wht"];
},
updateRightText: func() {
return [nil, nil, "ack"];
},
pushButtonLeft: func() {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT ALLOWED");
2020-01-07 20:48:27 +00:00
},
pushButtonRight: func() {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT ALLOWED");
2020-01-05 20:21:28 +00:00
},
};
2022-01-16 22:41:41 +00:00
var pseudoItem = {
2022-01-17 11:43:31 +00:00
new: func(computer, text, colour) {
2022-01-16 22:41:41 +00:00
var pI = {parents:[pseudoItem]};
pI.computer = computer;
pI.text = text;
pI.colour = colour;
2022-01-17 11:43:31 +00:00
pI.wp = "PSEUDO";
2022-01-16 22:41:41 +00:00
return pI;
},
updateLeftText: func() {
return [me.text, nil, me.colour];
},
updateCenterText: func() {
2022-01-18 12:46:08 +00:00
return ["---- ", nil, "wht"];
},
getDist: func() {
2022-01-18 19:54:27 +00:00
decelIndex = getprop("/instrumentation/nd/symbols/decel/index");
decelShow = getprop("/instrumentation/nd/symbols/decel/show");
if (decelShow) {
2022-01-18 12:46:08 +00:00
var prevWP = fmgc.flightPlanController.flightplans[2].getWP(decelIndex - 1);
2022-01-18 19:54:27 +00:00
if (prevWP != nil and prevWP.wp_name != "DISCONTINUITY") {
2022-01-18 12:46:08 +00:00
return sprintf("%3.0f", courseAndDistance(prevWP, fmgc.flightPlanController.decelPoint)[1]);
} else {
return " --";
}
}
2022-01-16 22:41:41 +00:00
},
updateRightText: func() {
2022-01-18 12:46:08 +00:00
return ["---/------", me.getDist() ~ "NM ", "wht"];
2022-01-16 22:41:41 +00:00
},
pushButtonLeft: func() {
mcdu_message(me.computer, "NOT ALLOWED");
},
pushButtonRight: func() {
mcdu_message(me.computer, "NOT ALLOWED");
},
};
2020-01-05 20:21:28 +00:00
var fplnPage = { # this one is only created once, and then updated - remember this
L1: [nil, nil, "ack"], # content, title, colour
L2: [nil, nil, "ack"],
L3: [nil, nil, "ack"],
L4: [nil, nil, "ack"],
L5: [nil, nil, "ack"],
L6: [nil, nil, "ack"],
C1: [nil, nil, "ack"],
C2: [nil, nil, "ack"],
C3: [nil, nil, "ack"],
C4: [nil, nil, "ack"],
C5: [nil, nil, "ack"],
C6: [nil, nil, "ack"],
R1: [nil, nil, "ack"],
R2: [nil, nil, "ack"],
R3: [nil, nil, "ack"],
R4: [nil, nil, "ack"],
R5: [nil, nil, "ack"],
R6: [nil, nil, "ack"],
planList: [],
outputList: [],
scroll: 0,
2020-01-07 20:48:27 +00:00
temporaryFlagFpln: 0,
2020-01-05 20:21:28 +00:00
new: func(plan, computer) {
2020-01-07 20:48:27 +00:00
var fp = {parents:[fplnPage]};
fp.plan = fmgc.flightPlanController.flightplans[plan];
fp.planIndex = plan;
fp.computer = computer;
fp.planList = [];
fp.outputList = [];
return fp;
2020-01-05 20:21:28 +00:00
},
_setupPageWithData: func() {
me.destInfo();
me.createPlanList();
},
2020-01-07 20:48:27 +00:00
updatePlan: func() {
if (!fmgc.flightPlanController.temporaryFlag[me.computer]) {
me.planIndex = 2;
me.plan = fmgc.flightPlanController.flightplans[2];
me.temporaryFlagFpln = 0;
} else {
me.planIndex = me.computer;
me.plan = fmgc.flightPlanController.flightplans[me.computer];
me.temporaryFlagFpln = 1;
}
me._setupPageWithData();
},
2020-01-05 20:21:28 +00:00
getText: func(type) {
2020-01-07 20:48:27 +00:00
if (type == "fplnEnd") {
2020-01-05 20:21:28 +00:00
return "------END OF F-PLN------";
2020-01-07 20:48:27 +00:00
} else if (type == "altnFplnEnd") {
2020-01-05 20:21:28 +00:00
return "----END OF ALTN F-PLN---";
2020-01-07 20:48:27 +00:00
} else if (type == "noAltnFpln") {
2020-01-05 20:21:28 +00:00
return "------NO ALTN F-PLN-----";
2022-01-16 22:41:41 +00:00
} else if (type == "decel") {
return "(DECEL)";
2020-01-07 20:48:27 +00:00
} else if (type == "empty") {
2020-01-05 20:21:28 +00:00
return "";
}
},
createPlanList: func() {
me.planList = [];
2020-01-07 20:48:27 +00:00
if (me.temporaryFlagFpln) {
2020-05-14 23:51:52 +00:00
colour = "yel";
2020-01-07 20:48:27 +00:00
} else {
2020-05-14 23:51:52 +00:00
colour = "grn";
}
2022-01-17 11:43:31 +00:00
2022-01-18 19:54:27 +00:00
decelIndex = getprop("/instrumentation/nd/symbols/decel/index");
decelShow = getprop("/instrumentation/nd/symbols/decel/show");
2022-01-17 11:43:31 +00:00
var startingIndex = fmgc.flightPlanController.currentToWptIndex.getValue() == -1 ? 0 : fmgc.flightPlanController.currentToWptIndex.getValue() - 1;
2022-02-13 10:01:11 +00:00
# Situation where currentIndex is equal to 0
startingIndex = (startingIndex == -1 ? 0 : startingIndex);
2022-01-26 15:28:19 +00:00
2022-01-17 11:43:31 +00:00
for (var i = startingIndex; i < me.plan.getPlanSize(); i += 1) {
2022-01-18 19:54:27 +00:00
if (!me.temporaryFlagFpln and decelShow) {
2022-01-17 11:43:31 +00:00
if (i == decelIndex) {
append(me.planList, pseudoItem.new(me.computer, me.getText("decel"), colour));
}
}
2020-07-10 21:15:37 +00:00
if (!me.temporaryFlagFpln and i > fmgc.flightPlanController.arrivalIndex[me.planIndex] and fmgc.FMGCInternal.phase != 6) {
2020-05-14 23:51:52 +00:00
append(me.planList, fplnItem.new(me.plan.getWP(i), i, me.planIndex, me.computer, "blu"));
} else {
2022-01-18 12:46:08 +00:00
if (i == fmgc.flightPlanController.currentToWptIndex.getValue() and !me.temporaryFlagFpln) {
append(me.planList, fplnItem.new(me.plan.getWP(i), i, me.planIndex, me.computer, "wht"));
} else {
append(me.planList, fplnItem.new(me.plan.getWP(i), i, me.planIndex, me.computer, colour));
}
2020-01-07 20:48:27 +00:00
}
2020-01-05 20:21:28 +00:00
}
2022-01-17 11:43:31 +00:00
2020-01-07 20:48:27 +00:00
append(me.planList, staticText.new(me.computer, me.getText("fplnEnd")));
2022-01-12 14:06:20 +00:00
if (!fmgc.FMGCInternal.altAirportSet) {
append(me.planList, staticText.new(me.computer, me.getText("noAltnFpln")));
} else {
2022-01-27 18:39:59 +00:00
var altnApt = findAirportsByICAO(fmgc.FMGCInternal.altAirport);
if (size(altnApt) > 0) {
append(me.planList, fplnItem.new({
alt_cstr: nil,
alt_cstr_type: nil,
fly_type: "flyBy",
2022-02-02 16:40:11 +00:00
lat: altnApt[0].lat,
2022-01-27 18:39:59 +00:00
leg_bearing: courseAndDistance(findAirportsByICAO(fmgc.FMGCInternal.arrApt)[0], altnApt[0])[0],
leg_distance: courseAndDistance(findAirportsByICAO(fmgc.FMGCInternal.arrApt)[0], altnApt[0])[1],
2022-02-02 16:40:11 +00:00
lon: altnApt[0].lon,
2022-01-27 18:39:59 +00:00
speed_cstr: nil,
speed_cstr_type: nil,
wp_name: fmgc.FMGCInternal.altAirport,
2022-02-02 16:46:35 +00:00
wp_parent_name: nil,
2022-01-27 18:39:59 +00:00
}, i, me.planIndex, me.computer, "blu"));
append(me.planList, staticText.new(me.computer, me.getText("altnFplnEnd")));
} else {
append(me.planList, staticText.new(me.computer, me.getText("noAltnFpln")));
}
2022-01-12 14:06:20 +00:00
}
2020-01-11 13:30:08 +00:00
me.basePage();
2020-01-05 20:21:28 +00:00
},
basePage: func() {
me.outputList = [];
2020-01-07 20:48:27 +00:00
for (var i = 0; i + me.scroll < size(me.planList); i += 1) {
2020-01-05 20:21:28 +00:00
append(me.outputList, me.planList[i + me.scroll] );
}
2020-01-07 20:48:27 +00:00
if (size(me.outputList) >= 1) {
2020-01-05 20:21:28 +00:00
me.L1 = me.outputList[0].updateLeftText();
me.C1 = me.outputList[0].updateCenterText();
2020-12-31 20:03:47 +00:00
me.C1[1] = (fmgc.flightPlanController.fromWptTime != nil) ? "UTC " : "TIME "; # since TO change to UTC time (1 space left to center)
2020-01-07 20:48:27 +00:00
me.R1 = me.outputList[0].updateRightText();
2020-05-14 23:51:52 +00:00
me.R1[1] = "SPD/ALT ";
2020-01-07 20:48:27 +00:00
} else {
me.L1 = [nil, nil, "ack"];
me.C1 = [nil, nil, "ack"];
me.R1 = [nil, nil, "ack"];
2020-01-05 20:21:28 +00:00
}
2020-01-07 20:48:27 +00:00
if (size(me.outputList) >= 2) {
2020-01-05 20:21:28 +00:00
me.L2 = me.outputList[1].updateLeftText();
me.C2 = me.outputList[1].updateCenterText();
2020-01-07 20:48:27 +00:00
me.R2 = me.outputList[1].updateRightText();
} else {
me.L2 = [nil, nil, "ack"];
me.C2 = [nil, nil, "ack"];
me.R2 = [nil, nil, "ack"];
2020-01-05 20:21:28 +00:00
}
2020-01-07 20:48:27 +00:00
if (size(me.outputList) >= 3) {
2020-01-05 20:21:28 +00:00
me.L3 = me.outputList[2].updateLeftText();
me.C3 = me.outputList[2].updateCenterText();
2020-01-07 20:48:27 +00:00
me.R3 = me.outputList[2].updateRightText();
} else {
me.L3 = [nil, nil, "ack"];
me.C3 = [nil, nil, "ack"];
me.R3 = [nil, nil, "ack"];
2020-01-05 20:21:28 +00:00
}
2020-01-07 20:48:27 +00:00
if (size(me.outputList) >= 4) {
2020-01-05 20:21:28 +00:00
me.L4 = me.outputList[3].updateLeftText();
me.C4 = me.outputList[3].updateCenterText();
2020-01-07 20:48:27 +00:00
me.R4 = me.outputList[3].updateRightText();
} else {
me.L4 = [nil, nil, "ack"];
me.C4 = [nil, nil, "ack"];
me.R4 = [nil, nil, "ack"];
2020-01-05 20:21:28 +00:00
}
2020-01-07 20:48:27 +00:00
if (size(me.outputList) >= 5) {
2020-01-05 20:21:28 +00:00
me.L5 = me.outputList[4].updateLeftText();
me.C5 = me.outputList[4].updateCenterText();
2020-01-07 20:48:27 +00:00
me.R5 = me.outputList[4].updateRightText();
} else {
me.L5 = [nil, nil, "ack"];
me.C5 = [nil, nil, "ack"];
me.R5 = [nil, nil, "ack"];
2020-01-05 20:21:28 +00:00
}
},
destInfo: func() {
2020-03-25 15:05:04 +00:00
if (me.plan.getWP(fmgc.flightPlanController.arrivalIndex[me.planIndex]) != nil) {
2022-02-02 12:05:42 +00:00
destName = split("-", me.plan.getWP(fmgc.flightPlanController.arrivalIndex[me.planIndex]).wp_name);
2020-05-14 23:51:52 +00:00
if (size(destName) == 2) {
me.L6 = [destName[0] ~ destName[1], " DEST", "wht"];
} else {
2020-05-15 11:02:29 +00:00
me.L6 = [destName[0], " DEST", "wht"];
2020-05-14 23:51:52 +00:00
}
2020-03-25 15:05:04 +00:00
} else {
me.L6 = ["----", " DEST", "wht"];
}
2020-05-14 23:51:52 +00:00
me.C6 = ["---- ", "TIME ", "wht"];
2022-01-17 11:43:31 +00:00
if (fmgc.flightPlanController.arrivalDist.getValue() != nil) {
me.R6 = [sprintf("%4.0f", int(fmgc.flightPlanController.arrivalDist.getValue())) ~ " --.-", "DIST EFOB", "wht"];
2020-03-25 15:05:04 +00:00
} else {
2020-05-14 23:51:52 +00:00
me.R6 = ["---- --.-", "DIST EFOB", "wht"];
2020-03-25 15:05:04 +00:00
}
2020-01-05 20:21:28 +00:00
},
update: func() {
2020-01-11 13:30:08 +00:00
#me.basePage();
2020-01-05 20:21:28 +00:00
},
2022-01-18 19:54:27 +00:00
planIndexFunc: func() {
decelIndex = getprop("/instrumentation/nd/symbols/decel/index");
decelShow = getprop("/instrumentation/nd/symbols/decel/show");
if (me.scroll < me.plan.getPlanSize()) {
2022-02-13 10:02:40 +00:00
decelOffset = 0;
2022-01-18 19:54:27 +00:00
if (decelShow) {
if (me.scroll > decelIndex) {
decelOffset = 1;
}
}
2022-02-02 12:05:42 +00:00
setprop("/instrumentation/efis[" ~ me.computer ~ "]/inputs/plan-wpt-index", (fmgc.flightPlanController.currentToWptIndex.getValue() - 1 + me.scroll - decelOffset));
2022-01-18 19:54:27 +00:00
}
},
2020-01-05 20:21:28 +00:00
scrollUp: func() {
2020-05-13 15:41:13 +00:00
if (size(me.planList) > 1) {
2020-01-05 20:21:28 +00:00
me.scroll += 1;
2020-05-13 15:41:13 +00:00
if (me.scroll > size(me.planList) - 3) {
2020-01-05 20:21:28 +00:00
me.scroll = 0;
}
2022-01-18 19:54:27 +00:00
me.planIndexFunc();
2020-01-07 20:48:27 +00:00
} else {
me.scroll = 0;
2020-05-13 15:41:13 +00:00
setprop("/instrumentation/efis[" ~ me.computer ~ "]/inputs/plan-wpt-index", -1);
2020-01-05 20:21:28 +00:00
}
},
scrollDn: func() {
2020-05-13 15:41:13 +00:00
if (size(me.planList) > 1) {
2020-01-07 20:48:27 +00:00
me.scroll -= 1;
2020-01-05 20:21:28 +00:00
if (me.scroll < 0) {
2020-05-13 15:41:13 +00:00
me.scroll = size(me.planList) - 3;
}
2022-01-18 19:54:27 +00:00
me.planIndexFunc();
2020-01-07 20:48:27 +00:00
} else {
me.scroll = 0;
2020-05-13 15:41:13 +00:00
setprop("/instrumentation/efis[" ~ me.computer ~ "]/inputs/plan-wpt-index", -1);
2020-01-07 20:48:27 +00:00
}
},
pushButtonLeft: func(index) {
if (index == 6) {
if (fmgc.flightPlanController.temporaryFlag[me.computer]) {
fmgc.flightPlanController.destroyTemporaryFlightPlan(me.computer, 0);
2020-05-18 19:18:17 +00:00
# push update to fuel
2020-10-03 09:59:43 +00:00
if (fmgc.FMGCInternal.blockConfirmed) {
fmgc.FMGCInternal.fuelCalculating = 0;
2020-10-03 11:34:29 +00:00
fmgc.fuelCalculating.setValue(0);
2020-10-03 09:59:43 +00:00
fmgc.FMGCInternal.fuelCalculating = 1;
2020-10-03 11:34:29 +00:00
fmgc.fuelCalculating.setValue(1);
2020-05-18 19:18:17 +00:00
}
2020-01-07 20:48:27 +00:00
} else {
2020-01-16 17:08:14 +00:00
if (canvas_mcdu.myLatRev[me.computer] != nil) {
canvas_mcdu.myLatRev[me.computer].del();
}
canvas_mcdu.myLatRev[me.computer] = nil;
2020-04-24 11:44:39 +00:00
canvas_mcdu.myLatRev[me.computer] = latRev.new(1, fmgc.flightPlanController.flightplans[2].getWP(fmgc.flightPlanController.arrivalIndex[2]), fmgc.flightPlanController.arrivalIndex[2], me.computer);
2020-03-09 18:00:22 +00:00
setprop("MCDU[" ~ me.computer ~ "]/page", "LATREV");
2020-01-07 20:48:27 +00:00
}
} else {
2022-01-18 20:11:31 +00:00
if ((index - 1 + me.scroll) < size(me.planList) and me.outputList[index - 1].wp != "STATIC" and me.outputList[index - 1].wp != "PSEUDO" and !mcdu_scratchpad.scratchpads[me.computer].showTypeIMsg and !mcdu_scratchpad.scratchpads[me.computer].showTypeIIMsg) {
2020-05-23 11:16:20 +00:00
if (size(mcdu_scratchpad.scratchpads[me.computer].scratchpad) > 0) {
2022-01-20 17:34:14 +00:00
# Use outputList.index to correct the index the call goes to after sequencing
var returny = fmgc.flightPlanController.scratchpad(mcdu_scratchpad.scratchpads[me.computer].scratchpad, me.outputList[index - 1].index, me.computer);
2020-03-29 15:55:30 +00:00
if (returny == 3) {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "DIR TO IN PROGRESS");
2020-03-29 15:55:30 +00:00
} elsif (returny == 0) {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT IN DATA BASE");
2020-01-07 20:48:27 +00:00
} elsif (returny == 1) {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT ALLOWED");
2020-05-17 00:37:42 +00:00
} elsif (returny == 4) {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "LIST OF 20 IN USE");
2020-01-07 20:48:27 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_scratchpad.scratchpads[me.computer].empty();
2020-01-07 20:48:27 +00:00
}
} else {
2020-01-11 14:48:18 +00:00
me.outputList[index - 1].pushButtonLeft();
2020-01-07 20:48:27 +00:00
}
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT ALLOWED");
2020-01-07 20:48:27 +00:00
}
}
},
pushButtonRight: func(index) {
if (index == 6) {
if (fmgc.flightPlanController.temporaryFlag[me.computer]) {
2020-03-31 15:33:28 +00:00
if (dirToFlag) { dirToFlag = 0; }
2020-01-07 20:48:27 +00:00
fmgc.flightPlanController.destroyTemporaryFlightPlan(me.computer, 1);
2020-05-02 00:26:05 +00:00
# push update to fuel
2020-10-03 09:59:43 +00:00
if (fmgc.FMGCInternal.blockConfirmed) {
fmgc.FMGCInternal.fuelCalculating = 0;
2020-10-03 11:34:29 +00:00
fmgc.fuelCalculating.setValue(0);
2020-10-03 09:59:43 +00:00
fmgc.FMGCInternal.fuelCalculating = 1;
2020-10-03 11:34:29 +00:00
fmgc.fuelCalculating.setValue(1);
2020-05-02 00:26:05 +00:00
}
2020-01-07 20:48:27 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT ALLOWED");
2020-01-05 20:21:28 +00:00
}
2020-01-07 20:48:27 +00:00
} else {
2020-03-09 18:00:22 +00:00
if (size(me.outputList) >= index) {
2020-06-15 15:29:05 +00:00
me.outputList[index - 1].pushButtonRight();
2020-03-09 18:00:22 +00:00
} else {
2020-05-23 11:16:20 +00:00
mcdu_message(me.computer, "NOT ALLOWED");
2020-03-09 18:00:22 +00:00
}
2020-01-05 20:21:28 +00:00
}
},
};
2020-01-07 20:48:27 +00:00
2020-01-05 20:21:28 +00:00
var decimalToShortString = func(dms, type) {
2020-01-11 13:30:08 +00:00
var degrees = split(".", sprintf(dms))[0];
2020-01-05 20:21:28 +00:00
if (type == "lat") {
var sign = degrees >= 0 ? "N" : "S";
2022-05-13 13:41:33 +00:00
return sprintf("%02d", abs(degrees)) ~ sign;
2020-01-05 20:21:28 +00:00
} else {
var sign = degrees >= 0 ? "E" : "W";
2022-05-13 13:41:33 +00:00
return sprintf("%03d", abs(degrees)) ~ sign;
2020-01-05 20:21:28 +00:00
}
}