Tupolev Tu-154B-2 by Yurik and his team.
[fg:toms-fgdata.git] / Aircraft / tu154b / Dialogs / nav.xml
1 <?xml version="1.0"?>
2 <PropertyList>
3         
4         <name>nav</name>        
5         <layout>vbox</layout>
6         <resizable>true</resizable>
7         <draggable>true</draggable>
8         <nasal>
9                 
10                 <open>
11                         var route = props.globals.getNode("/autopilot/route-manager/route", 1);
12                         var point = { lat : 0.0, lon : 0.0, num: 1 };
13                         var beacon_node = props.globals.getNode("/tu154/systems/nvu-calc/beacons", 1);
14                         result = cmdarg().getNode("list");
15                         # convertor from deg.decimal to deg.minutes 
16                 var dec2min = func{
17                         var arg_copy = arg[0];
18
19                         if( arg_copy > 360.0  ) arg_copy -= 360.0;
20                         if( 0 > arg_copy  ) arg_copy += 360.0;
21                         var integer = int( arg_copy );
22                         var dec = arg_copy - integer;
23                         return integer + dec * 0.6;
24                         }
25                 var min2dec = func{
26                         var integer = int( arg[0] );
27                         var min = arg[0] - integer;
28                         return integer + min/0.6;
29                         }
30                 var nvu_calc = func{
31                         # empty coord object - for departure, destination and beacon waypoints
32                         var begin_wpt = geo.Coord.new();
33                         var end_wpt = geo.Coord.new();
34                         var beacon_wpt = geo.Coord.new();
35                         
36                         var wp = route.getChildren("wp");
37                         var bc = beacon_node.getChildren("beacon");
38                         var rtstr = "";
39                         var az_corr = 0.0;
40                         var total_dist = 0.0;
41                         
42                         var magvar_dep = num(getprop( "/tu154/systems/nvu-calc/magvar-dep" ));
43                         if( magvar_dep == nil ) magvar_dep = 0.0;
44                         
45                         var magvar_dest = num( getprop( "/tu154/systems/nvu-calc/magvar-dest" ) );
46                         if( magvar_dest == nil ) magvar_dest = 0.0;
47                         var magvar_dep_current = num( getprop( "/tu154/systems/nvu-calc/magvar-dep-current" ) );
48                         if( magvar_dep_current == nil ) magvar_dep_current = 0;
49                         if( magvar_dep_current ) magvar_dep = getprop("/environment/magnetic-variation-deg");
50                         
51                         setprop( "/tu154/systems/nvu-calc/magvar-dep", magvar_dep );
52                         setprop( "/tu154/systems/nvu-calc/magvar-dest", magvar_dest );
53                                 
54                         # This cycle count fork only!
55                         forindex (var i; wp) {
56                          if( i > 0 ) {
57                                 var id1 = wp[i-1].getNode("id").getValue();
58                                 # get route start coord 
59                                 begin_wpt.set_latlon ( 
60                         wp[i-1].getNode("latitude-deg").getValue(),
61                         wp[i-1].getNode("longitude-deg").getValue(), 0 );
62                         
63                                 var id2 = wp[i].getNode("id").getValue();
64                                 # route end
65                                 end_wpt.set_latlon ( 
66                                 wp[i].getNode("latitude-deg").getValue(),
67                                 wp[i].getNode("longitude-deg").getValue(), 0 );
68                                 
69                         # Calculate nav parameters:
70                         var dist = begin_wpt.distance_to( end_wpt )/1000.0;
71                         total_dist += dist;
72                         var zipu = begin_wpt.course_to( end_wpt );
73                         var ozipu = end_wpt.course_to( begin_wpt );
74                         var zpu = zipu + az_corr;# az_corr = zero for first route       
75                         az_corr += zipu - (ozipu - 180.0);
76 #                       if( az_corr > 360.0 ) az_corr -= 360.0;
77                         if( az_corr > 180.0 ) az_corr -= 360.0;
78                         if( -180.0 > az_corr ) az_corr += 360.0;
79
80                         }}
81                                 
82                         # Fork with mag variation
83                         var fork = magvar_dep - magvar_dest - az_corr;                  
84                         setprop( "/tu154/systems/nvu-calc/fork", fork );
85                         setprop( "/tu154/systems/nvu-calc/dist", total_dist );
86                                                         
87                         # clear list
88                         result.removeChildren("value");
89                         # This cycle count all nav parameters
90                         az_corr = 0.0;
91                         forindex (var i; wp) {
92                         if( i > 0 ) {
93                         var id1 = wp[i-1].getNode("id").getValue();
94                         # get route start coord 
95                         begin_wpt.set_latlon ( 
96                         wp[i-1].getNode("latitude-deg").getValue(),
97                         wp[i-1].getNode("longitude-deg").getValue(), 0 );
98                         
99                         var id2 = wp[i].getNode("id").getValue();
100                         # route end
101                         end_wpt.set_latlon ( 
102                         wp[i].getNode("latitude-deg").getValue(),
103                         wp[i].getNode("longitude-deg").getValue(), 0 );
104                         
105                         # Calculate nav parameters:
106                         var dist = begin_wpt.distance_to( end_wpt )/1000.0;
107                         var zipu = begin_wpt.course_to( end_wpt );
108                         var ozipu = end_wpt.course_to( begin_wpt );
109                         var zpu = zipu - magvar_dep + az_corr;# az_corr=zero for first route
110                         var current_az_corr = zipu - (ozipu - 180.0);
111                         az_corr += current_az_corr;
112                         if( az_corr > 360.0 ) az_corr -= 360.0;
113                         if( zpu > 360.0 ) zpu -= 360.0;
114                         rtstr = sprintf("%d: %s - %s S: %.1f km ZPUdep: %.2f' ZPUdest: %.2f'", 
115                         i, id1, id2, -dist, dec2min( zpu ), dec2min( zpu+fork ) );
116                         # find beacon by route ident
117                                 forindex (var j; bc ) 
118                                 {
119                                 if( bc[j].getNode("num").getValue() == i )
120                                   { # found beacon for current route
121                                   # load beacon coordinates
122                                   beacon_wpt.set_latlon( bc[j].getNode("lat").getValue(),
123                                         bc[j].getNode("lon").getValue(), 0 );
124                                   # Convert to orthodromic coordinates
125                                   var beacon_angle = end_wpt.course_to( beacon_wpt );
126                                   var beacon_dist = end_wpt.distance_to(beacon_wpt)/1000.0;
127                                   var uk = ozipu - 180.0;
128                                   if( 0.0 > uk ) uk += 360.0;
129                                   var s_beacon = beacon_dist * 
130                                         math.cos( (uk - beacon_angle)/57.2958 );
131                                   var z_beacon = beacon_dist * 
132                                   math.sin( (uk - beacon_angle)/57.2958 );
133                                   var uk_az_corrected =  uk;
134                                   if( current_az_corr > 360.0 ) current_az_corr -= 360.0;
135                                   if( -360.0 > current_az_corr ) current_az_corr += 360.0;
136                         if( dist ) uk_az_corrected = uk - current_az_corr * s_beacon / dist;
137                                         rtstr ~= sprintf(" Beacon S: %.1f km Z: %.1f km UK: %.2f'", s_beacon, -z_beacon, uk_az_corrected );
138                                         
139                                 }}
140                         result.getChild("value", i-1, 1).setValue(rtstr);
141                         }}
142                         
143                         fgcommand("dialog-update", props.Node.new({"object-name":"result", "dialog-name":"nav"}));      
144                         } # nvu_calc
145                         
146                         # Beacon staff
147                 var insert_beacon = func{
148                         point.lat = num( getprop("/tu154/systems/nvu-calc/lat") );
149                         if( point.lat == nil ) return; # drop point if empty
150                         point.lon = num( getprop("/tu154/systems/nvu-calc/lon") );
151                         if( point.lon == nil ) return;
152                         point.num = num( getprop("/tu154/systems/nvu-calc/num") );
153                         if( point.num == nil ) return;
154                         var minutes = num( getprop("/tu154/systems/nvu-calc/minutes") );
155                         if( minutes == nil ) minutes = 0;
156                         # check minutes after dec point and convert to dec
157                         if( minutes ) 
158                                 {
159                                 point.lat = min2dec( point.lat );
160                                 point.lon = min2dec( point.lon );
161                                 }
162                         # create new empty node 
163                         var beacon = beacon_node.getChild("beacon", size(beacon_node.getChildren("beacon")) ,1);
164                         # store coordinates
165                         beacon.setValues( point );
166                         }
167                         
168                 var remove_beacon = func{
169                         route_num = num( getprop("/tu154/systems/nvu-calc/num") );
170                         if( route_num == nil ) return;
171                         var bc = beacon_node.getChildren("beacon");
172                         forindex (var i; bc ) {
173                                 if( bc[i].getNode("num").getValue() == route_num ) 
174                                         beacon_node.removeChild("beacon", i);
175                                         }
176                         }
177                         
178                         
179                 </open>
180                 <close>
181
182                 </close>
183         </nasal>
184         <group>
185                 <layout>hbox</layout>
186                 <empty><stretch>1</stretch></empty>
187                 
188                 <text>
189                         <label>Navigation</label>
190                 </text>
191                 
192                 <empty><stretch>1</stretch></empty>
193                 
194                 <button>
195                         <pref-width>16</pref-width>
196                         <pref-height>16</pref-height>
197                         <legend></legend>
198                         <default>1</default>
199                         <keynum>27</keynum>
200                         <border>2</border>
201                         
202                         <binding>
203                                 <command>dialog-close</command>
204                         </binding>
205                 </button>
206         </group>
207         
208         <hrule/>
209         <list>
210                 <name>result</name>
211                 <halign>fill</halign>
212                 <valign>fill</valign>
213                 <stretch>true</stretch>
214                 <pref-height>260</pref-height>
215                 <property>/tu154/systems/nvu-calc/list</property>
216                 <binding>
217                         <command>dialog-apply</command>
218                         <object-name>result</object-name>
219                 </binding>
220         </list>
221 <!--    
222         <text>
223                 <label>-9.9999</label>
224                 <format> Selected: %s</format>
225                 <property>/tu154/systems/nvu-calc/list</property>
226         </text>
227 -->
228         <group>
229                 <layout>hbox</layout>
230                 <default-padding>4</default-padding>
231                 <text>
232                         <label>Departure mag var:</label>
233                 </text>
234                 
235                 
236                 <input>
237                         <name>input-magvar-dep</name>
238                         <!--<halign>fill</halign>-->
239                         <stretch>false</stretch>
240                         <pref-width>60</pref-width>
241                         <property>/tu154/systems/nvu-calc/magvar-dep</property>
242                 </input>
243                 <checkbox>
244                         <property>/tu154/systems/nvu-calc/magvar-dep-current</property>
245                 </checkbox>
246                 
247                 <text>
248                         <label>use current            </label>
249                 </text>
250                 <text>
251                         <label>Destination mag var:</label>
252                 </text>
253                 
254                 <input>
255                         <name>input-magvar-dest</name>
256                         <!--<halign>fill</halign>-->
257                         <stretch>false</stretch>
258                         <pref-width>60</pref-width>
259                         <property>/tu154/systems/nvu-calc/magvar-dest</property>
260                 </input>
261                 
262                 <text>
263                         <label>Virtual navigator:</label>
264                 </text>
265                 
266                 <checkbox>
267                         <property>/tu154/systems/nvu-calc/vn</property>
268                 </checkbox>
269
270         </group>
271         <group>
272                 <layout>hbox</layout>
273                 <default-padding>4</default-padding>
274                 
275                 <text>
276                         <label>-9.9999</label>
277                         <format> Fork: %-0.2f</format>
278                         <property>/tu154/systems/nvu-calc/fork</property>
279                 </text>
280                 <button>
281                         <legend>Apply fork</legend>
282                         <default>true</default>
283                         <pref-width>100</pref-width>
284                         <binding>
285                                 <command>dialog-apply</command>
286                         </binding>
287                         <binding>
288                                 <command>nasal</command>
289                                 <script>instruments.fork_loader()</script>
290                         </binding>
291                         <binding>
292                                 <command>dialog-update</command>
293                         </binding>
294                 </button>
295
296                 <button>
297                         <legend>Calculate</legend>
298                         <default>true</default>
299                         <pref-width>100</pref-width>
300                         <binding>
301                                 <command>dialog-apply</command>
302                         </binding>
303                         <binding>
304                                 <command>nasal</command>
305                                 <script>nvu_calc()</script>
306                         </binding>
307                         <binding>
308                                 <command>dialog-update</command>
309                         </binding>
310                         
311                 </button>
312                 
313                 <text>
314                         <label>9999999.9999999</label>
315                         <format> Dist: %-0.1f km</format>
316                         <property>/tu154/systems/nvu-calc/dist</property>
317                 </text>
318                 
319
320         </group>
321         
322         <hrule/>
323         <group>
324                 <layout>hbox</layout>
325                 <default-padding>4</default-padding>
326                 
327                 <text>
328                         <label>Beacon for route:</label>
329                 </text>
330                 
331                 
332                 <input>
333                         <name>input-num</name>
334                         <halign>fill</halign>
335                         <stretch>true</stretch>
336                         <pref-width>40</pref-width>
337                         <property>/tu154/systems/nvu-calc/num</property>
338                 </input>
339                 
340                 <text>
341                         <label>lat:</label>
342                 </text>
343                 
344                 <input>
345                         <name>input-lat</name>
346                         <halign>fill</halign>
347                         <stretch>true</stretch>
348                         <pref-width>80</pref-width>
349                         <property>/tu154/systems/nvu-calc/lat</property>
350                 </input>
351                 <text>
352                         <label>lon:</label>
353                 </text>
354
355                 <input>
356                         <name>input-lon</name>
357                         <halign>fill</halign>
358                         <stretch>true</stretch>
359                         <pref-width>80</pref-width>
360                         <property>/tu154/systems/nvu-calc/lon</property>
361                 </input>
362                 
363                 <checkbox>
364                         <property>/tu154/systems/nvu-calc/minutes</property>
365                 </checkbox>
366                 
367                 <text>
368                         <label>deg.min</label>
369                 </text>
370
371                 <button>
372                         <legend>Add</legend>
373                         <default>true</default>
374                         <pref-width>50</pref-width>
375                         <binding>
376                                 <command>dialog-apply</command>
377                         </binding>
378
379                         <binding>
380                                 <command>nasal</command>
381                                 <script>insert_beacon()</script>
382                         </binding>
383                         <binding>
384                                 <command>dialog-update</command>
385                         </binding>
386                 </button>
387                 <button>
388                         <legend>Del</legend>
389                         <default>true</default>
390                         <pref-width>50</pref-width>
391                         <binding>
392                                 <command>dialog-apply</command>
393                         </binding>
394                         
395                         <binding>
396                                 <command>nasal</command>
397                                 <script>remove_beacon()</script>
398                         </binding>
399                         <binding>
400                                 <command>dialog-update</command>
401                         </binding>
402                 </button>
403
404         </group>
405 <!--    
406         <group>
407                 <layout>hbox</layout>
408                 <default-padding>4</default-padding>
409                 <input>
410                         <name>input-tst</name>
411                         <halign>fill</halign>
412                         <stretch>true</stretch>
413                         <pref-width>80</pref-width>
414                         <property>/tu154/systems/nvu-calc/test</property>
415                 </input>
416
417                 <button>
418                         <legend>nav test</legend>
419                         <default>true</default>
420                         <pref-width>70</pref-width>
421                         <binding>
422                                 <command>dialog-apply</command>
423                         </binding>
424                         <binding>
425                                 <command>nasal</command>
426                                 <script>instruments.nvu_load();</script>
427                         </binding>
428                         <binding>
429                                 <command>dialog-update</command>
430                         </binding>
431                 </button>
432         </group>-->
433
434         
435   </PropertyList>