1
0
Fork 0

Add Place / Bearing / Distance - uses magnetic heading for now

This commit is contained in:
legoboyvdlp R 2020-05-14 20:02:18 +01:00
parent f414119f18
commit 85a34eeb54
3 changed files with 137 additions and 41 deletions

View file

@ -125,6 +125,8 @@ var flightPlanController = {
me.addDiscontinuity(1, plan); me.addDiscontinuity(1, plan);
# reset mcdu if it exists # reset mcdu if it exists
if (canvas_mcdu.myFpln[0] != nil) { canvas_mcdu.myFpln[0].scroll = 0; }
if (canvas_mcdu.myFpln[1] != nil) { canvas_mcdu.myFpln[1].scroll = 0; }
if (canvas_mcdu.myArrival[0] != nil) { canvas_mcdu.myArrival[0].reset(); } if (canvas_mcdu.myArrival[0] != nil) { canvas_mcdu.myArrival[0].reset(); }
if (canvas_mcdu.myArrival[1] != nil) { canvas_mcdu.myArrival[1].reset(); } if (canvas_mcdu.myArrival[1] != nil) { canvas_mcdu.myArrival[1].reset(); }
if (canvas_mcdu.myDeparture[0] != nil) { canvas_mcdu.myDeparture[0].reset(); } if (canvas_mcdu.myDeparture[0] != nil) { canvas_mcdu.myDeparture[0].reset(); }
@ -227,11 +229,11 @@ var flightPlanController = {
# typeStr: optional argument to be passed to createWP, must be one of "sid", "star" "approach" "missed" or "pseudo" # typeStr: optional argument to be passed to createWP, must be one of "sid", "star" "approach" "missed" or "pseudo"
childWPBearingDistance: func(wpt, bearing, dist, name, typeStr = "") { childWPBearingDistance: func(wpt, bearing, dist, name, typeStr = "") {
var coordinates = greatCircleMove(wpt.lat, wpt.lon, bearing, dist); var coordinates = greatCircleMove(wpt.lat, wpt.lon, num(bearing), num(dist));
if (typeStr != "") { if (typeStr != "") {
return createWP(coordinates, name);
} else {
return createWP(coordinates, name, typeStr); return createWP(coordinates, name, typeStr);
} else {
return createWP(coordinates, name);
} }
}, },
@ -330,6 +332,23 @@ var flightPlanController = {
} }
}, },
# createDuplicateNames - helper to spawn DUPLICATENAMES page
# args: ghostContainer, index, flag, plan
# ghostContainer: vector of fgPositioned ghosts
# index: index
# flag: is it a navaids DUPLICATENAMES page or not?
# plan: plan
# flagPBD: do we return back to PBD handler or to default waypoint handler?
createDuplicateNames: func(ghostContainer, index, flag, plan, flagPBD = 0, bearing = -999, distance = -99) {
if (canvas_mcdu.myDuplicate[plan] != nil) {
canvas_mcdu.myDuplicate[plan].del();
}
canvas_mcdu.myDuplicate[plan] = nil;
canvas_mcdu.myDuplicate[plan] = mcdu.duplicateNamesPage.new(ghostContainer, index, flag, plan, flagPBD, bearing, distance);
setprop("MCDU[" ~ plan ~ "]/page", "DUPLICATENAMES");
},
insertAirport: func(text, index, plan, override = 0, overrideIndex = -1) { insertAirport: func(text, index, plan, override = 0, overrideIndex = -1) {
if (index == 0) { if (index == 0) {
return 1; return 1;
@ -371,12 +390,7 @@ var flightPlanController = {
} }
} }
} elsif (size(airport) >= 1) { } elsif (size(airport) >= 1) {
if (canvas_mcdu.myDuplicate[plan] != nil) { me.createDuplicateNames(airport, index, 0, plan);
canvas_mcdu.myDuplicate[plan].del();
}
canvas_mcdu.myDuplicate[plan] = nil;
canvas_mcdu.myDuplicate[plan] = mcdu.duplicateNamesPage.new(airport, index, 0, plan);
setprop("MCDU[" ~ plan ~ "]/page", "DUPLICATENAMES");
return 2; return 2;
} }
}, },
@ -422,12 +436,7 @@ var flightPlanController = {
} }
} }
} elsif (size(fix) >= 1) { } elsif (size(fix) >= 1) {
if (canvas_mcdu.myDuplicate[plan] != nil) { me.createDuplicateNames(fix, index, 0, plan);
canvas_mcdu.myDuplicate[plan].del();
}
canvas_mcdu.myDuplicate[plan] = nil;
canvas_mcdu.myDuplicate[plan] = mcdu.duplicateNamesPage.new(fix, index, 0, plan);
setprop("MCDU[" ~ plan ~ "]/page", "DUPLICATENAMES");
return 2; return 2;
} }
}, },
@ -503,16 +512,92 @@ var flightPlanController = {
} }
} }
} elsif (size(navaid) >= 1) { } elsif (size(navaid) >= 1) {
if (canvas_mcdu.myDuplicate[plan] != nil) { me.createDuplicateNames(navaid, index, 1, plan);
canvas_mcdu.myDuplicate[plan].del();
}
canvas_mcdu.myDuplicate[plan] = nil;
canvas_mcdu.myDuplicate[plan] = mcdu.duplicateNamesPage.new(navaid, index, 1, plan);
setprop("MCDU[" ~ plan ~ "]/page", "DUPLICATENAMES");
return 2; return 2;
} }
}, },
# getWPforPBD - parse scratchpad text to find waypoint ghost for PBD
# args: text, index, plan
# text: scratchpad text
# index: index at which waypoint will be inserted
# plan: plan to which waypoint will be inserted
# return:
# 0: not in database
# 1: notAllowed
# 2: o.k.
getWPforPBD: func(text, index, plan, override = 0, overrideIndex = -1) {
if (index == 0) {
return 1;
}
var textSplit = split("/", text);
if (size(split(".", textSplit[2])) != 1 or size(textSplit[1]) < 2 or size(textSplit[1]) > 3) {
return 1;
}
var wpGhost = nil;
var wpGhostContainer = nil;
var type = nil;
if (size(textSplit[0]) == 5) {
wpGhostContainer = findFixesByID(textSplit[0]);
if (size(wpGhostContainer) == 0) {
return 0;
}
type = "fix";
} elsif (size(textSplit[0]) == 4) {
wpGhostContainer = findAirportsByICAO(textSplit[0]);
if (size(wpGhostContainer) == 0) {
return 0;
}
type = "airport";
} elsif (size(textSplit[0]) == 3 or size(textSplit[0]) == 2) {
wpGhostContainer = findNavaidsByID(textSplit[0]);
if (size(wpGhostContainer) == 0) {
return 0;
}
type = "navaid";
} else {
return 1;
}
if (size(wpGhostContainer) == 0 or override) {
if (!override) {
wpGhost = wpGhostContainer[0];
} else {
wpGhost = wpGhostContainer[overrideIndex];
}
} else {
if (type == "navaid") {
me.createDuplicateNames(wpGhostContainer, index, 1, plan, 1, num(textSplit[1]), num(textSplit[2]));
} else {
me.createDuplicateNames(wpGhostContainer, index, 0, plan, 1, num(textSplit[1]), num(textSplit[2]));
}
return 2;
}
var localMagvar = magvar(wpGhost.lat, wpGhost.lon);
me.insertPlaceBearingDistance(wpGhost, textSplit[1] + localMagvar, textSplit[2], index, plan);
return 2;
},
# insertPlaceBearingDistance - insert PBD waypoint at specified index,
# at some specified bearing, distance from a specified location
# args: wp, index, plan
# wpt: waypoint ghost
# index: index to insert at in plan
# plan: plan to insert to
insertPlaceBearingDistance: func(wp, bearing, distance, index, plan) {
me.flightplans[plan].insertWP(me.childWPBearingDistance(wp, bearing, distance, "PBD" ~ index), index);
me.addDiscontinuity(index + 1, plan);
me.flightPlanChanged(plan);
},
scratchpad: func(text, index, plan) { # return 0 not in database, 1 not allowed, 2 success, 3 = not allowed due to dir to scratchpad: func(text, index, plan) { # return 0 not in database, 1 not allowed, 2 success, 3 = not allowed due to dir to
if (mcdu.dirToFlag) { if (mcdu.dirToFlag) {
return 3; return 3;
@ -529,7 +614,9 @@ var flightPlanController = {
var thePlan = plan; var thePlan = plan;
} }
if (text == "CLR") { if (size(split("/", text)) == 3) {
return me.getWPforPBD(text, index, thePlan);
} elsif (text == "CLR") {
return me.deleteWP(index, thePlan, 0); return me.deleteWP(index, thePlan, 0);
} elsif (size(text) > 12) { } elsif (size(text) > 12) {
return me.insertLatLonFix(text, index, thePlan); return me.insertLatLonFix(text, index, thePlan);

View file

@ -28,15 +28,18 @@ var duplicateNamesPage = {
enableScroll: 0, enableScroll: 0,
scroll: 0, scroll: 0,
distances: nil, distances: nil,
new: func(vector, index, type, computer) { new: func(vector, index, type, computer, flagPBD = 0, pbdBrg = -999, pbdDist = -99) {
var fp = {parents:[duplicateNamesPage]}; var dn = {parents:[duplicateNamesPage]};
fp.vector = vector; dn.vector = vector;
fp.index = index; dn.index = index;
fp.type = type; # 0 = other, 1 = navaid dn.type = type; # 0 = other, 1 = navaid
fp.computer = computer; dn.flagPBD = flagPBD;
fp._setupPageWithData(); dn.bearing = pbdBrg;
fp.distances = []; dn.distance = pbdDist;
return fp; dn.computer = computer;
dn._setupPageWithData();
dn.distances = [];
return dn;
}, },
del: func() { del: func() {
return nil; return nil;
@ -131,6 +134,7 @@ var duplicateNamesPage = {
}, },
pushButtonLeft: func(indexSelect) { pushButtonLeft: func(indexSelect) {
if (!dirToFlag) { if (!dirToFlag) {
if (!me.flagPBD) {
if (size(me.vector[0].id) == 5) { if (size(me.vector[0].id) == 5) {
fmgc.flightPlanController.insertFix(me.vector[0].id, me.index, me.computer, 1, indexSelect - 1); fmgc.flightPlanController.insertFix(me.vector[0].id, me.index, me.computer, 1, indexSelect - 1);
setprop("MCDU[" ~ me.computer ~ "]/page", "F-PLNA"); setprop("MCDU[" ~ me.computer ~ "]/page", "F-PLNA");
@ -141,6 +145,10 @@ var duplicateNamesPage = {
fmgc.flightPlanController.insertNavaid(me.vector[0].id, me.index, me.computer, 1, indexSelect - 1); fmgc.flightPlanController.insertNavaid(me.vector[0].id, me.index, me.computer, 1, indexSelect - 1);
setprop("MCDU[" ~ me.computer ~ "]/page", "F-PLNA"); setprop("MCDU[" ~ me.computer ~ "]/page", "F-PLNA");
} }
} else {
fmgc.flightPlanController.getWPforPBD(me.vector[0].id ~ "/" ~ me.bearing ~ "/" ~ me.distance, me.index, me.computer, 1, indexSelect - 1);
setprop("MCDU[" ~ me.computer ~ "]/page", "F-PLNA");
}
} else { } else {
canvas_mcdu.myDirTo[me.computer].fieldL1(me.vector[0].id, 1, indexSelect - 1); canvas_mcdu.myDirTo[me.computer].fieldL1(me.vector[0].id, 1, indexSelect - 1);
setprop("MCDU[" ~ me.computer ~ "]/page", "DIRTO"); setprop("MCDU[" ~ me.computer ~ "]/page", "DIRTO");

View file

@ -71,13 +71,14 @@ var fplnItem = {
} }
}, },
getBrg: func() { getBrg: func() {
me.brg = fmgc.wpCourse[me.plan][me.index].getValue() - pts.Environment.magVar.getValue(); me.brg = fmgc.wpCourse[me.plan][me.index].getValue() - magvar();
if (me.brg < 0) { me.brg += 360; } if (me.brg < 0) { me.brg += 360; }
if (me.brg > 360) { me.brg -= 360; } if (me.brg > 360) { me.brg -= 360; }
return sprintf("%03.0f", math.round(me.brg)); return sprintf("%03.0f", math.round(me.brg));
}, },
getTrack: func() { getTrack: func() {
me.trk = fmgc.wpCoursePrev[me.plan][me.index].getValue() - pts.Environment.magVar.getValue(); var wp = fmgc.flightPlanController.flightplans[me.plan].getWP(me.index);
me.trk = fmgc.wpCoursePrev[me.plan][me.index].getValue() - magvar(wp.lat, wp.lon);
if (me.trk < 0) { me.trk += 360; } if (me.trk < 0) { me.trk += 360; }
if (me.trk > 360) { me.trk -= 360; } if (me.trk > 360) { me.trk -= 360; }
return sprintf("%03.0f", math.round(me.trk)); return sprintf("%03.0f", math.round(me.trk));