zkv1000 / Nasal / maps / tcas.nas /
Newer Older
112 lines | 3.544kb
add TCAS
Sébastien MARQUE authored on 2017-12-21
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...
Sébastien MARQUE authored on 2017-12-31
9
        canvas.parsesvg(m._group, data.zkv1000_reldir ~ "Models/tcas.svg");
add TCAS
Sébastien MARQUE authored on 2017-12-21
10
        m._can = {
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
11
            Alt : m._group.getElementById("Alt_above").setVisible(0),
add TCAS
Sébastien MARQUE authored on 2017-12-21
12
            Arrow : [
13
                m._group.getElementById("Arrow_climb").setVisible(0),
14
                m._group.getElementById("Arrow_descent").setVisible(0)
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
15
            ],
16
            Callsign: m._group.getElementById("Callsign").setVisible(0),
17
            ThreadLevel: [],
add TCAS
Sébastien MARQUE authored on 2017-12-21
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

            
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
29
    setData : func(lat, lon, alt, vs, level, callsign) {
add TCAS
Sébastien MARQUE authored on 2017-12-21
30
        me._group.setVisible(1);
31
        me._group.setGeoPosition(lat, lon);
32
        
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
33
        if (alt and level)
34
            me._can.Alt
add TCAS
Sébastien MARQUE authored on 2017-12-21
35
                .setText(sprintf("%+i", alt))
36
                .set('fill', me._colors[level])
37
                .setVisible(1);
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
38
        else
39
            me._can.Alt.setVisible(0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
40
                
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
41
        if (abs(vs) > 50 and level > 1) {
42
            me._can.Arrow[vs < 0]
add TCAS
Sébastien MARQUE authored on 2017-12-21
43
                .set('fill', me._colors[level])
44
                .set('stroke', me._colors[level])
45
                .setVisible(1);
46

            
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
47
            me._can.Arrow[vs > 0].setVisible(0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
48
        }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
49
        else {
50
            me._can.Arrow[0].setVisible(0);
51
            me._can.Arrow[1].setVisible(0);
52
        }
53

            
54
        for (var i = 0; i < 4; i += 1)
55
            me._can.ThreadLevel[i].setVisible(level == i);
56

            
57
        me._can.Callsign
58
            .setText(callsign)
59
            .set('fill', me._colors[level])
60
            .setVisible(1);
add TCAS
Sébastien MARQUE authored on 2017-12-21
61
    },
62
};
63
# }}} 
64

            
65
var MapTcas = {
66
# init TCAS layer and update {{{
67
    new : func(device, group) {
68
        var m = {parents:[MapTcas]}; 
fix when TCAS isn't availabl...
Sébastien MARQUE authored on 2020-04-21
69
        m.device = device;
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
70
        m.visibility = 0;
71
        m.group = group.createChild('map', 'tcas')
72
            .setTranslation(
73
                m.device.role == 'MFD' ? (m.device.data.mapview[0] + m.device.data.mapclip.left)/2 : 120,
74
                m.device.role == 'MFD' ? 400 : 600)
75
            .setVisible(m.visibility);
76
        m._item      = [];
77
        m._itemIndex = 0;
78
        m._itemCount = 0;
add TCAS
Sébastien MARQUE authored on 2017-12-21
79
        return m;
80
    },
81

            
poweroff improved
Sébastien MARQUE authored on 2020-05-16
82
    off: func {
83
        me.setVisible(0);
84
    },
85

            
add TCAS
Sébastien MARQUE authored on 2017-12-21
86
    update : func() {
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
87
        if (me.group.getVisible() == 0)
add TCAS
Sébastien MARQUE authored on 2017-12-21
88
            return;
89
        me.group._node.getNode('ref-lat', 1).setDoubleValue(data.lat);
90
        me.group._node.getNode('ref-lon', 1).setDoubleValue(data.lon);
91
        me.group._node
92
            .getNode('range', 1).setDoubleValue(me.device.data['range-factor']);
93
        me._itemIndex = 0;
94
        foreach (var ac; data.tcas) {
95
            if (me._itemIndex >= me._itemCount) {
96
                append(me._item, TcasItemClass.new(me.group, me._itemIndex));
97
                me._itemCount += 1;
98
            }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
99
            me._item[me._itemIndex].setData(ac.lat, ac.lon, ac.alt, ac.vs, ac.level, ac.callsign);
add TCAS
Sébastien MARQUE authored on 2017-12-21
100
            me._itemIndex += 1;
101
        }
102
                
103
        for (; me._itemIndex < me._itemCount; me._itemIndex += 1) {
104
            me._item[me._itemIndex]._group.setVisible(0);
105
        }
106
    },
107

            
108
    setVisible : func (v) {
109
        me.group.setVisible(v);
110
    },
111
};
112
# }}}