]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
Constant-speed props were seeking to engine speed, not prop speed.
[flightgear.git] / src / Main / fg_commands.cxx
index 69edb7d0cc3d55f651006806d68d967b285ace92..335b25599c8ad379f7fcbb7da8a7cc04d91955d4 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
+#include <Cockpit/hud.hxx>
 #include <Environment/environment.hxx>
 #include <FDM/flight.hxx>
 #include <GUI/gui.h>
@@ -35,7 +36,7 @@
 #include "fg_commands.hxx"
 #include "fg_props.hxx"
 #include "globals.hxx"
-#include "logger.cxx"
+#include "logger.hxx"
 #include "util.hxx"
 #include "viewmgr.hxx"
 
@@ -227,6 +228,11 @@ do_reinit (const SGPropertyNode * arg)
     return result;
 }
 
+#if 0
+  //
+  // these routines look useful ??? but are never used in the code ???
+  //
+
 /**
  * Built-in command: suspend one or more subsystems.
  *
@@ -275,6 +281,8 @@ do_resume (const SGPropertyNode * arg)
     return result;
 }
 
+#endif
+
 
 /**
  * Built-in command: load flight.
@@ -448,6 +456,17 @@ do_screen_capture (const SGPropertyNode * arg)
 }
 
 
+/**
+ * Built-in command: hires capture screen.
+ */
+static bool
+do_hires_screen_capture (const SGPropertyNode * arg)
+{
+  fgHiResDump();
+  return true;
+}
+
+
 /**
  * Reload the tile cache.
  */
@@ -479,6 +498,43 @@ do_tile_cache_reload (const SGPropertyNode * arg)
 }
 
 
+/**
+ * Set the sea level outside air temperature and assigning that to all
+ * boundary and aloft environment layers.
+ */
+static bool
+do_set_sea_level_degc (const SGPropertyNode * arg)
+{
+    double temp_sea_level_degc = arg->getDoubleValue("temp-degc", 15.0);
+
+    SGPropertyNode *node, *child;
+
+    // boundary layers
+    node = fgGetNode( "/environment/config/boundary" );
+    if ( node != NULL ) {
+      int i = 0;
+      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+       child->setDoubleValue( "temperature-sea-level-degc",
+                              temp_sea_level_degc );
+       ++i;
+      }
+    }
+
+    // aloft layers
+    node = fgGetNode( "/environment/config/aloft" );
+    if ( node != NULL ) {
+      int i = 0;
+      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+       child->setDoubleValue( "temperature-sea-level-degc",
+                              temp_sea_level_degc );
+       ++i;
+      }
+    }
+
+    return true;
+}
+
+
 /**
  * Set the outside air temperature at the "current" altitude by first
  * calculating the corresponding sea level temp, and assigning that to
@@ -489,8 +545,12 @@ do_set_oat_degc (const SGPropertyNode * arg)
 {
     const string &temp_str = arg->getStringValue("temp-degc", "15.0");
 
-    static const SGPropertyNode *altitude_ft
-      = fgGetNode("/position/altitude-ft");
+    // check for an altitude specified in the arguments, otherwise use
+    // current aircraft altitude.
+    const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
+    if ( altitude_ft == NULL ) {
+        altitude_ft = fgGetNode("/position/altitude-ft");
+    }
 
     FGEnvironment dummy;       // instantiate a dummy so we can leech a method
     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
@@ -528,6 +588,96 @@ do_set_oat_degc (const SGPropertyNode * arg)
     return true;
 }
 
+/**
+ * Set the sea level outside air dewpoint and assigning that to all
+ * boundary and aloft environment layers.
+ */
+static bool
+do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
+{
+    double dewpoint_sea_level_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
+
+    SGPropertyNode *node, *child;
+
+    // boundary layers
+    node = fgGetNode( "/environment/config/boundary" );
+    if ( node != NULL ) {
+      int i = 0;
+      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+       child->setDoubleValue( "dewpoint-sea-level-degc",
+                              dewpoint_sea_level_degc );
+       ++i;
+      }
+    }
+
+    // aloft layers
+    node = fgGetNode( "/environment/config/aloft" );
+    if ( node != NULL ) {
+      int i = 0;
+      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+       child->setDoubleValue( "dewpoint-sea-level-degc",
+                              dewpoint_sea_level_degc );
+       ++i;
+      }
+    }
+
+    return true;
+}
+
+
+/**
+ * Set the outside air dewpoint at the "current" altitude by first
+ * calculating the corresponding sea level dewpoint, and assigning
+ * that to all boundary and aloft environment layers.
+ */
+static bool
+do_set_dewpoint_degc (const SGPropertyNode * arg)
+{
+    const string &dewpoint_str = arg->getStringValue("dewpoint-degc", "5.0");
+
+    // check for an altitude specified in the arguments, otherwise use
+    // current aircraft altitude.
+    const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
+    if ( altitude_ft == NULL ) {
+        altitude_ft = fgGetNode("/position/altitude-ft");
+    }
+
+    FGEnvironment dummy;       // instantiate a dummy so we can leech a method
+    dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
+    dummy.set_dewpoint_degc( atof( dewpoint_str.c_str() ) );
+    double dewpoint_sea_level_degc = dummy.get_dewpoint_sea_level_degc();
+
+    cout << "Altitude = " << altitude_ft->getDoubleValue() << endl;
+    cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl;
+    cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl;
+    SGPropertyNode *node, *child;
+
+    // boundary layers
+    node = fgGetNode( "/environment/config/boundary" );
+    if ( node != NULL ) {
+      int i = 0;
+      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+       child->setDoubleValue( "dewpoint-sea-level-degc",
+                              dewpoint_sea_level_degc );
+       ++i;
+      }
+    }
+
+    // aloft layers
+    node = fgGetNode( "/environment/config/aloft" );
+    if ( node != NULL ) {
+      int i = 0;
+      while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
+       child->setDoubleValue( "dewpoint-sea-level-degc",
+                              dewpoint_sea_level_degc );
+       ++i;
+      }
+    }
+
+    return true;
+}
+
 /**
  * Update the lighting manually.
  */
