+/**
+ * Built-in command: reinitialize one or more subsystems.
+ *
+ * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
+ * none is specified, reinitialize all of them.
+ */
+static bool
+do_reinit (const SGPropertyNode * arg)
+{
+ bool result = true;
+
+ vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
+ if (subsystems.size() == 0)
+ globals->get_subsystem_mgr()->reinit();
+ else for (int i = 0; i < subsystems.size(); i++) {
+ const char * name = subsystems[i]->getStringValue();
+ FGSubsystem * subsystem = globals->get_subsystem(name);
+ if (subsystem == 0) {
+ result = false;
+ SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
+ } else {
+ subsystem->reinit();
+ }
+ }
+ return result;
+}
+
+/**
+ * Built-in command: suspend one or more subsystems.
+ *
+ * subsystem[*] - the name(s) of the subsystem(s) to suspend.
+ */
+static bool
+do_suspend (const SGPropertyNode * arg)
+{
+ bool result = true;
+
+ vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
+ for (int i = 0; i < subsystems.size(); i++) {
+ const char * name = subsystems[i]->getStringValue();
+ FGSubsystem * subsystem = globals->get_subsystem(name);
+ if (subsystem == 0) {
+ result = false;
+ SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
+ } else {
+ subsystem->suspend();
+ }
+ }
+ return result;
+}
+
+/**
+ * Built-in command: suspend one or more subsystems.
+ *
+ * subsystem[*] - the name(s) of the subsystem(s) to suspend.
+ */
+static bool
+do_resume (const SGPropertyNode * arg)
+{
+ bool result = true;
+
+ vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
+ for (int i = 0; i < subsystems.size(); i++) {
+ const char * name = subsystems[i]->getStringValue();
+ FGSubsystem * subsystem = globals->get_subsystem(name);
+ if (subsystem == 0) {
+ result = false;
+ SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
+ } else {
+ subsystem->resume();
+ }
+ }
+ return result;
+}
+
+
+/**
+ * Built-in command: load flight.
+ *
+ * file (optional): the name of the file to load (relative to current
+ * directory). Defaults to "fgfs.sav"
+ */
+static bool
+do_load (const SGPropertyNode * arg)
+{
+ const string &file = arg->getStringValue("file", "fgfs.sav");
+ ifstream input(file.c_str());
+ if (input.good() && fgLoadFlight(input)) {
+ input.close();
+ SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
+ return true;
+ } else {
+ SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight from " << file);
+ return false;
+ }
+}
+
+
+/**
+ * Built-in command: save flight.
+ *
+ * file (optional): the name of the file to save (relative to the
+ * current directory). Defaults to "fgfs.sav".
+ */
+static bool
+do_save (const SGPropertyNode * arg)
+{
+ const string &file = arg->getStringValue("file", "fgfs.sav");
+ bool write_all = arg->getBoolValue("write-all", false);
+ SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
+ ofstream output(file.c_str());
+ if (output.good() && fgSaveFlight(output, write_all)) {
+ output.close();
+ SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
+ return true;
+ } else {
+ SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
+ return false;
+ }
+}
+
+
+/**
+ * Built-in command: (re)load the panel.
+ *
+ * path (optional): the file name to load the panel from
+ * (relative to FG_ROOT). Defaults to the value of /sim/panel/path,
+ * and if that's unspecified, to "Panels/Default/default.xml".
+ */
+static bool
+do_panel_load (const SGPropertyNode * arg)
+{
+ string panel_path =
+ arg->getStringValue("path",
+ fgGetString("/sim/panel/path",
+ "Panels/Default/default.xml"));
+ FGPanel * new_panel = fgReadPanel(panel_path);
+ if (new_panel == 0) {
+ SG_LOG(SG_INPUT, SG_ALERT,
+ "Error reading new panel from " << panel_path);
+ return false;
+ }
+ SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
+ globals->get_current_panel()->unbind();
+ delete globals->get_current_panel();
+ globals->set_current_panel( new_panel );
+ globals->get_current_panel()->bind();
+ return true;
+}
+
+
+/**
+ * Built-in command: pass a mouse click to the panel.
+ *
+ * button: the mouse button number, zero-based.
+ * is-down: true if the button is down, false if it is up.
+ * x-pos: the x position of the mouse click.
+ * y-pos: the y position of the mouse click.
+ */
+static bool
+do_panel_mouse_click (const SGPropertyNode * arg)
+{
+ if (globals->get_current_panel() != 0)
+ return globals->get_current_panel()
+ ->doMouseAction(arg->getIntValue("button"),
+ arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
+ arg->getIntValue("x-pos"),
+ arg->getIntValue("y-pos"));
+ else
+ return false;
+}
+
+
+/**
+ * Built-in command: (re)load preferences.
+ *
+ * path (optional): the file name to load the panel from (relative
+ * to FG_ROOT). Defaults to "preferences.xml".
+ */
+static bool
+do_preferences_load (const SGPropertyNode * arg)
+{
+ try {
+ fgLoadProps(arg->getStringValue("path", "preferences.xml"),
+ globals->get_props());
+ } catch (const sg_exception &e) {
+ guiErrorMessage("Error reading global preferences: ", e);
+ return false;
+ }
+ SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
+ return true;
+}
+
+
+static void
+fix_hud_visibility()
+{
+ if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
+ globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
+ if ( globals->get_viewmgr()->get_current() == 1 ) {
+ globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
+ }
+ }
+}
+
+static void
+do_view_next( bool )
+{
+ globals->get_current_view()->setHeadingOffset_deg(0.0);
+ globals->get_viewmgr()->next_view();
+ fix_hud_visibility();
+ globals->get_tile_mgr()->refresh_view_timestamps();
+}
+
+static void
+do_view_prev( bool )
+{
+ globals->get_current_view()->setHeadingOffset_deg(0.0);
+ globals->get_viewmgr()->prev_view();
+ fix_hud_visibility();
+ globals->get_tile_mgr()->refresh_view_timestamps();
+}
+