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