Debian Codegraph @

gui/dialogs/checklist.xml

raw symbols SCIP
1 <?xml version="1.0"?>
2
3 <PropertyList>
4 <name>checklist</name>
5 <layout>vbox</layout>
6 <x>-5</x>
7 <y>5</y>
8 <default-padding>1</default-padding>
9
10 <color>
11 <alpha type="float">1.0</alpha>
12 </color>
13
14 <nasal>
15 <open><![CDATA[
16 var dlgRoot = cmdarg();
17 var dlgname = dlgRoot.getNode("name").getValue();
18
19
20 # Update the checklist-combo with appropriate set of checklists for
21 # the user to select from
22 var setChecklistGroup = func(group_name) {
23 var combo = gui.findElementByName(dlgRoot, "checklist-combo");
24 combo.removeChildren("value");
25 var idx = 0;
26
27 foreach (var name; checklist_group[group_name]) {
28 combo.getChild("value", idx, 1).setValue(name);
29 idx = idx + 1;
30 }
31
32 var checklist_name = checklist_group[group_name][0];
33
34 var pgs = checklist_size[checklist_name];
35 if (pgs == nil) pgs = 1;
36
37 setprop("/sim/gui/dialogs/checklist/selected-checklist-group", group_name);
38 setprop("/sim/gui/dialogs/checklist/selected-checklist-max-pages", pgs);
39 setprop("/sim/gui/dialogs/checklist/selected-page-text", "1 / " ~ pgs);
40 setprop("sim/gui/dialogs/checklist/selected-checklist", checklist_name);
41 gui.dialog_update("checklist", "checklist-combo", "checklist-table-group");
42 };
43
44 var groups = props.globals.getNode("/sim/checklists", 1).getChildren("group");
45 var checklists = props.globals.getNode("/sim/checklists", 1).getChildren("checklist");
46 var checklist_size = {};
47 var checklist_group = {};
48 var current_group = nil;
49
50 # Set up the list of groups so the user can select a group and then
51 # a checklist.
52 var groups = props.globals.getNode("/sim/checklists").getChildren("group");
53
54 if (size(groups) > 0) {
55 foreach (var grp; groups) {
56 var name = grp.getNode("name", 1).getValue();
57 var checks = grp.getChildren("checklist");
58 foreach (var chk; checks) {
59 var title = chk.getNode("title", 1).getValue();
60 if (current_group == nil) current_group = name;
61 append(checklists, chk);
62 if (checklist_group[name] == nil) checklist_group[name] = [];
63 append(checklist_group[name], title);
64 }
65 }
66 } else {
67 checklists = props.globals.getNode("/sim/checklists").getChildren("checklist");
68 foreach (var chk; checklists) {
69 var title = chk.getNode("title", 1).getValue();
70 var grp = "Standard";
71 var items = [];
72 if (find("emergency", string.lc(title)) != -1) {
73 grp = "EMERGENCY";
74 }
75
76 if (current_group == nil) current_group = grp;
77
78 if (checklist_group[grp] == nil) checklist_group[grp] = [];
79 append(checklist_group[grp], title);
80 }
81 }
82
83 if (size(checklists) > 0) {
84
85 var current_checklist = getprop("sim/gui/dialogs/checklist/selected-checklist");
86 if (current_checklist == nil) {
87 current_checklist = checklists[0].getNode("title", 1).getValue();
88 setprop("sim/gui/dialogs/checklist/selected-checklist", current_checklist);
89 setprop("sim/gui/dialogs/checklist/selected-page", 0);
90 }
91
92 foreach (var grp; keys(checklist_group)) {
93 foreach (chklist; checklist_group[grp]) {
94 if (chklist == current_checklist) {
95 setChecklistGroup(grp);
96 setprop("sim/gui/dialogs/checklist/selected-checklist", current_checklist);
97 }
98 }
99 }
100
101 var combo = gui.findElementByName(dlgRoot, "checklist-group-combo");
102 var idx = 0;
103
104 foreach (var grp_name; sort(keys(checklist_group), func(a,b){string.icmp(a,b)})) {
105 combo.getChild("value", idx, 1).setValue(grp_name);
106 idx = idx + 1;
107 }
108
109 dlgRoot.setValues({"dialog-name": dlgname, "object-name": "checklist-group-combo"});
110 fgcommand("dialog-update", dlgRoot);
111
112 var group = gui.findElementByName(dlgRoot, "checklist-table-group");
113
114 var table_count = 0;
115
116 forindex (var idx; checklists) {
117 var checklist_name = checklists[idx].getNode("title", 1).getValue();
118
119 # Checklist may consist of one or more pages.
120 var pages = checklists[idx].getChildren("page");
121
122 if (size(pages) == 0) {
123 # Or no pages at all, in which case we need to create a checklist of one page
124 append(pages, checklists[idx]);
125 }
126
127 checklist_size[checklist_name] = size(pages);
128
129 if (idx == 0) {
130
131 setprop("/sim/gui/dialogs/checklist/next-available", 1);
132 setprop("/sim/gui/dialogs/checklist/selected-checklist-max-pages", checklist_size[checklist_name]);
133 setprop("/sim/gui/dialogs/checklist/selected-page-text", "1 / " ~ checklist_size[checklist_name]);
134 }
135
136 forindex (var p; pages) {
137 var c = pages[p];
138 var row = 0;
139
140 # Set up a new table, only visible when this checklist is selected.
141 var table = group.getChild("group", table_count, 1);
142 table.getNode("row", 1).setValue(0);
143 table.getNode("col", 1).setValue(0);
144 table.getNode("default-padding", 1).setValue(4);
145 table.getNode("layout", 1).setValue("table");
146 table.getNode("valign", 1).setValue("top");
147
148 # Set up conditional to only display when the checklist is selected
149 # and the page is correct.
150 var vis = table.getNode("visible", 1).getNode("and", 1);
151 var e = vis.getChild("equals", 0, 1);
152 e.getNode("property", 1).setValue("sim/gui/dialogs/checklist/selected-checklist");
153 e.getNode("value", 1).setValue(checklists[idx].getNode("title").getValue());
154 e = vis.getChild("equals", 1, 1);
155 e.getNode("property", 1).setValue("sim/gui/dialogs/checklist/selected-page");
156 e.getNode("value", 1).setValue(p);
157
158 var items = c.getChildren("item");
159 var txtcount = 0;
160 var btncount = 0;
161
162 forindex (var i; items) {
163 var item = items[i];
164
165 var t = table.getChild("text", txtcount, 1);
166 txtcount += 1;
167
168 var values = item.getChildren("value");
169
170 if ((size(values) == 0) or (values[0].getValue() == "")) {
171 # Single name element with no values. Used as title
172 t.getNode("halign", 1).setValue("center");
173 t.getNode("row", 1).setValue(row);
174 t.getNode("col", 1).setValue(0);
175 t.getNode("colspan", 1).setValue(2);
176 t.getNode("label", 1).setValue(item.getNode("name", 1).getValue());
177 row = row + 1;
178 } else {
179 t.getNode("halign", 1).setValue("left");
180 t.getNode("row", 1).setValue(row);
181 t.getNode("col", 1).setValue(0);
182 t.getNode("label", 1).setValue(item.getNode("name", 1).getValue());
183
184 forindex (var v; values) {
185 var t = table.getChild("text", txtcount, 1);
186 txtcount += 1;
187 t.getNode("halign", 1).setValue("right");
188 t.getNode("row", 1).setValue(row);
189 if (v > 0) {
190 # The second row of values can overlap with the
191 # first column if required - helps keep the
192 # checklist dialog as compact as possible
193 t.getNode("col", 1).setValue(0);
194 t.getNode("colspan", 1).setValue(2);
195 } else {
196 t.getNode("col", 1).setValue(1);
197 }
198
199 if (isscalar(values[v].getValue())) {
200 t.getNode("label", 1).setValue(values[v].getValue());
201 } else {
202 t.getNode("label", 1).setValue("");
203 }
204
205 # If there's a complete node, it contains a condition
206 # that can be checked to ensure the checklist item is
207 # complete. We display this item in yellow while the
208 # condition is not met, and green once it is complete.
209
210 var condition = item.getNode("condition");
211
212 if (condition != nil) {
213 var vis = t.getNode("visible", 1).getNode("and", 1);
214 props.copy(condition, vis);
215 var c = t.getNode("color", 1);
216 c.getNode("red", 1).setValue(0.2);
217 c.getNode("green", 1).setValue(1.0);
218 c.getNode("blue", 1).setValue(0.2);
219
220
221 # Now create an amber version for when the condition
222 # is not met.
223 t = table.getChild("text", txtcount, 1);
224 txtcount += 1;
225
226 t.getNode("halign", 1).setValue("right");
227 t.getNode("row", 1).setValue(row);
228 if (v > 0) {
229 # The second row of values can overlap with the
230 # first column if required - helps keep the
231 # checklist dialog as compact as possible
232 t.getNode("col", 1).setValue(0);
233 t.getNode("colspan", 1).setValue(2);
234 } else {
235 t.getNode("col", 1).setValue(1);
236 }
237
238 t.getNode("label", 1).setValue(values[v].getValue());
239
240 c = t.getNode("color", 1);
241 c.getNode("red", 1).setValue(1.0);
242 c.getNode("green", 1).setValue(0.7);
243 c.getNode("blue", 1).setValue(0.2);
244
245 vis = t.getNode("visible", 1).getNode("not", 1).getNode("and", 1);
246 props.copy(condition, vis);
247 }
248
249 # If there is a marker node we display a small
250 # button that enables the marker.
251 var marker = item.getNode("marker");
252
253 if ((v == 0) and (marker != nil)) {
254 var s = marker.getNode("scale");
255 var scale = s != nil ? s.getValue() : 1;
256
257 var btn = table.getChild("button", btncount, 1);
258 btncount += 1;
259 btn.getNode("row", 1).setValue(row);
260 btn.getNode("col", 1).setValue(2);
261 btn.getNode("pref-width", 1).setValue(20);
262 btn.getNode("pref-height", 1).setValue(20);
263 btn.getNode("padding", 1).setValue(0);
264 btn.getNode("legend", 1).setValue("?");
265 var binding = btn.getNode("binding", 1);
266 binding.getNode("command", 1).setValue("nasal");
267 binding.getNode("script", 1).setValue(
268 "placeMarker(" ~ marker.getNode("x-m", 1).getValue() ~ ", " ~
269 marker.getNode("y-m", 1).getValue() ~ ", " ~
270 marker.getNode("z-m", 1).getValue() ~ ", " ~
271 scale ~ ");");
272 }
273
274 # If there's one or more binding nodes we display a
275 # small button that executes the binding. Used to
276 # demonstrate the checklist item
277 var bindings = item.getChildren("binding");
278
279 if ((v == 0) and (size(bindings) > 0)) {
280 var btn = table.getChild("button", btncount, 1);
281 btncount += 1;
282 btn.getNode("row", 1).setValue(row);
283 btn.getNode("col", 1).setValue(3);
284 btn.getNode("pref-width", 1).setValue(20);
285 btn.getNode("pref-height", 1).setValue(20);
286 btn.getNode("padding", 1).setValue(1);
287 btn.getNode("legend", 1).setValue(">");
288
289 forindex (var bdg; bindings) {
290 var binding = btn.getChild("binding", bdg, 1);
291 props.copy(bindings[bdg], binding);
292 }
293 }
294
295 row = row + 1;
296 }
297
298 table_count = table_count + 1;
299 }
300 }
301 }
302 }
303
304 var s = getprop("/sim/gui/dialogs/checklist/selected-checklist");
305 setprop("/sim/gui/dialogs/checklist/selected-checklist-max-pages", checklist_size[s]);
306 var currentPage = getprop("/sim/gui/dialogs/checklist/selected-page");
307 setprop("/sim/gui/dialogs/checklist/next-available", 1);
308 setprop("/sim/gui/dialogs/checklist/selected-page-text", (currentPage + 1) ~ " / " ~ checklist_size[s]);
309
310 } else {
311 var group = gui.findElementByName(dlgRoot, "checklist-table-group");
312 var table = group.getNode("text", 1);
313 table.getNode("row", 1).setValue(0);
314 table.getNode("col", 1).setValue(0);
315 table.getNode("default-padding", 1).setValue(4);
316 table.getNode("layout", 1).setValue("table");
317 table.getNode("valign", 1).setValue("top");
318 table.getNode("halign", 1).setValue("center");
319 table.getNode("label", 1).setValue("No checklists exist for this aircraft");
320 }
321
322 var placeMarker = func(x,y,z,scale) {
323 var markerN = props.globals.getNode("/sim/model/marker", 1);
324
325 markerN.setValues({
326 "x/value": x,
327 "y/value": y,
328 "z/value": z,
329 "scale/value": scale,
330 "arrow-enabled": 1,
331 });
332
333 # Determine offset to the marker.
334 var vx = getprop("/sim/current-view/x-offset-m"); # Left/right (+ve right)
335 var vy = getprop("/sim/current-view/y-offset-m"); # Up/Down (+ve up)
336 var vz = getprop("/sim/current-view/z-offset-m"); # Forward/backwards (+ve aft)
337
338 # BUT the marker has a different coordinate system!
339 # x = fore/aft (+ve aft)
340 # y = left/right (+ve right)
341 # z = up/down (+ve up)
342
343 # So we need to do a coordinate transformation as we calculate the angles
344 var hdg = math.atan2(y-vx, x-vz) * R2D + 180;
345 var pitch = math.atan2((z-vy), math.sqrt((x-vz)*(x-vz) + (y-vx)*(y-vx))) * R2D;
346
347 if (! ((hdg > 160) and (hdg < 200))) {
348 # Making the assumption we're in the cockpit, there are limits to where we can look
349 # that are enforced by the view system. So we can't look into the region of heading
350 # 160-200.
351 var v = props.Node.new();
352 v.setValues({
353 "heading-offset-deg" : hdg,
354 "pitch-offset-deg": pitch,
355 });
356 view.point.move(v);
357 }
358
359 };
360
361
362 var nextPage = func() {
363 var currentPage = getprop("/sim/gui/dialogs/checklist/selected-page");
364 var s = getprop("/sim/gui/dialogs/checklist/selected-checklist");
365
366 if (currentPage < (checklist_size[s] - 1)) {
367 setprop("/sim/gui/dialogs/checklist/selected-page", currentPage + 1);
368 }
369
370 if (currentPage == (checklist_size[s] - 2)) {
371 setprop("/sim/gui/dialogs/checklist/next-available", 0);
372 }
373
374 setprop("/sim/gui/dialogs/checklist/selected-page-text", (currentPage + 2) ~ " / " ~ checklist_size[s]);
375 };
376
377 var previousPage = func() {
378 var currentPage = getprop("/sim/gui/dialogs/checklist/selected-page");
379
380 if (currentPage > 0) {
381 setprop("/sim/gui/dialogs/checklist/selected-page", currentPage - 1);
382 }
383
384 setprop("/sim/gui/dialogs/checklist/next-available", 1);
385 setprop("/sim/gui/dialogs/checklist/selected-page-text", currentPage ~ " / " ~ checklist_size[s]);
386 };
387
388 var setTransparency = func(updateDialog){
389 var alpha = (getprop("/sim/gui/dialogs/checklist/transparent") or 0);
390 dlgRoot.getNode("color/alpha").setValue(1-alpha*0.3);
391 var n = props.Node.new({ "dialog-name": "checklist" });
392 if (updateDialog)
393 {
394 fgcommand("dialog-close", n);
395 fgcommand("dialog-show", n);
396 }
397 };
398 setTransparency(0);
399
400 ]]></open>
401
402 <close><![CDATA[
403 # Hide the marker.
404 setprop("/sim/model/marker/arrow-enabled", 0);
405 ]]></close>
406 </nasal>
407
408 <group>
409 <layout>hbox</layout>
410 <empty><stretch>1</stretch></empty>
411
412 <text>
413 <label>Aircraft Checklists</label>
414 </text>
415
416 <empty><stretch>true</stretch></empty>
417
418 <button>
419 <legend>X</legend>
420 <key>Esc</key>
421 <pref-width>20</pref-width>
422 <pref-height>20</pref-height>
423 <binding>
424 <command>dialog-close</command>
425 </binding>
426 </button>
427 </group>
428
429 <hrule/>
430
431 <group>
432 <layout>hbox</layout>
433
434 <!-- gap to left border -->
435 <!--text>
436 <halign>right</halign>
437 <label> </label>
438 </text-->
439
440 <text>
441 <halign>right</halign>
442 <label>Group:</label>
443 </text>
444
445 <combo>
446 <name>checklist-group-combo</name>
447 <property>/sim/gui/dialogs/checklist/selected-checklist-group</property>
448 <editable>false</editable>
449 <pref-width>130</pref-width>
450 <halign>fill</halign>
451 <binding>
452 <command>dialog-apply</command>
453 <object-name>checklist-group-combo</object-name>
454 </binding>
455 <binding>
456 <command>nasal</command>
457 <script>
458 var s = getprop("/sim/gui/dialogs/checklist/selected-checklist-group");
459 setChecklistGroup(s);
460 </script>
461 </binding>
462 </combo>
463
464 <text>
465 <halign>right</halign>
466 <label>Checklist:</label>
467 </text>
468
469 <combo>
470 <name>checklist-combo</name>
471 <property>/sim/gui/dialogs/checklist/selected-checklist</property>
472 <editable>false</editable>
473 <live>true</live>
474 <pref-width>180</pref-width>
475 <halign>fill</halign>
476 <binding>
477 <command>dialog-apply</command>
478 <object-name>checklist-combo</object-name>
479 </binding>
480 <binding>
481 <command>nasal</command>
482 <script>
483 var s = getprop("/sim/gui/dialogs/checklist/selected-checklist");
484
485 setprop("/sim/gui/dialogs/checklist/selected-checklist-max-pages", checklist_size[s]);
486 setprop("/sim/gui/dialogs/checklist/selected-page", 0);
487 setprop("/sim/gui/dialogs/checklist/next-available", 1);
488 setprop("/sim/gui/dialogs/checklist/selected-page-text", "1 / " ~ checklist_size[s]);
489
490 </script>
491 </binding>
492
493 </combo>
494
495 <!--empty><stretch>true</stretch></empty-->
496
497 <!-- gap to next element -->
498 <!--text>
499 <halign>right</halign>
500 <label> </label>
501 </text-->
502
503 <button>
504 <pref-width>90</pref-width>
505 <legend>Toggle marker</legend>
506 <binding>
507 <command>property-toggle</command>
508 <property>/sim/model/marker/arrow-enabled</property>
509 </binding>
510 </button>
511
512 <checkbox>
513 <label>Transparent</label>
514 <property>/sim/gui/dialogs/checklist/transparent</property>
515 <live>true</live>
516 <halign>right</halign>
517 <binding>
518 <command>dialog-apply</command>
519 </binding>
520 <binding>
521 <command>property-toggle</command>
522 </binding>
523 <binding>
524 <command>nasal</command>
525 <script>setTransparency(1);</script>
526 </binding>
527 <halign>right</halign>
528 </checkbox>
529 </group>
530
531 <hrule/>
532
533 <group>
534 <default-padding>4</default-padding>
535 <halign>fill</halign>
536 <layout>table</layout>
537 <name>checklist-table-group</name>
538 </group>
539
540 <group>
541 <default-padding>5</default-padding>
542 <halign>fill</halign>
543 <layout>hbox</layout>
544
545 <visible>
546 <greater-than>
547 <property>/sim/gui/dialogs/checklist/selected-checklist-max-pages</property>
548 <value>1</value>
549 </greater-than>
550 </visible>
551
552 <empty>
553 <stretch>true</stretch>
554 </empty>
555
556 <button>
557 <legend>Previous page</legend>
558 <pref-height>24</pref-height>
559 <equal>true</equal>
560 <enable>
561 <greater-than>
562 <property>/sim/gui/dialogs/checklist/selected-page</property>
563 <value>0</value>
564 </greater-than>
565 </enable>
566 <binding>
567 <command>nasal</command>
568 <script>previousPage();</script>
569 </binding>
570 </button>
571
572 <empty>
573 <stretch>true</stretch>
574 </empty>
575
576 <text>
577 <halign>center</halign>
578 <label>XX/XX</label>
579 <property>/sim/gui/dialogs/checklist/selected-page-text</property>
580 <live>true</live>
581 </text>
582
583 <empty>
584 <stretch>true</stretch>
585 </empty>
586
587 <button>
588 <legend>Next page</legend>
589 <equal>true</equal>
590 <pref-height>24</pref-height>
591 <enable>
592 <property>/sim/gui/dialogs/checklist/next-available</property>
593 <value>1</value>
594 </enable>
595 <binding>
596 <command>nasal</command>
597 <script>nextPage();</script>
598 </binding>
599 </button>
600
601 <empty>
602 <stretch>true</stretch>
603 </empty>
604
605 </group>
606
607 </PropertyList>