Debian Codegraph @

Nasal/canvas/map/route.draw

raw
1 # WARNING: *.draw files will be deprecated, see: http://wiki.flightgear.org/MapStructure
2 ##
3 # Draw a route with tracks and waypoints
4 #
5
6 ## FIXME: encapsulate properly
7 var wp = [];
8 var text_wp = [];
9
10 # Change color of active waypoints
11 var updatewp = func(activeWp)
12 {
13 forindex(var i; wp) {
14 if(i == activeWp) {
15 wp[i].setColor(1,0,1);
16 #text_wp[i].setColor(1,0,1);
17 } else {
18 wp[i].setColor(1,1,1);
19 #text_wp[i].setColor(1,1,1);
20 }
21 }
22 };
23
24 var draw_route = func (group, theroute, controller=nil, lod=0)
25 {
26 #print("draw_route");
27 var route_group = group;
28
29 var route = route_group.createChild("path","route")
30 .setStrokeLineWidth(5)
31 .setColor(1,0,1)
32 .set("z-index",1);
33
34 var cmds = [];
35 var coords = [];
36
37 var fp = flightplan();
38 var fpSize = fp.getPlanSize();
39
40 wp = [];
41 text_wp = [];
42 setsize(wp,fpSize);
43 setsize(text_wp,fpSize);
44
45 # Retrieve route coordinates
46 for (var i=0; i<(fpSize); i += 1)
47 {
48 if (i == 0) {
49 var leg = fp.getWP(1);
50 var j = 0;
51 foreach (var pt; leg.path()) {
52 append(coords,"N"~pt.lat);
53 append(coords,"E"~pt.lon);
54 if (j==0){
55 append(cmds,2);
56 j=1;
57 } else
58 append(cmds,4);
59 }
60 canvas.drawwp(group, leg.path()[0].lat, leg.path()[0].lon, fp.getWP(0).alt_cstr, fp.getWP(0).wp_name, i, wp);
61 i+=1;
62 }
63 var leg = fp.getWP(i);
64 foreach (var pt; leg.path()) {
65 append(coords,"N"~pt.lat);
66 append(coords,"E"~pt.lon);
67 append(cmds,4);
68 }
69 canvas.drawwp(group, leg.path()[-1].lat, leg.path()[-1].lon, leg.alt_cstr, leg.wp_name, i, wp);
70 }
71
72 # Set Top Of Climb coordinate
73 canvas.drawprofile(route_group, "tc", "T/C");
74 # Set Top Of Descent coordinate
75 canvas.drawprofile(route_group, "td", "T/D");
76 # Set Step Climb coordinate
77 canvas.drawprofile(route_group, "sc", "S/C");
78 # Set Top Of Descent coordinate
79 canvas.drawprofile(route_group, "ed", "E/D");
80
81 # Update route coordinates
82 debug.dump(cmds);
83 debug.dump(coords);
84 route.setDataGeo(cmds, coords);
85 updatewp(getprop("/autopilot/route-manager/current-wp"));
86
87 }