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

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

            
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
49
            me._can.Arrow[vs > 0].setVisible(0);
add TCAS
Sébastien MARQUE authored on 2017-12-21
50
        }
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
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...
Sébastien MARQUE authored on 2021-04-12
57
            me._can.ThreadLevel[i]
58
                .setVisible(level == i);
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
59

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

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

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

            
add TCAS
Sébastien MARQUE authored on 2017-12-21
89
    update : func() {
traffic alert and display
Sébastien MARQUE authored on 2020-06-08
90
        if (me.group.getVisible() == 0)
add TCAS
Sébastien MARQUE authored on 2017-12-21
91
            return;
92
        me.group._node.getNode('ref-lat', 1).setDoubleValue(data.lat);
93
        me.group._node.getNode('ref-lon', 1).setDoubleValue(data.lon);
close issue with misplacing ...
Sébastien MARQUE authored on 2020-06-22
94
        me.group.setRange(me.device.data['range-nm']/2);
add TCAS
Sébastien MARQUE authored on 2017-12-21
95
        me._itemIndex = 0;
fix traffic display orientat...
Sébastien MARQUE authored on 2021-04-12
96
        var normOrientation = -me.device.data.orientation.map * D2R;
add TCAS
Sébastien MARQUE authored on 2017-12-21
97
        foreach (var ac; data.tcas) {
98
            if (me._itemIndex >= me._itemCount) {
99
                append(me._item, TcasItemClass.new(me.group, me._itemIndex));
100
                me._itemCount += 1;
101
            }
fix traffic display orientat...
Sébastien MARQUE authored on 2021-04-12
102
            me._item[me._itemIndex].setData(ac.lat, ac.lon, ac.alt, ac.vs, ac.level, ac.callsign, normOrientation);
add TCAS
Sébastien MARQUE authored on 2017-12-21
103
            me._itemIndex += 1;
104
        }
105
                
106
        for (; me._itemIndex < me._itemCount; me._itemIndex += 1) {
107
            me._item[me._itemIndex]._group.setVisible(0);
108
        }
109
    },
110

            
111
    setVisible : func (v) {
112
        me.group.setVisible(v);
113
    },
114
};
115
# }}}