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