navsymbols.nas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # mfd.nas to drive gauges of the VMD MFD #
  2. ### Original code copied from EC130.nas, original author Melchior Franz ###
  3. ### adopted by litzi for Helionix VMD-, NAVD-, DMAP- and FND-displays ###
  4. # ==== NAVDISPLAY =====
  5. # calculate bearing and distances of navaids for navdisplay (navd).
  6. # the last and the next 4 waypoints of the flightplan are
  7. # shown on the navd.
  8. var navdisplay = {
  9. new: func () {
  10. var m = { parents: [Timerloop.new(), navdisplay] };
  11. m.maxrng = 40;
  12. m.maxn = 20;
  13. m.navlist = [];
  14. m.usedids = std.Vector.new();
  15. m.navdfilter = 1;
  16. m.rr = 5;
  17. m.id = 99;
  18. return m;
  19. },
  20. addsym: func (i, x) {
  21. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/sym",
  22. x.symbol);
  23. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/distance-norm",
  24. x.reldst);
  25. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/distance-nm",
  26. x.distance_nm);
  27. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/rel-bearing",
  28. x.relbearing);
  29. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/bearing-deg",
  30. x.bearing_deg);
  31. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/rel-course",
  32. x.relcourse);
  33. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/id", x.id);
  34. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/ils-course", x.course);
  35. var info = "";
  36. # generate the info string for VOR and ILS
  37. if (x.symbol == 0 or x.symbol == 5)
  38. var info = sprintf("%-8.8s %6.2f", x.name, x.frequency/100);
  39. #..for waypoints
  40. if (x.symbol == 1 or x.symbol == 4) var info=sprintf("%-11.11s", x.name);
  41. if (x.symbol == 2)
  42. var info = sprintf("%-11.11s %3.0f", x.name, x.frequency/100);
  43. if (x.symbol == 3)
  44. var info = sprintf("%-8.8s %4.0fft", x.name, x.elevation*M2FT);
  45. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/info", info);
  46. if (x.type == "ILS" or x.type == "VOR" or x.type == "NDB")
  47. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/frequency", x.frequency);
  48. else
  49. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/frequency", 0);
  50. return x.id;
  51. },
  52. delsym: func (i) {
  53. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/sym", -1);
  54. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/distance-norm", 99);
  55. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/distance-nm", "");
  56. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/rel-bearing", 0);
  57. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/rel-course", 0);
  58. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/bearing-deg", "");
  59. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/ils-course", 0);
  60. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/frequency", 0);
  61. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/id", "");
  62. setprop(mfdroot ~ "navd/sym[" ~ i ~ "]/info", "");
  63. },
  64. update: func() {
  65. me.navlist = [];
  66. me.usedids = std.Vector.new();
  67. me.navdfilter = getprop(datafltr);
  68. me.rr = (getprop(rngprop) or 1) * (getprop(scaleprop) or 1);
  69. me.maxrng = (getprop(rngprop) or 5) * 1.4;
  70. if (me.navdfilter==2) {
  71. # add flightplan waypoints on top of list
  72. var fplan = flightplan();
  73. var fplans = fplan.getPlanSize();
  74. # for mode 1 show only 4 next wypts
  75. var first = max(0, fplan.current - 1);
  76. var n = (me.navdfilter!=1) ? fplans : min(5 + first, fplans);
  77. for (var i=first; i<n; i+=1) {
  78. var thiswp = fplan.getWP(i);
  79. me.addto([thiswp],(i == fplan.current) ? 4 : 1);
  80. me.usedids.append(thiswp.id);
  81. }
  82. }
  83. if (me.navdfilter==3) {
  84. var x=findNavaidsWithinRange(me.maxrng, "airport");
  85. me.addto(x,3);
  86. }
  87. if (me.navdfilter==1) {
  88. var x=findNavaidsWithinRange(me.maxrng, "vor");
  89. me.addto(x,0);
  90. }
  91. if (me.navdfilter==1) {
  92. var x=findNavaidsWithinRange(me.maxrng, "ndb");
  93. me.addto(x,2);
  94. }
  95. if (me.navdfilter==4) {
  96. var x=findNavaidsWithinRange(me.maxrng, "ils");
  97. me.addto(x,5);
  98. }
  99. if (me.navdfilter==2) {
  100. var x=findNavaidsWithinRange(me.maxrng, "fix");
  101. me.addto(x,6);
  102. }
  103. # sort all the symbols by distance from aircraft
  104. # except in flightplan views
  105. if (me.navdfilter!=2)
  106. me.navlist = sortNavaidByDistance(me.navlist);
  107. l = min(me.maxn, size(me.navlist));
  108. # then transfer up to maxn to the plan view properties
  109. for (var j=0; j < l; j+=1) me.addsym(j, me.navlist[j] );
  110. # deactivate unused symbols
  111. if (j <= me.maxn) for (var i = j; i < me.maxn; i+=1) me.delsym(i);
  112. },
  113. addto: func(x, symbol) {
  114. var myhdg = getprop("/orientation/heading-deg");
  115. foreach(var sym; x) {
  116. if (!me.usedids.contains(sym.id)) {
  117. var y = ghostcopy(sym);
  118. #do not add fixes with numbers, they seem to have
  119. #a (strange?) special meaning
  120. if (!(num(right(y.id,1))!=nil and y.type=="fix")) {
  121. var (c, d) = courseAndDistance(
  122. {lat: sym.lat,
  123. lon: sym.lon} );
  124. y.distance_nm = d;
  125. y.bearing_deg = c;
  126. y.symbol = symbol;
  127. y.relbearing = c - myhdg;
  128. y.relcourse = y.course - myhdg;
  129. y.reldst = d / me.rr;
  130. append(me.navlist, y);
  131. }
  132. }
  133. }
  134. }
  135. };
  136. var nav = navdisplay.new();
  137. # === UPDATERS ===
  138. # run updaters with delay for an even distrubution of load
  139. setlistener("sim/signals/fdm-initialized", func {
  140. nav.run(0.2, delay=0.12);
  141. } );