]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Merge branch 'next' of gitorious.org:fg/flightgear into next
[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
1044 /**
1045  * Apply a value in the active XML-configured dialog.
1046  *
1047  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1048  */
1049 static bool
1050 do_dialog_apply (const SGPropertyNode * arg)
1051 {
1052     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1053     FGDialog * dialog;
1054     if (arg->hasValue("dialog-name"))
1055         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1056     else
1057         dialog = gui->getActiveDialog();
1058
1059     if (dialog != 0) {
1060         dialog->applyValues(arg->getStringValue("object-name"));
1061         return true;
1062     } else {
1063         return false;
1064     }
1065 }
1066
1067
1068 /**
1069  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1070  * unlike reinit().
1071  */
1072 static bool
1073 do_gui_redraw (const SGPropertyNode * arg)
1074 {
1075     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1076     gui->redraw();
1077     return true;
1078 }
1079
1080
1081 /**
1082  * Adds model to the scenery. The path to the added branch (/models/model[*])
1083  * is returned in property "property".
1084  */
1085 static bool
1086 do_add_model (const SGPropertyNode * arg)
1087 {
1088     SGPropertyNode * model = fgGetNode("models", true);
1089     int i;
1090     for (i = 0; model->hasChild("model",i); i++);
1091     model = model->getChild("model", i, true);
1092     copyProperties(arg, model);
1093     if (model->hasValue("elevation-m"))
1094         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1095                 * SG_METER_TO_FEET);
1096     model->getNode("load", true);
1097     model->removeChildren("load");
1098     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1099     return true;
1100 }
1101
1102
1103 /**
1104  * Set mouse cursor coordinates and cursor shape.
1105  */
1106 static bool
1107 do_set_cursor (const SGPropertyNode * arg)
1108 {
1109     if (arg->hasValue("x") || arg->hasValue("y")) {
1110         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1111         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1112         int x = arg->getIntValue("x", mx->getIntValue());
1113         int y = arg->getIntValue("y", my->getIntValue());
1114         fgWarpMouse(x, y);
1115         mx->setIntValue(x);
1116         my->setIntValue(y);
1117     }
1118
1119     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1120     if (cursor->getType() != simgear::props::NONE)
1121         fgSetMouseCursor(cursor->getIntValue());
1122
1123     cursor->setIntValue(fgGetMouseCursor());
1124     return true;
1125 }
1126
1127
1128 /**
1129  * Built-in command: play an audio message (i.e. a wav file) This is
1130  * fire and forget.  Call this once per message and it will get dumped
1131  * into a queue.  Messages are played sequentially so they do not
1132  * overlap.
1133  */
1134 static bool
1135 do_play_audio_sample (const SGPropertyNode * arg)
1136 {
1137     string path = arg->getStringValue("path");
1138     string file = arg->getStringValue("file");
1139     float volume = arg->getFloatValue("volume");
1140     // cout << "playing " << path << " / " << file << endl;
1141     try {
1142         static FGSampleQueue *queue = 0;
1143         if ( !queue ) {
1144            SGSoundMgr *smgr = globals->get_soundmgr();
1145            queue = new FGSampleQueue(smgr, "chatter");
1146            queue->tie_to_listener();
1147         }
1148
1149         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1150         msg->set_volume( volume );
1151         queue->add( msg );
1152
1153         return true;
1154
1155     } catch (const sg_io_exception&) {
1156         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1157                 "failed to load" << path << '/' << file);
1158         return false;
1159     }
1160 }
1161
1162 /**
1163  * Built-in command: commit presets (read from in /sim/presets/)
1164  */
1165 static bool
1166 do_presets_commit (const SGPropertyNode * arg)
1167 {
1168     if (fgGetBool("/sim/initialized", false)) {
1169       fgReInitSubsystems();
1170     } else {
1171       // Nasal can trigger this during initial init, which confuses
1172       // the logic in ReInitSubsystems, since initial state has not been
1173       // saved at that time. Short-circuit everything here.
1174       fgInitPosition();
1175     }
1176     
1177     return true;
1178 }
1179
1180 /**
1181  * Built-in command: set log level (0 ... 7)
1182  */
1183 static bool
1184 do_log_level (const SGPropertyNode * arg)
1185 {
1186    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1187
1188    return true;
1189 }
1190
1191 /*
1192 static bool
1193 do_decrease_visibility (const SGPropertyNode * arg)
1194 {
1195     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1196     return true;
1197 }
1198  
1199 static bool
1200 do_increase_visibility (const SGPropertyNode * arg)
1201 {
1202     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1203     return true;
1204 }
1205 */
1206 /**
1207  * An fgcommand to allow loading of xml files via nasal,
1208  * the xml file's structure will be made available within
1209  * a property tree node defined under argument "targetnode",
1210  * or in the given argument tree under "data" otherwise.
1211  *
1212  * @param filename a string to hold the complete path & filename of an XML file
1213  * @param targetnode a string pointing to a location within the property tree
1214  * where to store the parsed XML file. If <targetnode> is undefined, then the
1215  * file contents are stored under a node <data> in the argument tree.
1216  */
1217
1218 static bool
1219 do_load_xml_to_proptree(const SGPropertyNode * arg)
1220 {
1221     SGPath file(arg->getStringValue("filename"));
1222     if (file.str().empty())
1223         return false;
1224
1225     if (file.extension() != "xml")
1226         file.concat(".xml");
1227     
1228     std::string icao = arg->getStringValue("icao");
1229     if (icao.empty()) {
1230         if (file.isRelative()) {
1231           SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
1232           if (!absPath.isNull())
1233               file = absPath;
1234           else
1235           {
1236               SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"  
1237                           << file.str() << "'.");
1238               return false;
1239           }
1240         }
1241     } else {
1242         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
1243           SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
1244             << file.str() << " at ICAO:" << icao);
1245           return false;
1246         }
1247     }
1248     
1249     if (!fgValidatePath(file.c_str(), false)) {
1250         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1251                 "(unauthorized access)");
1252         return false;
1253     }
1254
1255     SGPropertyNode *targetnode;
1256     if (arg->hasValue("targetnode"))
1257         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1258     else
1259         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1260
1261     try {
1262         readProperties(file.c_str(), targetnode, true);
1263     } catch (const sg_exception &e) {
1264         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1265         return false;
1266     }
1267
1268     return true;
1269 }
1270
1271
1272 /**
1273  * An fgcommand to allow saving of xml files via nasal,
1274  * the file's structure will be determined based on what's
1275  * encountered in the passed (source) property tree node
1276  *
1277  * @param filename a string to hold the complete path & filename of the (new)
1278  * XML file
1279  * @param sourcenode a string pointing to a location within the property tree
1280  * where to find the nodes that should be written recursively into an XML file
1281  * @param data if no sourcenode is given, then the file contents are taken from
1282  * the argument tree's "data" node.
1283  */
1284
1285 static bool
1286 do_save_xml_from_proptree(const SGPropertyNode * arg)
1287 {
1288     SGPath file(arg->getStringValue("filename"));
1289     if (file.str().empty())
1290         return false;
1291
1292     if (file.extension() != "xml")
1293         file.concat(".xml");
1294
1295     if (!fgValidatePath(file.c_str(), true)) {
1296         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1297                 "(unauthorized access)");
1298         return false;
1299     }
1300
1301     SGPropertyNode *sourcenode;
1302     if (arg->hasValue("sourcenode"))
1303         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1304     else if (arg->getNode("data", false))
1305         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1306     else
1307         return false;
1308
1309     try {
1310         writeProperties (file.c_str(), sourcenode, true);
1311     } catch (const sg_exception &e) {
1312         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1313         return false;
1314     }
1315
1316     return true;
1317 }
1318
1319 static bool
1320 do_press_cockpit_button (const SGPropertyNode *arg)
1321 {
1322   const char *prefix = arg->getStringValue("prefix");
1323
1324   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1325     return true;
1326
1327   string prop = string(prefix) + "-button";
1328   double value;
1329
1330   if (arg->getBoolValue("latching"))
1331     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1332   else
1333     value = 1;
1334
1335   fgSetDouble(prop.c_str(), value);
1336   fgSetBool(arg->getStringValue("discrete"), value > 0);
1337
1338   return true;
1339 }
1340
1341 static bool
1342 do_release_cockpit_button (const SGPropertyNode *arg)
1343 {
1344   const char *prefix = arg->getStringValue("prefix");
1345
1346   if (arg->getBoolValue("guarded")) {
1347     string prop = string(prefix) + "-guard";
1348     if (fgGetDouble(prop.c_str()) < 1) {
1349       fgSetDouble(prop.c_str(), 1);
1350       return true;
1351     }
1352   }
1353
1354   if (! arg->getBoolValue("latching")) {
1355     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1356     fgSetBool(arg->getStringValue("discrete"), false);
1357   }
1358
1359   return true;
1360 }
1361
1362 static SGGeod commandSearchPos(const SGPropertyNode* arg)
1363 {
1364   if (arg->hasChild("longitude-deg") && arg->hasChild("latitude-deg")) {
1365     return SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
1366                            arg->getDoubleValue("latitude-deg"));
1367   }
1368   
1369   // use current viewer/aircraft position
1370   return SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"), 
1371                          fgGetDouble("/position/latitude-deg"));
1372 }
1373   
1374 static bool
1375 do_comm_search(const SGPropertyNode* arg)
1376 {
1377   SGGeod pos = commandSearchPos(arg);
1378   int khz = static_cast<int>(arg->getDoubleValue("frequency-mhz") * 100.0 + 0.25);
1379   
1380   flightgear::CommStation* sta = flightgear::CommStation::findByFreq(khz, pos, NULL);
1381   if (!sta) {
1382     return true;
1383   }
1384   
1385   SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
1386   sta->createBinding(result);
1387   return true;
1388 }
1389
1390 static bool
1391 do_nav_search(const SGPropertyNode* arg)
1392 {
1393   SGGeod pos = commandSearchPos(arg);
1394   double mhz = arg->getDoubleValue("frequency-mhz");
1395
1396   FGNavList* navList = globals->get_navlist();
1397   string type(arg->getStringValue("type", "vor"));
1398   if (type == "dme") {
1399     navList = globals->get_dmelist();
1400   } else if (type == "tacan") {
1401     navList = globals->get_tacanlist();
1402   }
1403   
1404   FGNavRecord* nav = navList->findByFreq(mhz, pos);
1405   if (!nav && (type == "vor")) {
1406     // if we're searching VORs, look for localizers too
1407     nav = globals->get_loclist()->findByFreq(mhz, pos);
1408   }
1409   
1410   if (!nav) {
1411     return true;
1412   }
1413   
1414   SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
1415   nav->createBinding(result);
1416   return true;
1417 }
1418   
1419 ////////////////////////////////////////////////////////////////////////
1420 // Command setup.
1421 ////////////////////////////////////////////////////////////////////////
1422
1423
1424 /**
1425  * Table of built-in commands.
1426  *
1427  * New commands do not have to be added here; any module in the application
1428  * can add a new command using globals->get_commands()->addCommand(...).
1429  */
1430 static struct {
1431   const char * name;
1432   SGCommandMgr::command_t command;
1433 } built_ins [] = {
1434     { "null", do_null },
1435     { "nasal", do_nasal },
1436     { "exit", do_exit },
1437     { "reset", do_reset },
1438     { "reinit", do_reinit },
1439     { "suspend", do_reinit },
1440     { "resume", do_reinit },
1441     { "pause", do_pause },
1442     { "load", do_load },
1443     { "save", do_save },
1444     { "panel-load", do_panel_load },
1445     { "panel-mouse-click", do_panel_mouse_click },
1446     { "preferences-load", do_preferences_load },
1447     { "view-cycle", do_view_cycle },
1448     { "screen-capture", do_screen_capture },
1449     { "hires-screen-capture", do_hires_screen_capture },
1450     { "tile-cache-reload", do_tile_cache_reload },
1451     /*
1452     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1453     { "set-outside-air-temp-degc", do_set_oat_degc },
1454     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1455     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1456     */
1457     { "property-toggle", do_property_toggle },
1458     { "property-assign", do_property_assign },
1459     { "property-adjust", do_property_adjust },
1460     { "property-multiply", do_property_multiply },
1461     { "property-swap", do_property_swap },
1462     { "property-scale", do_property_scale },
1463     { "property-cycle", do_property_cycle },
1464     { "property-randomize", do_property_randomize },
1465     { "data-logging-commit", do_data_logging_commit },
1466     { "dialog-new", do_dialog_new },
1467     { "dialog-show", do_dialog_show },
1468     { "dialog-close", do_dialog_close },
1469     { "dialog-update", do_dialog_update },
1470     { "dialog-apply", do_dialog_apply },
1471     { "gui-redraw", do_gui_redraw },
1472     { "add-model", do_add_model },
1473     { "set-cursor", do_set_cursor },
1474     { "play-audio-sample", do_play_audio_sample },
1475     { "presets-commit", do_presets_commit },
1476     { "log-level", do_log_level },
1477     { "replay", do_replay },
1478     /*
1479     { "decrease-visibility", do_decrease_visibility },
1480     { "increase-visibility", do_increase_visibility },
1481     */
1482     { "loadxml", do_load_xml_to_proptree},
1483     { "savexml", do_save_xml_from_proptree },
1484     { "press-cockpit-button", do_press_cockpit_button },
1485     { "release-cockpit-button", do_release_cockpit_button },
1486     { "dump-scenegraph", do_dump_scene_graph },
1487     { "dump-terrainbranch", do_dump_terrain_branch },
1488     { "print-visible-scene", do_print_visible_scene_info },
1489     { "reload-shaders", do_reload_shaders },
1490   
1491     { "find-navaid", do_nav_search },
1492     { "find-comm", do_comm_search },
1493   
1494     { 0, 0 }                    // zero-terminated
1495 };
1496
1497
1498 /**
1499  * Initialize the default built-in commands.
1500  *
1501  * Other commands may be added by other parts of the application.
1502  */
1503 void
1504 fgInitCommands ()
1505 {
1506   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1507   for (int i = 0; built_ins[i].name != 0; i++) {
1508     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1509     globals->get_commands()->addCommand(built_ins[i].name,
1510                                         built_ins[i].command);
1511   }
1512
1513   typedef bool (*dummy)();
1514   fgTie( "/command/view/next", dummy(0), do_view_next );
1515   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1516 }
1517
1518 // end of fg_commands.cxx