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