]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Basic 2D canvas implementation.
[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 #if 0
536 These do_set_(some-environment-parameters) are deprecated and no longer 
537 useful/functional - Torsten Dreyer, January 2011
538 /**
539  * Set the sea level outside air temperature and assigning that to all
540  * boundary and aloft environment layers.
541  */
542 static bool
543 do_set_sea_level_degc ( double temp_sea_level_degc)
544 {
545     SGPropertyNode *node, *child;
546
547     // boundary layers
548     node = fgGetNode( "/environment/config/boundary" );
549     if ( node != NULL ) {
550       int i = 0;
551       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
552         child->setDoubleValue( "temperature-sea-level-degc",
553                                temp_sea_level_degc );
554         ++i;
555       }
556     }
557
558     // aloft layers
559     node = fgGetNode( "/environment/config/aloft" );
560     if ( node != NULL ) {
561       int i = 0;
562       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
563         child->setDoubleValue( "temperature-sea-level-degc",
564                                temp_sea_level_degc );
565         ++i;
566       }
567     }
568
569     return true;
570 }
571
572 static bool
573 do_set_sea_level_degc (const SGPropertyNode * arg)
574 {
575     return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
576 }
577
578
579 /**
580  * Set the outside air temperature at the "current" altitude by first
581  * calculating the corresponding sea level temp, and assigning that to
582  * all boundary and aloft environment layers.
583  */
584 static bool
585 do_set_oat_degc (const SGPropertyNode * arg)
586 {
587     double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
588     // check for an altitude specified in the arguments, otherwise use
589     // current aircraft altitude.
590     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
591     if ( altitude_ft == NULL ) {
592         altitude_ft = fgGetNode("/position/altitude-ft");
593     }
594
595     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
596     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
597     dummy.set_temperature_degc( oat_degc );
598     return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
599 }
600
601 /**
602  * Set the sea level outside air dewpoint and assigning that to all
603  * boundary and aloft environment layers.
604  */
605 static bool
606 do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
607 {
608
609     SGPropertyNode *node, *child;
610
611     // boundary layers
612     node = fgGetNode( "/environment/config/boundary" );
613     if ( node != NULL ) {
614       int i = 0;
615       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
616         child->setDoubleValue( "dewpoint-sea-level-degc",
617                                dewpoint_sea_level_degc );
618         ++i;
619       }
620     }
621
622     // aloft layers
623     node = fgGetNode( "/environment/config/aloft" );
624     if ( node != NULL ) {
625       int i = 0;
626       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
627         child->setDoubleValue( "dewpoint-sea-level-degc",
628                                dewpoint_sea_level_degc );
629         ++i;
630       }
631     }
632
633     return true;
634 }
635
636 static bool
637 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
638 {
639     return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
640 }
641
642 /**
643  * Set the outside air dewpoint at the "current" altitude by first
644  * calculating the corresponding sea level dewpoint, and assigning
645  * that to all boundary and aloft environment layers.
646  */
647 static bool
648 do_set_dewpoint_degc (const SGPropertyNode * arg)
649 {
650     double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
651
652     // check for an altitude specified in the arguments, otherwise use
653     // current aircraft altitude.
654     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
655     if ( altitude_ft == NULL ) {
656         altitude_ft = fgGetNode("/position/altitude-ft");
657     }
658
659     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
660     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
661     dummy.set_dewpoint_degc( dewpoint_degc );
662     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
663 }
664 #endif
665
666 /**
667  * Built-in command: toggle a bool property value.
668  *
669  * property: The name of the property to toggle.
670  */
671 static bool
672 do_property_toggle (const SGPropertyNode * arg)
673 {
674   SGPropertyNode * prop = get_prop(arg);
675   return prop->setBoolValue(!prop->getBoolValue());
676 }
677
678
679 /**
680  * Built-in command: assign a value to a property.
681  *
682  * property: the name of the property to assign.
683  * value: the value to assign; or
684  * property[1]: the property to copy from.
685  */
686 static bool
687 do_property_assign (const SGPropertyNode * arg)
688 {
689   SGPropertyNode * prop = get_prop(arg);
690   const SGPropertyNode * value = arg->getNode("value");
691
692   if (value != 0)
693       return prop->setUnspecifiedValue(value->getStringValue());
694   else
695   {
696       const SGPropertyNode * prop2 = get_prop2(arg);
697       if (prop2)
698           return prop->setUnspecifiedValue(prop2->getStringValue());
699       else
700           return false;
701   }
702 }
703
704
705 /**
706  * Built-in command: increment or decrement a property value.
707  *
708  * If the 'step' argument is present, it will be used; otherwise,
709  * the command uses 'offset' and 'factor', usually from the mouse.
710  *
711  * property: the name of the property to increment or decrement.
712  * step: the amount of the increment or decrement (default: 0).
713  * offset: offset from the current setting (used for the mouse; multiplied 
714  *         by factor)
715  * factor: scaling amount for the offset (defaults to 1).
716  * min: the minimum allowed value (default: no minimum).
717  * max: the maximum allowed value (default: no maximum).
718  * mask: 'integer' to apply only to the left of the decimal point, 
719  *       'decimal' to apply only to the right of the decimal point,
720  *       or 'all' to apply to the whole number (the default).
721  * wrap: true if the value should be wrapped when it passes min or max;
722  *       both min and max must be present for this to work (default:
723  *       false).
724  */
725 static bool
726 do_property_adjust (const SGPropertyNode * arg)
727 {
728   SGPropertyNode * prop = get_prop(arg);
729
730   double amount = 0;
731   if (arg->hasValue("step"))
732       amount = arg->getDoubleValue("step");
733   else
734       amount = (arg->getDoubleValue("factor", 1)
735                 * arg->getDoubleValue("offset"));
736           
737   double unmodifiable, modifiable;
738   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
739               &unmodifiable, &modifiable);
740   modifiable += amount;
741   limit_value(&modifiable, arg);
742
743   prop->setDoubleValue(unmodifiable + modifiable);
744
745   return true;
746 }
747
748
749 /**
750  * Built-in command: multiply a property value.
751  *
752  * property: the name of the property to multiply.
753  * factor: the amount by which to multiply.
754  * min: the minimum allowed value (default: no minimum).
755  * max: the maximum allowed value (default: no maximum).
756  * mask: 'integer' to apply only to the left of the decimal point, 
757  *       'decimal' to apply only to the right of the decimal point,
758  *       or 'all' to apply to the whole number (the default).
759  * wrap: true if the value should be wrapped when it passes min or max;
760  *       both min and max must be present for this to work (default:
761  *       false).
762  */
763 static bool
764 do_property_multiply (const SGPropertyNode * arg)
765 {
766   SGPropertyNode * prop = get_prop(arg);
767   double factor = arg->getDoubleValue("factor", 1);
768
769   double unmodifiable, modifiable;
770   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
771               &unmodifiable, &modifiable);
772   modifiable *= factor;
773   limit_value(&modifiable, arg);
774
775   prop->setDoubleValue(unmodifiable + modifiable);
776
777   return true;
778 }
779
780
781 /**
782  * Built-in command: swap two property values.
783  *
784  * property[0]: the name of the first property.
785  * property[1]: the name of the second property.
786  */
787 static bool
788 do_property_swap (const SGPropertyNode * arg)
789 {
790   SGPropertyNode * prop1 = get_prop(arg);
791   SGPropertyNode * prop2 = get_prop2(arg);
792
793                                 // FIXME: inefficient
794   const string & tmp = prop1->getStringValue();
795   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
796           prop2->setUnspecifiedValue(tmp.c_str()));
797 }
798
799
800 /**
801  * Built-in command: Set a property to an axis or other moving input.
802  *
803  * property: the name of the property to set.
804  * setting: the current input setting, usually between -1.0 and 1.0.
805  * offset: the offset to shift by, before applying the factor.
806  * factor: the factor to multiply by (use negative to reverse).
807  */
808 static bool
809 do_property_scale (const SGPropertyNode * arg)
810 {
811   SGPropertyNode * prop = get_prop(arg);
812   double setting = arg->getDoubleValue("setting");
813   double offset = arg->getDoubleValue("offset", 0.0);
814   double factor = arg->getDoubleValue("factor", 1.0);
815   bool squared = arg->getBoolValue("squared", false);
816   int power = arg->getIntValue("power", (squared ? 2 : 1));
817
818   int sign = (setting < 0 ? -1 : 1);
819
820   switch (power) {
821   case 1:
822       break;
823   case 2:
824       setting = setting * setting * sign;
825       break;
826   case 3:
827       setting = setting * setting * setting;
828       break;
829   case 4:
830       setting = setting * setting * setting * setting * sign;
831       break;
832   default:
833       setting =  pow(setting, power);
834       if ((power % 2) == 0)
835           setting *= sign;
836       break;
837   }
838
839   return prop->setDoubleValue((setting + offset) * factor);
840 }
841
842
843 /**
844  * Built-in command: cycle a property through a set of values.
845  *
846  * If the current value isn't in the list, the cycle will
847  * (re)start from the beginning.
848  *
849  * property: the name of the property to cycle.
850  * value[*]: the list of values to cycle through.
851  */
852 static bool
853 do_property_cycle (const SGPropertyNode * arg)
854 {
855     SGPropertyNode * prop = get_prop(arg);
856     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
857     int selection = -1;
858     int nSelections = values.size();
859
860     if (nSelections < 1) {
861         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
862         return false;
863     }
864
865                                 // Try to find the current selection
866     for (int i = 0; i < nSelections; i++) {
867         if (compare_values(prop, values[i])) {
868             selection = i + 1;
869             break;
870         }
871     }
872
873                                 // Default or wrap to the first selection
874     if (selection < 0 || selection >= nSelections)
875         selection = 0;
876
877     prop->setUnspecifiedValue(values[selection]->getStringValue());
878     return true;
879 }
880
881
882 /**
883  * Built-in command: randomize a numeric property value.
884  *
885  * property: the name of the property value to randomize.
886  * min: the minimum allowed value.
887  * max: the maximum allowed value.
888  */
889 static bool
890 do_property_randomize (const SGPropertyNode * arg)
891 {
892     SGPropertyNode * prop = get_prop(arg);
893     double min = arg->getDoubleValue("min", DBL_MIN);
894     double max = arg->getDoubleValue("max", DBL_MAX);
895     prop->setDoubleValue(sg_random() * (max - min) + min);
896     return true;
897 }
898
899 /**
900  * Built-in command: interpolate a property value over time
901  *
902  * property: the name of the property value to interpolate.
903  * value[0..n] any number of constant values to interpolate
904  * time[0..n]  time between each value, number of time elements must
905  *          match those of value elements
906  * -or-
907  * property[1..n] any number of target values taken from named properties
908  * time[0..n]     time between each value, number of time elements must
909  *                match those of property elements minus one
910  */
911 static bool
912 do_property_interpolate (const SGPropertyNode * arg)
913 {
914     SGPropertyNode * prop = get_prop(arg);
915
916     simgear::PropertyList valueNodes = arg->getChildren( "value" );
917     simgear::PropertyList timeNodes = arg->getChildren( "time" );
918
919     boost::scoped_array<double> value;
920     boost::scoped_array<double> time;
921
922     if( valueNodes.size() > 0 ) {
923         // must match
924         if( timeNodes.size() != valueNodes.size() )
925             return false;
926
927         value.reset( new double[valueNodes.size()] );
928         for( simgear::PropertyList::size_type n = 0; n < valueNodes.size(); n++ ) {
929             value[n] = valueNodes[n]->getDoubleValue();
930         }
931     } else {
932         valueNodes = arg->getChildren("property");
933         // must have one more property node
934         if( valueNodes.size() - 1 != timeNodes.size() )
935           return false;
936
937         value.reset( new double[valueNodes.size()-1] );
938         for( simgear::PropertyList::size_type n = 0; n < valueNodes.size()-1; n++ ) {
939             value[n] = fgGetNode(valueNodes[n+1]->getStringValue(), "/null")->getDoubleValue();
940         }
941
942     }
943
944     time.reset( new double[timeNodes.size()] );
945     for( simgear::PropertyList::size_type n = 0; n < timeNodes.size(); n++ ) {
946         time[n] = timeNodes[n]->getDoubleValue();
947     }
948
949     ((SGInterpolator*)globals->get_subsystem_mgr()
950       ->get_group(SGSubsystemMgr::INIT)->get_subsystem("interpolator"))
951       ->interpolate(prop, timeNodes.size(), value.get(), time.get() );
952
953     return true;
954 }
955
956 /**
957  * Built-in command: reinit the data logging system based on the
958  * current contents of the /logger tree.
959  */
960 static bool
961 do_data_logging_commit (const SGPropertyNode * arg)
962 {
963     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
964     log->reinit();
965     return true;
966 }
967
968 /**
969  * Built-in command: Add a dialog to the GUI system.  Does *not*
970  * display the dialog.  The property node should have the same format
971  * as a dialog XML configuration.  It must include:
972  *
973  * name: the name of the GUI dialog for future reference.
974  */
975 static bool
976 do_dialog_new (const SGPropertyNode * arg)
977 {
978     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
979
980     // Note the casting away of const: this is *real*.  Doing a
981     // "dialog-apply" command later on will mutate this property node.
982     // I'm not convinced that this isn't the Right Thing though; it
983     // allows client to create a node, pass it to dialog-new, and get
984     // the values back from the dialog by reading the same node.
985     // Perhaps command arguments are not as "const" as they would
986     // seem?
987     gui->newDialog((SGPropertyNode*)arg);
988     return true;
989 }
990
991 /**
992  * Built-in command: Show an XML-configured dialog.
993  *
994  * dialog-name: the name of the GUI dialog to display.
995  */
996 static bool
997 do_dialog_show (const SGPropertyNode * arg)
998 {
999     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1000     gui->showDialog(arg->getStringValue("dialog-name"));
1001     return true;
1002 }
1003
1004
1005 /**
1006  * Built-in Command: Hide the active XML-configured dialog.
1007  */
1008 static bool
1009 do_dialog_close (const SGPropertyNode * arg)
1010 {
1011     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1012     if(arg->hasValue("dialog-name"))
1013         return gui->closeDialog(arg->getStringValue("dialog-name"));
1014     return gui->closeActiveDialog();
1015 }
1016
1017
1018 /**
1019  * Update a value in the active XML-configured dialog.
1020  *
1021  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1022  */
1023 static bool
1024 do_dialog_update (const SGPropertyNode * arg)
1025 {
1026     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1027     FGDialog * dialog;
1028     if (arg->hasValue("dialog-name"))
1029         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1030     else
1031         dialog = gui->getActiveDialog();
1032
1033     if (dialog != 0) {
1034         dialog->updateValues(arg->getStringValue("object-name"));
1035         return true;
1036     } else {
1037         return false;
1038     }
1039 }
1040
1041 static bool
1042 do_open_browser (const SGPropertyNode * arg)
1043 {
1044     string path;
1045     if (arg->hasValue("path"))
1046         path = arg->getStringValue("path");
1047     else
1048     if (arg->hasValue("url"))
1049         path = arg->getStringValue("url");
1050     else
1051         return false;
1052
1053     return openBrowser(path);
1054 }
1055
1056 /**
1057  * Apply a value in the active XML-configured dialog.
1058  *
1059  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1060  */
1061 static bool
1062 do_dialog_apply (const SGPropertyNode * arg)
1063 {
1064     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1065     FGDialog * dialog;
1066     if (arg->hasValue("dialog-name"))
1067         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1068     else
1069         dialog = gui->getActiveDialog();
1070
1071     if (dialog != 0) {
1072         dialog->applyValues(arg->getStringValue("object-name"));
1073         return true;
1074     } else {
1075         return false;
1076     }
1077 }
1078
1079
1080 /**
1081  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1082  * unlike reinit().
1083  */
1084 static bool
1085 do_gui_redraw (const SGPropertyNode * arg)
1086 {
1087     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1088     gui->redraw();
1089     return true;
1090 }
1091
1092
1093 /**
1094  * Adds model to the scenery. The path to the added branch (/models/model[*])
1095  * is returned in property "property".
1096  */
1097 static bool
1098 do_add_model (const SGPropertyNode * arg)
1099 {
1100     SGPropertyNode * model = fgGetNode("models", true);
1101     int i;
1102     for (i = 0; model->hasChild("model",i); i++);
1103     model = model->getChild("model", i, true);
1104     copyProperties(arg, model);
1105     if (model->hasValue("elevation-m"))
1106         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1107                 * SG_METER_TO_FEET);
1108     model->getNode("load", true);
1109     model->removeChildren("load");
1110     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1111     return true;
1112 }
1113
1114
1115 /**
1116  * Set mouse cursor coordinates and cursor shape.
1117  */
1118 static bool
1119 do_set_cursor (const SGPropertyNode * arg)
1120 {
1121     if (arg->hasValue("x") || arg->hasValue("y")) {
1122         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1123         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1124         int x = arg->getIntValue("x", mx->getIntValue());
1125         int y = arg->getIntValue("y", my->getIntValue());
1126         fgWarpMouse(x, y);
1127         mx->setIntValue(x);
1128         my->setIntValue(y);
1129     }
1130
1131     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1132     if (cursor->getType() != simgear::props::NONE)
1133         fgSetMouseCursor(cursor->getIntValue());
1134
1135     cursor->setIntValue(fgGetMouseCursor());
1136     return true;
1137 }
1138
1139
1140 /**
1141  * Built-in command: play an audio message (i.e. a wav file) This is
1142  * fire and forget.  Call this once per message and it will get dumped
1143  * into a queue.  Messages are played sequentially so they do not
1144  * overlap.
1145  */
1146 static bool
1147 do_play_audio_sample (const SGPropertyNode * arg)
1148 {
1149     string path = arg->getStringValue("path");
1150     string file = arg->getStringValue("file");
1151     float volume = arg->getFloatValue("volume");
1152     // cout << "playing " << path << " / " << file << endl;
1153     try {
1154         static FGSampleQueue *queue = 0;
1155         if ( !queue ) {
1156            SGSoundMgr *smgr = globals->get_soundmgr();
1157            queue = new FGSampleQueue(smgr, "chatter");
1158            queue->tie_to_listener();
1159         }
1160
1161         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1162         msg->set_volume( volume );
1163         queue->add( msg );
1164
1165         return true;
1166
1167     } catch (const sg_io_exception&) {
1168         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1169                 "failed to load" << path << '/' << file);
1170         return false;
1171     }
1172 }
1173
1174 /**
1175  * Built-in command: commit presets (read from in /sim/presets/)
1176  */
1177 static bool
1178 do_presets_commit (const SGPropertyNode * arg)
1179 {
1180     if (fgGetBool("/sim/initialized", false)) {
1181       fgReInitSubsystems();
1182     } else {
1183       // Nasal can trigger this during initial init, which confuses
1184       // the logic in ReInitSubsystems, since initial state has not been
1185       // saved at that time. Short-circuit everything here.
1186       fgInitPosition();
1187     }
1188     
1189     return true;
1190 }
1191
1192 /**
1193  * Built-in command: set log level (0 ... 7)
1194  */
1195 static bool
1196 do_log_level (const SGPropertyNode * arg)
1197 {
1198    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1199
1200    return true;
1201 }
1202
1203 /*
1204 static bool
1205 do_decrease_visibility (const SGPropertyNode * arg)
1206 {
1207     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1208     return true;
1209 }
1210  
1211 static bool
1212 do_increase_visibility (const SGPropertyNode * arg)
1213 {
1214     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1215     return true;
1216 }
1217 */
1218 /**
1219  * An fgcommand to allow loading of xml files via nasal,
1220  * the xml file's structure will be made available within
1221  * a property tree node defined under argument "targetnode",
1222  * or in the given argument tree under "data" otherwise.
1223  *
1224  * @param filename a string to hold the complete path & filename of an XML file
1225  * @param targetnode a string pointing to a location within the property tree
1226  * where to store the parsed XML file. If <targetnode> is undefined, then the
1227  * file contents are stored under a node <data> in the argument tree.
1228  */
1229
1230 static bool
1231 do_load_xml_to_proptree(const SGPropertyNode * arg)
1232 {
1233     SGPath file(arg->getStringValue("filename"));
1234     if (file.str().empty())
1235         return false;
1236
1237     if (file.extension() != "xml")
1238         file.concat(".xml");
1239     
1240     std::string icao = arg->getStringValue("icao");
1241     if (icao.empty()) {
1242         if (file.isRelative()) {
1243           SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
1244           if (!absPath.isNull())
1245               file = absPath;
1246           else
1247           {
1248               SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"  
1249                           << file.str() << "'.");
1250               return false;
1251           }
1252         }
1253     } else {
1254         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
1255           SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for "
1256             << file.str() << " at ICAO:" << icao);
1257           return false;
1258         }
1259     }
1260     
1261     if (!fgValidatePath(file.c_str(), false)) {
1262         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1263                 "(unauthorized access)");
1264         return false;
1265     }
1266
1267     SGPropertyNode *targetnode;
1268     if (arg->hasValue("targetnode"))
1269         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1270     else
1271         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1272
1273     try {
1274         readProperties(file.c_str(), targetnode, true);
1275     } catch (const sg_exception &e) {
1276         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1277         return false;
1278     }
1279
1280     return true;
1281 }
1282
1283 class RemoteXMLRequest : public simgear::HTTP::Request
1284 {
1285 public:
1286     SGPropertyNode_ptr _complete;
1287     SGPropertyNode_ptr _status;
1288     SGPropertyNode_ptr _failed;
1289     SGPropertyNode_ptr _target;
1290     string propsData;
1291     
1292     RemoteXMLRequest(const std::string& url, SGPropertyNode* targetNode) : 
1293         simgear::HTTP::Request(url),
1294         _target(targetNode)
1295     {
1296     }
1297     
1298     void setCompletionProp(SGPropertyNode_ptr p)
1299     {
1300         _complete = p;
1301     }
1302     
1303     void setStatusProp(SGPropertyNode_ptr p)
1304     {
1305         _status = p;
1306     }
1307     
1308     void setFailedProp(SGPropertyNode_ptr p)
1309     {
1310         _failed = p;
1311     }
1312 protected:
1313     virtual void gotBodyData(const char* s, int n)
1314     {
1315         propsData += string(s, n);
1316     }
1317     
1318     virtual void responseComplete()
1319     {
1320         int response = responseCode();
1321         bool failed = false;
1322         if (response == 200) {
1323             try {
1324                 const char* buffer = propsData.c_str();
1325                 readProperties(buffer, propsData.size(), _target, true);
1326             } catch (const sg_exception &e) {
1327                 SG_LOG(SG_IO, SG_WARN, "parsing XML from remote, failed: " << e.getFormattedMessage());
1328                 failed = true;
1329                 response = 406; // 'not acceptable', anything better?
1330             }
1331         } else {
1332             failed = true;
1333         }
1334     // now the response data is output, signal Nasal / listeners
1335         if (_complete) _complete->setBoolValue(true);
1336         if (_status) _status->setIntValue(response);
1337         if (_failed) _failed->setBoolValue(failed);
1338     }
1339 };
1340
1341
1342 static bool
1343 do_load_xml_from_url(const SGPropertyNode * arg)
1344 {
1345     std::string url(arg->getStringValue("url"));
1346     if (url.empty())
1347         return false;
1348         
1349     SGPropertyNode *targetnode;
1350     if (arg->hasValue("targetnode"))
1351         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1352     else
1353         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1354     
1355     RemoteXMLRequest* req = new RemoteXMLRequest(url, targetnode);
1356     
1357 // connect up optional reporting properties
1358     if (arg->hasValue("complete")) 
1359         req->setCompletionProp(fgGetNode(arg->getStringValue("complete"), true));
1360     if (arg->hasValue("failure")) 
1361         req->setFailedProp(fgGetNode(arg->getStringValue("failure"), true));
1362     if (arg->hasValue("status")) 
1363         req->setStatusProp(fgGetNode(arg->getStringValue("status"), true));
1364         
1365     FGHTTPClient::instance()->makeRequest(req);
1366     
1367     return true;
1368 }
1369
1370
1371 /**
1372  * An fgcommand to allow saving of xml files via nasal,
1373  * the file's structure will be determined based on what's
1374  * encountered in the passed (source) property tree node
1375  *
1376  * @param filename a string to hold the complete path & filename of the (new)
1377  * XML file
1378  * @param sourcenode a string pointing to a location within the property tree
1379  * where to find the nodes that should be written recursively into an XML file
1380  * @param data if no sourcenode is given, then the file contents are taken from
1381  * the argument tree's "data" node.
1382  */
1383
1384 static bool
1385 do_save_xml_from_proptree(const SGPropertyNode * arg)
1386 {
1387     SGPath file(arg->getStringValue("filename"));
1388     if (file.str().empty())
1389         return false;
1390
1391     if (file.extension() != "xml")
1392         file.concat(".xml");
1393
1394     if (!fgValidatePath(file.c_str(), true)) {
1395         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1396                 "(unauthorized access)");
1397         return false;
1398     }
1399
1400     SGPropertyNode *sourcenode;
1401     if (arg->hasValue("sourcenode"))
1402         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1403     else if (arg->getNode("data", false))
1404         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1405     else
1406         return false;
1407
1408     try {
1409         writeProperties (file.c_str(), sourcenode, true);
1410     } catch (const sg_exception &e) {
1411         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1412         return false;
1413     }
1414
1415     return true;
1416 }
1417
1418 static bool
1419 do_press_cockpit_button (const SGPropertyNode *arg)
1420 {
1421   const char *prefix = arg->getStringValue("prefix");
1422
1423   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1424     return true;
1425
1426   string prop = string(prefix) + "-button";
1427   double value;
1428
1429   if (arg->getBoolValue("latching"))
1430     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1431   else
1432     value = 1;
1433
1434   fgSetDouble(prop.c_str(), value);
1435   fgSetBool(arg->getStringValue("discrete"), value > 0);
1436
1437   return true;
1438 }
1439
1440 static bool
1441 do_release_cockpit_button (const SGPropertyNode *arg)
1442 {
1443   const char *prefix = arg->getStringValue("prefix");
1444
1445   if (arg->getBoolValue("guarded")) {
1446     string prop = string(prefix) + "-guard";
1447     if (fgGetDouble(prop.c_str()) < 1) {
1448       fgSetDouble(prop.c_str(), 1);
1449       return true;
1450     }
1451   }
1452
1453   if (! arg->getBoolValue("latching")) {
1454     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1455     fgSetBool(arg->getStringValue("discrete"), false);
1456   }
1457
1458   return true;
1459 }
1460   
1461 ////////////////////////////////////////////////////////////////////////
1462 // Command setup.
1463 ////////////////////////////////////////////////////////////////////////
1464
1465
1466 /**
1467  * Table of built-in commands.
1468  *
1469  * New commands do not have to be added here; any module in the application
1470  * can add a new command using globals->get_commands()->addCommand(...).
1471  */
1472 static struct {
1473   const char * name;
1474   SGCommandMgr::command_t command;
1475 } built_ins [] = {
1476     { "null", do_null },
1477     { "nasal", do_nasal },
1478     { "exit", do_exit },
1479     { "reset", do_reset },
1480     { "reinit", do_reinit },
1481     { "suspend", do_reinit },
1482     { "resume", do_reinit },
1483     { "pause", do_pause },
1484     { "load", do_load },
1485     { "save", do_save },
1486     { "panel-load", do_panel_load },
1487     { "preferences-load", do_preferences_load },
1488     { "view-cycle", do_view_cycle },
1489     { "screen-capture", do_screen_capture },
1490     { "hires-screen-capture", do_hires_screen_capture },
1491     { "tile-cache-reload", do_tile_cache_reload },
1492     /*
1493     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1494     { "set-outside-air-temp-degc", do_set_oat_degc },
1495     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1496     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1497     */
1498     { "property-toggle", do_property_toggle },
1499     { "property-assign", do_property_assign },
1500     { "property-adjust", do_property_adjust },
1501     { "property-multiply", do_property_multiply },
1502     { "property-swap", do_property_swap },
1503     { "property-scale", do_property_scale },
1504     { "property-cycle", do_property_cycle },
1505     { "property-randomize", do_property_randomize },
1506     { "property-interpolate", do_property_interpolate },
1507     { "data-logging-commit", do_data_logging_commit },
1508     { "dialog-new", do_dialog_new },
1509     { "dialog-show", do_dialog_show },
1510     { "dialog-close", do_dialog_close },
1511     { "dialog-update", do_dialog_update },
1512     { "dialog-apply", do_dialog_apply },
1513     { "open-browser", do_open_browser },
1514     { "gui-redraw", do_gui_redraw },
1515     { "add-model", do_add_model },
1516     { "set-cursor", do_set_cursor },
1517     { "play-audio-sample", do_play_audio_sample },
1518     { "presets-commit", do_presets_commit },
1519     { "log-level", do_log_level },
1520     { "replay", do_replay },
1521     /*
1522     { "decrease-visibility", do_decrease_visibility },
1523     { "increase-visibility", do_increase_visibility },
1524     */
1525     { "loadxml", do_load_xml_to_proptree},
1526     { "savexml", do_save_xml_from_proptree },
1527     { "xmlhttprequest", do_load_xml_from_url },
1528     { "press-cockpit-button", do_press_cockpit_button },
1529     { "release-cockpit-button", do_release_cockpit_button },
1530     { "dump-scenegraph", do_dump_scene_graph },
1531     { "dump-terrainbranch", do_dump_terrain_branch },
1532     { "print-visible-scene", do_print_visible_scene_info },
1533     { "reload-shaders", do_reload_shaders },
1534
1535     { 0, 0 }                    // zero-terminated
1536 };
1537
1538
1539 /**
1540  * Initialize the default built-in commands.
1541  *
1542  * Other commands may be added by other parts of the application.
1543  */
1544 void
1545 fgInitCommands ()
1546 {
1547   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1548   for (int i = 0; built_ins[i].name != 0; i++) {
1549     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1550     globals->get_commands()->addCommand(built_ins[i].name,
1551                                         built_ins[i].command);
1552   }
1553
1554   typedef bool (*dummy)();
1555   fgTie( "/command/view/next", dummy(0), do_view_next );
1556   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1557 }
1558
1559 // end of fg_commands.cxx