zkv1000 / Nasal / maps / tcas.nas /
Newer Older
121 lines | 3.969kb
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

            
9
        canvas.parsesvg(m._group, data.zkv1000_reldir ~ "Systems/tcas.svg");
10
        m._can = {
11
            Alt : [
12
                m._group.getElementById("Alt_above").setVisible(0),
13
                m._group.getElementById("Alt_below").setVisible(0)
14
            ],
15
            Arrow : [
16
                m._group.getElementById("Arrow_climb").setVisible(0),
17
                m._group.getElementById("Arrow_descent").setVisible(0)
18
            ]
19
        };
20
        m._can.ThreadLevel = [];
21

            
22
        for (var i=0; i<4; i+=1)
23
            append(m._can.ThreadLevel,
24
                    m._group.getElementById("Thread_Level_" ~ i).setVisible(0));
25

            
26
        m._colors = [ '#00ffff', '#00ffff', '#ff7f2a', '#ff0000' ];
27

            
28
        return m;
29
    },
30

            
31
    setData : func(lat, lon, alt, vs, level) {
32
        me._group.setVisible(1);
33
        me._group.setGeoPosition(lat, lon);
34
        
35
        if (alt == 0) {
36
            me._can.Alt[0].setVisible(0);
37
            me._can.Alt[1].setVisible(0);
38
        }
39
        else {
40
            me._can.Alt[alt < 0]
41
                .setText(sprintf("%+i", alt))
42
                .set('fill', me._colors[level])
43
                .setVisible(1);
44

            
45
            me._can.Alt[alt > 0].setVisible(0);
46
        }
47
                
48
        if (vs >= -3 and vs <= 3) {
49
            me._can.Arrow[0].setVisible(0);
50
            me._can.Arrow[1].setVisible(0);
51
        }
52
        else {
53
            me._can.Arrow[vs < -3]
54
                .set('fill', me._colors[level])
55
                .set('stroke', me._colors[level])
56
                .setVisible(1);
57

            
58
            me._can.Arrow[vs > 3].setVisible(0);
59
        }
60
        
61
        me._can.ThreadLevel[0].setVisible(level == 0);
62
        me._can.ThreadLevel[1].setVisible(level == 1);
63
        me._can.ThreadLevel[2].setVisible(level == 2);
64
        me._can.ThreadLevel[3].setVisible(level == 3);
65
        me._group.set("z-index", level + 1);
66
    },
67
};
68
# }}} 
69

            
70
var MapTcas = {
71
# init TCAS layer and update {{{
72
    new : func(device, group) {
73
        var m = {parents:[MapTcas]}; 
74
        if (getprop('/instrumentation/tcas/serviceable') == nil) {
75
            m.update = func;
76
            m.setVisible = func;
77
        }
78
        else {
79
            m.device = device;
80
            m.visibility = 0;
81
            m.group = group.createChild('map', 'tcas')
82
                .setTranslation(
83
                    m.device.role == 'MFD' ? (m.device.data.mapview[0] + m.device.data.mapclip.left)/2 : 120,
84
                    m.device.role == 'MFD' ? 400 : 600)
85
                .setVisible(m.visibility);
86
            m._item      = [];
87
            m._itemIndex = 0;
88
            m._itemCount = 0;
89
# /instrumentation/tcas/inputs/mode
90
            m.MODE      = ["Normal","Above","Unlimited","Below"];
91
        }
92
        return m;
93
    },
94

            
95
    update : func() {
96
        if (me.device.data.tcas == 0)
97
            return;
98
        me.group._node.getNode('ref-lat', 1).setDoubleValue(data.lat);
99
        me.group._node.getNode('ref-lon', 1).setDoubleValue(data.lon);
100
        me.group._node
101
            .getNode('range', 1).setDoubleValue(me.device.data['range-factor']);
102
        me._itemIndex = 0;
103
        foreach (var ac; data.tcas) {
104
            if (me._itemIndex >= me._itemCount) {
105
                append(me._item, TcasItemClass.new(me.group, me._itemIndex));
106
                me._itemCount += 1;
107
            }
108
            me._item[me._itemIndex].setData(ac.lat, ac.lon, ac.alt, ac.vs, ac.level);
109
            me._itemIndex += 1;
110
        }
111
                
112
        for (; me._itemIndex < me._itemCount; me._itemIndex += 1) {
113
            me._item[me._itemIndex]._group.setVisible(0);
114
        }
115
    },
116

            
117
    setVisible : func (v) {
118
        me.group.setVisible(v);
119
    },
120
};
121
# }}}