8142fc2b95f86285bbb78f28197982a8ab093858
[extra500:extra500.git] / Nasal / AvidyneEntegra9 / page_PFD.nas
1 #    This file is part of extra500
2 #
3 #    extra500 is free software: you can redistribute it and/or modify
4 #    it under the terms of the GNU General Public License as published by
5 #    the Free Software Foundation, either version 2 of the License, or
6 #    (at your option) any later version.
7 #
8 #    extra500 is distributed in the hope that it will be useful,
9 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #    GNU General Public License for more details.
12 #
13 #    You should have received a copy of the GNU General Public License
14 #    along with extra500.  If not, see <http://www.gnu.org/licenses/>.
15 #
16 #      Authors: Dirk Dittmann
17 #      Date: Jul 20 2013
18 #
19 #      Last change:      Eric van den Berg
20 #      Date:             20.07.14
21 #
22
23
24
25 # var NAV_SOURCE_NAME   = ["Nav 1","Nav 2","FMS"];
26 # var NAV_SOURCE_TREE   = ["/instrumentation/nav[0]","/instrumentation/nav[1]","/instrumentation/fms"];
27
28 # var BEARING_SOURCE_NAME = ["0ff","Nav 1","Nav 2","FMS"];
29 # var BEARING_SOURCE_TREE = [nil,"/instrumentation/nav[0]","/instrumentation/nav[1]","/instrumentation/fms"];
30
31
32 var AutopilotWidget = {
33         
34         new: func(page,canvasGroup,name){
35                 var m = {parents:[AutopilotWidget,IfdWidget.new(page,canvasGroup,name)]};
36                 m._class = "AutopilotWidget";
37                 m._can          = {
38                         Autopilot       : m._group.getElementById("Autopilot"),
39                         Off             : m._group.getElementById("AP_Off").setVisible(0),
40                         State           : m._group.getElementById("AP_State"),
41                         ModeHDG         : m._group.getElementById("AP_HDG").setVisible(0),
42                         ModeNAV         : m._group.getElementById("AP_NAV").setVisible(0),
43                         ModeAPR         : m._group.getElementById("AP_APR").setVisible(0),
44                         ModeGPSS        : m._group.getElementById("AP_GPSS").setVisible(0),
45                         ModeCWS         : m._group.getElementById("AP_CWS").setVisible(0),
46                         ModeCAP         : m._group.getElementById("AP_CAP").setVisible(0),
47                         ModeSOFT        : m._group.getElementById("AP_SOFT").setVisible(0),
48                         ModeTRIM        : m._group.getElementById("AP_TRIM").setVisible(0),
49                         ModeALT         : m._group.getElementById("AP_ALT").setVisible(0),
50                         ModeVS          : m._group.getElementById("AP_VS").setVisible(0),
51                         ModeGS          : m._group.getElementById("AP_GS").setVisible(0),
52                         ModeDSBL        : m._group.getElementById("AP_DSBL").setVisible(0),
53                         ModeFD          : m._group.getElementById("AP_FD").setVisible(0),
54                         ModeREV         : m._group.getElementById("AP_REV").setVisible(0),
55                         
56                 };
57                 me._state       = 0;
58                 me._ready       = 0;
59                 me._fail        = 0;
60                 
61                 me._modeALT     = 0;
62                 me._modeHDG     = 0;
63                 me._modeVS      = 0;
64                 return m;
65         },
66         setListeners : func(instance) {
67                 append(me._listeners, setlistener("/extra500/instrumentation/Autopilot/state",func(n){me._onStateChange(n)},1,0));
68                 append(me._listeners, setlistener("/autopilot/mode/rdy",func(n){me._onReady(n)},1,0));
69                 append(me._listeners, setlistener("/autopilot/mode/fail",func(n){me._onFail(n)},1,0));
70                 append(me._listeners, setlistener("/autopilot/mode/heading",func(n){me._onHDG(n)},1,0));
71                 append(me._listeners, setlistener("/autopilot/mode/nav",func(n){me._onNAV(n)},1,0));
72                 append(me._listeners, setlistener("/autopilot/mode/apr",func(n){me._onAPR(n)},1,0));
73                 append(me._listeners, setlistener("/autopilot/mode/rev",func(n){me._onREV(n)},1,0));
74                 append(me._listeners, setlistener("/autopilot/mode/gpss",func(n){me._onGPSS(n)},1,0));
75                 append(me._listeners, setlistener("/autopilot/mode/cws",func(n){me._onCWS(n)},1,0));
76                 append(me._listeners, setlistener("/autopilot/mode/cws-armed",func(n){me._onCWSarmed(n)},1,0));
77                 append(me._listeners, setlistener("/autopilot/mode/cap",func(n){me._onCAP(n)},1,0));
78                 append(me._listeners, setlistener("/autopilot/mode/soft",func(n){me._onSOFT(n)},1,0));
79                 append(me._listeners, setlistener("/autopilot/mode/trim",func(n){me._onTRIM(n)},1,0));
80                 append(me._listeners, setlistener("/autopilot/mode/alt",func(n){me._onALT(n)},1,0));
81                 append(me._listeners, setlistener("/autopilot/mode/vs",func(n){me._onVS(n)},1,0));
82                 append(me._listeners, setlistener("/autopilot/mode/gs",func(n){me._onGS(n)},1,0));
83                 append(me._listeners, setlistener("/autopilot/mode/dsbl",func(n){me._onDSBL(n)},1,0));
84                 append(me._listeners, setlistener("/autopilot/settings/ap",func(n){me._onAP(n)},1,0));
85                 append(me._listeners, setlistener("/autopilot/settings/fd",func(n){me._onFP(n)},1,0));
86                 
87         },
88         _onStateChange: func(n){
89                 me._state       = n.getValue();
90                 me._can.Autopilot.setVisible(me._state);
91                 me._can.Off.setVisible(!me._state);
92         },
93         _checkState : func(){
94                 if( me._fail == 1 ){
95                         me._can.State.setText("AP FAIL");
96                         me._can.State.setColor(COLOR["Yellow"]);
97                         me._can.State.setVisible(1);
98                         me._can.ModeFD.setVisible(0);
99                         me._Page._widget.Attitude._can.FDBug.setVisible(0);
100                 }else{
101                         if( me._ready == 1 ){
102                                 me._can.State.setText("AP RDY");
103                                 me._can.State.setColor(COLOR["Green"]);
104                                 me._can.State.setVisible(1);
105                                 me._can.ModeFD.setVisible(0);
106                                 me._Page._widget.Attitude._can.FDBug.setVisible(0);
107                         }else{
108                                 me._can.State.setVisible(0);
109                                 me._can.ModeFD.setVisible(1);
110                         }
111                 }
112         },
113         _onReady : func(n){
114                 me._ready       = n.getValue();
115                 me._checkState();
116         },
117         _onFail : func(n){
118                 me._fail        = n.getValue();
119                 me._checkState();
120         },
121         _onHDG : func(n){
122                 me._modeHDG = n.getValue();
123                 me._can.ModeHDG.setVisible(me._modeHDG);
124         },
125         _onNAV : func(n){
126                 me._can.ModeNAV.setVisible(n.getValue());
127         },
128         _onAPR : func(n){
129                 me._can.ModeAPR.setVisible(n.getValue());
130         },
131         _onREV : func(n){
132                 me._can.ModeREV.setVisible(n.getValue());
133         },
134         _onGPSS : func(n){
135                 me._can.ModeGPSS.setVisible(n.getValue());
136         },
137         _onCWS : func(n){
138                 me._can.ModeCWS.setVisible(n.getValue());
139         },
140         _onCWSarmed : func(n){
141                 var cwsarmed = n.getValue();
142                 var cws = getprop("/autopilot/mode/cws");
143                 if (cwsarmed == 1) {
144                         me._Page._widget.Attitude._can.FDBug.setVisible(0);
145                         me._can.ModeFD.setVisible(0);
146                 }
147                 if ( (cws == 1) and (cwsarmed == 0) ) {
148                         me._can.ModeFD.setVisible(1);
149                         me._Page._widget.Attitude._can.FDBug.setVisible(1);
150                 }
151         },
152         _onCAP : func(n){
153                 me._can.ModeCAP.setVisible(n.getValue());
154         },
155         _onSOFT : func(n){
156                 me._can.ModeSOFT.setVisible(n.getValue());
157         },
158         _onTRIM : func(n){
159                 me._can.ModeTRIM.setVisible(n.getValue());
160         },
161         _onALT : func(n){
162                 me._modeALT = n.getValue();
163                 me._can.ModeALT.setVisible(me._modeALT);
164                 if(me._modeALT == 1){
165                         me._Page._widget.Altitude._can.Bug.set("fill",COLOR["Magenta"]);
166                         me._Page._widget.Attitude._can.FDBug.setVisible(1);
167                 }else{
168                         me._Page._widget.Altitude._can.Bug.set("fill","none");
169                 }
170         },
171         _onVS : func(n){
172                 me._modeVS = n.getValue();
173                 me._can.ModeVS.setVisible(me._modeVS);
174                 if(me._modeVS == 1){
175                         me._Page._widget.VerticalSpeed._can.Bug.set("fill",COLOR["Magenta"]);
176                         if ( getprop("/autopilot/mode/cws-armed") == 0) {
177                                 me._Page._widget.Attitude._can.FDBug.setVisible(1);
178                         }       
179                 }else{
180                         me._Page._widget.VerticalSpeed._can.Bug.set("fill","none");
181                 }
182         },
183         _onGS : func(n){
184                 if(n.getValue() == 1){
185                         me._can.ModeGS.setVisible(1);
186                         me._Page._widget.Attitude._can.FDBug.setVisible(1);
187                 } else {
188                         me._can.ModeGS.setVisible(0);
189                 }
190         },
191         _onDSBL : func(n){
192                 me._can.ModeDSBL.setVisible(n.getValue());
193         },
194         _onAP : func(n){
195                 if(n.getValue()){
196                         me._can.ModeFD.setText("AP");
197                         me._Page._widget.Attitude._can.FDBugColor.set("fill",COLOR["Magenta"]);
198                 }
199         },
200         _onFP : func(n){
201                 if(n.getValue()){
202                         me._can.ModeFD.setText("FD");
203                         me._Page._widget.Attitude._can.FDBugColor.set("fill",COLOR["Green"]);
204                 }
205         },
206         init : func(instance=me){
207                 #print("AutopilotWidget.init() ... ");
208 #               me.setListeners(instance);
209         },
210         deinit : func(){
211                 #print("AutopilotWidget.deinit() ... ");
212                 me.removeListeners();   
213         },
214         _onVisibiltyChange : func(){
215                 if(me._visibility == 1){
216                         me.setListeners(me);
217                 }else{
218                         me.removeListeners();
219                 }
220         }
221 };
222
223 var VerticalSpeedWidget = {
224         new: func(page,canvasGroup,name){
225                 var m = {parents:[VerticalSpeedWidget,IfdWidget.new(page,canvasGroup,name)]};
226                 m._class        = "VerticalSpeedWidget";
227                 m._ptree        = {
228                         vs      : props.globals.initNode("/instrumentation/ivsi-IFD-"~m._ifd.name~"/indicated-speed-fpm",0.0,"DOUBLE"),
229                 };
230                 m._can          = {
231                         Needle          : m._group.getElementById("VS_Needle").updateCenter(),
232                         Bug             : m._group.getElementById("VS_Bug").updateCenter(),
233                         BugFMS          : m._group.getElementById("VS_Bug_FMS").updateCenter(),
234                         BugValue        : m._group.getElementById("VS_Indicated"),
235                         
236                 };
237                 m._ap           = 0;
238                 m._bug          = 0;
239                 m._vs           = 0;
240                 m._vsr          = 0;
241                 return m;
242         },
243         setListeners : func(instance) {
244                 append(me._listeners, setlistener("/autopilot/mode/vs",func(n){me._onApChange(n)},1,0));        
245                 append(me._listeners, setlistener("/autopilot/settings/vertical-speed-fpm",func(n){me._onBugChange(n)},1,0));   
246                 append(me._listeners, setlistener(fms._node.vsrRate,func(n){me._onVsrChange(n)},1,0));
247         },
248         _onApChange : func(n){
249                 me._ap = n.getValue();
250                 if(me._ap == 1){
251                         me._can.Bug.set("fill",COLOR["Magenta"]);
252                 }else{
253                         me._can.Bug.set("fill","none");
254                 }
255         },
256         _onBugChange : func(n){
257                 me._bug = n.getValue();
258                 me._can.BugValue.setText(sprintf("%4i",global.roundInt(me._bug)));
259                 me._can.Bug.setRotation(me._rotateScale(me._bug));
260                 
261         },
262         _onVsrChange : func(n){
263                 if(fms._constraint.VSR.rate != 0){
264                         me._can.BugFMS.setRotation(me._rotateScale(fms._constraint.VSR.rate));
265                 }
266                 me._can.BugFMS.setVisible(fms._constraint.VSR.visible);
267         },
268         _onFplReadyChange : func(n){
269                 if(fms._flightPlan.isReady){
270                         
271                 }else{
272                         me._can.BugFMS.setVisible(0);
273                 }
274         },
275         _rotateScale : func(vs){
276                 if (vs >= -1000 ){
277                         if (vs <= 1000){
278                                 return ((vs/100*1.50) * global.CONST.DEG2RAD);
279                         }else{
280                                 return ( ( 15 + ((vs-1000)/100*0.75) ) * global.CONST.DEG2RAD);
281                         }
282                 }else{
283                         return ( ( -15 + ((vs+1000)/100*0.75) ) * global.CONST.DEG2RAD);
284                 }
285         },
286         init : func(instance=me){
287 #               me.setListeners(instance);
288         },
289         deinit : func(){
290                 me.removeListeners();   
291         },
292         _onVisibiltyChange : func(){
293                 if(me._visibility == 1){
294                         me.setListeners(me);
295                 }else{
296                         me.removeListeners();
297                 }
298         },
299         update20Hz : func(now,dt){
300                 me._vs  = me._ptree.vs.getValue();
301                 me._can.Needle.setRotation(me._rotateScale(me._vs));
302         },
303         
304 };
305
306 var AirspeedSpeedWidget = {
307         new: func(page,canvasGroup,name){
308                 var m = {parents:[AirspeedSpeedWidget,IfdWidget.new(page,canvasGroup,name)]};
309                 m._class        = "AirspeedSpeedWidget";
310                 m._ptree        = {
311                         ias     : props.globals.initNode("/instrumentation/airspeed-IFD-"~m._ifd.name~"/indicated-airspeed-kt",0.0,"DOUBLE"),
312                         iasRate : props.globals.initNode("/instrumentation/airspeed-IFD-"~m._ifd.name~"/airspeed-change-ktps",0.0,"DOUBLE"),
313                         tas     : props.globals.initNode("/instrumentation/airspeed-IFD-"~m._ifd.name~"/true-speed-kt",0.0,"DOUBLE"),
314                 };
315                 m._can          = {
316                         IAS_Ladder      : m._group.getElementById("IAS_Ladder").set("clip","rect(84px, 639px, 688px, 320px)"),
317                         IAS_001         : m._group.getElementById("IAS_001").set("clip","rect(327px, 639px, 506px, 320px)"),
318                         IAS_010         : m._group.getElementById("IAS_010").set("clip","rect(385px, 639px, 449px, 320px)"),
319                         IAS_100         : m._group.getElementById("IAS_100").set("clip","rect(385px, 639px, 449px, 320px)"),
320                         Plade           : m._group.getElementById("IAS_BlackPlade"),
321                         Zero            : m._group.getElementById("IAS_Zero").setVisible(1),
322                         Rate            : m._group.getElementById("IAS_Rate").set("clip","rect(84px, 639px, 688px, 320px)"),
323                         TAS             : m._group.getElementById("IAS_TAS"),
324                 };
325                 m._ias          = 0;
326                 m._rate         = 0;
327                 m._tas          = 0;
328                 m._limitVne     = 207;
329                 m._limitVso     = 58;
330                 m._limitZero    = 20;
331                 m._LADER_PX     = 63.463;
332                 m._RATE_OFFSET  = m._can.Rate.get("coord[3]");
333                 
334                 m._speed        = 0;
335                 m._speedAdd     = 0;
336                 
337                 return m;
338         },
339         setListeners : func(instance) {
340                 
341         },
342         init : func(instance=me){
343 #               me.setListeners(instance);
344         },
345         deinit : func(){
346                 me.removeListeners();
347         },
348         _onVisibiltyChange : func(){
349                 if(me._visibility == 1){
350                         me.setListeners(me);
351                 }else{
352                         me.removeListeners();
353                 }
354         },
355         
356         update20Hz : func(now,dt){
357                 me._ias         = me._ptree.ias.getValue();
358                 me._rate        = me._ptree.iasRate.getValue();;
359                 me._tas         = me._ptree.tas.getValue();;
360                 
361                 
362                 me._can.IAS_Ladder.setTranslation(0,(me._ias-20)*8.4978);
363                 if ( me._ias < me._limitZero ){
364                         me._can.IAS_100.setVisible(0);
365                         me._can.IAS_010.setVisible(0);
366                         me._can.IAS_001.setVisible(0);
367                         me._can.Plade.setVisible(0);
368                         me._can.Rate.setVisible(0);
369                         me._can.Zero.setVisible(1);
370                         me._can.TAS.setText("---");
371                 }else{
372                         me._can.Zero.setVisible(0);
373                         me._can.Rate.setVisible(1);
374                         me._can.Plade.setVisible(1);
375                         me._can.IAS_001.setVisible(1);
376                         
377                         me._can.Rate.set("coord[1]",me._RATE_OFFSET+(-me._rate*58));
378                 
379                         me._can.TAS.setText(sprintf("%3i",me._tas));
380                         
381                         me._speed = math.mod(me._ias,10);
382                         
383                         me._can.IAS_001.setTranslation(0,(me._speed * me._LADER_PX));
384                         
385                         if (me._ias > 10){
386                                 if (me._speed >= 9){
387                                         me._speedAdd = me._speed - 9;
388                                 }else{
389                                         me._speedAdd = 0;
390                                 }
391                                 me._speed = math.floor(math.mod(me._ias,100)/10);
392                                 me._can.IAS_010.setTranslation(0,((me._speed+me._speedAdd) * me._LADER_PX));
393                                 me._can.IAS_010.setVisible(1);
394                                 
395                                 if (me._ias > 99){
396                                         
397                                         if (me._speed < 9){
398                                                 me._speedAdd = 0;
399                                         }
400                                         
401                                         me._speed = math.floor(math.mod(me._ias,1000)/100);
402                                         me._can.IAS_100.setTranslation(0,((me._speed+me._speedAdd) * me._LADER_PX));
403                                         me._can.IAS_100.setVisible(1);
404                                 
405                                         me._can.IAS_100.setVisible(1);
406                                 }else{
407                                         me._can.IAS_100.setVisible(0);
408                                 }
409                                 
410                         }else{
411                                 me._can.IAS_100.setVisible(0);
412                                 me._can.IAS_010.setVisible(0);
413                         }
414                         
415                         if( me._ias >= me._limitVne){
416                                 me._can.IAS_100.set("fill",COLOR["Red"]);
417                                 me._can.IAS_010.set("fill",COLOR["Red"]);
418                                 me._can.IAS_001.set("fill",COLOR["Red"]);
419                         }elsif (me._ias < me._limitVso){
420                                 me._can.IAS_100.set("fill",COLOR["Red"]);
421                                 me._can.IAS_010.set("fill",COLOR["Red"]);
422                                 me._can.IAS_001.set("fill",COLOR["Red"]);
423                         }else{
424                                 me._can.IAS_100.set("fill",COLOR["White"]);
425                                 me._can.IAS_010.set("fill",COLOR["White"]);
426                                 me._can.IAS_001.set("fill",COLOR["White"]);
427                         }
428                         
429                         if( me._ias >= me._limitVne + 3.0){
430                                 me._ifd._nOverSpeedWarning.setValue(1);
431                         }else{
432                                 me._ifd._nOverSpeedWarning.setValue(0);
433                         }
434                         
435                 }
436         },
437         
438 };
439
440 var AltitudeWidget = {
441         new: func(page,canvasGroup,name){
442                 var m = {parents:[AltitudeWidget,IfdWidget.new(page,canvasGroup,name)]};
443                 m._class        = "AltitudeWidget";
444                 m._ptree        = {
445                         alt     : props.globals.initNode("/instrumentation/altimeter-IFD-"~m._ifd.name~"/indicated-altitude-ft",0.0,"DOUBLE"),
446                 };
447                 m._can          = {
448                         Ladder          : m._group.getElementById("ALT_Ladder").set("clip","rect(145px, 1718px, 688px, 1410px)"),
449                         U300T           : m._group.getElementById("ALT_LAD_U300T"),
450                         U300H           : m._group.getElementById("ALT_LAD_U300H"),
451                         U200T           : m._group.getElementById("ALT_LAD_U200T"),
452                         U200H           : m._group.getElementById("ALT_LAD_U200H"),
453                         U100T           : m._group.getElementById("ALT_LAD_U100T"),
454                         U100H           : m._group.getElementById("ALT_LAD_U100H"),
455                         C000T           : m._group.getElementById("ALT_LAD_C000T"),
456                         C000H           : m._group.getElementById("ALT_LAD_C000H"),
457                         D100T           : m._group.getElementById("ALT_LAD_D100T"),
458                         D100H           : m._group.getElementById("ALT_LAD_D100H"),
459                         D200T           : m._group.getElementById("ALT_LAD_D200T"),
460                         D200H           : m._group.getElementById("ALT_LAD_D200H"),
461                         Plade           : m._group.getElementById("AltBlackPlade"),
462                         BarMinus        : m._group.getElementById("AltBarMinus").setVisible(0),
463                         BarPlus10       : m._group.getElementById("AltBarPlus10").set("clip","rect(326px, 1718px, 507px, 1478px)"),
464                         BarMinus10      : m._group.getElementById("AltBarMinus10").set("clip","rect(326px, 1718px, 507px, 1478px)").setVisible(0),
465                         Bar100          : m._group.getElementById("AltBar100").set("clip","rect(385px, 1718px, 449px, 1478px)"),
466                         Bar1000         : m._group.getElementById("AltBar1000").set("clip","rect(385px, 1718px, 449px, 1478px)"),
467                         Bar10000        : m._group.getElementById("AltBar10000").set("clip","rect(385px, 1718px, 449px, 1478px)"),
468                         Bug             : m._group.getElementById("ALT_Bug").set("clip","rect(145px, 1718px, 688px, 1410px)"),
469                         BugValue        : m._group.getElementById("ALT_Selected"),
470                         HPA             : m._group.getElementById("hPa"),
471                 };
472                 m._alt          = 0;
473                 m._absAlt       = 0;
474                 m._bugDiff      = 0;
475                 m._hpa          = 0;
476                 m._tmpAlt       = 0;
477                 m._tmpAltAdd    = 0;
478                 m._SCALE_BAR_PX_100     = 63.426;
479                 m._SCALE_BAR_PX_10      = (m._SCALE_BAR_PX_100/20);
480                 m._SCALE_LAD_PX         = 1.14901;# 114.901 px
481                 return m;
482         },
483         setListeners : func(instance) {
484                 append(me._listeners, setlistener("/autopilot/alt-channel/alt-bug-ft",func(n){me._onBugChange1(n)},1,0));
485                 append(me._listeners, setlistener("/autopilot/settings/tgt-altitude-ft",func(n){me._onBugChange2(n)},1,0));     
486                 append(me._listeners, setlistener("/instrumentation/altimeter-IFD-"~me._ifd.name~"/setting-hpa",func(n){me._onHpaChange(n)},1,0));      
487         
488         },
489         init : func(instance=me){
490 #               me.setListeners(instance);
491         },
492         deinit : func(){
493                 me.removeListeners();   
494         },
495         _onVisibiltyChange : func(){
496                 if(me._visibility == 1){
497                         me.setListeners(me);
498                 }else{
499                         me.removeListeners();
500                 }
501         },
502         
503         _onHpaChange : func(n){
504                 me._hpa         = n.getValue();
505                 me._can.HPA.setText(sprintf("%4i",me._hpa));
506         },
507         _onBugChange1 : func(n){
508                 me._bug1 = n.getValue();
509                                 
510                 me._bugDiff = (me._alt - me._bug1) * me._SCALE_LAD_PX;
511                 me._bugDiff = global.clamp(me._bugDiff,-272,254);
512                 me._can.Bug.setTranslation(0,me._bugDiff);
513         },
514         _onBugChange2 : func(n){
515                 me._bug2 = n.getValue();
516                                 
517                 me._can.BugValue.setText(sprintf("%4i",global.roundInt( me._bug2 )));
518         },
519         update20Hz : func(now,dt){
520                 me._alt         = me._ptree.alt.getValue();
521                 
522                 me._bugDiff = (me._alt - me._bug1) * me._SCALE_LAD_PX;
523                 me._bugDiff = global.clamp(me._bugDiff,-272,254);
524                 me._can.Bug.setTranslation(0,me._bugDiff);
525                 
526                 me._tmpAlt      = me._alt + 300;
527                 if(me._tmpAlt>=0){
528                         me._can.U300T.setText(sprintf("%i",math.floor((me._tmpAlt/1000))));
529                         me._can.U300H.setText(sprintf("%03i",math.floor(math.mod(me._tmpAlt,1000) / 100) * 100));
530                 }else{
531                         me._can.U300T.setText(sprintf("-%i",math.floor(math.abs(me._tmpAlt-100)/1000) ));
532                         me._can.U300H.setText(sprintf("%03i",math.floor(math.mod(math.abs(me._tmpAlt-100),1000) / 100) * 100));
533                 
534                 }
535                 me._tmpAlt-=100;
536                 
537                 if(me._tmpAlt>=0){
538                         me._can.U200T.setText(sprintf("%i",math.floor((me._tmpAlt/1000))));
539                         me._can.U200H.setText(sprintf("%03i",math.floor(math.mod(me._tmpAlt,1000) / 100) * 100));
540                 }else{
541                         me._can.U200T.setText(sprintf("-%i",math.floor(math.abs(me._tmpAlt-100)/1000) ));
542                         me._can.U200H.setText(sprintf("%03i",math.floor(math.mod(math.abs(me._tmpAlt-100),1000) / 100) * 100));
543                         
544                 }
545                 me._tmpAlt-=100;
546                 
547                 if(me._tmpAlt>=0){
548                         me._can.U100T.setText(sprintf("%i",math.floor((me._tmpAlt/1000))));
549                         me._can.U100H.setText(sprintf("%03i",math.floor(math.mod(me._tmpAlt,1000) / 100) * 100));
550                 }else{
551                         me._can.U100T.setText(sprintf("-%i",math.floor(math.abs(me._tmpAlt-100)/1000) ));
552                         me._can.U100H.setText(sprintf("%03i",math.floor(math.mod(math.abs(me._tmpAlt-100),1000) / 100) * 100));
553                         
554                 }
555                 me._tmpAlt-=100;
556                 
557                 if(me._tmpAlt>=0){
558                         me._can.C000T.setText(sprintf("%i",math.floor((me._tmpAlt/1000))));
559                         me._can.C000H.setText(sprintf("%03i",math.floor(math.mod(me._tmpAlt,1000) / 100) * 100));
560                 }else{
561                         me._can.C000T.setText(sprintf("-%i",math.floor(math.abs(me._tmpAlt-100)/1000) ));
562                         me._can.C000H.setText(sprintf("%03i",math.floor(math.mod(math.abs(me._tmpAlt-100),1000) / 100) * 100));
563                         
564                 }
565                 me._tmpAlt-=100;
566                 
567                 if(me._tmpAlt>=0){
568                         me._can.D100T.setText(sprintf("%i",math.floor((me._tmpAlt/1000))));
569                         me._can.D100H.setText(sprintf("%03i",math.floor(math.mod(me._tmpAlt,1000) / 100) * 100));
570                 }else{
571                         me._can.D100T.setText(sprintf("-%i",math.floor(math.abs(me._tmpAlt-100)/1000) ));
572                         me._can.D100H.setText(sprintf("%03i",math.floor(math.mod(math.abs(me._tmpAlt-100),1000) / 100) * 100));
573                         
574                 }
575                 me._tmpAlt-=100;
576                 
577                 if(me._tmpAlt>=0){
578                         me._can.D200T.setText(sprintf("%i",math.floor((me._tmpAlt/1000))));
579                         me._can.D200H.setText(sprintf("%03i",math.floor(math.mod(me._tmpAlt,1000) / 100) * 100));
580                 }else{
581                         me._can.D200T.setText(sprintf("-%i",math.floor(math.abs(me._tmpAlt-100)/1000) ));
582                         me._can.D200H.setText(sprintf("%03i",math.floor(math.mod(math.abs(me._tmpAlt-100),1000) / 100) * 100));
583                         
584                 }
585                 
586                 me._can.Ladder.setTranslation(0,math.mod(me._alt,100) * me._SCALE_LAD_PX);
587                 
588                 
589                 
590                 me._tmpAlt = math.mod(me._alt,100);
591                 if (me._alt >= 0){
592                         me._can.BarMinus10.setVisible(0);
593                         me._can.BarPlus10.setVisible(1);
594                         me._can.BarPlus10.setTranslation(0, me._tmpAlt * me._SCALE_BAR_PX_10);
595                 }else{
596                         me._can.BarPlus10.setVisible(0);
597                         me._can.BarMinus10.setVisible(1);
598                         me._can.BarMinus10.setTranslation(0, me._tmpAlt * me._SCALE_BAR_PX_10);
599                 }
600                 me._absAlt = math.abs(me._alt);
601                 
602                 me._can.BarMinus.setVisible( (me._alt<0) );
603                 
604                 if (me._absAlt>=100){
605                         if (me._tmpAlt > 80) {
606                                 me._tmpAltAdd = me._tmpAlt - 80;
607                         }else{
608                                 me._tmpAltAdd = 0;
609                         }
610                 
611                         me._tmpAlt = math.floor(math.mod(me._absAlt,1000)/100);
612                         me._can.Bar100.setTranslation(0,(me._tmpAlt * me._SCALE_BAR_PX_100) + ( me._tmpAltAdd * me._SCALE_BAR_PX_10 ));
613                         me._can.Bar100.setVisible(1);
614                         if(me._absAlt>=980){
615                                 if (me._tmpAlt == 9) {
616 #                                       me._tmpAltAdd = me._tmpAlt - 9;
617                                 }else{
618                                         me._tmpAltAdd = 0;
619                                 }
620                                 #print("update20Hz() ... "~me._tmpAlt~" + "~me._tmpAltAdd);
621                                 
622                                 me._tmpAlt = math.floor(math.mod(me._absAlt,10000)/1000);
623                                 me._can.Bar1000.setTranslation(0,me._tmpAlt * me._SCALE_BAR_PX_100 + ( me._tmpAltAdd * me._SCALE_BAR_PX_10 ));
624                                 me._can.Bar1000.setVisible(1);
625                                 if (me._absAlt>=9980){
626                                         if (me._tmpAlt == 9) {
627                                                 #me._tmpAltAdd = me._tmpAlt - 9;
628                                         }else{
629                                                 me._tmpAltAdd = 0;
630                                         }
631                                         
632                                         me._tmpAlt = math.floor(math.mod(me._absAlt,100000)/10000);
633                                         me._can.Bar10000.setTranslation(0,me._tmpAlt * me._SCALE_BAR_PX_100 + ( me._tmpAltAdd * me._SCALE_BAR_PX_10 ));
634                                         me._can.Bar10000.setVisible(1);
635                                 }else{
636                                         me._can.Bar10000.setVisible(0);
637                                 }
638                         }else{
639                                 me._can.Bar10000.setVisible(0);
640                                 me._can.Bar1000.setVisible(0);
641                         }
642                 }else{
643                         me._can.Bar10000.setVisible(0);
644                         me._can.Bar1000.setVisible(0);
645                         me._can.Bar100.setVisible(0);
646                 }
647         },
648         
649 };
650
651 var AttitudeIndicatorWidget = {
652         new: func(page,canvasGroup,name){
653                 var m = {parents:[AttitudeIndicatorWidget,IfdWidget.new(page,canvasGroup,name)]};
654                 m._class        = "AttitudeIndicatorWidget";
655                 m._ptree        = {
656                         pitch   : props.globals.initNode("/orientation/pitch-deg",0.0,"DOUBLE"),
657                         roll    : props.globals.initNode("/orientation/roll-deg",0.0,"DOUBLE"),
658                         SlipSkid: props.globals.initNode("/instrumentation/slip-skid-ball/indicated-slip-skid",0.0,"DOUBLE"),
659                         fdroll: props.globals.initNode("/autopilot/flight-director/fld-bank-deg",0.0,"DOUBLE"),
660                         fdpitch: props.globals.initNode("/autopilot/flight-director/fld-pitch-deg",0.0,"DOUBLE"),
661                 };
662                 m._can          = {
663                         PitchLadder     : m._group.getElementById("PitchLadder").updateCenter().set("clip","rect(144px, 1293px, 671px, 750px)"),
664                         BankAngle       : m._group.getElementById("BankAngleIndicator").updateCenter(),
665                         SlipSkid        : m._group.getElementById("SlipSkidIndicator").updateCenter(),
666                         Horizon         : m._group.getElementById("Horizon"),
667                         FDBug           : m._group.getElementById("FD_Bug").setVisible(0).updateCenter(),
668                         FDBugColor      : m._group.getElementById("path5241"),
669                         
670                 };
671                 
672                 m._pitch        = 0;
673                 m._roll         = 0;
674                 m._slipskid     = 0;
675                 m._fdroll = 0;
676                 m._fdpitch = 0;
677                 return m;
678         },
679         setListeners : func(instance) {
680         
681                 
682         },
683         init : func(instance=me){
684 #               me.setListeners(instance);
685         },
686         deinit : func(){
687                 me.removeListeners();
688         },
689         _onVisibiltyChange : func(){
690                 if(me._visibility == 1){
691                         me.setListeners(me);
692                 }else{
693                         me.removeListeners();
694                 }
695         },
696         
697         update20Hz : func(now,dt){
698                 
699                 me._pitch       = me._ptree.pitch.getValue();
700                 me._roll        = me._ptree.roll.getValue();
701                 me._slipskid    = me._ptree.SlipSkid.getValue();
702                 me._fdroll      = me._ptree.fdroll.getValue();
703                 me._fdpitch     = me._ptree.fdpitch.getValue();
704
705                 me._can.PitchLadder.setRotation(-me._roll * global.CONST.DEG2RAD);
706                 me._can.PitchLadder.setTranslation(0,me._pitch * 10);
707                 me._can.SlipSkid.setTranslation(-me._slipskid * 50,0);
708                 me._can.BankAngle.setRotation(-me._roll * global.CONST.DEG2RAD);
709                 
710                 me._can.Horizon.setTranslation(0,me._pitch * 10);
711                 me._can.Horizon.setRotation(-me._roll * global.CONST.DEG2RAD);
712
713                 me._can.FDBug.setTranslation(0,-me._fdpitch * 10);
714                 me._can.FDBug.setRotation(me._fdroll * global.CONST.DEG2RAD);
715                 
716         },
717         
718 };
719
720
721 var MarkerWidget = {
722         new: func(page,canvasGroup,name){
723                 var m = {parents:[MarkerWidget,IfdWidget.new(page,canvasGroup,name)]};
724                 m._class        = "MarkerWidget";
725                 m._ptree        = {
726                         markerInner     : props.globals.initNode("/instrumentation/marker-beacon/inner",0,"BOOL"),
727                         markerMiddle    : props.globals.initNode("/instrumentation/marker-beacon/middle",0,"BOOL"),
728                         markerOuter     : props.globals.initNode("/instrumentation/marker-beacon/outer",0,"BOOL"),
729                         
730                 };
731                 m._can          = {
732                         Marker          : m._group.getElementById("Marker").setVisible(0),
733                         MarkerBack      : m._group.getElementById("Marker_Back"),
734                         MarkerText      : m._group.getElementById("Marker_Text"),
735                 };
736                 
737                 m._active       = 0;
738                 m._seqence      = [];
739                 m._seqenceIndex = 0;
740                 m._seqenceSize = 0;
741                 m._Time = 0;
742                 m._slipskid     = 0;
743                 m._timer        = nil;
744                 
745                 m._inner        = 0;
746                 m._middle       = 0;
747                 m._outer        = 0;
748                 
749                 return m;
750         },
751         setListeners : func(instance) {
752                 #append(me._listeners, setlistener(me._ptree.markerInner,func(n){me._onMarkerInnerChange(n);},1,0));
753                 #append(me._listeners, setlistener(me._ptree.markerMiddle,func(n){me._onMarkerMiddleChange(n);},1,0));
754                 #append(me._listeners, setlistener(me._ptree.markerOuter,func(n){me._onMarkerOuterChange(n);},1,0));
755                 
756         },
757         init : func(instance=me){
758 #               me.setListeners(instance);
759         },
760         deinit : func(){
761                 me.removeListeners();   
762         },
763         _onVisibiltyChange : func(){
764                 if(me._visibility == 1){
765                         me.setListeners(me);
766                 }else{
767                         me.removeListeners();
768                 }
769         },
770         
771         _onMarkerInnerChange : func(n){
772                 me._inner = n.getValue();
773                 print("MarkerWidget._onMarkerInnerChange() ... IM " ~ me._inner);
774                 if (me._inner == 1){
775                         me._can.MarkerText.setText("IM");
776                         me._can.MarkerBack.set("fill",COLOR["White"]);
777                         me._can.Marker.setVisible(1);
778                 }else{
779                         me._can.Marker.setVisible(0);
780                 }
781         },
782         _onMarkerMiddleChange : func(n){
783                 me._middle = n.getValue();
784                 print("MarkerWidget._onMarkerMiddleChange() ... MM " ~ me._middle);
785                 if (me._middle == 1){
786                         me._can.MarkerText.setText("MM");
787                         me._can.MarkerBack.set("fill",COLOR["Yellow"]);
788                         me._can.Marker.setVisible(1);
789                 }else{
790                         me._can.Marker.setVisible(0);
791                 }
792         },
793         _onMarkerOuterChange : func(n){
794                 me._outer = n.getValue();
795                 print("MarkerWidget._onMarkerOuterChange() ... OM " ~ me._outer);
796                 if (me._outer == 1){
797                         me._can.MarkerText.setText("OM");
798                         me._can.MarkerBack.set("fill",COLOR["Blue"]);
799                         me._can.Marker.setVisible(1);
800                 }else{
801                         me._can.Marker.setVisible(0);
802                 }
803
804         },
805         update20Hz : func(now,dt){
806                 me._inner       = me._ptree.markerInner.getValue();
807                 me._middle      = me._ptree.markerMiddle.getValue();
808                 me._outer       = me._ptree.markerOuter.getValue();
809                 
810                 if (me._inner){
811                         me._can.MarkerText.setText("IM");
812                         me._can.MarkerBack.set("fill",COLOR["White"]);
813                         
814                 }
815                 if (me._middle){
816                         me._can.MarkerText.setText("MM");
817                         me._can.MarkerBack.set("fill",COLOR["Yellow"]);
818                         
819                 }
820                 if (me._outer){
821                         me._can.MarkerText.setText("OM");
822                         me._can.MarkerBack.set("fill",COLOR["Blue"]);
823                         
824                 }
825                 me._can.Marker.setVisible(me._inner or me._middle or me._outer);
826
827         }
828         
829 };
830
831 var NavSourceWidget = {
832         new: func(page,canvasGroup,name){
833                 var m = {parents:[NavSourceWidget,IfdWidget.new(page,canvasGroup,name)]};
834                 m._class        = "NavSourceWidget";
835                 m._SOURCE       = ["Nav1","Nav2","FMS"];
836                 m._NAME         = ["Nav 1","Nav 2","FMS"];
837                 m._PATH =       {
838                         FMS     : {
839                                 Pointer                 : "/autopilot/fms-channel/indicated-course-deg",
840                                 horizontalDeviation     : "/autopilot/fms-channel/indicated-course-error-norm",
841                                 verticalDeviation       : "/instrumentation/fms[0]/gs-needle-deflection-norm",
842                                 Frequency               : "/autopilot/route-manager/wp/id",
843                                 isInRange               : "/instrumentation/fms[0]/in-range",
844                                 isLOC                   : "/instrumentation/fms[0]/frequencies/is-localizer-frequency",
845                                 isGSinRange             : "/instrumentation/fms[0]/gs-in-range",
846                                 hasGS                   : "/instrumentation/fms[0]/has-gs",
847                                 fromFlag                : "/instrumentation/fms[0]/from-flag",
848                                 toFlag                  : "/instrumentation/fms[0]/to-flag",
849                                 distance                : "/autopilot/route-manager/wp/dist",
850                                 bearing                 : "/autopilot/route-manager/wp/bearing-deg",
851                                 targetCourse            : "/autopilot/fms-channel/indicated-course-deg",
852                                 
853                                 
854                         },
855                         Nav1    : {
856                                 Pointer                 : "/instrumentation/nav[0]/radials/selected-deg",
857                                 horizontalDeviation     : "/instrumentation/nav[0]/heading-needle-deflection-norm",
858                                 verticalDeviation       : "/instrumentation/nav[0]/gs-needle-deflection-norm",
859                                 Frequency               : "/instrumentation/nav[0]/frequencies/selected-mhz-fmt",
860                                 isInRange               : "/instrumentation/nav[0]/in-range",
861                                 isLOC                   : "/instrumentation/nav[0]/frequencies/is-localizer-frequency",
862                                 isGSinRange             : "/instrumentation/nav[0]/gs-in-range",
863                                 hasGS                   : "/instrumentation/nav[0]/has-gs",
864                                 fromFlag                : "/instrumentation/nav[0]/from-flag",
865                                 toFlag                  : "/instrumentation/nav[0]/to-flag",
866                                 distance                : "/autopilot/radionav-channel/nav-distance-nm",
867                                 bearing                 : "/instrumentation/nav[0]/radials/reciprocal-radial-deg",
868                                 targetCourse            : "/instrumentation/nav[0]/radials/target-radial-deg",
869                         },
870                         Nav2    : {
871                                 Pointer                 : "/instrumentation/nav[1]/radials/selected-deg",
872                                 horizontalDeviation     : "/instrumentation/nav[1]/heading-needle-deflection-norm",
873                                 verticalDeviation       : "/instrumentation/nav[1]/gs-needle-deflection-norm",
874                                 Frequency               : "/instrumentation/nav[1]/frequencies/selected-mhz-fmt",
875                                 isInRange               : "/instrumentation/nav[1]/in-range",
876                                 isLOC                   : "/instrumentation/nav[1]/frequencies/is-localizer-frequency",
877                                 isGSinRange             : "/instrumentation/nav[1]/gs-in-range",
878                                 hasGS                   : "/instrumentation/nav[1]/has-gs",
879                                 fromFlag                : "/instrumentation/nav[1]/from-flag",
880                                 toFlag                  : "/instrumentation/nav[1]/to-flag",
881                                 distance                : "/autopilot/radionav-channel/nav-distance-nm",
882                                 bearing                 : "/instrumentation/nav[1]/radials/reciprocal-radial-deg",
883                                 targetCourse            : "/instrumentation/nav[1]/radials/target-radial-deg",
884                         },
885                         
886                         
887                 };
888                 
889                 
890                 m._ptree        = {
891                         hDev            : nil,
892                         vDev            : nil,
893                         inRange         : nil,
894                         LOC             : nil,
895                         GSinRange       : nil,
896                         FromFlag        : nil,
897                         ToFlag          : nil,
898                         Pointer         : nil,
899                         Distance        : nil,
900                         Source          : props.globals.initNode("/instrumentation/nav-source",0,"INT"),
901                         FMSCourse       : props.globals.initNode("/instrumentation/fms[0]/selected-course-deg",0,"DOUBLE"),
902                         
903                 };
904                 
905                 m._can          = {
906                         Source          : m._group.getElementById("NAV_SourceName"),
907                         ID              : m._group.getElementById("NAV_ID"),
908                         Crs             : m._group.getElementById("NAV_CRS"),
909                         Distance        : m._group.getElementById("NAV_Distance"),
910                 };
911                 
912                 m._sourceListeners      = [];
913                 
914                 m._routeManagerActive   = 0;
915                 m._fmsServiceable       = 0;
916                 
917                 m._source               = 2;
918                 m._horizontalDeviation  = 0;
919                 m._verticalDeviation    = 0;
920                 m._isInRange            = 0;
921                 m._isLOC                = 0;
922                 m._isGSinRange          = 0;
923                 m._fromFlag             = 0;
924                 m._toFlag               = 0;
925                 m._Pointer              = 0;
926                 m._stationType          = "";
927                 m._distance             = 0;
928                 m._frequency            = "";
929                 
930                 m._btnObsMode   = 0;
931                 
932                 
933                 return m;
934         },
935         setListeners : func(instance) {
936                 
937                 append(me._listeners, setlistener(me._ptree.Source,func(n){me._onSourceChange(n);},1,0));
938                 append(me._listeners, setlistener(fms._node.btnObsMode,func(n){me._onObsModeChange(n);},1,0));
939                 append(me._listeners, setlistener("/autopilot/route-manager/active",func(n){me._onRouteActiveChange(n);},1,0));
940                 append(me._listeners, setlistener("/autopilot/fms-channel/serviceable",func(n){me._onFmsServiceChange(n);},1,0));
941                                 
942         },
943         removeListeners : func(){
944                 foreach(var l;me._listeners){
945                         removelistener(l);
946                 }
947                 me._listeners = [];
948                 foreach(var l;me._sourceListeners){
949                         removelistener(l);
950                 }
951                 me._sourceListeners = [];
952         },
953         init : func(instance=me){
954
955         },
956         deinit : func(){
957                 me.removeListeners();
958
959         },
960         _onVisibiltyChange : func(){
961                 if(me._visibility == 1){
962                         me.setListeners(me);
963                         
964                         me._ifd.ui.bindKey("L1",{
965                                 "<"     : func(){me._scroll(-1);},
966                                 ">"     : func(){me._scroll(1);},
967                         });
968                         
969                         me._checkKnob();
970                         
971                         me._scroll(0);
972                 }else{
973                         me.removeListeners();
974                         
975                         me._ifd.ui.bindKey("L1");
976                         me._ifd.ui.bindKnob("LK");
977                 }
978         },
979         _checkKnob : func(){
980                         if(me._source == 2){
981                                 if(me._btnObsMode == 1){
982                                         me._ifd.ui.bindKnob("LK",{
983                                                 "<<"    : func(){me._adjustRadial(-10);},
984                                                 "<"     : func(){me._adjustRadial(-1);},
985                                                 "push"  : func(){me._setObsMode(0);},
986                                                 ">"     : func(){me._adjustRadial(1);},
987                                                 ">>"    : func(){me._adjustRadial(10);},
988                                         },{
989                                                 "scroll"        : "Course",
990                                                 "push"          : "Cancel",
991                                         });
992                                 }else{
993                                         me._ifd.ui.bindKnob("LK",{
994                                                 "<<"    : func(){me._setObsMode(1);me._adjustRadial(-10);},
995                                                 "<"     : func(){me._setObsMode(1);me._adjustRadial(-1);},
996                                                 "push"  : nil,
997                                                 ">"     : func(){me._setObsMode(1);me._adjustRadial(1);},
998                                                 ">>"    : func(){me._setObsMode(1);me._adjustRadial(10);},
999                                         },{
1000                                                 "scroll"        : "Course",
1001                                                 "push"          : "",
1002                                         });
1003                                 }
1004                         }else{
1005                                 
1006                                 if( me._isInRange ){
1007                                         me._ifd.ui.bindKnob("LK",{
1008                                                 "<<"    : func(){me._adjustRadial(-10);},
1009                                                 "<"     : func(){me._adjustRadial(-1);},
1010                                                 "push"  : func(){me._onSyncCourse();},
1011                                                 ">"     : func(){me._adjustRadial(1);},
1012                                                 ">>"    : func(){me._adjustRadial(10);},
1013                                         },{
1014                                                 "scroll"        : "Course",
1015                                                 "push"          : "Sync",
1016                                         });
1017                                 
1018                                 }else{
1019                                         me._ifd.ui.bindKnob("LK",{
1020                                                 "<<"    : func(){me._adjustRadial(-10);},
1021                                                 "<"     : func(){me._adjustRadial(-1);},
1022                                                 "push"  : nil,
1023                                                 ">"     : func(){me._adjustRadial(1);},
1024                                                 ">>"    : func(){me._adjustRadial(10);},
1025                                         },{
1026                                                 "scroll"        : "Course",
1027                                                 "push"          : "",
1028                                         });
1029                                 }
1030                         }
1031         },
1032         _onObsModeChange :func(n){
1033                 me._btnObsMode = n.getValue();
1034                 me.checkSource();
1035         },
1036         _onSourceChange : func(n){
1037                 me._source = n.getValue();
1038                 me._setObsMode(me._btnObsMode and (me._source == 2));
1039                 me.checkSource();
1040         },
1041         checkSource : func(){
1042                 
1043                 foreach(var l;me._sourceListeners){
1044                         removelistener(l);
1045                 }
1046                 me._sourceListeners = [];
1047                 
1048                 me._ptree.hDev          = props.globals.initNode(me._PATH[me._SOURCE[me._source]].horizontalDeviation,0,"DOUBLE");
1049                 me._ptree.vDev          = props.globals.initNode(me._PATH[me._SOURCE[me._source]].verticalDeviation,0,"DOUBLE");
1050                 me._ptree.Distance      = props.globals.initNode(me._PATH[me._SOURCE[me._source]].distance,0,"DOUBLE");
1051                 me._ptree.Pointer       = props.globals.initNode(me._PATH[me._SOURCE[me._source]].Pointer,0,"DOUBLE");
1052
1053                         
1054                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].isInRange,func(n){me._onInRangeChange(n);},1,0));
1055                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].isLOC,func(n){me._onIsLocChange(n);},1,0));
1056                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].isGSinRange,func(n){me._onGsInRangeChange(n);},1,0));
1057                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].fromFlag,func(n){me._onFromFlagChange(n);},1,0));
1058                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].toFlag,func(n){me._onToFlagChange(n);},1,0));
1059                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].hasGS,func(n){me._onHasGSChange(n);},1,0));
1060                 append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].Frequency,func(n){me._onFrequencyChange(n);},1,0));
1061                                 
1062                 if(me._btnObsMode == 1){
1063                         if(getprop("/instrumentation/gps[0]/serviceable")){
1064                                 append(me._sourceListeners, setlistener("/instrumentation/gps[0]/desired-course-deg",func(n){me._onCourseChange(n);},1,0));
1065                         }elsif(getprop("/instrumentation/gps[1]/serviceable")){
1066                                 append(me._sourceListeners, setlistener("/instrumentation/gps[1]/desired-course-deg",func(n){me._onCourseChange(n);},1,0));
1067                         }else{
1068                                 
1069                         }
1070                 }else{
1071                         append(me._sourceListeners, setlistener(me._PATH[me._SOURCE[me._source]].Pointer,func(n){me._onCourseChange(n);},1,0));
1072                 }
1073                 me._Page._widgetTab.NavSelect.registerKeyCDI();
1074                 
1075                 me._checkStationType();
1076                 me._checkKnob();
1077                 
1078         },
1079         _scroll : func(amount){
1080                 me._source += amount;
1081                 if (me._source > 2){ me._source = 0; }
1082                 if (me._source < 0){ me._source = 2; }
1083                 if (me._source != 2){ setprop("/autopilot/settings/fly-vector",0); }            # to switch off vectors when fms is no longer the nav source
1084                 me._ptree.Source.setValue(me._source);  
1085         },
1086         _adjustRadial : func(amount){
1087                 #me._Pointer += amount;
1088                 var course = tool.adjustStep(me._Pointer,amount,10);
1089                 course = tool.course(course);
1090                 setprop("/instrumentation/nav[0]/radials/selected-deg",course);
1091                 setprop("/instrumentation/nav[1]/radials/selected-deg",course);
1092                 if(me._btnObsMode == 1){
1093                         
1094                         setprop("/instrumentation/gps[0]/selected-course-deg",course);
1095                         setprop("/instrumentation/gps[1]/selected-course-deg",course);
1096                 }
1097         },
1098         _onSyncCourse : func(){
1099                 var course = 0;
1100                 if(me._isLOC == 1){
1101                         # localizer target course
1102                         var magVar = getprop("environment/magnetic-variation-deg");
1103                         course = getprop(me._PATH[me._SOURCE[me._source]].targetCourse) - magVar;
1104                 }else{
1105                         # direct
1106                         course = getprop(me._PATH[me._SOURCE[me._source]].bearing);
1107                 }
1108                 setprop("/instrumentation/nav[0]/radials/selected-deg",course);
1109                 setprop("/instrumentation/nav[1]/radials/selected-deg",course);
1110         },
1111         _setObsMode : func(active=0){
1112                 if(me._btnObsMode != active){
1113                         
1114                         setprop("/instrumentation/gps[0]/selected-course-deg",me._Pointer);
1115                         setprop("/instrumentation/gps[1]/selected-course-deg",me._Pointer);
1116                                 
1117                         fms._node.btnObsMode.setValue(active);
1118                 }
1119         },
1120         _onRouteActiveChange : func(n){
1121                 me._routeManagerActive = n.getValue();
1122                 setprop(me._PATH.FMS.isInRange,( (me._fmsServiceable == 1) and (me._routeManagerActive == 1) ) );
1123         },
1124         _onFmsServiceChange : func(n){
1125                 me._fmsServiceable = n.getValue();
1126                 setprop(me._PATH.FMS.isInRange,( (me._fmsServiceable == 1) and (me._routeManagerActive == 1) ) );
1127         },
1128         _onInRangeChange : func(n){
1129                 me._isInRange = n.getValue();
1130                 me._checkKnob();
1131         },
1132         _onGsInRangeChange : func(n){
1133                 me._isGSinRange = n.getValue();
1134                 
1135         },
1136         _onIsLocChange : func(n){
1137                 me._isLOC = n.getValue();
1138                 me._checkStationType();
1139                 
1140         },
1141         _onFromFlagChange : func(n){
1142                 me._fromFlag = n.getValue();
1143         },
1144         _onToFlagChange : func(n){
1145                 me._toFlag = n.getValue();
1146         },
1147         _onHasGSChange : func(n){
1148                 me._hasGS = n.getValue();
1149                 me._checkStationType();
1150         },
1151         _onFrequencyChange : func(n){
1152                 me._frequency = n.getValue();
1153                 me._checkStationType();
1154         },
1155         _checkStationType : func(){
1156                 me._distance    = me._ptree.Distance.getValue();
1157                 me._can.Distance.setText(sprintf("%.1f",me._distance));
1158                 me._can.Source.setText(me._NAME[me._source]);
1159                 if (me._source == 2){
1160                         me._can.ID.setText(sprintf("%s",me._frequency));
1161                 }else{
1162                         if (me._isLOC == 1){
1163                                 if (me._hasGS == 1){
1164                                         me._stationType = "ILS";
1165                                 }else{
1166                                         me._stationType = "LOC";
1167                                 }
1168                         }else{
1169                                 me._stationType = "VOR";
1170                         }
1171                         me._can.ID.setText(sprintf("%.2f (%s)",me._frequency,me._stationType));
1172                         
1173                         
1174                 }
1175         },
1176         _onCourseChange : func(n){
1177                 me._Pointer             = n.getValue();
1178 #               me._ptree.FMSCourse.setValue(me._Pointer);
1179                 me._can.Crs.setText(sprintf("%i",tool.course(me._Pointer)));
1180                 
1181         },
1182         update2Hz : func(now,dt){
1183                 
1184                 me._distance    = me._ptree.Distance.getValue();
1185                 me._can.Distance.setText(sprintf("%.1f",me._distance));
1186                 
1187         },
1188         
1189         update20Hz : func(now,dt){
1190 #               me._Pointer             = me._ptree.Pointer.getValue();
1191                 me._horizontalDeviation = me._ptree.hDev.getValue();
1192                 me._verticalDeviation   = -me._ptree.vDev.getValue();
1193                 
1194 #               me._isInRange           = me._ptree.inRange.getValue();
1195 #               me._isGSinRange         = me._ptree.GSinRange.getValue();
1196 #               me._isLOC               = me._ptree.LOC.getValue();
1197 #               me._fromFlag            = me._ptree.FromFlag.getValue();
1198 #               me._toFlag              = me._ptree.FromFlag.getValue();
1199                                 
1200                 
1201         },
1202 };
1203
1204 var BearingSourceWidget = {
1205         new: func(page,canvasGroup,name){
1206                 var m = {parents:[BearingSourceWidget,IfdWidget.new(page,canvasGroup,name)]};
1207                 m._class        = "BearingSourceWidget";
1208                 m._SOURCE       = ["0ff","Nav1","Nav2","FMS"];
1209                 m._NAME         = ["0ff","Nav 1","Nav 2","FMS"];
1210                 m._PATH =       {
1211                         FMS     : {
1212                                 isLOC                   : "/instrumentation/fms[0]/frequencies/is-localizer-frequency",
1213                                 isInRange               : "/instrumentation/fms[0]/in-range",
1214                                 Frequency               : "/autopilot/route-manager/wp/id",
1215                                 Pointer                 : "/autopilot/route-manager/wp/bearing-deg",
1216                                 hasGS                   : "/instrumentation/fms[0]/has-gs",
1217                                 distance                : "/autopilot/route-manager/wp/dist",
1218                         },
1219                         Nav1    : {
1220                                 isLOC                   : "/instrumentation/nav[0]/frequencies/is-localizer-frequency",
1221                                 isInRange               : "/instrumentation/nav[0]/in-range",
1222                                 Frequency               : "/instrumentation/nav[0]/frequencies/selected-mhz-fmt",
1223 #                               Pointer                 : "/instrumentation/nav[0]/radials/reciprocal-radial-deg",
1224                                 Pointer                 : "/instrumentation/nav[0]/heading-deg",
1225                                 hasGS                   : "/instrumentation/nav[0]/has-gs",
1226                                 distance                : "/instrumentation/nav[0]/nav-distance",
1227                         },
1228                         Nav2    : {
1229                                 isLOC                   : "/instrumentation/nav[1]/frequencies/is-localizer-frequency",
1230                                 isInRange               : "/instrumentation/nav[1]/in-range",
1231                                 Frequency               : "/instrumentation/nav[1]/frequencies/selected-mhz-fmt",
1232 #                               Pointer                 : "/instrumentation/nav[1]/radials/reciprocal-radial-deg",
1233                                 Pointer                 : "/instrumentation/nav[1]/heading-deg",
1234                                 hasGS                   : "/instrumentation/nav[1]/has-gs",
1235                                 distance                : "/instrumentation/nav[1]/nav-distance",
1236                         },
1237                         
1238                 };
1239                 m._ptree        = {
1240                         Pointer         : nil,
1241                         Distance        : nil,
1242                 };
1243                 m._can          = {
1244                         Off             : m._group.getElementById("BearingPtr_Off"),
1245                         On              : m._group.getElementById("BearingPtr_On").setVisible(0),
1246                         Source          : m._group.getElementById("BearingPtr_Source"),
1247                         ID              : m._group.getElementById("BearingPtr_ID"),
1248                         Brg             : m._group.getElementById("BearingPtr_BRG"),
1249                         Distance        : m._group.getElementById("BearingPtr_NM"),
1250                         Pointer         : m._group.getElementById("BearingPtr_Pointer").updateCenter().setVisible(0),
1251                 };
1252                 
1253                 m._source               = 0;
1254                 m._isLOC                = 0;
1255                 m._hasGS                = 0;
1256                 m._Pointer              = 0;
1257                 m._stationType          = "";
1258                 m._distance             = 0;
1259                 m._isInRange            = 0;
1260                 
1261                 return m;
1262         },
1263         setListeners : func(instance) {
1264                 if (me._source != 0){
1265                         me._ptree.Distance      = props.globals.initNode(me._PATH[me._SOURCE[me._source]].distance,0,"DOUBLE");
1266                         me._ptree.Pointer       = props.globals.initNode(me._PATH[me._SOURCE[me._source]].Pointer,0,"DOUBLE");
1267                         
1268                         append(me._listeners, setlistener(me._PATH[me._SOURCE[me._source]].Frequency,func(n){me._onFrequencyChange(n);},1,0));
1269                         append(me._listeners, setlistener(me._PATH[me._SOURCE[me._source]].isLOC,func(n){me._onIsLocChange(n);},1,0));
1270                         append(me._listeners, setlistener(me._PATH[me._SOURCE[me._source]].hasGS,func(n){me._onHasGSChange(n);},1,0));
1271                         append(me._listeners, setlistener(me._PATH[me._SOURCE[me._source]].isInRange,func(n){me._onInRangeChange(n);},1,0));
1272                         
1273                 }
1274         },
1275         init : func(instance=me){
1276 #               me.setListeners(instance);
1277                 
1278         },
1279         deinit : func(){
1280                 me.removeListeners();
1281         },
1282         _onVisibiltyChange : func(){
1283                 if(me._visibility == 1){
1284                         me.setListeners(me);
1285                         me._ifd.ui.bindKey("L3",{
1286                                 "<"     : func(){me._scroll(-1);},
1287                                 ">"     : func(){me._scroll(1);},
1288                         });
1289                         me._scroll(0);
1290                 }else{
1291                         me.removeListeners();
1292                         me._ifd.ui.bindKey("L3");
1293                 }
1294         },
1295         
1296         setSource : func(src){
1297                 me._source = src;
1298                 me.removeListeners();
1299                 me.setListeners(me);
1300         },
1301         _scroll : func(amount){
1302                 me._source += amount;
1303                 if (me._source > 3){ me._source = 0; }
1304                 if (me._source < 0){ me._source = 3; }
1305                 me.setSource(me._source);
1306                 
1307                 me._can.Source.setText(me._NAME[me._source]);
1308                 
1309                 me.update20Hz(0,0);
1310                 me.update2Hz(0,0);
1311                 
1312                 me._can.Off.setVisible (!me._source);
1313                 me._can.On.setVisible (me._source);
1314                 me._can.Pointer.setVisible(me._isInRange and me._source!=0);    
1315                 
1316                 
1317         },
1318         _onFrequencyChange : func(n){
1319                 me._frequency = n.getValue();
1320                 me._checkStationType();
1321         },
1322         _onIsLocChange : func(n){
1323                 me._isLOC = n.getValue();
1324                 me._checkStationType();
1325         },
1326         _onInRangeChange : func(n){
1327                 me._isInRange = n.getValue();
1328                 me._can.Pointer.setVisible(me._isInRange);
1329         },
1330         _onHasGSChange : func(n){
1331                 me._hasGS = n.getValue();
1332                 me._checkStationType();
1333         },
1334         _checkStationType : func(){
1335                 me._distance    = me._ptree.Distance.getValue();
1336                 if (me._source == 3){
1337                         me._can.ID.setText(sprintf("%s",me._frequency));
1338                 }else{
1339                         me._distance *= global.CONST.METER2NM;
1340                 
1341                         if (me._isLOC == 1){
1342                                 if (me._hasGS == 1){
1343                                         me._stationType = "ILS";
1344                                 }else{
1345                                         me._stationType = "LOC";
1346                                 }
1347                         }else{
1348                                 me._stationType = "VOR";
1349                         }
1350                         me._can.ID.setText(sprintf("%.2f (%s)",me._frequency,me._stationType));
1351                 }
1352                 me._can.Distance.setText(sprintf("%.1f",me._distance));
1353                 
1354         },
1355         update2Hz : func(now,dt){
1356                 if (me._source > 0){
1357                         me._distance    = me._ptree.Distance.getValue();
1358                         if (me._source != 3){
1359                                 me._distance *= global.CONST.METER2NM;
1360                         }
1361                         me._can.Distance.setText(sprintf("%.1f",me._distance));
1362                 }
1363         },
1364         update20Hz : func(now,dt){
1365                 if (me._source > 0){
1366                         if(me._source == 1 or me._source == 2){
1367                                 me._Pointer     = me._ptree.Pointer.getValue() - getprop("environment/magnetic-variation-deg");
1368                         }else{
1369                                 me._Pointer     = me._ptree.Pointer.getValue()  
1370                         }
1371                         me._can.Pointer.setRotation((me._Pointer - me._Page._widget.HSI._heading) * global.CONST.DEG2RAD);
1372                         me._can.Brg.setText(sprintf("%i",tool.course(me._Pointer)));
1373                 }
1374         },
1375 };
1376
1377 var DeviationIndicatorWidget = {
1378         new: func(page,canvasGroup,name){
1379                 var m = {parents:[DeviationIndicatorWidget,IfdWidget.new(page,canvasGroup,name)]};
1380                 m._class        = "DeviationIndicatorWidget";
1381                 m._can          = {
1382                         DI              : m._group.getElementById("DI"),
1383                         DI_Source_Text  : m._group.getElementById("DI_Source_Text"),
1384                         HDI             : m._group.getElementById("HDI"),
1385                         HDI_Needle      : m._group.getElementById("HDI_Needle"),
1386                         VDI             : m._group.getElementById("VDI"),
1387                         VDI_Needle      : m._group.getElementById("VDI_Needle"),
1388                 };
1389                 m._apModeRev = 0;
1390                 return m;
1391         },
1392         setListeners : func(instance) {
1393
1394                 append(me._listeners, setlistener(extra500.autopilot.nModeRev,func(n){me._onApModeRevChange(n);},1,0));
1395                 
1396         },
1397         _onVisibiltyChange : func(){
1398                 if(me._visibility == 1){
1399                         me.setListeners(me);
1400                 }else{
1401                         me.removeListeners();
1402                 }
1403         },
1404         
1405         _onApModeRevChange : func(n){
1406                 
1407                 me._apModeRev = n.getValue();
1408 #               print("DeviationIndicatorWidget._onApModeRevChange("~me._apModeRev~")");
1409         },
1410         update20Hz : func(now,dt){
1411
1412                 if(me._Page._widget.NavSource._isInRange == 1){
1413                         me._can.HDI_Needle.setVisible(1);
1414                         me._can.DI.setVisible(1);
1415                         me._Page._widget.HSI._can.CDI.setVisible(1);
1416                         me._can.HDI_Needle.setTranslation(me._Page._widget.NavSource._horizontalDeviation * 240,0);
1417                         if (me._Page._widget.NavSource._source == 2){
1418                                 me._can.DI_Source_Text.setText("FMS");
1419                                 if (me._Page._widget.NavSource._isGSinRange == 1){
1420                                         me._can.VDI_Needle.setTranslation(0, me._Page._widget.NavSource._verticalDeviation * 240);
1421                                         me._can.VDI.setVisible(1);
1422                                         me._can.VDI_Needle.setVisible(1);
1423                                         
1424                                 }else{
1425                                         me._can.VDI.setVisible(0);
1426                                         me._can.VDI_Needle.setVisible(0);
1427                                 }
1428                         }else{
1429                                 if(me._Page._widget.NavSource._isLOC == 1){
1430                                         me._can.DI_Source_Text.setText("LOC");
1431                                 }else{
1432                                         me._can.DI_Source_Text.setText("VOR");
1433                                 }
1434                                 
1435                                 if (me._Page._widget.NavSource._isGSinRange == 1 and (me._apModeRev == 0) ){
1436                                         me._can.VDI_Needle.setTranslation(0, me._Page._widget.NavSource._verticalDeviation * 240);
1437                                         me._can.DI_Source_Text.setText("ILS");
1438                                         me._can.VDI.setVisible(1);
1439                                         me._can.VDI_Needle.setVisible(1);
1440                                         
1441                                 }else{
1442                                         me._can.VDI.setVisible(0);
1443                                         me._can.VDI_Needle.setVisible(0);
1444                                         
1445                                 }
1446                         }
1447                         if ((me._Page._widget.NavSource._verticalDeviation <= -0.99) or (me._Page._widget.NavSource._verticalDeviation >= 0.99)){
1448                                 me._can.VDI_Needle.set("fill",COLOR["Yellow"]);
1449                         }else{
1450                                 me._can.VDI_Needle.set("fill",COLOR["White"]);
1451                         }
1452                         
1453                         if ((me._Page._widget.NavSource._horizontalDeviation <= -0.99) or (me._Page._widget.NavSource._horizontalDeviation >= 0.99)){
1454                                 me._Page._widget.HSI._can.CDI.set("fill",COLOR["Yellow"]);
1455                                 me._can.HDI_Needle.set("fill",COLOR["Yellow"]);
1456                         }else{
1457                                 me._Page._widget.HSI._can.CDI.set("fill",COLOR["Green"]);
1458                                 me._can.HDI_Needle.set("fill",COLOR["White"]);  
1459                         }
1460                         
1461                 }else{
1462                         me._can.HDI_Needle.setVisible(0);
1463                         me._can.DI.setVisible(0);
1464                         #me._Page._widget.HSI._can.CDI.set("fill",COLOR["Green"]);
1465                         me._Page._widget.HSI._can.CDI.setVisible(0);
1466                 }
1467                         
1468                 
1469         },
1470         
1471 };
1472
1473
1474 var HeadingSituationIndicatorWidget = {
1475         new: func(page,canvasGroup,name){
1476                 var m = {parents:[HeadingSituationIndicatorWidget,IfdWidget.new(page,canvasGroup,name)]};
1477                 m._class        = "HeadingSituationIndicatorWidget";
1478                 m._ptree        = {
1479                         Heading         : props.globals.initNode("/instrumentation/heading-indicator-IFD-"~m._ifd.name~"/indicated-heading-deg",0.0,"DOUBLE"),
1480 #                       HeadingTrue     : props.globals.initNode("/orientation/heading-deg",0.0,"DOUBLE"),
1481                         TrunRate        : props.globals.initNode("/instrumentation/turn-indicator/indicated-turn-rate",0.0,"DOUBLE"),
1482 #                       FmsHeading      : props.globals.initNode("/autopilot/fms-channel/course-target-deg",0.0,"DOUBLE"),
1483                 };
1484                 m._can          = {
1485                         CoursePointer   : m._group.getElementById("CoursePointer").updateCenter(),
1486                         CDI             : m._group.getElementById("CDI").updateCenter(),
1487                         FromFlag        : m._group.getElementById("CDI_FromFlag"),
1488                         ToFlag          : m._group.getElementById("CDI_ToFlag"),
1489                         HeadingBug_Text : m._group.getElementById("HDG_Bug_Value").updateCenter(),
1490                         Heading_Text    : m._group.getElementById("HDG_Value").updateCenter(),
1491                         TrunRate        : m._group.getElementById("TrunRate_Needle").updateCenter(),
1492 #                       FMS_Bug         : m._group.getElementById("FMS_BUG").updateCenter().setVisible(0),
1493 #                       HeadingBug      : m._group.getElementById("HDG_Bug").updateCenter().setVisible(0),
1494 #                       HeadingTrue     : m._group.getElementById("HDG_True").updateCenter().setVisible(0),
1495 #                       CompassRose     : m._group.getElementById("CompassRose").updateCenter().setVisible(0),
1496                 };
1497                 
1498                 m._heading              = 0;
1499                 m._headingBug           = 0;
1500                 m._trunRate             = 0;
1501                 m._fmsHeading           = 0;
1502                 
1503                 return m;
1504         },
1505         setListeners : func(instance) {
1506                 append(me._listeners, setlistener("/autopilot/settings/heading-bug-deg",func(n){me._onHdgBugChange(n)},1,0));   
1507         },
1508         _onHdgBugChange : func(n){
1509                 me._headingBug          = n.getValue();
1510                 me._can.HeadingBug_Text.setText(sprintf("%03i",tool.course(me._headingBug)));
1511         },
1512         init : func(instance=me){
1513 #               me.setListeners(instance);
1514                 #me._movingMap.init();
1515                 
1516         },
1517         _onVisibiltyChange : func(){
1518                 if(me._visibility == 1){
1519                         me.setListeners(me);
1520                         me._ifd.movingMap.setLayout("pfd");
1521                 }else{
1522                         me.removeListeners();
1523                 }
1524         },
1525         update20Hz : func(now,dt){
1526                 me._heading             = me._ptree.Heading.getValue();
1527 #               me._headingTrue         = me._ptree.HeadingTrue.getValue();
1528                 me._trunRate            = me._ptree.TrunRate.getValue();
1529 #               me._fmsHeading          = me._ptree.FmsHeading.getValue();
1530                 
1531                 
1532                 me._can.Heading_Text.setText(sprintf("%03i",tool.course( me._heading)));
1533 #               me._can.CompassRose.setRotation(-me._heading * global.CONST.DEG2RAD);
1534                 me._can.TrunRate.setRotation(me._trunRate * 30.0 * global.CONST.DEG2RAD);
1535                 
1536                 
1537 #               me._can.HeadingBug.setRotation((me._headingBug - me._heading) * global.CONST.DEG2RAD);
1538 #               me._can.HeadingTrue.setRotation((me._headingTrue - me._heading) * global.CONST.DEG2RAD);
1539                 
1540                 me._can.CoursePointer.setRotation((me._Page._widget.NavSource._Pointer - me._heading) * global.CONST.DEG2RAD);
1541                 me._can.FromFlag.setVisible(me._Page._widget.NavSource._fromFlag);
1542                 me._can.ToFlag.setVisible(me._Page._widget.NavSource._toFlag);
1543                         
1544                 me._can.CDI.setTranslation(me._Page._widget.NavSource._horizontalDeviation * 240,0);
1545                 # CDI visibility/color contolled by DeviationIndicatorWidget
1546                 
1547 #               if(me._Page._widget.NavSource._source == 2){
1548 #                       me._can.FMS_Bug.setRotation((me._fmsHeading - me._heading) * global.CONST.DEG2RAD);
1549 #                       me._can.FMS_Bug.setVisible(1);
1550 #               }else{
1551 #                       me._can.FMS_Bug.setVisible(0);
1552 #               }
1553                 
1554                 
1555                 # Bearing Pointer visibility/rotation controlled by BearingSourceWidget
1556                 
1557                 
1558         },
1559         
1560 };
1561
1562
1563 var EnvironmentWidget = {
1564         new: func(page,canvasGroup,name){
1565                 var m = {parents:[EnvironmentWidget,IfdWidget.new(page,canvasGroup,name)]};
1566                 m._class        = "EnvironmentWidget";
1567                 m._can          = {
1568                         WindVector      : m._group.getElementById("WindVector"),
1569                         WindArrow       : m._group.getElementById("WindArrow").updateCenter(),
1570                         OAT             : m._group.getElementById("OAT"),
1571                         GroundSpeed     : m._group.getElementById("GroundSpeed"),
1572                         IceWarning      : m._group.getElementById("ICE_Warning").setVisible(0), 
1573                 };
1574                 return m;
1575         },
1576         update2Hz : func(now,dt){
1577                 me._can.IceWarning.setVisible(getprop("/extra500/system/deice/iceWarning"));
1578         },
1579         update20Hz : func(now,dt){
1580                 var OAT                 = getprop("/fdm/jsbsim/aircraft/engine/OAT-degC");
1581                 var windDirection               = getprop("/environment/wind-from-heading-deg");
1582                 var windSpeed           = getprop("/environment/wind-speed-kt");
1583                 var groundSpeed         = getprop("/velocities/groundspeed-kt");
1584                                 
1585                 if (windSpeed > 2){
1586                         me._can.WindVector.setText(sprintf("%03i / %3i",windDirection,windSpeed));
1587                         me._can.WindArrow.setRotation((180 + windDirection - me._Page._widget.HSI._heading) * global.CONST.DEG2RAD);
1588                         me._can.WindArrow.setVisible(1);
1589                 }else{
1590                         me._can.WindVector.setText("Wind Calm");
1591                         me._can.WindArrow.setVisible(0);
1592                 }
1593                 
1594                 me._can.OAT.setText(sprintf("%2i",global.roundInt(OAT)));
1595                 me._can.GroundSpeed.setText(sprintf("%2i",groundSpeed));        
1596         },
1597 };
1598
1599
1600 var FlyVectorsWidget = {
1601         new: func(page,canvasGroup,name){
1602                 var m = {parents:[FlyVectorsWidget,IfdWidget.new(page,canvasGroup,name)]};
1603                 m._class        = "FlyVectorsWidget";
1604                 m._can          = {
1605                         FlyVector               : m._group.getElementById("FlyVector"),
1606                         FlyVector_label_up      : m._group.getElementById("FlyVector_label_up"),
1607                         FlyVector_label_down    : m._group.getElementById("FlyVector_label_down"),
1608                         FlyVector_border        : m._group.getElementById("FlyVector_border"),
1609                 };
1610                 m._flyVectors = 0;
1611                 return m;
1612         },
1613         init : func(instance=me){
1614                 
1615         },
1616         deinit : func(){
1617                 me.removeListeners();
1618         },
1619         setListeners : func(instance) {
1620                 append(me._listeners, setlistener(fms._node.FlyVector,func(n){me._onFlyVectorsChange(n);},1,0) );
1621         },
1622         _onVisibiltyChange : func(){
1623                 if(me._visibility == 1){
1624                         me.setListeners(me);
1625                         me._ifd.ui.bindKey("L5",{
1626                                 "<"     : func(){keypad.onV();},
1627                                 ">"     : func(){keypad.onV();},
1628                         });
1629                         me._can.FlyVector.setVisible(1);
1630                 }else{
1631                         me.removeListeners();
1632
1633                         me._ifd.ui.bindKey("L5");
1634                         
1635                         #me.registerKeyCDI();
1636                         
1637                                                 
1638                         
1639                 }
1640         },
1641         _onFlyVectorsChange : func(n){
1642                 me._flyVectors = n.getValue();
1643                 if(me._flyVectors){
1644 #                       me._can.FlyVector_label_up.setText("Cancel");
1645                         me._can.FlyVector_label_up.set("fill",COLOR["White"]);
1646                         me._can.FlyVector_label_down.set("fill",COLOR["White"]);
1647                         me._can.FlyVector_border.set("stroke",COLOR["Turquoise"]);
1648                         me._can.FlyVector_border.set("stroke-width",20);
1649                 }else{
1650 #                       me._can.FlyVector_label_up.setText("Fly");
1651                         me._can.FlyVector_label_up.set("fill",COLOR["Turquoise"]);
1652                         me._can.FlyVector_label_down.set("fill",COLOR["Turquoise"]);
1653                         me._can.FlyVector_border.set("stroke",COLOR["Blue"]);
1654                         me._can.FlyVector_border.set("stroke-width",10);
1655                 }
1656         },
1657 };
1658
1659 var NavSelectWidget = {
1660         new: func(page,canvasGroup,name){
1661                 var m = {parents:[NavSelectWidget,IfdWidget.new(page,canvasGroup,name)]};
1662                 m._class        = "NavSelectWidget";
1663                 m._can          = {
1664                         content         : m._group.getElementById("Tab_Nav_Content").setVisible(0),
1665 #                       SynVis          : m._group.getElementById("SynVis_State"),
1666                         FlightPlan      : m._group.getElementById("FlightPlan_State"),
1667                         CDI             : m._group.getElementById("CDI_State"),
1668                         CDI_Button      : m._group.getElementById("PFD_CDI_Button"),
1669                 };
1670                 m._widget       = {
1671                         
1672                 };
1673                 
1674                 m._synVis = 0;
1675                 m._flightPlan = 1;
1676                 m._cdi = 1;
1677                 m._userCDI = 0;
1678                 m._mapView      = 0;
1679                 return m;
1680         },
1681         init : func(instance=me){
1682                 
1683         },
1684         deinit : func(){
1685                 me.removeListeners();
1686         },
1687         _onVisibiltyChange : func(){
1688                 if(me._visibility == 1){
1689                         me.setListeners(me);
1690 #                       me._ifd.ui.bindKey("R3",{
1691 #                               "<"     : func(){me.setSynVis();},
1692 #                               ">"     : func(){me.setSynVis();},
1693 #                       });
1694                         me._ifd.ui.bindKey("R4",{
1695                                 "<"     : func(){me.setFlighPlan();},
1696                                 ">"     : func(){me.setFlighPlan();},
1697                         });
1698                         
1699                         me.registerKeyCDI() ;
1700                 
1701                         me._ifd.movingMap.setLayerVisible("route",me._flightPlan);
1702                         
1703                         
1704                         
1705 #                       me._can.SynVis.setText(LABEL_OFFON[me._synVis]);
1706                         me._can.FlightPlan.setText(LABEL_OFFON[me._flightPlan]);
1707                         me._can.CDI.setText(LABEL_OFFON[me._cdi]);
1708                         
1709                 }else{
1710                         me.removeListeners();
1711 #                       me._ifd.ui.bindKey("R3");
1712                         me._ifd.ui.bindKey("R4");
1713                         
1714                         
1715                         #me.registerKeyCDI();
1716                         
1717                                                 
1718                         me._ifd.movingMap.setLayerVisible("route",1);
1719                 }
1720                 me._can.content.setVisible(me._visibility);
1721                 
1722         },
1723         registerKeyCDI : func(){
1724                 me._can.CDI_Button.setVisible( me._Page._widget.Tab._index == 0 and me._Page._widget.NavSource._source == 2);
1725                 if(me._Page._widget.Tab._index == 0){
1726                         if(me._Page._widget.NavSource._source == 2){
1727                                 me.setCDI(me._userCDI);
1728                                 me._ifd.ui.bindKey("R5",{
1729                                         "<"     : func(){me.setCDI();},
1730                                         ">"     : func(){me.setCDI();},
1731                                 });
1732                         
1733                                                         
1734                         }else{
1735                                 me._ifd.ui.bindKey("R5");
1736                                 me.setCDI(1);
1737                         }
1738                 }else{
1739                         if(me._Page._widget.NavSource._source == 2){
1740                                 me.setCDI(me._userCDI);
1741                         }else{
1742                                 me.setCDI(1);
1743                         }
1744                 }
1745         },
1746         setSynVis : func(value=nil){
1747                 if (value == nil){
1748                         me._synVis = !me._synVis;
1749                 }else{
1750                         me._synVis = value;
1751                 }
1752                 me._can.SynVis.setText(LABEL_OFFON[me._synVis]);
1753                 
1754         },
1755         setFlighPlan : func(value=nil){
1756                 if (value == nil){
1757                         me._flightPlan = !me._flightPlan;
1758                 }else{
1759                         me._flightPlan = value;
1760                 }
1761                 me._can.FlightPlan.setText(LABEL_OFFON[me._flightPlan]);
1762                 me._ifd.movingMap.setLayerVisible("route",me._flightPlan);
1763                 
1764         },
1765         setCDI : func(value=nil){
1766                 if (value == nil){
1767                         me._cdi = !me._cdi;
1768                 }else{
1769                         me._cdi = value;
1770                 }
1771                 if(me._Page._widget.NavSource._source == 2){
1772                         me._userCDI = me._cdi;
1773                 }
1774                 
1775                 me._can.CDI.setText(LABEL_OFFON[me._cdi]);
1776                 me._Page._widget.HSI._can.CoursePointer.setVisible(me._cdi);
1777         },
1778 };
1779
1780 var BugSelectWidget = {
1781         new: func(page,canvasGroup,name){
1782                 var m = {parents:[BugSelectWidget,IfdWidget.new(page,canvasGroup,name)]};
1783                 m._class        = "BugSelectWidget";
1784                 m._can          = {
1785                         content         : m._group.getElementById("Tab_Bug_Content").setVisible(0),
1786                         Heading         : m._group.getElementById("Set_Heading"),
1787                         HeadingBorder   : m._group.getElementById("Set_Heading_Border"),
1788                         Altitude        : m._group.getElementById("Set_Altitude"),
1789                         AltitudeBorder  : m._group.getElementById("Set_Altitude_Border"),
1790                         VS              : m._group.getElementById("Set_VS"),
1791                         VSBorder        : m._group.getElementById("Set_VS_Border"),
1792                 };
1793                 m._modeRK = "HDG";
1794                 m._ResetTimer = maketimer(10.0,m,BugSelectWidget._resetMode);
1795                 m._ResetTimer.singleShot = 1;
1796                 return m;
1797         },
1798         init : func(instance=me){
1799                 
1800         },
1801         deinit : func(){
1802                 me.removeListeners();
1803         },
1804         _resetMode : func(){
1805 #               print("BugSelectWidget._resetMode() ... ");
1806                 me._setModeRK("HDG");
1807         },
1808         registerKeys : func(){
1809
1810                 me._ifd.ui.bindKey("R3",{
1811                         "<"     : func(){me._setModeRK("HDG");},
1812                         ">"     : func(){me._setModeRK("HDG");},
1813                 });
1814                 me._ifd.ui.bindKey("R4",{
1815                         "<"     : func(){me._setModeRK("ALT");},
1816                         ">"     : func(){me._setModeRK("ALT");},
1817                 });
1818                 me._ifd.ui.bindKey("R5",{
1819                         "<"     : func(){me._setModeRK("VS");},
1820                         ">"     : func(){me._setModeRK("VS");},
1821                 });
1822                         
1823                 
1824         },
1825         _onVisibiltyChange : func(){
1826                 if(me._visibility == 1){
1827                         me.setListeners(me);
1828                         me.registerKeys();
1829                         #me._setModeRK(me._modeRK);
1830                         me._setModeRK("HDG");
1831                         
1832                 }else{
1833                         me.removeListeners();
1834
1835                         me._ifd.ui.bindKey("R3");
1836                         me._ifd.ui.bindKey("R4");
1837                         me._ifd.ui.bindKey("R5");
1838                         
1839                         me._ifd.ui.bindKnob("RK");
1840                         
1841                         me._ResetTimer.stop();
1842                 }
1843                 me._can.content.setVisible(me._visibility);
1844         },
1845         _setModeRK : func(value=nil){
1846                 
1847                 me._modeRK = value;
1848                 
1849                 me._can.HeadingBorder.set("stroke",COLOR["Blue"]);
1850                 me._can.HeadingBorder.set("stroke-width",10);
1851                 me._can.Heading.set("z-index",1);
1852                 me._can.AltitudeBorder.set("stroke",COLOR["Blue"]);
1853                 me._can.AltitudeBorder.set("stroke-width",10);
1854                 me._can.Altitude.set("z-index",1);
1855                 me._can.VSBorder.set("stroke",COLOR["Blue"]);
1856                 me._can.VSBorder.set("stroke-width",10);
1857                 me._can.VS.set("z-index",1);
1858                         
1859                 
1860                 if (me._modeRK == "HDG"){
1861                         me._can.HeadingBorder.set("stroke",COLOR["Turquoise"]);
1862                         me._can.HeadingBorder.set("stroke-width",20);
1863                         me._can.Heading.set("z-index",2);
1864                 
1865                         me._ifd.ui.bindKnob("RK",{
1866                                 "<<"    : func(){keypad.onAdjustHeading(-10);},
1867                                 "<"     : func(){keypad.onAdjustHeading(-1);},
1868                                 "push"  : func(){keypad.onHeadingSync();},
1869                                 ">"     : func(){keypad.onAdjustHeading(1);},
1870                                 ">>"    : func(){keypad.onAdjustHeading(10);},
1871                         },{
1872                                 "scroll"        : "Heading",
1873                                 "push"          : "Sync",
1874                         });
1875                         
1876                         
1877                 }elsif (me._modeRK == "ALT"){
1878                         me._can.AltitudeBorder.set("stroke",COLOR["Turquoise"]);
1879                         me._can.AltitudeBorder.set("stroke-width",20);
1880                         me._can.Altitude.set("z-index",2);
1881                                                 
1882                         me._ifd.ui.bindKnob("RK",{
1883                                 "<<"    : func(){keypad.onAdjustAltitude(-500);me._ResetTimer.restart(10);},
1884                                 "<"     : func(){keypad.onAdjustAltitude(-100);me._ResetTimer.restart(10);},
1885                                 "push"  : func(){keypad.onAltitudeSync();me._ResetTimer.restart(10);},
1886                                 ">"     : func(){keypad.onAdjustAltitude(100);me._ResetTimer.restart(10);},
1887                                 ">>"    : func(){keypad.onAdjustAltitude(500);me._ResetTimer.restart(10);},
1888                         },{
1889                                 "scroll"        : "Altitude",
1890                                 "push"          : "Sync",
1891                         });
1892                         me._ResetTimer.restart(10);
1893                 }elsif (me._modeRK == "VS"){
1894                         me._can.VSBorder.set("stroke",COLOR["Turquoise"]);
1895                         me._can.VSBorder.set("stroke-width",20);
1896                         me._can.VS.set("z-index",2);
1897                         
1898                         me._ifd.ui.bindKnob("RK",{
1899                                 "<<"    : func(){extra500.autopilot.onAdjustVS(-100,"ifd");me._ResetTimer.restart(10);},
1900                                 "<"     : func(){extra500.autopilot.onAdjustVS(-50,"ifd");me._ResetTimer.restart(10);},
1901                                 "push"  : func(){extra500.autopilot.onSetVS(0);me._ResetTimer.restart(10);},
1902                                 ">"     : func(){extra500.autopilot.onAdjustVS(50,"ifd");me._ResetTimer.restart(10);},
1903                                 ">>"    : func(){extra500.autopilot.onAdjustVS(100,"ifd");me._ResetTimer.restart(10);},
1904                         },{
1905                                 "scroll"        : "VS",
1906                                 "push"          : "Sync",
1907                         });
1908                         me._ResetTimer.restart(10);
1909                 }else{
1910                                                         
1911                         me._ifd.ui.bindKnob("RK");
1912                 }
1913                 
1914                 
1915                 
1916         }
1917 };
1918
1919 var TimerWidget = {
1920         new: func(page,canvasGroup,name){
1921                 var m = {parents:[TimerWidget,IfdWidget.new(page,canvasGroup,name)]};
1922                 m._class        = "TimerWidget";
1923                 m._ptree        = {
1924                         OAT             : props.globals.initNode("/environment/temperature-degc",0.0,"DOUBLE"),
1925                         WindDirection   : props.globals.initNode("/environment/wind-from-heading-deg",0.0,"DOUBLE"),
1926                         WindSpeed       : props.globals.initNode("/environment/wind-speed-kt",0.0,"DOUBLE"),
1927                         GroundSpeed     : props.globals.initNode("/velocities/groundspeed-kt",0.0,"DOUBLE"),
1928                 };
1929                 m._can          = {
1930                         On              : m._group.getElementById("Timer_On"),
1931                         Center          : m._group.getElementById("Timer_btn_Center").updateCenter(),
1932                         Left            : m._group.getElementById("Timer_btn_Left"),
1933                         Time            : m._group.getElementById("Timer_Time"),
1934                         
1935                 };
1936                 m._windSpeed            = 0;
1937                 m._windDirection        = 0;
1938                 m._oat                  = 0;
1939                 m._groundSpeed          = 0;
1940                 return m;
1941         },
1942         init : func(instance=me){
1943                 
1944         },
1945         deinit : func(){
1946                 me.removeListeners();
1947         },
1948         _onVisibiltyChange : func(){
1949                 if(me._visibility == 1){
1950                         me.setListeners(me);
1951                         me.registerKeys();
1952                 }else{
1953                         me.removeListeners();
1954                         me._ifd.ui.bindKey("R2");
1955                 }
1956         },
1957         registerKeys : func(){
1958                 if ((me._Page.data.timerState == 0)){
1959
1960                         me._ifd.ui.bindKey("R2",{
1961                                 "<"     : func(){me._Page.data.timerStart();me.registerKeys();},
1962                                 ">"     : func(){me._Page.data.timerStart();me.registerKeys();},
1963                         });
1964                                                 
1965                         me._can.On.setVisible(0);
1966                         me._can.Center.setVisible(1);
1967                         
1968                 }elsif ((me._Page.data.timerState == 1)){
1969
1970                         me._ifd.ui.bindKey("R2",{
1971                                 "<"     : func(){me._Page.data.timerStart();me.registerKeys();},
1972                                 ">"     : func(){me._Page.data.timerReset();me.registerKeys();},
1973                         });
1974                                                 
1975                         
1976                         me._can.Left.setText("Start");
1977                         me._can.On.setVisible(1);
1978                         me._can.Center.setVisible(0);
1979                 }elsif ((me._Page.data.timerState == 2)){
1980
1981                         me._ifd.ui.bindKey("R2",{
1982                                 "<"     : func(){me._Page.data.timerStop();me.registerKeys();},
1983                                 ">"     : func(){me._Page.data.timerReset();me.registerKeys();},
1984                         });
1985                         
1986                         
1987                         me._can.Left.setText("Stop");
1988                         me._can.On.setVisible(1);
1989                         me._can.Center.setVisible(0);
1990                 }
1991                 me._can.Time.setText(me._Page.data.timerGetTime());
1992         },
1993         update2Hz : func(now,dt){
1994                 me._can.Time.setText(me._Page.data.timerGetTime());
1995         }
1996 };
1997
1998 var ActiveComWidget = {
1999         new : func(page,canvasGroup,name){
2000                 var m = {parents:[ActiveComWidget,IfdWidget.new(page,canvasGroup,name)]};
2001                 m._class        = "ActiveComWidget";
2002                 m._tab          = [];
2003                 m._can          = {};
2004                 m._activeChannelListener = nil;
2005                 return m;
2006         },
2007         setListeners : func(instance) {
2008                 #append(me._listeners, setlistener("/extra500/instrumentation/Keypad/tuningSource",func(n){me._onComSelectedChange(n)},1,0));   
2009                 append(me._listeners, setlistener("/instrumentation/comm-selected-index",func(n){me._onComSelectedChange(n)},1,0));     
2010         },
2011         init : func(instance=me){
2012                 #print("ActiveComWidget.init() ... ");
2013                 me._can = {
2014                         freqency        : me._group.getElementById("Com_active_Channel_Freqency"),
2015                         info            : me._group.getElementById("Com_active_Channel_Info").setText("active"),
2016                         airport         : me._group.getElementById("Com_active_Channel_Airport").setText(""),
2017                 };
2018         },
2019         _onVisibiltyChange : func(){
2020                 if(me._visibility == 1){
2021                         me.setListeners(me);
2022                 }else{
2023                         me.removeListeners();
2024                 }
2025         },
2026         _setActiveListener : func(index=nil){
2027                 if(index == nil){
2028                         if(me._activeChannelListener != nil){
2029                                 removelistener(me._activeChannelListener);
2030                                 me._activeChannelListener = nil;
2031                         }
2032                 }else{
2033                         if(me._activeChannelListener != nil){
2034                                 removelistener(me._activeChannelListener);
2035                                 me._activeChannelListener = nil;
2036                         }
2037                         me._activeChannelListener = setlistener("/instrumentation/comm["~index~"]/frequencies/selected-mhz",func(n){me._onFreqencyChange(n)},1,0);
2038                 }
2039         },
2040         _onComSelectedChange : func(n){
2041                 var index = n.getValue();
2042                 me._setActiveListener(index);
2043                 if(index==0){
2044                         me._can.airport.setText("Com 1");
2045                 }else{
2046                         me._can.airport.setText("Com 2");
2047                 }
2048         },
2049         _onFreqencyChange : func(n){
2050                 var freqency = n.getValue();
2051                 me._can.freqency.setText(sprintf("%.3f",freqency));
2052         },
2053 };
2054
2055 var AvidynePagePFD = {
2056         new: func(ifd,name,data){
2057                 var m = { parents: [
2058                         AvidynePagePFD,
2059                         PageClass.new(ifd,name,data)
2060                 ] };
2061                 
2062                 # creating the page 
2063                 m.svgFile       = "IFD_PFD.svg";
2064                 
2065                 m.nHorizon = m.page.createChild("image","Horizon");
2066                 m.nHorizon.set("file", "Models/instruments/IFDs/Horizon.png");
2067                 m.nHorizon.setSize(m.IFD.width ,m.IFD.height);
2068                 m.nHorizon.setScale(2.0);
2069                 
2070                 m.nHorizonTF = m.nHorizon.createTransform();
2071                 m.nHorizonTF.setTranslation(-m.IFD.width *1/2,-m.IFD.height*3/4 +80);
2072                 
2073                 m.nHorizon.updateCenter();
2074                 m.nHorizon.set("clip","rect(0px, 2048px,768px, 0px)");
2075                 
2076                 
2077 #               m.nOatBorder = m.page.createChild("image")
2078 #                       .set("file", "Models/instruments/IFDs/SliceBorder.png")
2079 #                       .set("slice", "32")
2080 #                       .setSize(254,768)
2081 #                       .setTranslation(32,96);
2082                         
2083                 
2084
2085                 canvas.parsesvg(m.page, "Models/instruments/IFDs/"~m.svgFile,{
2086                         "font-mapper": global.canvas.FontMapper
2087                         }
2088                 );
2089
2090                 
2091                 m._widget       = {
2092                         Attitude                : AttitudeIndicatorWidget.new(m,m.page,"Altitude"),
2093                         Autopilot               : AutopilotWidget.new(m,m.page,"Autopilot"),
2094                         VerticalSpeed           : VerticalSpeedWidget.new(m,m.page,"Vertical Speed"),
2095                         AirSpeed                : AirspeedSpeedWidget.new(m,m.page,"Airspeed Speed"),
2096                         Altitude                : AltitudeWidget.new(m,m.page,"Altitude"),
2097                         DI                      : DeviationIndicatorWidget.new(m,m.page,"Deviation Indicator"),
2098                         Environment             : EnvironmentWidget.new(m,m.page,"Environment"),NavSource               : NavSourceWidget.new(m,m.page,"Nav Source"),
2099                         BearingSource           : BearingSourceWidget.new(m,m.page,"Bearing Source"),
2100                         HSI                     : HeadingSituationIndicatorWidget.new(m,m.page,"Heading Situation Indicator"),
2101                         Timer                   : TimerWidget.new(m,m.page,"Timer"),
2102                         Tab                     : TabWidget.new(m,m.page,"TabSelectPFD"),
2103                         Marker                  : MarkerWidget.new(m,m.page,"Marker"),
2104                         ActiveCom               : ActiveComWidget.new(m,m.page,"ActiveCom"),
2105                         FlyVectors              : FlyVectorsWidget.new(m,m.page,"FlyVectors"),
2106                         
2107                         
2108                         
2109                         
2110                 };
2111                 m._widgetTab = {
2112                         BugSelect               : BugSelectWidget.new(m,m.page,"BugSelect"),
2113                         NavSelect               : NavSelectWidget.new(m,m.page,"NavSelectWidget"),
2114                         MapKnob                 : MovingMapKnobWidget.new(m,m.page,"MovingMapKnob")
2115                 };
2116                 
2117                 m._widget.Tab._tab = ["Nav","Bug"];
2118                 
2119                                 
2120
2121                 return m;
2122         },
2123         init : func(instance=me){
2124                 #print("AvidynePagePFD.init() ... ");
2125                 foreach(var widget;keys(me._widget)){
2126                         #print("widget : "~widget);
2127                         if(me._widget[widget] != nil){
2128                                 
2129                                 me._widget[widget].init();
2130                         }
2131                 }
2132         },
2133         deinit : func(){
2134                 foreach(var widget;keys(me._widget)){
2135                         if(me._widget[widget] != nil){
2136                                 me._widget[widget].setVisible(0);
2137                                 me._widget[widget].deinit();
2138                         }
2139                 }
2140         },
2141         _onVisibiltyChange : func(){
2142                 me.IFD.setLayout(IFD_LAYOUT.PFD);
2143                 if(me._visibility == 1){
2144                         me.setListeners(me);
2145 #                       me.IFD._widget.Headline.setVisible(0);
2146 #                       me.IFD._widget.PlusData.setVisible(0);
2147                         #me.IFD.movingMap.setLayout("pfd");
2148                         #me._widget.Tab.initActiveTab();
2149                         me.registerKeys();
2150                         
2151                 }else{
2152                         me.IFD.movingMap.setVisible(0);
2153                         me.keys = {};
2154                         me.removeListeners();
2155                         
2156                         foreach(var widget;keys(me._widgetTab)){
2157                                 if(me._widgetTab[widget] != nil){
2158                                         me._widgetTab[widget].setVisible(me._visibility);
2159                                 }
2160                         }
2161                         
2162                 }
2163                         
2164                 foreach(var widget;keys(me._widget)){
2165                         if(me._widget[widget] != nil){
2166                                 me._widget[widget].setVisible(me._visibility);
2167                         }
2168                 }
2169                 
2170                 
2171                 me.page.setVisible(me._visibility);
2172         },
2173         _initWidgetsForTab : func(index){
2174                         
2175                 if (index == 0){ # Tab NavDisplay
2176                         
2177                         me._widgetTab.BugSelect.setVisible(0);
2178                         me._widgetTab.NavSelect.setVisible(1);
2179                         me._widgetTab.MapKnob.setHand(1);
2180                         me._widgetTab.MapKnob.setVisible(1);
2181                         
2182                 }elsif(index == 1){ # Tab BugSelect
2183                         me._widgetTab.MapKnob.setVisible(0);
2184                         me._widgetTab.NavSelect.setVisible(0);
2185                         me._widgetTab.BugSelect.setVisible(1);
2186                         
2187                         
2188                 }else{
2189                         print("_scrollToTab() ... mist");
2190                 }
2191         },
2192
2193         update2Hz : func(now,dt){
2194
2195                 me._widget.NavSource.update2Hz(now,dt);
2196                 me._widget.BearingSource.update2Hz(now,dt);
2197                 me._widget.Timer.update2Hz(now,dt);
2198                 
2199         },
2200         update20Hz : func(now,dt){
2201                 
2202                 me._widget.AirSpeed.update20Hz(now,dt);
2203                 me._widget.VerticalSpeed.update20Hz(now,dt);
2204                 me._widget.Altitude.update20Hz(now,dt);
2205                 me._widget.Attitude.update20Hz(now,dt);
2206                 me._widget.NavSource.update20Hz(now,dt);
2207                 me._widget.DI.update20Hz(now,dt);
2208                 me._widget.HSI.update20Hz(now,dt);
2209                 me._widget.BearingSource.update20Hz(now,dt);
2210                 me._widget.Environment.update20Hz(now,dt);
2211                 me._widget.Marker.update20Hz(now,dt);
2212         
2213         },
2214 };
2215