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