@@ -1003,7 +1153,7 @@ static bool
 do_replay (const SGPropertyNode * arg)
 {
     // freeze the master fdm
-    fgSetBool( "/sim/freeze/replay", true );
+    fgSetInt( "/sim/freeze/replay-state", 1 );
 
     FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
 
@@ -1046,6 +1196,101 @@ do_increase_visibility (const SGPropertyNode * arg)
     return true;
 }
 
+static bool
+do_hud_brightkey(const SGPropertyNode *)
+{
+    HUD_brightkey( true );
+    return true;
+}
+
+static bool
+do_hud_masterswitch(const SGPropertyNode *)
+{
+    HUD_masterswitch( true );
+    return true;
+}
+
+static bool
+do_hud_init(const SGPropertyNode *)
+{
+    fgHUDInit(0); // minimal HUD
+    return true;
+}
+
+static bool
+do_hud_init2(const SGPropertyNode *)
+{
+    fgHUDInit2(0);  // normal HUD
+    return true;
+}
+
+/**
+ * An fgcommand to allow loading of xml files via nasal,
+ * the xml file's structure will be made available within
+ * a (definable) property tree node
+ *
+ * @param filename a string to hold the complete path & filename of a XML file
+ * @param targetnode a string pointing to a location within the property tree
+ * where to store the parsed XML file
+ */
+
+static bool 
+do_load_xml_to_proptree(const SGPropertyNode * node)
+{
+    // SG_LOG(SG_GENERAL, SG_ALERT, "fgcommand loadxml executed");
+
+    SGPropertyNode * targetnode;
+    targetnode = fgGetNode(node->getNode("targetnode")->getStringValue(),true);
+               
+    const char *filename = node->getNode("filename")->getStringValue();
+    try {
+        fgLoadProps(filename, targetnode);
+    } catch (const sg_exception &e) {
+        string errmsg = "Error reading file " + string(filename) + ":\n";
+        guiErrorMessage(errmsg.c_str(), e);
+        return false;
+    }
+
+    return  true;
+}
+
+
+/**
+ * an fgcommand to allow saving of xml files via nasal,
+ * the file's structure will be determined based on what's
+ * encountered in the passed (source) property tree node
+ *
+ * @param filename a string to hold the complete path & filename of the (new)
+ * XML file
+ * @param sourcenode a string pointing to a location within the property tree
+ * where to find the nodes that should be written recursively into an XML file
+ *
+ * TODO: 
+ *   deal with already existing filenames, optionally return error/success
+ *   values in a separate node to provide status information
+ *
+ * note: it's directly using writeProperties, which is not necessarily
+ *       preferable, but for now it should work ...
+ */
+
+static bool 
+do_save_xml_from_proptree(const SGPropertyNode * node)
+{
+    //TODO: do Parameter validation !
+    SGPropertyNode * sourcenode;
+    sourcenode = fgGetNode(node->getNode("sourcenode")->getStringValue(),true);
+
+    const char *filename = node->getNode("filename")->getStringValue();
+    try {
+        writeProperties (filename, sourcenode, true);
+    } catch (const sg_exception &e) {
+        string errmsg = "Error writing file " + string(filename) + ":\n";
+        guiErrorMessage(errmsg.c_str(), e);
+        return false;
+    }
+
+    return true;
+}
 
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
@@ -1078,8 +1323,12 @@ static struct {
     { "preferences-load", do_preferences_load },
     { "view-cycle", do_view_cycle },
     { "screen-capture", do_screen_capture },
+    { "hires-screen-capture", do_hires_screen_capture },
     { "tile-cache-reload", do_tile_cache_reload },
+    { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
     { "set-outside-air-temp-degc", do_set_oat_degc },
+    { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
+    { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
     { "timeofday", do_timeofday },
     { "property-toggle", do_property_toggle },
     { "property-assign", do_property_assign },
@@ -1101,6 +1350,12 @@ static struct {
     { "replay", do_replay },
     { "decrease-visibility", do_decrease_visibility },
     { "increase-visibility", do_increase_visibility },
+    { "hud-brightkey", do_hud_brightkey },
+    { "hud-masterswitch", do_hud_masterswitch },
+    { "hud-init", do_hud_init },
+    { "hud-init2", do_hud_init2 },
+    { "loadxml", do_load_xml_to_proptree},
+    { "savexml", do_save_xml_from_proptree },    
     { 0, 0 }                   // zero-terminated
 };