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