--- ./data/gui/dialogs/location-in-air.xml 2007/01/28 12:05:09 1.1 +++ ./data/gui/dialogs/location-in-air.xml 2007/01/28 12:56:07 @@ -1,4 +1,10 @@ + + + location-in-air vbox @@ -6,15 +12,21 @@ - p = props.globals.getNode("/sim/gui/dialogs/location-in-air/", 1); + + me = "/sim/gui/dialogs/location-in-air"; + magvar = getprop("/environment/magnetic-variation-deg"); + + mynode = props.globals.getNode(me, 1); mode = { - airport: p.getNode("airport", 1), - lonlat: p.getNode("lonlat", 1), - vor: p.getNode("vor", 1), - ndb: p.getNode("ndb", 1), - fix: p.getNode("fix", 1), + "airport-btn": mynode.getNode("airport-btn", 1), + "lonlat-btn": mynode.getNode("lonlat-btn", 1), + "vor-btn": mynode.getNode("vor-btn", 1), + "ndb-btn": mynode.getNode("ndb-btn", 1), + "fix-btn": mynode.getNode("fix-btn", 1), + "ppos-btn": mynode.getNode("ppos-btn", 1), }; +# Function to push a radio button and clear all the others: set_radio = func(m) { foreach (k; keys(mode)) { mode[k].setBoolValue(m == k); @@ -29,21 +41,138 @@ initialized += mode[k].getBoolValue(); } if (!initialized) { - set_radio("airport"); + set_radio("airport-btn"); + } + +# We need our own private variables, to have and to hold, +# without worrying about whether the FDM will mess with +# them. A subset of these will be copied to FDM variables +# with similar names. Which subset depends on which radio +# button is pushed. + + myvars = {"airport-id" : 0, "runway" : 0, + "latitude-deg" : 4, "longitude-deg" : 4, + "vor-id" : 0, "ndb-id" : 0, "fix" : 0, + "offset-distance" : 0, "course-deg-mag" : 0, + "altitude-ft" : 0, "glideslope-deg" : 0, + "airspeed-kt" : 0, "heading-deg-mag" : 0, + }; + +# Inherit a few things from the fgfs command line: + if (!getprop(me, "did1")) { + setprop(me, "did1", 1); # inherit only once + + foreach (varname ; keys(myvars)) { + nnn = props.globals.getNode("/sim/presets/" ~ varname, 1); + ttt = nnn.getType(); + value = nnn.getValue(); + # The reason for the following "if" is to make + # sure we assign a /string/ (not a numeric) to + # our copy of the variable. + # The reason for that is so that (later) we can distinguish + # between "" (which means take the default) + # and zero (which means the user wants a value of zero). + if (ttt == "STRING") { + setprop(me, varname, nnn.getValue()); + } elsif (value != nil) { + # must be some kind of numeric + fmt = sprintf("%%1.%df", myvars[varname]); + setprop(me, varname, sprintf(fmt, nnn.getValue())); + } else { + setprop(me, varname, ""); + } + } + +# Now fix up a few of the inherited values, +# taking care of special cases: + +# Relocating to surface doesn't make sense; +# we are supposed to be relocating aloft: + alt = getprop("/sim/presets/altitude-ft"); + if (alt == -9999) { + alt = ""; + } # else default to "inherited" reset-to-air altitude + setprop(me, "altitude-ft", alt); + +# Inherit preset airspeed from command line: + ktas = getprop("/sim/presets/airspeed-kt"); + if (ktas == 0) { + ktas = ""; + } + setprop(me, "airspeed-kt", ktas); + +# Probably never a good idea to inherit a heading; +# instead use current heading as the default. + if (1) { + setprop(me, "heading-deg-mag", ""); + } else { +# Preset heading from command line was treated as +# /true/ heading; we want the corresponding +# /magnetic/ heading: + hdg = getprop("/sim/presets/heading-deg"); + setprop(me, "heading-deg-mag", sprintf("%d", hdg - magvar)); + } + + } # end inheriting things + + setprop(me, "altitude-agl-ft", + sprintf("%5.2f", getprop("/position/altitude-agl-ft"))); + + copycontrol = func(vvv, factor){ + setprop(me, vvv, + sprintf("%5.2f", factor * getprop("/controls/flight", vvv))); } + copycontrol("aileron", 1); + copycontrol("aileron-trim", 1); + copycontrol("elevator", -1); + copycontrol("elevator-trim", -1); + copycontrol("rudder", 1); + copycontrol("rudder-trim", 1); + +# The rule is, if it doesn't say "mag" in the name, it +# is a true bearing, not a magnetic bearing. +# Like the FDM, we do as much as possible with true +# bearings internally. + +# When displaying magnetic bearings to a user, +# convert them /immediately/ beforehand to magnetic +# by subtracting magvar. +# Similarly, when getting magnetic bearings from the user, +# convert them /immediately/ afterward to true +# by adding magvar. + + hdg1 = getprop("/orientation/heading-deg"); + setprop(me, "this-heading-deg-mag", sprintf("%d", hdg1 - magvar)); + setprop(me, "this-throttle", sprintf("%5.2f", + getprop("/controls/engines/engine/throttle"))); + + setprop(me, "this-latitude-deg", + sprintf("%1.4f", getprop("/position/latitude-deg"))); + setprop(me, "this-longitude-deg", + sprintf("%1.4f", getprop("/position/longitude-deg"))); + - # just kept for educational purposes :-) + # just kept for educational purposes :-) + +# Note that I would like to use the degree /symbol/ +# rather than spelling out "deg" in the dialog labels. +# The utf-8 for this symbol is (°). +# However, alas, putting that into the label produces +# no visible result. Rumor suggests that we are using +# a font that doesn't have a glyph for this character. + + - + - + @@ -52,134 +181,182 @@ 00 true - /sim/gui/dialogs/location-in-air/airport + /sim/gui/dialogs/location-in-air/airport-btn dialog-apply nasal - + 01 + left 02 - /sim/presets/airport-id + left + /sim/gui/dialogs/location-in-air/airport-id + 03 04 - /sim/presets/runway + left + /sim/gui/dialogs/location-in-air/runway 10 true - /sim/gui/dialogs/location-in-air/lonlat + /sim/gui/dialogs/location-in-air/lonlat-btn dialog-apply nasal - + 11 - + left + 12 - /sim/presets/longitude-deg + 130 + left + /sim/gui/dialogs/location-in-air/latitude-deg 13 - + left + 14 - /sim/presets/latitude-deg + 130 + left + /sim/gui/dialogs/location-in-air/longitude-deg 20 true - /sim/gui/dialogs/location-in-air/vor + /sim/gui/dialogs/location-in-air/vor-btn dialog-apply nasal - + 21 - right + left 22 - /sim/presets/vor-id + left + /sim/gui/dialogs/location-in-air/vor-id 30 true - left - - /sim/gui/dialogs/location-in-air/ndb + /sim/gui/dialogs/location-in-air/ndb-btn dialog-apply nasal - + 31 - right + left 32 - /sim/presets/ndb-id + left + /sim/gui/dialogs/location-in-air/ndb-id + + 33 + left + + 40 true - /sim/gui/dialogs/location-in-air/fix - left - + /sim/gui/dialogs/location-in-air/fix-btn dialog-apply nasal - + 41 - right - + left + 42 - /sim/presets/fix + left + /sim/gui/dialogs/location-in-air/fix + + 43 + left + + + + + 50 + true + /sim/gui/dialogs/location-in-air/ppos-btn + + dialog-apply + + + nasal + + + + + 51 + left + + + + 52 + left + /sim/gui/dialogs/location-in-air/this-latitude-deg + + + 54 + left + /sim/gui/dialogs/location-in-air/this-longitude-deg + + - + @@ -187,63 +364,177 @@ 00 right - + 01 - /sim/presets/offset-distance + /sim/gui/dialogs/location-in-air/offset-distance - 02 + left + + + + + 03 right - + - 03 - /sim/presets/offset-azimuth + 04 + /sim/gui/dialogs/location-in-air/course-deg-mag + + 05 + left + + + + 12 + left + + - 10 + 20 right - + - 11 - /sim/presets/altitude-ft + 21 + /sim/gui/dialogs/location-in-air/altitude-ft + + 22 + left + + - 12 + 23 right - + - 13 - /sim/presets/glidescope-deg + 24 + /sim/gui/dialogs/location-in-air/glideslope-deg + + 25 + left + + + - 20 + 30 right - + - 21 - /sim/presets/airspeed-kt + 31 + /sim/gui/dialogs/location-in-air/airspeed-kt + + 32 + left + + + - 22 + 33 right - + - 23 - /sim/presets/heading-deg + 34 + /sim/gui/dialogs/location-in-air/heading-deg-mag + + 35 + left + + + + + + + table + + 0 + + + + 31 + left + + + + 32 + left + + + + + 50 + + + + 51 + left + /sim/gui/dialogs/location-in-air/aileron + + + 52 + left + /sim/gui/dialogs/location-in-air/aileron-trim + + + 53 + left + + + + + + 60 + + + + 61 + left + /sim/gui/dialogs/location-in-air/elevator + + + 62 + left + /sim/gui/dialogs/location-in-air/elevator-trim + + + 63 + left + + + + + 70 + + + + 71 + left + /sim/gui/dialogs/location-in-air/rudder + + + 72 + left + /sim/gui/dialogs/location-in-air/rudder-trim + + + @@ -257,51 +548,189 @@ dialog-apply + nasal - + + + presets-commit + + nasal - + dialog-close