add TCAS
|
1 |
# vim: set foldmethod=marker foldmarker={{{,}}} : |
2 | ||
3 |
var TcasItemClass = { |
|
4 |
# get data from AI and multiplayers {{{ |
|
5 |
new : func(canvasGroup, index) { |
|
6 |
var m = {parents : [TcasItemClass]}; |
|
7 |
m._group = canvasGroup.createChild("group", "TcasItem_" ~ index); |
|
8 | ||
relocate SVG files in Models...
|
9 |
canvas.parsesvg(m._group, data.zkv1000_reldir ~ "Models/tcas.svg"); |
add TCAS
|
10 |
m._can = { |
traffic alert and display
|
11 |
Alt : m._group.getElementById("Alt_above").setVisible(0), |
add TCAS
|
12 |
Arrow : [ |
13 |
m._group.getElementById("Arrow_climb").setVisible(0), |
|
14 |
m._group.getElementById("Arrow_descent").setVisible(0) |
|
traffic alert and display
|
15 |
], |
16 |
Callsign: m._group.getElementById("Callsign").setVisible(0), |
|
17 |
ThreadLevel: [], |
|
add TCAS
|
18 |
}; |
19 | ||
20 |
for (var i=0; i<4; i+=1) |
|
21 |
append(m._can.ThreadLevel, |
|
22 |
m._group.getElementById("Thread_Level_" ~ i).setVisible(0)); |
|
23 | ||
24 |
m._colors = [ '#00ffff', '#00ffff', '#ff7f2a', '#ff0000' ]; |
|
25 | ||
26 |
return m; |
|
27 |
}, |
|
28 | ||
fix bad orientation on tcas ...
|
29 |
setData : func(lat, lon, alt, vs, level, callsign, orientation) { |
add TCAS
|
30 |
me._group.setVisible(1); |
31 |
me._group.setGeoPosition(lat, lon); |
|
32 |
|
|
traffic alert and display
|
33 |
if (alt and level) |
34 |
me._can.Alt |
|
add TCAS
|
35 |
.setText(sprintf("%+i", alt)) |
36 |
.set('fill', me._colors[level]) |
|
fix traffic display orientat...
|
37 |
.setRotation(orientation) |
add TCAS
|
38 |
.setVisible(1); |
traffic alert and display
|
39 |
else |
40 |
me._can.Alt.setVisible(0); |
|
add TCAS
|
41 |
|
traffic alert and display
|
42 |
if (abs(vs) > 50 and level > 1) { |
43 |
me._can.Arrow[vs < 0] |
|
add TCAS
|
44 |
.set('fill', me._colors[level]) |
45 |
.set('stroke', me._colors[level]) |
|
fix traffic display orientat...
|
46 |
.setRotation(orientation) |
add TCAS
|
47 |
.setVisible(1); |
48 | ||
traffic alert and display
|
49 |
me._can.Arrow[vs > 0].setVisible(0); |
add TCAS
|
50 |
} |
traffic alert and display
|
51 |
else { |
52 |
me._can.Arrow[0].setVisible(0); |
|
53 |
me._can.Arrow[1].setVisible(0); |
|
54 |
} |
|
55 | ||
56 |
for (var i = 0; i < 4; i += 1) |
|
fix traffic display orientat...
|
57 |
me._can.ThreadLevel[i] |
58 |
.setRotation(orientation) |
|
59 |
.setVisible(level == i); |
|
traffic alert and display
|
60 | |
61 |
me._can.Callsign |
|
62 |
.setText(callsign) |
|
63 |
.set('fill', me._colors[level]) |
|
fix traffic display orientat...
|
64 |
.setRotation(orientation) |
traffic alert and display
|
65 |
.setVisible(1); |
add TCAS
|
66 |
}, |
67 |
}; |
|
68 |
# }}} |
|
69 | ||
70 |
var MapTcas = { |
|
71 |
# init TCAS layer and update {{{ |
|
72 |
new : func(device, group) { |
|
73 |
var m = {parents:[MapTcas]}; |
|
fix when TCAS isn't availabl...
|
74 |
m.device = device; |
traffic alert and display
|
75 |
m.visibility = 0; |
76 |
m.group = group.createChild('map', 'tcas') |
|
77 |
.setTranslation( |
|
78 |
m.device.role == 'MFD' ? (m.device.data.mapview[0] + m.device.data.mapclip.left)/2 : 120, |
|
79 |
m.device.role == 'MFD' ? 400 : 600) |
|
80 |
.setVisible(m.visibility); |
|
81 |
m._item = []; |
|
82 |
m._itemIndex = 0; |
|
83 |
m._itemCount = 0; |
|
add TCAS
|
84 |
return m; |
85 |
}, |
|
86 | ||
poweroff improved
|
87 |
off: func { |
88 |
me.setVisible(0); |
|
89 |
}, |
|
90 | ||
add TCAS
|
91 |
update : func() { |
traffic alert and display
|
92 |
if (me.group.getVisible() == 0) |
add TCAS
|
93 |
return; |
94 |
me.group._node.getNode('ref-lat', 1).setDoubleValue(data.lat); |
|
95 |
me.group._node.getNode('ref-lon', 1).setDoubleValue(data.lon); |
|
close issue with misplacing ...
|
96 |
me.group.setRange(me.device.data['range-nm']/2); |
add TCAS
|
97 |
me._itemIndex = 0; |
fix traffic display orientat...
|
98 |
var normOrientation = -me.device.data.orientation.map * D2R; |
add TCAS
|
99 |
foreach (var ac; data.tcas) { |
100 |
if (me._itemIndex >= me._itemCount) { |
|
101 |
append(me._item, TcasItemClass.new(me.group, me._itemIndex)); |
|
102 |
me._itemCount += 1; |
|
103 |
} |
|
fix traffic display orientat...
|
104 |
me._item[me._itemIndex].setData(ac.lat, ac.lon, ac.alt, ac.vs, ac.level, ac.callsign, normOrientation); |
add TCAS
|
105 |
me._itemIndex += 1; |
106 |
} |
|
107 |
|
|
108 |
for (; me._itemIndex < me._itemCount; me._itemIndex += 1) { |
|
109 |
me._item[me._itemIndex]._group.setVisible(0); |
|
110 |
} |
|
111 |
}, |
|
112 | ||
113 |
setVisible : func (v) { |
|
114 |
me.group.setVisible(v); |
|
115 |
}, |
|
116 |
}; |
|
117 |
# }}} |