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