1 // fg_commands.cxx - internal FGFS commands.
3 #include <string.h> // strcmp()
5 #include <simgear/compiler.h>
10 #include <simgear/sg_inlines.h>
11 #include <simgear/debug/logstream.hxx>
12 #include <simgear/math/sg_random.h>
13 #include <simgear/structure/exception.hxx>
14 #include <simgear/structure/commands.hxx>
15 #include <simgear/props/props.hxx>
17 #include <Cockpit/panel.hxx>
18 #include <Cockpit/panel_io.hxx>
19 #include <Environment/environment.hxx>
20 #include <FDM/flight.hxx>
22 #include <GUI/new_gui.hxx>
23 #include <GUI/dialog.hxx>
24 #include <Replay/replay.hxx>
25 #include <Scenery/tilemgr.hxx>
26 #if defined(HAVE_PLIB_PSL)
27 # include <Scripting/scriptmgr.hxx>
29 #include <Time/sunsolver.hxx>
30 #include <Time/tmp.hxx>
32 #include "fg_init.hxx"
34 #include "fg_commands.hxx"
35 #include "fg_props.hxx"
36 #include "globals.hxx"
39 #include "viewmgr.hxx"
42 SG_USING_STD(ifstream);
43 SG_USING_STD(ofstream);
47 ////////////////////////////////////////////////////////////////////////
48 // Static helper functions.
49 ////////////////////////////////////////////////////////////////////////
52 static inline SGPropertyNode *
53 get_prop (const SGPropertyNode * arg)
55 return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
58 static inline SGPropertyNode *
59 get_prop2 (const SGPropertyNode * arg)
61 return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
66 * Get a double value and split it as required.
69 split_value (double full_value, const char * mask,
70 double * unmodifiable, double * modifiable)
72 if (!strcmp("integer", mask)) {
73 *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
74 *unmodifiable = full_value - *modifiable;
75 } else if (!strcmp("decimal", mask)) {
76 *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
77 *modifiable = full_value - *unmodifiable;
79 if (strcmp("all", mask))
80 SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
81 << " assuming 'all'");
83 *modifiable = full_value;
89 * Clamp or wrap a value as specified.
92 limit_value (double * value, const SGPropertyNode * arg)
94 const SGPropertyNode * min_node = arg->getChild("min");
95 const SGPropertyNode * max_node = arg->getChild("max");
97 bool wrap = arg->getBoolValue("wrap");
99 if (min_node == 0 || max_node == 0)
102 if (wrap) { // wrap such that min <= x < max
103 double min_val = min_node->getDoubleValue();
104 double max_val = max_node->getDoubleValue();
105 double resolution = arg->getDoubleValue("resolution");
106 if (resolution > 0.0) {
107 // snap to (min + N*resolution), taking special care to handle imprecision
108 int n = (int)floor((*value - min_val) / resolution + 0.5);
109 int steps = (int)floor((max_val - min_val) / resolution + 0.5);
110 SG_NORMALIZE_RANGE(n, 0, steps);
111 *value = min_val + resolution * n;
113 // plain circular wrapping
114 SG_NORMALIZE_RANGE(*value, min_val, max_val);
116 } else { // clamp such that min <= x <= max
117 if ((min_node != 0) && (*value < min_node->getDoubleValue()))
118 *value = min_node->getDoubleValue();
119 else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
120 *value = max_node->getDoubleValue();
125 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
127 switch (value1->getType()) {
128 case SGPropertyNode::BOOL:
129 return (value1->getBoolValue() == value2->getBoolValue());
130 case SGPropertyNode::INT:
131 return (value1->getIntValue() == value2->getIntValue());
132 case SGPropertyNode::LONG:
133 return (value1->getLongValue() == value2->getLongValue());
134 case SGPropertyNode::FLOAT:
135 return (value1->getFloatValue() == value2->getFloatValue());
136 case SGPropertyNode::DOUBLE:
137 return (value1->getDoubleValue() == value2->getDoubleValue());
139 return !strcmp(value1->getStringValue(), value2->getStringValue());
145 ////////////////////////////////////////////////////////////////////////
146 // Command implementations.
147 ////////////////////////////////////////////////////////////////////////
151 * Built-in command: do nothing.
154 do_null (const SGPropertyNode * arg)
159 #if defined(HAVE_PLIB_PSL)
161 * Built-in command: run a PSL script.
163 * script: the PSL script to execute
166 do_script (const SGPropertyNode * arg)
168 FGScriptMgr * mgr = (FGScriptMgr *)globals->get_subsystem("scripting");
169 return mgr->run(arg->getStringValue("script"));
171 #endif // HAVE_PLIB_PSL
175 * Built-in command: exit FlightGear.
177 * status: the exit status to return to the operating system (defaults to 0)
180 do_exit (const SGPropertyNode * arg)
182 SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
183 fgExit(arg->getIntValue("status", 0));
189 * Built-in command: reinitialize one or more subsystems.
191 * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
192 * none is specified, reinitialize all of them.
195 do_reinit (const SGPropertyNode * arg)
199 vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
200 if (subsystems.size() == 0) {
201 globals->get_subsystem_mgr()->reinit();
203 for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
204 const char * name = subsystems[i]->getStringValue();
205 SGSubsystem * subsystem = globals->get_subsystem(name);
206 if (subsystem == 0) {
208 SG_LOG( SG_GENERAL, SG_ALERT,
209 "Subsystem " << name << "not found" );
216 globals->get_event_mgr()->reinit();
222 * Built-in command: suspend one or more subsystems.
224 * subsystem[*] - the name(s) of the subsystem(s) to suspend.
227 do_suspend (const SGPropertyNode * arg)
231 vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
232 for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
233 const char * name = subsystems[i]->getStringValue();
234 SGSubsystem * subsystem = globals->get_subsystem(name);
235 if (subsystem == 0) {
237 SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
239 subsystem->suspend();
246 * Built-in command: suspend one or more subsystems.
248 * subsystem[*] - the name(s) of the subsystem(s) to suspend.
251 do_resume (const SGPropertyNode * arg)
255 vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
256 for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
257 const char * name = subsystems[i]->getStringValue();
258 SGSubsystem * subsystem = globals->get_subsystem(name);
259 if (subsystem == 0) {
261 SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
271 * Built-in command: load flight.
273 * file (optional): the name of the file to load (relative to current
274 * directory). Defaults to "fgfs.sav"
277 do_load (const SGPropertyNode * arg)
279 const string &file = arg->getStringValue("file", "fgfs.sav");
280 ifstream input(file.c_str());
281 if (input.good() && fgLoadFlight(input)) {
283 SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
286 SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight from " << file);
293 * Built-in command: save flight.
295 * file (optional): the name of the file to save (relative to the
296 * current directory). Defaults to "fgfs.sav".
299 do_save (const SGPropertyNode * arg)
301 const string &file = arg->getStringValue("file", "fgfs.sav");
302 bool write_all = arg->getBoolValue("write-all", false);
303 SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
304 ofstream output(file.c_str());
305 if (output.good() && fgSaveFlight(output, write_all)) {
307 SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
310 SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
317 * Built-in command: (re)load the panel.
319 * path (optional): the file name to load the panel from
320 * (relative to FG_ROOT). Defaults to the value of /sim/panel/path,
321 * and if that's unspecified, to "Panels/Default/default.xml".
324 do_panel_load (const SGPropertyNode * arg)
327 arg->getStringValue("path",
328 fgGetString("/sim/panel/path",
329 "Panels/Default/default.xml"));
330 FGPanel * new_panel = fgReadPanel(panel_path);
331 if (new_panel == 0) {
332 SG_LOG(SG_INPUT, SG_ALERT,
333 "Error reading new panel from " << panel_path);
336 SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
337 globals->get_current_panel()->unbind();
338 delete globals->get_current_panel();
339 globals->set_current_panel( new_panel );
340 globals->get_current_panel()->bind();
346 * Built-in command: pass a mouse click to the panel.
348 * button: the mouse button number, zero-based.
349 * is-down: true if the button is down, false if it is up.
350 * x-pos: the x position of the mouse click.
351 * y-pos: the y position of the mouse click.
354 do_panel_mouse_click (const SGPropertyNode * arg)
356 if (globals->get_current_panel() != 0)
357 return globals->get_current_panel()
358 ->doMouseAction(arg->getIntValue("button"),
359 arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
360 arg->getIntValue("x-pos"),
361 arg->getIntValue("y-pos"));
368 * Built-in command: (re)load preferences.
370 * path (optional): the file name to load the panel from (relative
371 * to FG_ROOT). Defaults to "preferences.xml".
374 do_preferences_load (const SGPropertyNode * arg)
377 fgLoadProps(arg->getStringValue("path", "preferences.xml"),
378 globals->get_props());
379 } catch (const sg_exception &e) {
380 guiErrorMessage("Error reading global preferences: ", e);
383 SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
391 if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
392 globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
393 if ( globals->get_viewmgr()->get_current() == 1 ) {
394 globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
402 globals->get_current_view()->setHeadingOffset_deg(0.0);
403 globals->get_viewmgr()->next_view();
404 fix_hud_visibility();
405 globals->get_tile_mgr()->refresh_view_timestamps();
411 globals->get_current_view()->setHeadingOffset_deg(0.0);
412 globals->get_viewmgr()->prev_view();
413 fix_hud_visibility();
414 globals->get_tile_mgr()->refresh_view_timestamps();
418 * Built-in command: cycle view.
421 do_view_cycle (const SGPropertyNode * arg)
423 globals->get_current_view()->setHeadingOffset_deg(0.0);
424 globals->get_viewmgr()->next_view();
425 fix_hud_visibility();
426 globals->get_tile_mgr()->refresh_view_timestamps();
427 // fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
432 * Built-in command: capture screen.
435 do_screen_capture (const SGPropertyNode * arg)
443 * Reload the tile cache.
446 do_tile_cache_reload (const SGPropertyNode * arg)
448 static const SGPropertyNode *master_freeze
449 = fgGetNode("/sim/freeze/master");
450 bool freeze = master_freeze->getBoolValue();
451 SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
453 fgSetBool("/sim/freeze/master", true);
456 if ( globals->get_tile_mgr()->init() ) {
457 // Load the local scenery data
458 double visibility_meters = fgGetDouble("/environment/visibility-m");
459 globals->get_tile_mgr()->update( visibility_meters );
461 SG_LOG( SG_GENERAL, SG_ALERT,
462 "Error in Tile Manager initialization!" );
467 fgSetBool("/sim/freeze/master", false);
474 * Set the outside air temperature at the "current" altitude by first
475 * calculating the corresponding sea level temp, and assigning that to
476 * all boundary and aloft environment layers.
479 do_set_oat_degc (const SGPropertyNode * arg)
481 const string &temp_str = arg->getStringValue("temp-degc", "15.0");
483 static const SGPropertyNode *altitude_ft
484 = fgGetNode("/position/altitude-ft");
486 FGEnvironment dummy; // instantiate a dummy so we can leech a method
487 dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
488 dummy.set_temperature_degc( atof( temp_str.c_str() ) );
489 double temp_sea_level_degc = dummy.get_temperature_sea_level_degc();
491 cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
492 cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl;
493 cout << "Temp sea level (C) = " << temp_sea_level_degc << endl;
495 SGPropertyNode *node, *child;
498 node = fgGetNode( "/environment/config/boundary" );
499 if ( node != NULL ) {
501 while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
502 child->setDoubleValue( "temperature-sea-level-degc",
503 temp_sea_level_degc );
509 node = fgGetNode( "/environment/config/aloft" );
510 if ( node != NULL ) {
512 while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
513 child->setDoubleValue( "temperature-sea-level-degc",
514 temp_sea_level_degc );
523 * Update the lighting manually.
526 do_timeofday (const SGPropertyNode * arg)
528 const string &offset_type = arg->getStringValue("timeofday", "noon");
530 static const SGPropertyNode *longitude
531 = fgGetNode("/position/longitude-deg");
532 static const SGPropertyNode *latitude
533 = fgGetNode("/position/latitude-deg");
534 static const SGPropertyNode *cur_time_override
535 = fgGetNode("/sim/time/cur-time-override", true);
537 int orig_warp = globals->get_warp();
538 SGTime *t = globals->get_time_params();
539 time_t cur_time = t->get_cur_time();
540 // cout << "cur_time = " << cur_time << endl;
541 // cout << "orig_warp = " << orig_warp << endl;
544 if ( offset_type == "real" ) {
546 } else if ( offset_type == "dawn" ) {
547 warp = fgTimeSecondsUntilSunAngle( cur_time,
548 longitude->getDoubleValue()
549 * SGD_DEGREES_TO_RADIANS,
550 latitude->getDoubleValue()
551 * SGD_DEGREES_TO_RADIANS,
553 } else if ( offset_type == "morning" ) {
554 warp = fgTimeSecondsUntilSunAngle( cur_time,
555 longitude->getDoubleValue()
556 * SGD_DEGREES_TO_RADIANS,
557 latitude->getDoubleValue()
558 * SGD_DEGREES_TO_RADIANS,
560 } else if ( offset_type == "noon" ) {
561 warp = fgTimeSecondsUntilSunAngle( cur_time,
562 longitude->getDoubleValue()
563 * SGD_DEGREES_TO_RADIANS,
564 latitude->getDoubleValue()
565 * SGD_DEGREES_TO_RADIANS,
567 } else if ( offset_type == "afternoon" ) {
568 warp = fgTimeSecondsUntilSunAngle( cur_time,
569 longitude->getDoubleValue()
570 * SGD_DEGREES_TO_RADIANS,
571 latitude->getDoubleValue()
572 * SGD_DEGREES_TO_RADIANS,
574 } else if ( offset_type == "dusk" ) {
575 warp = fgTimeSecondsUntilSunAngle( cur_time,
576 longitude->getDoubleValue()
577 * SGD_DEGREES_TO_RADIANS,
578 latitude->getDoubleValue()
579 * SGD_DEGREES_TO_RADIANS,
581 } else if ( offset_type == "evening" ) {
582 warp = fgTimeSecondsUntilSunAngle( cur_time,
583 longitude->getDoubleValue()
584 * SGD_DEGREES_TO_RADIANS,
585 latitude->getDoubleValue()
586 * SGD_DEGREES_TO_RADIANS,
588 } else if ( offset_type == "midnight" ) {
589 warp = fgTimeSecondsUntilSunAngle( cur_time,
590 longitude->getDoubleValue()
591 * SGD_DEGREES_TO_RADIANS,
592 latitude->getDoubleValue()
593 * SGD_DEGREES_TO_RADIANS,
596 // cout << "warp = " << warp << endl;
597 globals->set_warp( orig_warp + warp );
599 t->update( longitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
600 latitude->getDoubleValue() * SGD_DEGREES_TO_RADIANS,
601 cur_time_override->getLongValue(),
602 globals->get_warp() );
609 * Built-in command: toggle a bool property value.
611 * property: The name of the property to toggle.
614 do_property_toggle (const SGPropertyNode * arg)
616 SGPropertyNode * prop = get_prop(arg);
617 return prop->setBoolValue(!prop->getBoolValue());
622 * Built-in command: assign a value to a property.
624 * property: the name of the property to assign.
625 * value: the value to assign; or
626 * property[1]: the property to copy from.
629 do_property_assign (const SGPropertyNode * arg)
631 SGPropertyNode * prop = get_prop(arg);
632 const SGPropertyNode * prop2 = get_prop2(arg);
633 const SGPropertyNode * value = arg->getNode("value");
636 return prop->setUnspecifiedValue(value->getStringValue());
638 return prop->setUnspecifiedValue(prop2->getStringValue());
645 * Built-in command: increment or decrement a property value.
647 * If the 'step' argument is present, it will be used; otherwise,
648 * the command uses 'offset' and 'factor', usually from the mouse.
650 * property: the name of the property to increment or decrement.
651 * step: the amount of the increment or decrement (default: 0).
652 * offset: offset from the current setting (used for the mouse; multiplied
654 * factor: scaling amount for the offset (defaults to 1).
655 * min: the minimum allowed value (default: no minimum).
656 * max: the maximum allowed value (default: no maximum).
657 * mask: 'integer' to apply only to the left of the decimal point,
658 * 'decimal' to apply only to the right of the decimal point,
659 * or 'all' to apply to the whole number (the default).
660 * wrap: true if the value should be wrapped when it passes min or max;
661 * both min and max must be present for this to work (default:
665 do_property_adjust (const SGPropertyNode * arg)
667 SGPropertyNode * prop = get_prop(arg);
670 if (arg->hasValue("step"))
671 amount = arg->getDoubleValue("step");
673 amount = (arg->getDoubleValue("factor", 1)
674 * arg->getDoubleValue("offset"));
676 double unmodifiable, modifiable;
677 split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
678 &unmodifiable, &modifiable);
679 modifiable += amount;
680 limit_value(&modifiable, arg);
682 prop->setDoubleValue(unmodifiable + modifiable);
689 * Built-in command: multiply a property value.
691 * property: the name of the property to multiply.
692 * factor: the amount by which to multiply.
693 * min: the minimum allowed value (default: no minimum).
694 * max: the maximum allowed value (default: no maximum).
695 * mask: 'integer' to apply only to the left of the decimal point,
696 * 'decimal' to apply only to the right of the decimal point,
697 * or 'all' to apply to the whole number (the default).
698 * wrap: true if the value should be wrapped when it passes min or max;
699 * both min and max must be present for this to work (default:
703 do_property_multiply (const SGPropertyNode * arg)
705 SGPropertyNode * prop = get_prop(arg);
706 double factor = arg->getDoubleValue("factor", 1);
708 double unmodifiable, modifiable;
709 split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
710 &unmodifiable, &modifiable);
711 modifiable *= factor;
712 limit_value(&modifiable, arg);
714 prop->setDoubleValue(unmodifiable + modifiable);
721 * Built-in command: swap two property values.
723 * property[0]: the name of the first property.
724 * property[1]: the name of the second property.
727 do_property_swap (const SGPropertyNode * arg)
729 SGPropertyNode * prop1 = get_prop(arg);
730 SGPropertyNode * prop2 = get_prop2(arg);
732 // FIXME: inefficient
733 const string & tmp = prop1->getStringValue();
734 return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
735 prop2->setUnspecifiedValue(tmp.c_str()));
740 * Built-in command: Set a property to an axis or other moving input.
742 * property: the name of the property to set.
743 * setting: the current input setting, usually between -1.0 and 1.0.
744 * offset: the offset to shift by, before applying the factor.
745 * factor: the factor to multiply by (use negative to reverse).
748 do_property_scale (const SGPropertyNode * arg)
750 SGPropertyNode * prop = get_prop(arg);
751 double setting = arg->getDoubleValue("setting");
752 double offset = arg->getDoubleValue("offset", 0.0);
753 double factor = arg->getDoubleValue("factor", 1.0);
754 bool squared = arg->getBoolValue("squared", false);
755 int power = arg->getIntValue("power", (squared ? 2 : 1));
757 int sign = (setting < 0 ? -1 : 1);
763 setting = setting * setting * sign;
766 setting = setting * setting * setting;
769 setting = setting * setting * setting * setting * sign;
772 setting = pow(setting, power);
773 if ((power % 2) == 0)
778 return prop->setDoubleValue((setting + offset) * factor);
783 * Built-in command: cycle a property through a set of values.
785 * If the current value isn't in the list, the cycle will
786 * (re)start from the beginning.
788 * property: the name of the property to cycle.
789 * value[*]: the list of values to cycle through.
792 do_property_cycle (const SGPropertyNode * arg)
794 SGPropertyNode * prop = get_prop(arg);
795 vector<SGPropertyNode_ptr> values = arg->getChildren("value");
797 int nSelections = values.size();
799 if (nSelections < 1) {
800 SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
804 // Try to find the current selection
805 for (int i = 0; i < nSelections; i++) {
806 if (compare_values(prop, values[i])) {
812 // Default or wrap to the first selection
813 if (selection < 0 || selection >= nSelections)
816 prop->setUnspecifiedValue(values[selection]->getStringValue());
822 * Built-in command: randomize a numeric property value.
824 * property: the name of the property value to randomize.
825 * min: the minimum allowed value.
826 * max: the maximum allowed value.
829 do_property_randomize (const SGPropertyNode * arg)
831 SGPropertyNode * prop = get_prop(arg);
832 double min = arg->getDoubleValue("min", DBL_MIN);
833 double max = arg->getDoubleValue("max", DBL_MAX);
834 prop->setDoubleValue(sg_random() * (max - min) + min);
840 * Built-in command: Show an XML-configured dialog.
842 * dialog-name: the name of the GUI dialog to display.
845 do_data_logging_commit (const SGPropertyNode * arg)
847 FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
854 * Built-in command: Show an XML-configured dialog.
856 * dialog-name: the name of the GUI dialog to display.
859 do_dialog_show (const SGPropertyNode * arg)
861 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
862 gui->showDialog(arg->getStringValue("dialog-name"));
868 * Built-in Command: Hide the active XML-configured dialog.
871 do_dialog_close (const SGPropertyNode * arg)
873 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
874 return gui->closeActiveDialog();
879 * Update a value in the active XML-configured dialog.
881 * object-name: The name of the GUI object(s) (all GUI objects if omitted).
884 do_dialog_update (const SGPropertyNode * arg)
886 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
887 FGDialog * dialog = gui->getActiveDialog();
889 if (arg->hasValue("object-name")) {
890 dialog->updateValue(arg->getStringValue("object-name"));
892 dialog->updateValues();
902 * Apply a value in the active XML-configured dialog.
904 * object-name: The name of the GUI object(s) (all GUI objects if omitted).
907 do_dialog_apply (const SGPropertyNode * arg)
909 NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
910 FGDialog * dialog = gui->getActiveDialog();
912 if (arg->hasValue("object-name")) {
913 const char * name = arg->getStringValue("object-name");
914 dialog->applyValue(name);
915 dialog->updateValue(name);
917 dialog->applyValues();
918 dialog->updateValues();
928 * Built-in command: commit presets (read from in /sim/presets/)
931 do_presets_commit (const SGPropertyNode * arg)
933 // unbind the current fdm state so property changes
934 // don't get lost when we subsequently delete this fdm
935 // and create a new one.
936 cur_fdm_state->unbind();
938 // set position from presets
942 fgReInitSubsystems();
944 globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") );
947 if ( ! fgGetBool("/sim/presets/onground") ) {
948 fgSetBool( "/sim/freeze/master", true );
949 fgSetBool( "/sim/freeze/clock", true );
957 * Built-in command: set log level (0 ... 7)
960 do_log_level (const SGPropertyNode * arg)
962 sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
968 * Built-in command: replay the FDR buffer
971 do_replay (const SGPropertyNode * arg)
973 // freeze the master fdm
974 fgSetBool( "/sim/freeze/replay", true );
976 FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
978 fgSetDouble( "/sim/replay/start-time", r->get_start_time() );
979 fgSetDouble( "/sim/replay/end-time", r->get_end_time() );
980 double duration = fgGetDouble( "/sim/replay/duration" );
981 if( duration && duration < (r->get_end_time() - r->get_start_time()) ) {
982 fgSetDouble( "/sim/replay/time", r->get_end_time() - duration );
984 fgSetDouble( "/sim/replay/time", r->get_start_time() );
987 cout << "start = " << r->get_start_time()
988 << " end = " << r->get_end_time() << endl;
996 do_decrease_visibility (const SGPropertyNode * arg)
998 double new_value = fgGetDouble("/environment/visibility-m") * 0.9;
999 fgSetDouble("/environment/visibility-m", new_value);
1000 fgDefaultWeatherValue("visibility-m", new_value);
1001 globals->get_subsystem("environment")->reinit();
1007 do_increase_visibility (const SGPropertyNode * arg)
1009 double new_value = fgGetDouble("/environment/visibility-m") * 1.1;
1010 fgSetDouble("/environment/visibility-m", new_value);
1011 fgDefaultWeatherValue("visibility-m", new_value);
1012 globals->get_subsystem("environment")->reinit();
1018 ////////////////////////////////////////////////////////////////////////
1020 ////////////////////////////////////////////////////////////////////////
1024 * Table of built-in commands.
1026 * New commands do not have to be added here; any module in the application
1027 * can add a new command using globals->get_commands()->addCommand(...).
1031 SGCommandMgr::command_t command;
1033 { "null", do_null },
1034 #if defined(HAVE_PLIB_PSL)
1035 { "script", do_script },
1036 #endif // HAVE_PLIB_PSL
1037 { "exit", do_exit },
1038 { "reinit", do_reinit },
1039 { "suspend", do_reinit },
1040 { "resume", do_reinit },
1041 { "load", do_load },
1042 { "save", do_save },
1043 { "panel-load", do_panel_load },
1044 { "panel-mouse-click", do_panel_mouse_click },
1045 { "preferences-load", do_preferences_load },
1046 { "view-cycle", do_view_cycle },
1047 { "screen-capture", do_screen_capture },
1048 { "tile-cache-reload", do_tile_cache_reload },
1049 { "set-outside-air-temp-degc", do_set_oat_degc },
1050 { "timeofday", do_timeofday },
1051 { "property-toggle", do_property_toggle },
1052 { "property-assign", do_property_assign },
1053 { "property-adjust", do_property_adjust },
1054 { "property-multiply", do_property_multiply },
1055 { "property-swap", do_property_swap },
1056 { "property-scale", do_property_scale },
1057 { "property-cycle", do_property_cycle },
1058 { "property-randomize", do_property_randomize },
1059 { "data-logging-commit", do_data_logging_commit },
1060 { "dialog-show", do_dialog_show },
1061 { "dialog-close", do_dialog_close },
1062 { "dialog-show", do_dialog_show },
1063 { "dialog-update", do_dialog_update },
1064 { "dialog-apply", do_dialog_apply },
1065 { "presets-commit", do_presets_commit },
1066 { "log-level", do_log_level },
1067 { "replay", do_replay },
1068 { "decrease-visibility", do_decrease_visibility },
1069 { "increase-visibility", do_increase_visibility },
1070 { 0, 0 } // zero-terminated
1075 * Initialize the default built-in commands.
1077 * Other commands may be added by other parts of the application.
1082 SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
1083 for (int i = 0; built_ins[i].name != 0; i++) {
1084 SG_LOG(SG_GENERAL, SG_INFO, " " << built_ins[i].name);
1085 globals->get_commands()->addCommand(built_ins[i].name,
1086 built_ins[i].command);
1089 typedef bool (*dummy)();
1090 fgTie( "/command/view/next", dummy(0), do_view_next );
1091 fgTie( "/command/view/prev", dummy(0), do_view_prev );
1094 // end of fg_commands.cxx