| 1 |
# Copyright 2018 Stuart Buchanan |
| 2 |
# This file is part of FlightGear. |
| 3 |
# |
| 4 |
# FlightGear is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 2 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# FlightGear is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with FlightGear. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
# |
| 17 |
# NearestFrequencies |
| 18 |
var NearestFrequencies = |
| 19 |
{ |
| 20 |
new : func (mfd, myCanvas, device, svg) |
| 21 |
{ |
| 22 |
var obj = { |
| 23 |
parents : [ |
| 24 |
NearestFrequencies, |
| 25 |
MFDPage.new(mfd, myCanvas, device, svg, "NearestFrequencies", "NRST - NEAREST FREQUENCIES") |
| 26 |
], |
| 27 |
}; |
| 28 |
|
| 29 |
var textElements = ["ARTCCName", "ARTCCBRG", "ARTCCDIS", "FSSName", "FSSBRG", "FSSDIS"]; |
| 30 |
|
| 31 |
obj.addTextElements(textElements); |
| 32 |
|
| 33 |
obj.artccSelect = PFD.GroupElement.new( |
| 34 |
obj.pageName, |
| 35 |
svg, |
| 36 |
["ARTCCFreq"], |
| 37 |
3, |
| 38 |
"ARTCCFreq", |
| 39 |
0, |
| 40 |
); |
| 41 |
|
| 42 |
obj.fssSelect = PFD.GroupElement.new( |
| 43 |
obj.pageName, |
| 44 |
svg, |
| 45 |
["FSSFreq"], |
| 46 |
3, |
| 47 |
"FSSFreq", |
| 48 |
0, |
| 49 |
); |
| 50 |
|
| 51 |
obj.wxSelect = PFD.GroupElement.new( |
| 52 |
obj.pageName, |
| 53 |
svg, |
| 54 |
["WXID", "WXType", "WXFreq"], |
| 55 |
8, |
| 56 |
"WXFreq", |
| 57 |
0, |
| 58 |
"ScrollTrough", |
| 59 |
"ScrollThumb", |
| 60 |
(181 - 116) |
| 61 |
); |
| 62 |
|
| 63 |
obj.topMenu(device, obj, nil); |
| 64 |
|
| 65 |
obj.setController(fg1000.NearestFrequenciesController.new(obj, svg)); |
| 66 |
|
| 67 |
return obj; |
| 68 |
}, |
| 69 |
|
| 70 |
# Clear any cursor, highlights. Used when exiting from CRSR mode |
| 71 |
resetCRSR : func() { |
| 72 |
me.artccSelect.hideCRSR(); |
| 73 |
me.fssSelect.hideCRSR(); |
| 74 |
me.wxSelect.hideCRSR(); |
| 75 |
me.resetMenuColors(); |
| 76 |
}, |
| 77 |
|
| 78 |
|
| 79 |
updateARTCC : func(artcc) { |
| 80 |
if (artcc != nil) { |
| 81 |
me.setTextElement("ARTCCName", artcc.name); |
| 82 |
me.setTextElementBearing("ARTCCBRG", artcc.brg); |
| 83 |
me.setTextElementDistance("ARTCCDIS", artcc.dis); |
| 84 |
me.artccSelect.setValues(artcc.freqs); |
| 85 |
} else { |
| 86 |
me.setTextElement("ARTCCName", ""); |
| 87 |
me.setTextElementBearing("ARTCCBRG", nil); |
| 88 |
me.setTextElementDistance("ARTCCDIS", nil); |
| 89 |
me.artccSelect.setValues([]); |
| 90 |
} |
| 91 |
|
| 92 |
}, |
| 93 |
|
| 94 |
updateFSS : func(fss) { |
| 95 |
if (fss != nil) { |
| 96 |
me.setTextElement("FSSName", fss.name); |
| 97 |
me.setTextElementBearing("FSSBRG", fss.brg); |
| 98 |
me.setTextElementDistance("FSSDIS", fss.dis); |
| 99 |
me.fssSelect.setValues(fss.freqs); |
| 100 |
} else { |
| 101 |
me.setTextElement("FSSName", ""); |
| 102 |
me.setTextElementBearing("FSSBRG", nil); |
| 103 |
me.setTextElementDistance("FSSDIS", nil); |
| 104 |
me.fssSelect.setValues([]); |
| 105 |
} |
| 106 |
}, |
| 107 |
|
| 108 |
updateWX : func(freqs) { |
| 109 |
var values = []; |
| 110 |
|
| 111 |
if (freqs != nil) { |
| 112 |
foreach (var f; freqs) { |
| 113 |
append(values, { WXID: f.id, WXType: f.type, WXFreq: sprintf("%0.03f", f.freq) } ); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
me.wxSelect.setValues(values); |
| 118 |
}, |
| 119 |
|
| 120 |
getSelectedARTCC : func() { |
| 121 |
return me.artccSelect.getValue(); |
| 122 |
}, |
| 123 |
getSelectedFSS : func() { |
| 124 |
return me.fssSelect.getValue(); |
| 125 |
}, |
| 126 |
getSelectedWX : func() { |
| 127 |
return me.wxSelect.getValue(); |
| 128 |
}, |
| 129 |
|
| 130 |
# Function to highlight the ARTCC softkey - used when CRSR is pressed to indicate |
| 131 |
# that we're editing the ARTCC selection. |
| 132 |
selectARTCC : func() { |
| 133 |
me.resetMenuColors(); |
| 134 |
var bg_name = sprintf("SoftKey%d-bg",5); |
| 135 |
var tname = sprintf("SoftKey%d",5); |
| 136 |
me.device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5); |
| 137 |
me.device.svg.getElementById(tname).setColor(0.0,0.0,0.0); |
| 138 |
}, |
| 139 |
|
| 140 |
offdisplay : func() { |
| 141 |
me._group.setVisible(0); |
| 142 |
# The Nearest... pages use the underlying navigation map. |
| 143 |
me.mfd.NavigationMap.offdisplayPartial(); |
| 144 |
me.resetMenuColors(); |
| 145 |
me.getController().offdisplay(); |
| 146 |
}, |
| 147 |
ondisplay : func() { |
| 148 |
me._group.setVisible(1); |
| 149 |
me.mfd.setPageTitle(me.title); |
| 150 |
|
| 151 |
# The Nearest... pages use the underlying navigation map. |
| 152 |
me.mfd.NavigationMap.ondisplayPartial(); |
| 153 |
|
| 154 |
me.getController().ondisplay(); |
| 155 |
}, |
| 156 |
|
| 157 |
# Indicate which group is selected by colour of the softkeys |
| 158 |
display_toggle : func(device, svg, mi, group) { |
| 159 |
var bg_name = sprintf("SoftKey%d-bg",mi.menu_id); |
| 160 |
if (me.getController().getSelectedGroup() == group) { |
| 161 |
device.svg.getElementById(bg_name).setColorFill(0.5,0.5,0.5); |
| 162 |
svg.setColor(0.0,0.0,0.0); |
| 163 |
} else { |
| 164 |
device.svg.getElementById(bg_name).setColorFill(0.0,0.0,0.0); |
| 165 |
svg.setColor(1.0,1.0,1.0); |
| 166 |
} |
| 167 |
svg.setText(mi.title); |
| 168 |
svg.setVisible(1); # display function |
| 169 |
}, |
| 170 |
|
| 171 |
topMenu : func(device, pg, menuitem) { |
| 172 |
pg.clearMenu(); |
| 173 |
pg.resetMenuColors(); |
| 174 |
|
| 175 |
pg.addMenuItem(0, "ENGINE", pg, pg.mfd.EIS.engineMenu); |
| 176 |
pg.addMenuItem(2, "MAP", pg, pg.mfd.NavigationMap.mapMenu); |
| 177 |
pg.addMenuItem(5, "ARTCC", pg, |
| 178 |
func(dev, pg, mi) { pg.getController().selectARTCC(); device.updateMenus(); }, # callback |
| 179 |
func(svg, mi) { pg.display_toggle(device, svg, mi, NearestFrequenciesController.UIGROUP.ARTCC); } |
| 180 |
); |
| 181 |
pg.addMenuItem(6, "FSS", pg, |
| 182 |
func(dev, pg, mi) { pg.getController().selectFSS(); device.updateMenus(); }, # callback |
| 183 |
func(svg, mi) { pg.display_toggle(device, svg, mi, NearestFrequenciesController.UIGROUP.FSS); } |
| 184 |
); |
| 185 |
pg.addMenuItem(7, "WX", pg, |
| 186 |
func(dev, pg, mi) { pg.getController().selectWX(); device.updateMenus(); }, # callback |
| 187 |
func(svg, mi) { pg.display_toggle(device, svg, mi, NearestFrequenciesController.UIGROUP.WX); } |
| 188 |
); |
| 189 |
|
| 190 |
device.updateMenus(); |
| 191 |
}, |
| 192 |
|
| 193 |
|
| 194 |
}; |