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