]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
#545: Fix ATC chatter sound settings being ignored
[flightgear.git] / src / Main / fg_commands.cxx
1 // fg_commands.cxx - internal FGFS commands.
2
3 #ifdef HAVE_CONFIG_H
4 #  include "config.h"
5 #endif
6
7 #include <string.h>             // strcmp()
8
9 #include <simgear/compiler.h>
10
11 #include <string>
12 #include <fstream>
13
14 #include <simgear/sg_inlines.h>
15 #include <simgear/debug/logstream.hxx>
16 #include <simgear/math/sg_random.h>
17 #include <simgear/scene/material/mat.hxx>
18 #include <simgear/scene/material/matlib.hxx>
19 #include <simgear/structure/exception.hxx>
20 #include <simgear/structure/commands.hxx>
21 #include <simgear/props/props.hxx>
22 #include <simgear/props/props_io.hxx>
23 #include <simgear/structure/event_mgr.hxx>
24 #include <simgear/sound/soundmgr_openal.hxx>
25 #include <simgear/timing/sg_time.hxx>
26
27 #include <Cockpit/panel.hxx>
28 #include <Cockpit/panel_io.hxx>
29 #include <FDM/flight.hxx>
30 #include <GUI/gui.h>
31 #include <GUI/new_gui.hxx>
32 #include <GUI/dialog.hxx>
33 #include <Aircraft/replay.hxx>
34 #include <Scenery/scenery.hxx>
35 #include <Scripting/NasalSys.hxx>
36 #include <Sound/sample_queue.hxx>
37 #include <Airports/xmlloader.hxx>
38 #include <ATC/CommStation.hxx>
39 #include <Navaids/navrecord.hxx>
40 #include <Navaids/navlist.hxx>
41
42 #include "fg_init.hxx"
43 #include "fg_io.hxx"
44 #include "fg_os.hxx"
45 #include "fg_commands.hxx"
46 #include "fg_props.hxx"
47 #include "globals.hxx"
48 #include "logger.hxx"
49 #include "util.hxx"
50 #include "viewmgr.hxx"
51 #include "main.hxx"
52 #include <Main/viewer.hxx>
53 #include <Environment/presets.hxx>
54
55 using std::string;
56 using std::ifstream;
57 using std::ofstream;
58
59
60 \f
61 ////////////////////////////////////////////////////////////////////////
62 // Static helper functions.
63 ////////////////////////////////////////////////////////////////////////
64
65
66 static inline SGPropertyNode *
67 get_prop (const SGPropertyNode * arg)
68 {
69     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
70 }
71
72 static inline SGPropertyNode *
73 get_prop2 (const SGPropertyNode * arg)
74 {
75     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
76 }
77
78
79 /**
80  * Get a double value and split it as required.
81  */
82 static void
83 split_value (double full_value, const char * mask,
84              double * unmodifiable, double * modifiable)
85 {
86     if (!strcmp("integer", mask)) {
87         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
88         *unmodifiable = full_value - *modifiable;
89     } else if (!strcmp("decimal", mask)) {
90         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
91         *modifiable = full_value - *unmodifiable;
92     } else {
93         if (strcmp("all", mask))
94             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
95                    << " assuming 'all'");
96         *unmodifiable = 0;
97         *modifiable = full_value;
98     }
99 }
100
101
102 /**
103  * Clamp or wrap a value as specified.
104  */
105 static void
106 limit_value (double * value, const SGPropertyNode * arg)
107 {
108     const SGPropertyNode * min_node = arg->getChild("min");
109     const SGPropertyNode * max_node = arg->getChild("max");
110
111     bool wrap = arg->getBoolValue("wrap");
112
113     if (min_node == 0 || max_node == 0)
114         wrap = false;
115   
116     if (wrap) {                 // wrap such that min <= x < max
117         double min_val = min_node->getDoubleValue();
118         double max_val = max_node->getDoubleValue();
119         double resolution = arg->getDoubleValue("resolution");
120         if (resolution > 0.0) {
121             // snap to (min + N*resolution), taking special care to handle imprecision
122             int n = (int)floor((*value - min_val) / resolution + 0.5);
123             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
124             SG_NORMALIZE_RANGE(n, 0, steps);
125             *value = min_val + resolution * n;
126         } else {
127             // plain circular wrapping
128             SG_NORMALIZE_RANGE(*value, min_val, max_val);
129         }
130     } else {                    // clamp such that min <= x <= max
131         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
132             *value = min_node->getDoubleValue();
133         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
134             *value = max_node->getDoubleValue();
135     }
136 }
137
138 static bool
139 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
140 {
141     switch (value1->getType()) {
142     case simgear::props::BOOL:
143         return (value1->getBoolValue() == value2->getBoolValue());
144     case simgear::props::INT:
145         return (value1->getIntValue() == value2->getIntValue());
146     case simgear::props::LONG:
147         return (value1->getLongValue() == value2->getLongValue());
148     case simgear::props::FLOAT:
149         return (value1->getFloatValue() == value2->getFloatValue());
150     case simgear::props::DOUBLE:
151         return (value1->getDoubleValue() == value2->getDoubleValue());
152     default:
153         return !strcmp(value1->getStringValue(), value2->getStringValue());
154     }
155 }
156
157
158 \f
159 ////////////////////////////////////////////////////////////////////////
160 // Command implementations.
161 ////////////////////////////////////////////////////////////////////////
162
163
164 /**
165  * Built-in command: do nothing.
166  */
167 static bool
168 do_null (const SGPropertyNode * arg)
169 {
170   return true;
171 }
172
173 /**
174  * Built-in command: run a Nasal script.
175  */
176 static bool
177 do_nasal (const SGPropertyNode * arg)
178 {
179     return ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(arg);
180 }
181
182 /**
183  * Built-in command: exit FlightGear.
184  *
185  * status: the exit status to return to the operating system (defaults to 0)
186  */
187 static bool
188 do_exit (const SGPropertyNode * arg)
189 {
190     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
191     fgSetBool("/sim/signals/exit", true);
192
193     if (fgGetBool("/sim/startup/save-on-exit")) {
194       SGPath autosaveFile(fgGetString("/sim/fg-home"));
195       autosaveFile.append( "autosave.xml" );
196       autosaveFile.create_dir( 0700 );
197       SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
198       try {
199         writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
200       } catch (const sg_exception &e) {
201         guiErrorMessage("Error writing autosave.xml: ", e);
202       }
203       
204       SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
205
206     }
207     
208     fgOSExit(arg->getIntValue("status", 0));
209     return true;
210 }
211
212
213 /**
214  * Reset FlightGear (Shift-Escape or Menu->File->Reset)
215  */
216 static bool
217 do_reset (const SGPropertyNode * arg)
218 {
219     fgReInitSubsystems();
220     return true;
221 }
222
223
224 /**
225  * Built-in command: reinitialize one or more subsystems.
226  *
227  * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
228  * none is specified, reinitialize all of them.
229  */
230 static bool
231 do_reinit (const SGPropertyNode * arg)
232 {
233     bool result = true;
234
235     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
236     if (subsystems.size() == 0) {
237         globals->get_subsystem_mgr()->reinit();
238     } else {
239         for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
240             const char * name = subsystems[i]->getStringValue();
241             SGSubsystem * subsystem = globals->get_subsystem(name);
242             if (subsystem == 0) {
243                 result = false;
244                 SG_LOG( SG_GENERAL, SG_ALERT,
245                         "Subsystem " << name << " not found" );
246             } else {
247                 subsystem->reinit();
248             }
249         }
250     }
251
252     globals->get_event_mgr()->reinit();
253
254     return result;
255 }
256
257 #if 0
258   //
259   // these routines look useful ??? but are never used in the code ???
260   //
261
262 /**
263  * Built-in command: suspend one or more subsystems.
264  *
265  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
266  */
267 static bool
268 do_suspend (const SGPropertyNode * arg)
269 {
270     bool result = true;
271
272     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
273     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
274         const char * name = subsystems[i]->getStringValue();
275         SGSubsystem * subsystem = globals->get_subsystem(name);
276         if (subsystem == 0) {
277             result = false;
278             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
279         } else {
280             subsystem->suspend();
281         }
282     }
283     return result;
284 }
285
286 /**
287  * Built-in command: suspend one or more subsystems.
288  *
289  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
290  */
291 static bool
292 do_resume (const SGPropertyNode * arg)
293 {
294     bool result = true;
295
296     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
297     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
298         const char * name = subsystems[i]->getStringValue();
299         SGSubsystem * subsystem = globals->get_subsystem(name);
300         if (subsystem == 0) {
301             result = false;
302             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
303         } else {
304             subsystem->resume();
305         }
306     }
307     return result;
308 }
309
310 #endif
311
312 /**
313  * Built-in command: replay the FDR buffer
314  */
315 static bool
316 do_replay (const SGPropertyNode * arg)
317 {
318     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
319     return r->start();
320 }
321
322 /**
323  * Built-in command: pause/unpause the sim
324  */
325 static bool
326 do_pause (const SGPropertyNode * arg)
327 {
328     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
329     if (paused && (fgGetInt("/sim/freeze/replay-state",0)>0))
330     {
331         do_replay(NULL);
332     }
333     else
334     {
335         fgSetBool("/sim/freeze/master",!paused);
336         fgSetBool("/sim/freeze/clock",!paused);
337     }
338     return true;
339 }
340
341 /**
342  * Built-in command: load flight.
343  *
344  * file (optional): the name of the file to load (relative to current
345  *   directory).  Defaults to "fgfs.sav"
346  */
347 static bool
348 do_load (const SGPropertyNode * arg)
349 {
350     string file = arg->getStringValue("file", "fgfs.sav");
351     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
352         file += ".sav";
353
354     if (!fgValidatePath(file.c_str(), false)) {
355         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
356                 "(unauthorized access)");
357         return false;
358     }
359
360     ifstream input(file.c_str());
361     if (input.good() && fgLoadFlight(input)) {
362         input.close();
363         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
364         return true;
365     } else {
366         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
367         return false;
368     }
369 }
370
371
372 /**
373  * Built-in command: save flight.
374  *
375  * file (optional): the name of the file to save (relative to the
376  * current directory).  Defaults to "fgfs.sav".
377  */
378 static bool
379 do_save (const SGPropertyNode * arg)
380 {
381     string file = arg->getStringValue("file", "fgfs.sav");
382     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
383         file += ".sav";
384
385     if (!fgValidatePath(file.c_str(), false)) {
386         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
387                 "(unauthorized access)");
388         return false;
389     }
390
391     bool write_all = arg->getBoolValue("write-all", false);
392     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
393     ofstream output(file.c_str());
394     if (output.good() && fgSaveFlight(output, write_all)) {
395         output.close();
396         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
397         return true;
398     } else {
399         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
400         return false;
401     }
402 }
403
404
405 /**
406  * Built-in command: (re)load the panel.
407  *
408  * path (optional): the file name to load the panel from 
409  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
410  * and if that's unspecified, to "Panels/Default/default.xml".
411  */
412 static bool
413 do_panel_load (const SGPropertyNode * arg)
414 {
415   string panel_path =
416     arg->getStringValue("path", fgGetString("/sim/panel/path"));
417   if (panel_path.empty()) {
418     return false;
419   }
420   
421   FGPanel * new_panel = fgReadPanel(panel_path);
422   if (new_panel == 0) {
423     SG_LOG(SG_INPUT, SG_ALERT,
424            "Error reading new panel from " << panel_path);
425     return false;
426   }
427   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
428   globals->get_current_panel()->unbind();
429   delete globals->get_current_panel();
430   globals->set_current_panel( new_panel );
431   globals->get_current_panel()->bind();
432   return true;
433 }
434
435
436 /**
437  * Built-in command: pass a mouse click to the panel.
438  *
439  * button: the mouse button number, zero-based.
440  * is-down: true if the button is down, false if it is up.
441  * x-pos: the x position of the mouse click.
442  * y-pos: the y position of the mouse click.
443  */
444 static bool
445 do_panel_mouse_click (const SGPropertyNode * arg)
446 {
447   if (globals->get_current_panel() != 0)
448     return globals->get_current_panel()
449       ->doMouseAction(arg->getIntValue("button"),
450                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
451                       arg->getIntValue("x-pos"),
452                       arg->getIntValue("y-pos"));
453   else
454     return false;
455 }
456
457
458 /**
459  * Built-in command: (re)load preferences.
460  *
461  * path (optional): the file name to load the panel from (relative
462  * to FG_ROOT). Defaults to "preferences.xml".
463  */
464 static bool
465 do_preferences_load (const SGPropertyNode * arg)
466 {
467   try {
468     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
469                 globals->get_props());
470   } catch (const sg_exception &e) {
471     guiErrorMessage("Error reading global preferences: ", e);
472     return false;
473   }
474   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
475   return true;
476 }
477
478 static void
479 do_view_next( bool )
480 {
481     globals->get_current_view()->setHeadingOffset_deg(0.0);
482     globals->get_viewmgr()->next_view();
483 }
484
485 static void
486 do_view_prev( bool )
487 {
488     globals->get_current_view()->setHeadingOffset_deg(0.0);
489     globals->get_viewmgr()->prev_view();
490 }
491
492 /**
493  * Built-in command: cycle view.
494  */
495 static bool
496 do_view_cycle (const SGPropertyNode * arg)
497 {
498   globals->get_current_view()->setHeadingOffset_deg(0.0);
499   globals->get_viewmgr()->next_view();
500   return true;
501 }
502
503 /**
504  * Built-in command: capture screen.
505  */
506 static bool
507 do_screen_capture (const SGPropertyNode * arg)
508 {
509   return fgDumpSnapShot();
510 }
511
512 static bool
513 do_reload_shaders (const SGPropertyNode*)
514 {
515     simgear::reload_shaders();
516     return true;
517 }
518
519 static bool
520 do_dump_scene_graph (const SGPropertyNode*)
521 {
522     fgDumpSceneGraph();
523     return true;
524 }
525
526 static bool
527 do_dump_terrain_branch (const SGPropertyNode*)
528 {
529     fgDumpTerrainBranch();
530
531     double lon_deg = fgGetDouble("/position/longitude-deg");
532     double lat_deg = fgGetDouble("/position/latitude-deg");
533     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
534     SGVec3d zero = SGVec3d::fromGeod(geodPos);
535
536     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
537     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
538     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
539
540     return true;
541 }
542
543 static bool
544 do_print_visible_scene_info(const SGPropertyNode*)
545 {
546     fgPrintVisibleSceneInfoCommand();
547     return true;
548 }
549
550 /**
551  * Built-in command: hires capture screen.
552  */
553 static bool
554 do_hires_screen_capture (const SGPropertyNode * arg)
555 {
556   fgHiResDump();
557   return true;
558 }
559
560
561 /**
562  * Reload the tile cache.
563  */
564 static bool
565 do_tile_cache_reload (const SGPropertyNode * arg)
566 {
567     static const SGPropertyNode *master_freeze
568         = fgGetNode("/sim/freeze/master");
569     bool freeze = master_freeze->getBoolValue();
570     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
571     if ( !freeze ) {
572         fgSetBool("/sim/freeze/master", true);
573     }
574
575     globals->get_subsystem("tile-manager")->reinit();
576
577     if ( !freeze ) {
578         fgSetBool("/sim/freeze/master", false);
579     }
580     return true;
581 }
582
583
584 #if 0
585 These do_set_(some-environment-parameters) are deprecated and no longer 
586 useful/functional - Torsten Dreyer, January 2011
587 /**
588  * Set the sea level outside air temperature and assigning that to all
589  * boundary and aloft environment layers.
590  */
591 static bool
592 do_set_sea_level_degc ( double temp_sea_level_degc)
593 {
594     SGPropertyNode *node, *child;
595
596     // boundary layers
597     node = fgGetNode( "/environment/config/boundary" );
598     if ( node != NULL ) {
599       int i = 0;
600       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
601         child->setDoubleValue( "temperature-sea-level-degc",
602                                temp_sea_level_degc );
603         ++i;
604       }
605     }
606
607     // aloft layers
608     node = fgGetNode( "/environment/config/aloft" );
609     if ( node != NULL ) {
610       int i = 0;
611       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
612         child->setDoubleValue( "temperature-sea-level-degc",
613                                temp_sea_level_degc );
614         ++i;
615       }
616     }
617
618     return true;
619 }
620
621 static bool
622 do_set_sea_level_degc (const SGPropertyNode * arg)
623 {
624     return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
625 }
626
627
628 /**
629  * Set the outside air temperature at the "current" altitude by first
630  * calculating the corresponding sea level temp, and assigning that to
631  * all boundary and aloft environment layers.
632  */
633 static bool
634 do_set_oat_degc (const SGPropertyNode * arg)
635 {
636     double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
637     // check for an altitude specified in the arguments, otherwise use
638     // current aircraft altitude.
639     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
640     if ( altitude_ft == NULL ) {
641         altitude_ft = fgGetNode("/position/altitude-ft");
642     }
643
644     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
645     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
646     dummy.set_temperature_degc( oat_degc );
647     return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
648 }
649
650 /**
651  * Set the sea level outside air dewpoint and assigning that to all
652  * boundary and aloft environment layers.
653  */
654 static bool
655 do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
656 {
657
658     SGPropertyNode *node, *child;
659
660     // boundary layers
661     node = fgGetNode( "/environment/config/boundary" );
662     if ( node != NULL ) {
663       int i = 0;
664       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
665         child->setDoubleValue( "dewpoint-sea-level-degc",
666                                dewpoint_sea_level_degc );
667         ++i;
668       }
669     }
670
671     // aloft layers
672     node = fgGetNode( "/environment/config/aloft" );
673     if ( node != NULL ) {
674       int i = 0;
675       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
676         child->setDoubleValue( "dewpoint-sea-level-degc",
677                                dewpoint_sea_level_degc );
678         ++i;
679       }
680     }
681
682     return true;
683 }
684
685 static bool
686 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
687 {
688     return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
689 }
690
691 /**
692  * Set the outside air dewpoint at the "current" altitude by first
693  * calculating the corresponding sea level dewpoint, and assigning
694  * that to all boundary and aloft environment layers.
695  */
696 static bool
697 do_set_dewpoint_degc (const SGPropertyNode * arg)
698 {
699     double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
700
701     // check for an altitude specified in the arguments, otherwise use
702     // current aircraft altitude.
703     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
704     if ( altitude_ft == NULL ) {
705         altitude_ft = fgGetNode("/position/altitude-ft");
706     }
707
708     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
709     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
710     dummy.set_dewpoint_degc( dewpoint_degc );
711     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
712 }
713 #endif
714
715 /**
716  * Built-in command: toggle a bool property value.
717  *
718  * property: The name of the property to toggle.
719  */
720 static bool
721 do_property_toggle (const SGPropertyNode * arg)
722 {
723   SGPropertyNode * prop = get_prop(arg);
724   return prop->setBoolValue(!prop->getBoolValue());
725 }
726
727
728 /**
729  * Built-in command: assign a value to a property.
730  *
731  * property: the name of the property to assign.
732  * value: the value to assign; or
733  * property[1]: the property to copy from.
734  */
735 static bool
736 do_property_assign (const SGPropertyNode * arg)
737 {
738   SGPropertyNode * prop = get_prop(arg);
739   const SGPropertyNode * value = arg->getNode("value");
740
741   if (value != 0)
742       return prop->setUnspecifiedValue(value->getStringValue());
743   else
744   {
745       const SGPropertyNode * prop2 = get_prop2(arg);
746       if (prop2)
747           return prop->setUnspecifiedValue(prop2->getStringValue());
748       else
749           return false;
750   }
751 }
752
753
754 /**
755  * Built-in command: increment or decrement a property value.
756  *
757  * If the 'step' argument is present, it will be used; otherwise,
758  * the command uses 'offset' and 'factor', usually from the mouse.
759  *
760  * property: the name of the property to increment or decrement.
761  * step: the amount of the increment or decrement (default: 0).
762  * offset: offset from the current setting (used for the mouse; multiplied 
763  *         by factor)
764  * factor: scaling amount for the offset (defaults to 1).
765  * min: the minimum allowed value (default: no minimum).
766  * max: the maximum allowed value (default: no maximum).
767  * mask: 'integer' to apply only to the left of the decimal point, 
768  *       'decimal' to apply only to the right of the decimal point,
769  *       or 'all' to apply to the whole number (the default).
770  * wrap: true if the value should be wrapped when it passes min or max;
771  *       both min and max must be present for this to work (default:
772  *       false).
773  */
774 static bool
775 do_property_adjust (const SGPropertyNode * arg)
776 {
777   SGPropertyNode * prop = get_prop(arg);
778
779   double amount = 0;
780   if (arg->hasValue("step"))
781       amount = arg->getDoubleValue("step");
782   else
783       amount = (arg->getDoubleValue("factor", 1)
784                 * arg->getDoubleValue("offset"));
785           
786   double unmodifiable, modifiable;
787   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
788               &unmodifiable, &modifiable);
789   modifiable += amount;
790   limit_value(&modifiable, arg);
791
792   prop->setDoubleValue(unmodifiable + modifiable);
793
794   return true;
795 }
796
797
798 /**
799  * Built-in command: multiply a property value.
800  *
801  * property: the name of the property to multiply.
802  * factor: the amount by which to multiply.
803  * min: the minimum allowed value (default: no minimum).
804  * max: the maximum allowed value (default: no maximum).
805  * mask: 'integer' to apply only to the left of the decimal point, 
806  *       'decimal' to apply only to the right of the decimal point,
807  *       or 'all' to apply to the whole number (the default).
808  * wrap: true if the value should be wrapped when it passes min or max;
809  *       both min and max must be present for this to work (default:
810  *       false).
811  */
812 static bool
813 do_property_multiply (const SGPropertyNode * arg)
814 {
815   SGPropertyNode * prop = get_prop(arg);
816   double factor = arg->getDoubleValue("factor", 1);
817
818   double unmodifiable, modifiable;
819   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
820               &unmodifiable, &modifiable);
821   modifiable *= factor;
822   limit_value(&modifiable, arg);
823
824   prop->setDoubleValue(unmodifiable + modifiable);
825
826   return true;
827 }
828
829
830 /**
831  * Built-in command: swap two property values.
832  *
833  * property[0]: the name of the first property.
834  * property[1]: the name of the second property.
835  */
836 static bool
837 do_property_swap (const SGPropertyNode * arg)
838 {
839   SGPropertyNode * prop1 = get_prop(arg);
840   SGPropertyNode * prop2 = get_prop2(arg);
841
842                                 // FIXME: inefficient
843   const string & tmp = prop1->getStringValue();
844   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
845           prop2->setUnspecifiedValue(tmp.c_str()));
846 }
847
848
849 /**
850  * Built-in command: Set a property to an axis or other moving input.
851  *
852  * property: the name of the property to set.
853  * setting: the current input setting, usually between -1.0 and 1.0.
854  * offset: the offset to shift by, before applying the factor.
855  * factor: the factor to multiply by (use negative to reverse).
856  */
857 static bool
858 do_property_scale (const SGPropertyNode * arg)
859 {
860   SGPropertyNode * prop = get_prop(arg);
861   double setting = arg->getDoubleValue("setting");
862   double offset = arg->getDoubleValue("offset", 0.0);
863   double factor = arg->getDoubleValue("factor", 1.0);
864   bool squared = arg->getBoolValue("squared", false);
865   int power = arg->getIntValue("power", (squared ? 2 : 1));
866
867   int sign = (setting < 0 ? -1 : 1);
868
869   switch (power) {
870   case 1:
871       break;
872   case 2:
873       setting = setting * setting * sign;
874       break;
875   case 3:
876       setting = setting * setting * setting;
877       break;
878   case 4:
879       setting = setting * setting * setting * setting * sign;
880       break;
881   default:
882       setting =  pow(setting, power);
883       if ((power % 2) == 0)
884           setting *= sign;
885       break;
886   }
887
888   return prop->setDoubleValue((setting + offset) * factor);
889 }
890
891
892 /**
893  * Built-in command: cycle a property through a set of values.
894  *
895  * If the current value isn't in the list, the cycle will
896  * (re)start from the beginning.
897  *
898  * property: the name of the property to cycle.
899  * value[*]: the list of values to cycle through.
900  */
901 static bool
902 do_property_cycle (const SGPropertyNode * arg)
903 {
904     SGPropertyNode * prop = get_prop(arg);
905     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
906     int selection = -1;
907     int nSelections = values.size();
908
909     if (nSelections < 1) {
910         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
911         return false;
912     }
913
914                                 // Try to find the current selection
915     for (int i = 0; i < nSelections; i++) {
916         if (compare_values(prop, values[i])) {
917             selection = i + 1;
918             break;
919         }
920     }
921
922                                 // Default or wrap to the first selection
923     if (selection < 0 || selection >= nSelections)
924         selection = 0;
925
926     prop->setUnspecifiedValue(values[selection]->getStringValue());
927     return true;
928 }
929
930
931 /**
932  * Built-in command: randomize a numeric property value.
933  *
934  * property: the name of the property value to randomize.
935  * min: the minimum allowed value.
936  * max: the maximum allowed value.
937  */
938 static bool
939 do_property_randomize (const SGPropertyNode * arg)
940 {
941     SGPropertyNode * prop = get_prop(arg);
942     double min = arg->getDoubleValue("min", DBL_MIN);
943     double max = arg->getDoubleValue("max", DBL_MAX);
944     prop->setDoubleValue(sg_random() * (max - min) + min);
945     return true;
946 }
947
948
949 /**
950  * Built-in command: reinit the data logging system based on the
951  * current contents of the /logger tree.
952  */
953 static bool
954 do_data_logging_commit (const SGPropertyNode * arg)
955 {
956     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
957     log->reinit();
958     return true;
959 }
960
961 /**
962  * Built-in command: Add a dialog to the GUI system.  Does *not*
963  * display the dialog.  The property node should have the same format
964  * as a dialog XML configuration.  It must include:
965  *
966  * name: the name of the GUI dialog for future reference.
967  */
968 static bool
969 do_dialog_new (const SGPropertyNode * arg)
970 {
971     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
972
973     // Note the casting away of const: this is *real*.  Doing a
974     // "dialog-apply" command later on will mutate this property node.
975     // I'm not convinced that this isn't the Right Thing though; it
976     // allows client to create a node, pass it to dialog-new, and get
977     // the values back from the dialog by reading the same node.
978     // Perhaps command arguments are not as "const" as they would
979     // seem?
980     gui->newDialog((SGPropertyNode*)arg);
981     return true;
982 }
983
984 /**
985  * Built-in command: Show an XML-configured dialog.
986  *
987  * dialog-name: the name of the GUI dialog to display.
988  */
989 static bool
990 do_dialog_show (const SGPropertyNode * arg)
991 {
992     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
993     gui->showDialog(arg->getStringValue("dialog-name"));
994     return true;
995 }
996
997
998 /**
999  * Built-in Command: Hide the active XML-configured dialog.
1000  */
1001 static bool
1002 do_dialog_close (const SGPropertyNode * arg)
1003 {
1004     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1005     if(arg->hasValue("dialog-name"))
1006         return gui->closeDialog(arg->getStringValue("dialog-name"));
1007     return gui->closeActiveDialog();
1008 }
1009
1010
1011 /**
1012  * Update a value in the active XML-configured dialog.
1013  *
1014  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1015  */
1016 static bool
1017 do_dialog_update (const SGPropertyNode * arg)
1018 {
1019     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1020     FGDialog * dialog;
1021     if (arg->hasValue("dialog-name"))
1022         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1023     else
1024         dialog = gui->getActiveDialog();
1025
1026     if (dialog != 0) {
1027         dialog->updateValues(arg->getStringValue("object-name"));
1028         return true;
1029     } else {
1030         return false;
1031     }
1032 }
1033
1034 static bool
1035 do_open_browser (const SGPropertyNode * arg)
1036 {
1037     string path;
1038     if (arg->hasValue("path"))
1039         path = arg->getStringValue("path");
1040     else
1041     if (arg->hasValue("url"))
1042         path = arg->getStringValue("url");
1043     else
1044         return false;
1045
1046     return openBrowser(path);
1047 }
1048
1049 /**
1050  * Apply a value in the active XML-configured dialog.
1051  *
1052  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1053  */
1054 static bool
1055 do_dialog_apply (const SGPropertyNode * arg)
1056 {
1057     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1058     FGDialog * dialog;
1059     if (arg->hasValue("dialog-name"))
1060         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1061     else
1062         dialog = gui->getActiveDialog();
1063
1064     if (dialog != 0) {
1065         dialog->applyValues(arg->getStringValue("object-name"));
1066         return true;
1067     } else {
1068         return false;
1069     }
1070 }
1071
1072
1073 /**
1074  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1075  * unlike reinit().
1076  */
1077 static bool
1078 do_gui_redraw (const SGPropertyNode * arg)
1079 {
1080     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1081     gui->redraw();
1082     return true;
1083 }
1084
1085
1086 /**
1087  * Adds model to the scenery. The path to the added branch (/models/model[*])
1088  * is returned in property "property".
1089  */
1090 static bool
1091 do_add_model (const SGPropertyNode * arg)
1092 {
1093     SGPropertyNode * model = fgGetNode("models", true);
1094     int i;
1095     for (i = 0; model->hasChild("model",i); i++);
1096     model = model->getChild("model", i, true);
1097     copyProperties(arg, model);
1098     if (model->hasValue("elevation-m"))
1099         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1100                 * SG_METER_TO_FEET);
1101     model->getNode("load", true);
1102     model->removeChildren("load");
1103     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1104     return true;
1105 }
1106
1107
1108 /**
1109  * Set mouse cursor coordinates and cursor shape.
1110  */
1111 static bool
1112 do_set_cursor (const SGPropertyNode * arg)
1113 {
1114     if (arg->hasValue("x") || arg->hasValue("y")) {
1115         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1116         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1117         int x = arg->getIntValue("x", mx->getIntValue());
1118         int y = arg->getIntValue("y", my->getIntValue());
1119         fgWarpMouse(x, y);
1120         mx->setIntValue(x);
1121         my->setIntValue(y);
1122     }
1123
1124     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1125     if (cursor->getType() != simgear::props::NONE)
1126         fgSetMouseCursor(cursor->getIntValue());
1127
1128     cursor->setIntValue(fgGetMouseCursor());
1129     return true;
1130 }
1131
1132
1133 /**
1134  * Built-in command: play an audio message (i.e. a wav file) This is
1135  * fire and forget.  Call this once per message and it will get dumped
1136  * into a queue.  Messages are played sequentially so they do not
1137  * overlap.
1138  */
1139 static bool
1140 do_play_audio_sample (const SGPropertyNode * arg)
1141 {
1142     string path = arg->getStringValue("path");
1143     string file = arg->getStringValue("file");
1144     float volume = arg->getFloatValue("volume");
1145     // cout << "playing " << path << " / " << file << endl;
1146     try {
1147         static FGSampleQueue *queue = 0;
1148         if ( !queue ) {
1149            SGSoundMgr *smgr = globals->get_soundmgr();
1150            queue = new FGSampleQueue(smgr, "chatter");
1151            queue->tie_to_listener();
1152         }
1153
1154         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1155         msg->set_volume( volume );
1156         queue->add( msg );
1157
1158         return true;
1159
1160     } catch (const sg_io_exception&) {
1161         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1162                 "failed to load" << path << '/' << file);
1163         return false;
1164     }
1165 }
1166
1167 /**
1168  * Built-in command: commit presets (read from in /sim/presets/)
1169  */
1170 static bool
1171 do_presets_commit (const SGPropertyNode * arg)
1172 {
1173     if (fgGetBool("/sim/initialized", false)) {
1174       fgReInitSubsystems();
1175     } else {
1176       // Nasal can trigger this during initial init, which confuses
1177       // the logic in ReInitSubsystems, since initial state has not been
1178       // saved at that time. Short-circuit everything here.
1179       fgInitPosition();
1180     }
1181     
1182     return true;
1183 }
1184
1185 /**
1186  * Built-in command: set log level (0 ... 7)
1187  */
1188 static bool
1189 do_log_level (const SGPropertyNode * arg)
1190 {
1191    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1192
1193    return true;
1194 }
1195
1196 /*
1197 static bool
1198 do_decrease_visibility (const SGPropertyNode * arg)
1199 {
1200     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1201     return true;
1202 }
1203  
1204 static bool
1205 do_increase_visibility (const SGPropertyNode * arg)
1206 {
1207     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1208     return true;
1209 }
1210 */
1211 /**
1212  * An fgcommand to allow loading of xml files via nasal,
1213  * the xml file's structure will be made available within
1214  * a property tree node defined under argument "targetnode",
1215  * or in the given argument tree under "data" otherwise.
1216  *
1217  * @param filename a string to hold the complete path & filename of an XML file
1218  * @param targetnode a string pointing to a location within the property tree
1219  * where to store the parsed XML file. If <targetnode> is undefined, then the
1220  * file contents are stored under a node <data> in the argument tree.
1221  */
1222
1223 static bool
1224 do_load_xml_to_proptree(const SGPropertyNode * arg)
1225 {
1226     SGPath file(arg->getStringValue("filename"));
1227     if (file.str().empty())
1228         return false;
1229
1230     if (file.extension() != "xml")
1231         file.concat(".xml");
1232     
1233     std::string icao = arg->getStringValue("icao");
1234     if (icao.empty()) {
1235         if (file.isRelative()) {
1236           SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
1237           if (!absPath.isNull())
1238               file = absPath;
1239           else
1240           {
1241               SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"  
1242                           << file.str() << "'.");
1243               return false;
1244           }
1245         }
1246     } else {
1247         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
1248           SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
1249             << file.str() << " at ICAO:" << icao);
1250           return false;
1251         }
1252     }
1253     
1254     if (!fgValidatePath(file.c_str(), false)) {
1255         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1256                 "(unauthorized access)");
1257         return false;
1258     }
1259
1260     SGPropertyNode *targetnode;
1261     if (arg->hasValue("targetnode"))
1262         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1263     else
1264         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1265
1266     try {
1267         readProperties(file.c_str(), targetnode, true);
1268     } catch (const sg_exception &e) {
1269         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1270         return false;
1271     }
1272
1273     return true;
1274 }
1275
1276
1277 /**
1278  * An fgcommand to allow saving of xml files via nasal,
1279  * the file's structure will be determined based on what's
1280  * encountered in the passed (source) property tree node
1281  *
1282  * @param filename a string to hold the complete path & filename of the (new)
1283  * XML file
1284  * @param sourcenode a string pointing to a location within the property tree
1285  * where to find the nodes that should be written recursively into an XML file
1286  * @param data if no sourcenode is given, then the file contents are taken from
1287  * the argument tree's "data" node.
1288  */
1289
1290 static bool
1291 do_save_xml_from_proptree(const SGPropertyNode * arg)
1292 {
1293     SGPath file(arg->getStringValue("filename"));
1294     if (file.str().empty())
1295         return false;
1296
1297     if (file.extension() != "xml")
1298         file.concat(".xml");
1299
1300     if (!fgValidatePath(file.c_str(), true)) {
1301         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1302                 "(unauthorized access)");
1303         return false;
1304     }
1305
1306     SGPropertyNode *sourcenode;
1307     if (arg->hasValue("sourcenode"))
1308         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1309     else if (arg->getNode("data", false))
1310         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1311     else
1312         return false;
1313
1314     try {
1315         writeProperties (file.c_str(), sourcenode, true);
1316     } catch (const sg_exception &e) {
1317         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1318         return false;
1319     }
1320
1321     return true;
1322 }
1323
1324 static bool
1325 do_press_cockpit_button (const SGPropertyNode *arg)
1326 {
1327   const char *prefix = arg->getStringValue("prefix");
1328
1329   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1330     return true;
1331
1332   string prop = string(prefix) + "-button";
1333   double value;
1334
1335   if (arg->getBoolValue("latching"))
1336     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1337   else
1338     value = 1;
1339
1340   fgSetDouble(prop.c_str(), value);
1341   fgSetBool(arg->getStringValue("discrete"), value > 0);
1342
1343   return true;
1344 }
1345
1346 static bool
1347 do_release_cockpit_button (const SGPropertyNode *arg)
1348 {
1349   const char *prefix = arg->getStringValue("prefix");
1350
1351   if (arg->getBoolValue("guarded")) {
1352     string prop = string(prefix) + "-guard";
1353     if (fgGetDouble(prop.c_str()) < 1) {
1354       fgSetDouble(prop.c_str(), 1);
1355       return true;
1356     }
1357   }
1358
1359   if (! arg->getBoolValue("latching")) {
1360     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1361     fgSetBool(arg->getStringValue("discrete"), false);
1362   }
1363
1364   return true;
1365 }
1366
1367 static SGGeod commandSearchPos(const SGPropertyNode* arg)
1368 {
1369   if (arg->hasChild("longitude-deg") && arg->hasChild("latitude-deg")) {
1370     return SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
1371                            arg->getDoubleValue("latitude-deg"));
1372   }
1373   
1374   // use current viewer/aircraft position
1375   return SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"), 
1376                          fgGetDouble("/position/latitude-deg"));
1377 }
1378   
1379 static bool
1380 do_comm_search(const SGPropertyNode* arg)
1381 {
1382   SGGeod pos = commandSearchPos(arg);
1383   int khz = static_cast<int>(arg->getDoubleValue("frequency-mhz") * 100.0 + 0.25);
1384   
1385   flightgear::CommStation* sta = flightgear::CommStation::findByFreq(khz, pos, NULL);
1386   if (!sta) {
1387     return true;
1388   }
1389   
1390   SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
1391   sta->createBinding(result);
1392   return true;
1393 }
1394
1395 static bool
1396 do_nav_search(const SGPropertyNode* arg)
1397 {
1398   SGGeod pos = commandSearchPos(arg);
1399   double mhz = arg->getDoubleValue("frequency-mhz");
1400
1401   FGNavList* navList = globals->get_navlist();
1402   string type(arg->getStringValue("type", "vor"));
1403   if (type == "dme") {
1404     navList = globals->get_dmelist();
1405   } else if (type == "tacan") {
1406     navList = globals->get_tacanlist();
1407   }
1408   
1409   FGNavRecord* nav = navList->findByFreq(mhz, pos);
1410   if (!nav && (type == "vor")) {
1411     // if we're searching VORs, look for localizers too
1412     nav = globals->get_loclist()->findByFreq(mhz, pos);
1413   }
1414   
1415   if (!nav) {
1416     return true;
1417   }
1418   
1419   SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
1420   nav->createBinding(result);
1421   return true;
1422 }
1423   
1424 ////////////////////////////////////////////////////////////////////////
1425 // Command setup.
1426 ////////////////////////////////////////////////////////////////////////
1427
1428
1429 /**
1430  * Table of built-in commands.
1431  *
1432  * New commands do not have to be added here; any module in the application
1433  * can add a new command using globals->get_commands()->addCommand(...).
1434  */
1435 static struct {
1436   const char * name;
1437   SGCommandMgr::command_t command;
1438 } built_ins [] = {
1439     { "null", do_null },
1440     { "nasal", do_nasal },
1441     { "exit", do_exit },
1442     { "reset", do_reset },
1443     { "reinit", do_reinit },
1444     { "suspend", do_reinit },
1445     { "resume", do_reinit },
1446     { "pause", do_pause },
1447     { "load", do_load },
1448     { "save", do_save },
1449     { "panel-load", do_panel_load },
1450     { "panel-mouse-click", do_panel_mouse_click },
1451     { "preferences-load", do_preferences_load },
1452     { "view-cycle", do_view_cycle },
1453     { "screen-capture", do_screen_capture },
1454     { "hires-screen-capture", do_hires_screen_capture },
1455     { "tile-cache-reload", do_tile_cache_reload },
1456     /*
1457     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1458     { "set-outside-air-temp-degc", do_set_oat_degc },
1459     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1460     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1461     */
1462     { "property-toggle", do_property_toggle },
1463     { "property-assign", do_property_assign },
1464     { "property-adjust", do_property_adjust },
1465     { "property-multiply", do_property_multiply },
1466     { "property-swap", do_property_swap },
1467     { "property-scale", do_property_scale },
1468     { "property-cycle", do_property_cycle },
1469     { "property-randomize", do_property_randomize },
1470     { "data-logging-commit", do_data_logging_commit },
1471     { "dialog-new", do_dialog_new },
1472     { "dialog-show", do_dialog_show },
1473     { "dialog-close", do_dialog_close },
1474     { "dialog-update", do_dialog_update },
1475     { "dialog-apply", do_dialog_apply },
1476     { "open-browser", do_open_browser },
1477     { "gui-redraw", do_gui_redraw },
1478     { "add-model", do_add_model },
1479     { "set-cursor", do_set_cursor },
1480     { "play-audio-sample", do_play_audio_sample },
1481     { "presets-commit", do_presets_commit },
1482     { "log-level", do_log_level },
1483     { "replay", do_replay },
1484     /*
1485     { "decrease-visibility", do_decrease_visibility },
1486     { "increase-visibility", do_increase_visibility },
1487     */
1488     { "loadxml", do_load_xml_to_proptree},
1489     { "savexml", do_save_xml_from_proptree },
1490     { "press-cockpit-button", do_press_cockpit_button },
1491     { "release-cockpit-button", do_release_cockpit_button },
1492     { "dump-scenegraph", do_dump_scene_graph },
1493     { "dump-terrainbranch", do_dump_terrain_branch },
1494     { "print-visible-scene", do_print_visible_scene_info },
1495     { "reload-shaders", do_reload_shaders },
1496   
1497     { "find-navaid", do_nav_search },
1498     { "find-comm", do_comm_search },
1499   
1500     { 0, 0 }                    // zero-terminated
1501 };
1502
1503
1504 /**
1505  * Initialize the default built-in commands.
1506  *
1507  * Other commands may be added by other parts of the application.
1508  */
1509 void
1510 fgInitCommands ()
1511 {
1512   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1513   for (int i = 0; built_ins[i].name != 0; i++) {
1514     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1515     globals->get_commands()->addCommand(built_ins[i].name,
1516                                         built_ins[i].command);
1517   }
1518
1519   typedef bool (*dummy)();
1520   fgTie( "/command/view/next", dummy(0), do_view_next );
1521   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1522 }
1523
1524 // end of fg_commands.cxx