]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
ee56f9ad820fb297c6f5a885a2ad1943b6d0172f
[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 static bool
322 do_pause (const SGPropertyNode * arg)
323 {
324     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
325     fgSetBool("/sim/freeze/master",!paused);
326     fgSetBool("/sim/freeze/clock",!paused);
327     if (fgGetBool("/sim/freeze/replay-state",false))
328         fgSetBool("/sim/replay/disable",true);
329     return true;
330 }
331
332 /**
333  * Built-in command: load flight.
334  *
335  * file (optional): the name of the file to load (relative to current
336  *   directory).  Defaults to "fgfs.sav"
337  */
338 static bool
339 do_load (const SGPropertyNode * arg)
340 {
341     string file = arg->getStringValue("file", "fgfs.sav");
342     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
343         file += ".sav";
344
345     if (!fgValidatePath(file.c_str(), false)) {
346         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
347                 "(unauthorized access)");
348         return false;
349     }
350
351     ifstream input(file.c_str());
352     if (input.good() && fgLoadFlight(input)) {
353         input.close();
354         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
355         return true;
356     } else {
357         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
358         return false;
359     }
360 }
361
362
363 /**
364  * Built-in command: save flight.
365  *
366  * file (optional): the name of the file to save (relative to the
367  * current directory).  Defaults to "fgfs.sav".
368  */
369 static bool
370 do_save (const SGPropertyNode * arg)
371 {
372     string file = arg->getStringValue("file", "fgfs.sav");
373     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
374         file += ".sav";
375
376     if (!fgValidatePath(file.c_str(), false)) {
377         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
378                 "(unauthorized access)");
379         return false;
380     }
381
382     bool write_all = arg->getBoolValue("write-all", false);
383     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
384     ofstream output(file.c_str());
385     if (output.good() && fgSaveFlight(output, write_all)) {
386         output.close();
387         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
388         return true;
389     } else {
390         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
391         return false;
392     }
393 }
394
395
396 /**
397  * Built-in command: (re)load the panel.
398  *
399  * path (optional): the file name to load the panel from 
400  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
401  * and if that's unspecified, to "Panels/Default/default.xml".
402  */
403 static bool
404 do_panel_load (const SGPropertyNode * arg)
405 {
406   string panel_path =
407     arg->getStringValue("path", fgGetString("/sim/panel/path"));
408   if (panel_path.empty()) {
409     return false;
410   }
411   
412   FGPanel * new_panel = fgReadPanel(panel_path);
413   if (new_panel == 0) {
414     SG_LOG(SG_INPUT, SG_ALERT,
415            "Error reading new panel from " << panel_path);
416     return false;
417   }
418   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
419   globals->get_current_panel()->unbind();
420   delete globals->get_current_panel();
421   globals->set_current_panel( new_panel );
422   globals->get_current_panel()->bind();
423   return true;
424 }
425
426
427 /**
428  * Built-in command: pass a mouse click to the panel.
429  *
430  * button: the mouse button number, zero-based.
431  * is-down: true if the button is down, false if it is up.
432  * x-pos: the x position of the mouse click.
433  * y-pos: the y position of the mouse click.
434  */
435 static bool
436 do_panel_mouse_click (const SGPropertyNode * arg)
437 {
438   if (globals->get_current_panel() != 0)
439     return globals->get_current_panel()
440       ->doMouseAction(arg->getIntValue("button"),
441                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
442                       arg->getIntValue("x-pos"),
443                       arg->getIntValue("y-pos"));
444   else
445     return false;
446 }
447
448
449 /**
450  * Built-in command: (re)load preferences.
451  *
452  * path (optional): the file name to load the panel from (relative
453  * to FG_ROOT). Defaults to "preferences.xml".
454  */
455 static bool
456 do_preferences_load (const SGPropertyNode * arg)
457 {
458   try {
459     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
460                 globals->get_props());
461   } catch (const sg_exception &e) {
462     guiErrorMessage("Error reading global preferences: ", e);
463     return false;
464   }
465   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
466   return true;
467 }
468
469 static void
470 do_view_next( bool )
471 {
472     globals->get_current_view()->setHeadingOffset_deg(0.0);
473     globals->get_viewmgr()->next_view();
474 }
475
476 static void
477 do_view_prev( bool )
478 {
479     globals->get_current_view()->setHeadingOffset_deg(0.0);
480     globals->get_viewmgr()->prev_view();
481 }
482
483 /**
484  * Built-in command: cycle view.
485  */
486 static bool
487 do_view_cycle (const SGPropertyNode * arg)
488 {
489   globals->get_current_view()->setHeadingOffset_deg(0.0);
490   globals->get_viewmgr()->next_view();
491   return true;
492 }
493
494 /**
495  * Built-in command: capture screen.
496  */
497 static bool
498 do_screen_capture (const SGPropertyNode * arg)
499 {
500   return fgDumpSnapShot();
501 }
502
503 static bool
504 do_reload_shaders (const SGPropertyNode*)
505 {
506     simgear::reload_shaders();
507     return true;
508 }
509
510 static bool
511 do_dump_scene_graph (const SGPropertyNode*)
512 {
513     fgDumpSceneGraph();
514     return true;
515 }
516
517 static bool
518 do_dump_terrain_branch (const SGPropertyNode*)
519 {
520     fgDumpTerrainBranch();
521
522     double lon_deg = fgGetDouble("/position/longitude-deg");
523     double lat_deg = fgGetDouble("/position/latitude-deg");
524     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
525     SGVec3d zero = SGVec3d::fromGeod(geodPos);
526
527     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
528     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
529     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
530
531     return true;
532 }
533
534 static bool
535 do_print_visible_scene_info(const SGPropertyNode*)
536 {
537     fgPrintVisibleSceneInfoCommand();
538     return true;
539 }
540
541 /**
542  * Built-in command: hires capture screen.
543  */
544 static bool
545 do_hires_screen_capture (const SGPropertyNode * arg)
546 {
547   fgHiResDump();
548   return true;
549 }
550
551
552 /**
553  * Reload the tile cache.
554  */
555 static bool
556 do_tile_cache_reload (const SGPropertyNode * arg)
557 {
558     static const SGPropertyNode *master_freeze
559         = fgGetNode("/sim/freeze/master");
560     bool freeze = master_freeze->getBoolValue();
561     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
562     if ( !freeze ) {
563         fgSetBool("/sim/freeze/master", true);
564     }
565
566     globals->get_subsystem("tile-manager")->reinit();
567
568     if ( !freeze ) {
569         fgSetBool("/sim/freeze/master", false);
570     }
571     return true;
572 }
573
574
575 #if 0
576 These do_set_(some-environment-parameters) are deprecated and no longer 
577 useful/functional - Torsten Dreyer, January 2011
578 /**
579  * Set the sea level outside air temperature and assigning that to all
580  * boundary and aloft environment layers.
581  */
582 static bool
583 do_set_sea_level_degc ( double temp_sea_level_degc)
584 {
585     SGPropertyNode *node, *child;
586
587     // boundary layers
588     node = fgGetNode( "/environment/config/boundary" );
589     if ( node != NULL ) {
590       int i = 0;
591       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
592         child->setDoubleValue( "temperature-sea-level-degc",
593                                temp_sea_level_degc );
594         ++i;
595       }
596     }
597
598     // aloft layers
599     node = fgGetNode( "/environment/config/aloft" );
600     if ( node != NULL ) {
601       int i = 0;
602       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
603         child->setDoubleValue( "temperature-sea-level-degc",
604                                temp_sea_level_degc );
605         ++i;
606       }
607     }
608
609     return true;
610 }
611
612 static bool
613 do_set_sea_level_degc (const SGPropertyNode * arg)
614 {
615     return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
616 }
617
618
619 /**
620  * Set the outside air temperature at the "current" altitude by first
621  * calculating the corresponding sea level temp, and assigning that to
622  * all boundary and aloft environment layers.
623  */
624 static bool
625 do_set_oat_degc (const SGPropertyNode * arg)
626 {
627     double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
628     // check for an altitude specified in the arguments, otherwise use
629     // current aircraft altitude.
630     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
631     if ( altitude_ft == NULL ) {
632         altitude_ft = fgGetNode("/position/altitude-ft");
633     }
634
635     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
636     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
637     dummy.set_temperature_degc( oat_degc );
638     return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
639 }
640
641 /**
642  * Set the sea level outside air dewpoint and assigning that to all
643  * boundary and aloft environment layers.
644  */
645 static bool
646 do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
647 {
648
649     SGPropertyNode *node, *child;
650
651     // boundary layers
652     node = fgGetNode( "/environment/config/boundary" );
653     if ( node != NULL ) {
654       int i = 0;
655       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
656         child->setDoubleValue( "dewpoint-sea-level-degc",
657                                dewpoint_sea_level_degc );
658         ++i;
659       }
660     }
661
662     // aloft layers
663     node = fgGetNode( "/environment/config/aloft" );
664     if ( node != NULL ) {
665       int i = 0;
666       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
667         child->setDoubleValue( "dewpoint-sea-level-degc",
668                                dewpoint_sea_level_degc );
669         ++i;
670       }
671     }
672
673     return true;
674 }
675
676 static bool
677 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
678 {
679     return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
680 }
681
682 /**
683  * Set the outside air dewpoint at the "current" altitude by first
684  * calculating the corresponding sea level dewpoint, and assigning
685  * that to all boundary and aloft environment layers.
686  */
687 static bool
688 do_set_dewpoint_degc (const SGPropertyNode * arg)
689 {
690     double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
691
692     // check for an altitude specified in the arguments, otherwise use
693     // current aircraft altitude.
694     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
695     if ( altitude_ft == NULL ) {
696         altitude_ft = fgGetNode("/position/altitude-ft");
697     }
698
699     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
700     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
701     dummy.set_dewpoint_degc( dewpoint_degc );
702     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
703 }
704 #endif
705
706 /**
707  * Built-in command: toggle a bool property value.
708  *
709  * property: The name of the property to toggle.
710  */
711 static bool
712 do_property_toggle (const SGPropertyNode * arg)
713 {
714   SGPropertyNode * prop = get_prop(arg);
715   return prop->setBoolValue(!prop->getBoolValue());
716 }
717
718
719 /**
720  * Built-in command: assign a value to a property.
721  *
722  * property: the name of the property to assign.
723  * value: the value to assign; or
724  * property[1]: the property to copy from.
725  */
726 static bool
727 do_property_assign (const SGPropertyNode * arg)
728 {
729   SGPropertyNode * prop = get_prop(arg);
730   const SGPropertyNode * value = arg->getNode("value");
731
732   if (value != 0)
733       return prop->setUnspecifiedValue(value->getStringValue());
734   else
735   {
736       const SGPropertyNode * prop2 = get_prop2(arg);
737       if (prop2)
738           return prop->setUnspecifiedValue(prop2->getStringValue());
739       else
740           return false;
741   }
742 }
743
744
745 /**
746  * Built-in command: increment or decrement a property value.
747  *
748  * If the 'step' argument is present, it will be used; otherwise,
749  * the command uses 'offset' and 'factor', usually from the mouse.
750  *
751  * property: the name of the property to increment or decrement.
752  * step: the amount of the increment or decrement (default: 0).
753  * offset: offset from the current setting (used for the mouse; multiplied 
754  *         by factor)
755  * factor: scaling amount for the offset (defaults to 1).
756  * min: the minimum allowed value (default: no minimum).
757  * max: the maximum allowed value (default: no maximum).
758  * mask: 'integer' to apply only to the left of the decimal point, 
759  *       'decimal' to apply only to the right of the decimal point,
760  *       or 'all' to apply to the whole number (the default).
761  * wrap: true if the value should be wrapped when it passes min or max;
762  *       both min and max must be present for this to work (default:
763  *       false).
764  */
765 static bool
766 do_property_adjust (const SGPropertyNode * arg)
767 {
768   SGPropertyNode * prop = get_prop(arg);
769
770   double amount = 0;
771   if (arg->hasValue("step"))
772       amount = arg->getDoubleValue("step");
773   else
774       amount = (arg->getDoubleValue("factor", 1)
775                 * arg->getDoubleValue("offset"));
776           
777   double unmodifiable, modifiable;
778   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
779               &unmodifiable, &modifiable);
780   modifiable += amount;
781   limit_value(&modifiable, arg);
782
783   prop->setDoubleValue(unmodifiable + modifiable);
784
785   return true;
786 }
787
788
789 /**
790  * Built-in command: multiply a property value.
791  *
792  * property: the name of the property to multiply.
793  * factor: the amount by which to multiply.
794  * min: the minimum allowed value (default: no minimum).
795  * max: the maximum allowed value (default: no maximum).
796  * mask: 'integer' to apply only to the left of the decimal point, 
797  *       'decimal' to apply only to the right of the decimal point,
798  *       or 'all' to apply to the whole number (the default).
799  * wrap: true if the value should be wrapped when it passes min or max;
800  *       both min and max must be present for this to work (default:
801  *       false).
802  */
803 static bool
804 do_property_multiply (const SGPropertyNode * arg)
805 {
806   SGPropertyNode * prop = get_prop(arg);
807   double factor = arg->getDoubleValue("factor", 1);
808
809   double unmodifiable, modifiable;
810   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
811               &unmodifiable, &modifiable);
812   modifiable *= factor;
813   limit_value(&modifiable, arg);
814
815   prop->setDoubleValue(unmodifiable + modifiable);
816
817   return true;
818 }
819
820
821 /**
822  * Built-in command: swap two property values.
823  *
824  * property[0]: the name of the first property.
825  * property[1]: the name of the second property.
826  */
827 static bool
828 do_property_swap (const SGPropertyNode * arg)
829 {
830   SGPropertyNode * prop1 = get_prop(arg);
831   SGPropertyNode * prop2 = get_prop2(arg);
832
833                                 // FIXME: inefficient
834   const string & tmp = prop1->getStringValue();
835   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
836           prop2->setUnspecifiedValue(tmp.c_str()));
837 }
838
839
840 /**
841  * Built-in command: Set a property to an axis or other moving input.
842  *
843  * property: the name of the property to set.
844  * setting: the current input setting, usually between -1.0 and 1.0.
845  * offset: the offset to shift by, before applying the factor.
846  * factor: the factor to multiply by (use negative to reverse).
847  */
848 static bool
849 do_property_scale (const SGPropertyNode * arg)
850 {
851   SGPropertyNode * prop = get_prop(arg);
852   double setting = arg->getDoubleValue("setting");
853   double offset = arg->getDoubleValue("offset", 0.0);
854   double factor = arg->getDoubleValue("factor", 1.0);
855   bool squared = arg->getBoolValue("squared", false);
856   int power = arg->getIntValue("power", (squared ? 2 : 1));
857
858   int sign = (setting < 0 ? -1 : 1);
859
860   switch (power) {
861   case 1:
862       break;
863   case 2:
864       setting = setting * setting * sign;
865       break;
866   case 3:
867       setting = setting * setting * setting;
868       break;
869   case 4:
870       setting = setting * setting * setting * setting * sign;
871       break;
872   default:
873       setting =  pow(setting, power);
874       if ((power % 2) == 0)
875           setting *= sign;
876       break;
877   }
878
879   return prop->setDoubleValue((setting + offset) * factor);
880 }
881
882
883 /**
884  * Built-in command: cycle a property through a set of values.
885  *
886  * If the current value isn't in the list, the cycle will
887  * (re)start from the beginning.
888  *
889  * property: the name of the property to cycle.
890  * value[*]: the list of values to cycle through.
891  */
892 static bool
893 do_property_cycle (const SGPropertyNode * arg)
894 {
895     SGPropertyNode * prop = get_prop(arg);
896     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
897     int selection = -1;
898     int nSelections = values.size();
899
900     if (nSelections < 1) {
901         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
902         return false;
903     }
904
905                                 // Try to find the current selection
906     for (int i = 0; i < nSelections; i++) {
907         if (compare_values(prop, values[i])) {
908             selection = i + 1;
909             break;
910         }
911     }
912
913                                 // Default or wrap to the first selection
914     if (selection < 0 || selection >= nSelections)
915         selection = 0;
916
917     prop->setUnspecifiedValue(values[selection]->getStringValue());
918     return true;
919 }
920
921
922 /**
923  * Built-in command: randomize a numeric property value.
924  *
925  * property: the name of the property value to randomize.
926  * min: the minimum allowed value.
927  * max: the maximum allowed value.
928  */
929 static bool
930 do_property_randomize (const SGPropertyNode * arg)
931 {
932     SGPropertyNode * prop = get_prop(arg);
933     double min = arg->getDoubleValue("min", DBL_MIN);
934     double max = arg->getDoubleValue("max", DBL_MAX);
935     prop->setDoubleValue(sg_random() * (max - min) + min);
936     return true;
937 }
938
939
940 /**
941  * Built-in command: reinit the data logging system based on the
942  * current contents of the /logger tree.
943  */
944 static bool
945 do_data_logging_commit (const SGPropertyNode * arg)
946 {
947     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
948     log->reinit();
949     return true;
950 }
951
952 /**
953  * Built-in command: Add a dialog to the GUI system.  Does *not*
954  * display the dialog.  The property node should have the same format
955  * as a dialog XML configuration.  It must include:
956  *
957  * name: the name of the GUI dialog for future reference.
958  */
959 static bool
960 do_dialog_new (const SGPropertyNode * arg)
961 {
962     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
963
964     // Note the casting away of const: this is *real*.  Doing a
965     // "dialog-apply" command later on will mutate this property node.
966     // I'm not convinced that this isn't the Right Thing though; it
967     // allows client to create a node, pass it to dialog-new, and get
968     // the values back from the dialog by reading the same node.
969     // Perhaps command arguments are not as "const" as they would
970     // seem?
971     gui->newDialog((SGPropertyNode*)arg);
972     return true;
973 }
974
975 /**
976  * Built-in command: Show an XML-configured dialog.
977  *
978  * dialog-name: the name of the GUI dialog to display.
979  */
980 static bool
981 do_dialog_show (const SGPropertyNode * arg)
982 {
983     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
984     gui->showDialog(arg->getStringValue("dialog-name"));
985     return true;
986 }
987
988
989 /**
990  * Built-in Command: Hide the active XML-configured dialog.
991  */
992 static bool
993 do_dialog_close (const SGPropertyNode * arg)
994 {
995     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
996     if(arg->hasValue("dialog-name"))
997         return gui->closeDialog(arg->getStringValue("dialog-name"));
998     return gui->closeActiveDialog();
999 }
1000
1001
1002 /**
1003  * Update a value in the active XML-configured dialog.
1004  *
1005  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1006  */
1007 static bool
1008 do_dialog_update (const SGPropertyNode * arg)
1009 {
1010     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1011     FGDialog * dialog;
1012     if (arg->hasValue("dialog-name"))
1013         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1014     else
1015         dialog = gui->getActiveDialog();
1016
1017     if (dialog != 0) {
1018         dialog->updateValues(arg->getStringValue("object-name"));
1019         return true;
1020     } else {
1021         return false;
1022     }
1023 }
1024
1025
1026 /**
1027  * Apply a value in the active XML-configured dialog.
1028  *
1029  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1030  */
1031 static bool
1032 do_dialog_apply (const SGPropertyNode * arg)
1033 {
1034     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1035     FGDialog * dialog;
1036     if (arg->hasValue("dialog-name"))
1037         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1038     else
1039         dialog = gui->getActiveDialog();
1040
1041     if (dialog != 0) {
1042         dialog->applyValues(arg->getStringValue("object-name"));
1043         return true;
1044     } else {
1045         return false;
1046     }
1047 }
1048
1049
1050 /**
1051  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1052  * unlike reinit().
1053  */
1054 static bool
1055 do_gui_redraw (const SGPropertyNode * arg)
1056 {
1057     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1058     gui->redraw();
1059     return true;
1060 }
1061
1062
1063 /**
1064  * Adds model to the scenery. The path to the added branch (/models/model[*])
1065  * is returned in property "property".
1066  */
1067 static bool
1068 do_add_model (const SGPropertyNode * arg)
1069 {
1070     SGPropertyNode * model = fgGetNode("models", true);
1071     int i;
1072     for (i = 0; model->hasChild("model",i); i++);
1073     model = model->getChild("model", i, true);
1074     copyProperties(arg, model);
1075     if (model->hasValue("elevation-m"))
1076         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1077                 * SG_METER_TO_FEET);
1078     model->getNode("load", true);
1079     model->removeChildren("load");
1080     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1081     return true;
1082 }
1083
1084
1085 /**
1086  * Set mouse cursor coordinates and cursor shape.
1087  */
1088 static bool
1089 do_set_cursor (const SGPropertyNode * arg)
1090 {
1091     if (arg->hasValue("x") || arg->hasValue("y")) {
1092         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1093         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1094         int x = arg->getIntValue("x", mx->getIntValue());
1095         int y = arg->getIntValue("y", my->getIntValue());
1096         fgWarpMouse(x, y);
1097         mx->setIntValue(x);
1098         my->setIntValue(y);
1099     }
1100
1101     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1102     if (cursor->getType() != simgear::props::NONE)
1103         fgSetMouseCursor(cursor->getIntValue());
1104
1105     cursor->setIntValue(fgGetMouseCursor());
1106     return true;
1107 }
1108
1109
1110 /**
1111  * Built-in command: play an audio message (i.e. a wav file) This is
1112  * fire and forget.  Call this once per message and it will get dumped
1113  * into a queue.  Messages are played sequentially so they do not
1114  * overlap.
1115  */
1116 static bool
1117 do_play_audio_sample (const SGPropertyNode * arg)
1118 {
1119     string path = arg->getStringValue("path");
1120     string file = arg->getStringValue("file");
1121     float volume = arg->getFloatValue("volume");
1122     // cout << "playing " << path << " / " << file << endl;
1123     try {
1124         static FGSampleQueue *queue = 0;
1125         if ( !queue ) {
1126            SGSoundMgr *smgr = globals->get_soundmgr();
1127            queue = new FGSampleQueue(smgr, "chatter");
1128            queue->tie_to_listener();
1129         }
1130
1131         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1132         msg->set_volume( volume );
1133         queue->add( msg );
1134
1135         return true;
1136
1137     } catch (const sg_io_exception&) {
1138         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1139                 "failed to load" << path << '/' << file);
1140         return false;
1141     }
1142 }
1143
1144 /**
1145  * Built-in command: commit presets (read from in /sim/presets/)
1146  */
1147 static bool
1148 do_presets_commit (const SGPropertyNode * arg)
1149 {
1150     if (fgGetBool("/sim/initialized", false)) {
1151       fgReInitSubsystems();
1152     } else {
1153       // Nasal can trigger this during initial init, which confuses
1154       // the logic in ReInitSubsystems, since initial state has not been
1155       // saved at that time. Short-circuit everything here.
1156       fgInitPosition();
1157     }
1158     
1159     return true;
1160 }
1161
1162 /**
1163  * Built-in command: set log level (0 ... 7)
1164  */
1165 static bool
1166 do_log_level (const SGPropertyNode * arg)
1167 {
1168    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1169
1170    return true;
1171 }
1172
1173 /**
1174  * Built-in command: replay the FDR buffer
1175  */
1176 static bool
1177 do_replay (const SGPropertyNode * arg)
1178 {
1179     // freeze the fdm, resume from sim pause 
1180     fgSetInt( "/sim/freeze/replay-state", 1 );
1181     fgSetBool("/sim/freeze/master", 0 );
1182     fgSetBool("/sim/freeze/clock", 0 );
1183     fgSetDouble( "/sim/replay/time", -1 );
1184
1185     // cout << "start = " << r->get_start_time()
1186     //      << "  end = " << r->get_end_time() << endl;
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