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