]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_commands.cxx
Fix shared library build for metar executable
[flightgear.git] / src / Main / fg_commands.cxx
index 607c11c88aa97e04c1bd90eaa67eddf39224fa94..a07739d2ae74352e831ce59ee31ccb3eebdff6f6 100644 (file)
@@ -19,6 +19,7 @@
 #include <simgear/structure/exception.hxx>
 #include <simgear/structure/commands.hxx>
 #include <simgear/props/props.hxx>
+#include <simgear/props/props_io.hxx>
 #include <simgear/structure/event_mgr.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/timing/sg_time.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.hxx>
-#include <Time/sunsolver.hxx>
 #include <Airports/xmlloader.hxx>
+#include <ATC/CommStation.hxx>
+#include <Navaids/navrecord.hxx>
+#include <Navaids/navlist.hxx>
 
 #include "fg_init.hxx"
 #include "fg_io.hxx"
@@ -188,27 +191,18 @@ do_exit (const SGPropertyNode * arg)
     fgSetBool("/sim/signals/exit", true);
 
     if (fgGetBool("/sim/startup/save-on-exit")) {
-#ifdef _WIN32
-        char* envp = ::getenv( "APPDATA" );
-        if ( envp != NULL ) {
-            SGPath config( envp );
-            config.append( "flightgear.org" );
-#else
-        if ( homedir != NULL ) {
-            SGPath config( homedir );
-            config.append( ".fgfs" );
-#endif
-            config.append( "autosave.xml" );
-            config.create_dir( 0700 );
-            SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str());
-            try {
-                writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
-            } catch (const sg_exception &e) {
-                guiErrorMessage("Error writing autosave.xml: ", e);
-            }
+      SGPath autosaveFile(fgGetString("/sim/fg-home"));
+      autosaveFile.append( "autosave.xml" );
+      autosaveFile.create_dir( 0700 );
+      SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
+      try {
+        writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
+      } catch (const sg_exception &e) {
+        guiErrorMessage("Error writing autosave.xml: ", e);
+      }
+      
+      SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
 
-            SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
-        }
     }
     
     fgOSExit(arg->getIntValue("status", 0));
@@ -315,14 +309,32 @@ do_resume (const SGPropertyNode * arg)
 
 #endif
 
+/**
+ * Built-in command: replay the FDR buffer
+ */
+static bool
+do_replay (const SGPropertyNode * arg)
+{
+    FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));
+    return r->start();
+}
+
+/**
+ * Built-in command: pause/unpause the sim
+ */
 static bool
 do_pause (const SGPropertyNode * arg)
 {
     bool paused = fgGetBool("/sim/freeze/master",true) || fgGetBool("/sim/freeze/clock",true);
-    fgSetBool("/sim/freeze/master",!paused);
-    fgSetBool("/sim/freeze/clock",!paused);
-    if (fgGetBool("/sim/freeze/replay-state",false))
-        fgSetBool("/sim/replay/disable",true);
+    if (paused && (fgGetInt("/sim/freeze/replay-state",0)>0))
+    {
+        do_replay(NULL);
+    }
+    else
+    {
+        fgSetBool("/sim/freeze/master",!paused);
+        fgSetBool("/sim/freeze/clock",!paused);
+    }
     return true;
 }
 
@@ -699,85 +711,6 @@ do_set_dewpoint_degc (const SGPropertyNode * arg)
     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
 }
 #endif
-/**
- * Update the lighting manually.
- */
-static bool
-do_timeofday (const SGPropertyNode * arg)
-{
-    const string &offset_type = arg->getStringValue("timeofday", "noon");
-
-    static const SGPropertyNode *longitude
-        = fgGetNode("/position/longitude-deg");
-    static const SGPropertyNode *latitude
-        = fgGetNode("/position/latitude-deg");
-
-    int orig_warp = globals->get_warp();
-    SGTime *t = globals->get_time_params();
-    time_t cur_time = t->get_cur_time();
-    // cout << "cur_time = " << cur_time << endl;
-    // cout << "orig_warp = " << orig_warp << endl;
-
-    int warp = 0;
-    if ( offset_type == "real" ) {
-        warp = -orig_warp;
-    } else if ( offset_type == "dawn" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           90.0, true ); 
-    } else if ( offset_type == "morning" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           75.0, true ); 
-    } else if ( offset_type == "noon" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           0.0, true ); 
-    } else if ( offset_type == "afternoon" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           60.0, false ); 
-     } else if ( offset_type == "dusk" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           90.0, false ); 
-     } else if ( offset_type == "evening" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           100.0, false ); 
-    } else if ( offset_type == "midnight" ) {
-        warp = fgTimeSecondsUntilSunAngle( cur_time,
-                                           longitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           latitude->getDoubleValue()
-                                             * SGD_DEGREES_TO_RADIANS,
-                                           180.0, false ); 
-    }
-    
-
-    fgSetInt("/sim/time/warp", orig_warp + warp);
-    
-    return true;
-}
-
 
 /**
  * Built-in command: toggle a bool property value.
@@ -803,15 +736,18 @@ static bool
 do_property_assign (const SGPropertyNode * arg)
 {
   SGPropertyNode * prop = get_prop(arg);
-  const SGPropertyNode * prop2 = get_prop2(arg);
   const SGPropertyNode * value = arg->getNode("value");
 
   if (value != 0)
       return prop->setUnspecifiedValue(value->getStringValue());
-  else if (prop2)
-      return prop->setUnspecifiedValue(prop2->getStringValue());
   else
-      return false;
+  {
+      const SGPropertyNode * prop2 = get_prop2(arg);
+      if (prop2)
+          return prop->setUnspecifiedValue(prop2->getStringValue());
+      else
+          return false;
+  }
 }
 
 
@@ -1095,6 +1031,20 @@ do_dialog_update (const SGPropertyNode * arg)
     }
 }
 
+static bool
+do_open_browser (const SGPropertyNode * arg)
+{
+    string path;
+    if (arg->hasValue("path"))
+        path = arg->getStringValue("path");
+    else
+    if (arg->hasValue("url"))
+        path = arg->getStringValue("url");
+    else
+        return false;
+
+    return openBrowser(path);
+}
 
 /**
  * Apply a value in the active XML-configured dialog.
@@ -1141,14 +1091,9 @@ static bool
 do_add_model (const SGPropertyNode * arg)
 {
     SGPropertyNode * model = fgGetNode("models", true);
-    for (int i = 0;; i++) {
-        if (i < 0)
-            return false;
-        if (!model->getChild("model", i, false)) {
-            model = model->getChild("model", i, true);
-            break;
-        }
-    }
+    int i;
+    for (i = 0; model->hasChild("model",i); i++);
+    model = model->getChild("model", i, true);
     copyProperties(arg, model);
     if (model->hasValue("elevation-m"))
         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
@@ -1248,24 +1193,6 @@ do_log_level (const SGPropertyNode * arg)
    return true;
 }
 
-/**
- * Built-in command: replay the FDR buffer
- */
-static bool
-do_replay (const SGPropertyNode * arg)
-{
-    // freeze the fdm, resume from sim pause 
-    fgSetInt( "/sim/freeze/replay-state", 1 );
-    fgSetBool("/sim/freeze/master", 0 );
-    fgSetBool("/sim/freeze/clock", 0 );
-    fgSetDouble( "/sim/replay/time", -1 );
-
-    // cout << "start = " << r->get_start_time()
-    //      << "  end = " << r->get_end_time() << endl;
-
-    return true;
-}
-
 /*
 static bool
 do_decrease_visibility (const SGPropertyNode * arg)
@@ -1306,7 +1233,15 @@ do_load_xml_to_proptree(const SGPropertyNode * arg)
     std::string icao = arg->getStringValue("icao");
     if (icao.empty()) {
         if (file.isRelative()) {
-          file = globals->resolve_maybe_aircraft_path(file.str());
+          SGPath absPath = globals->resolve_maybe_aircraft_path(file.str());
+          if (!absPath.isNull())
+              file = absPath;
+          else
+          {
+              SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '"  
+                          << file.str() << "'.");
+              return false;
+          }
         }
     } else {
         if (!XMLLoader::findAirportData(icao, file.str(), file)) {
@@ -1429,7 +1364,63 @@ do_release_cockpit_button (const SGPropertyNode *arg)
   return true;
 }
 
+static SGGeod commandSearchPos(const SGPropertyNode* arg)
+{
+  if (arg->hasChild("longitude-deg") && arg->hasChild("latitude-deg")) {
+    return SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
+                           arg->getDoubleValue("latitude-deg"));
+  }
+  
+  // use current viewer/aircraft position
+  return SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"), 
+                         fgGetDouble("/position/latitude-deg"));
+}
+  
+static bool
+do_comm_search(const SGPropertyNode* arg)
+{
+  SGGeod pos = commandSearchPos(arg);
+  int khz = static_cast<int>(arg->getDoubleValue("frequency-mhz") * 100.0 + 0.25);
+  
+  flightgear::CommStation* sta = flightgear::CommStation::findByFreq(khz, pos, NULL);
+  if (!sta) {
+    return true;
+  }
+  
+  SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
+  sta->createBinding(result);
+  return true;
+}
 
+static bool
+do_nav_search(const SGPropertyNode* arg)
+{
+  SGGeod pos = commandSearchPos(arg);
+  double mhz = arg->getDoubleValue("frequency-mhz");
+
+  FGNavList* navList = globals->get_navlist();
+  string type(arg->getStringValue("type", "vor"));
+  if (type == "dme") {
+    navList = globals->get_dmelist();
+  } else if (type == "tacan") {
+    navList = globals->get_tacanlist();
+  }
+  
+  FGNavRecord* nav = navList->findByFreq(mhz, pos);
+  if (!nav && (type == "vor")) {
+    // if we're searching VORs, look for localizers too
+    nav = globals->get_loclist()->findByFreq(mhz, pos);
+  }
+  
+  if (!nav) {
+    return true;
+  }
+  
+  SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
+  nav->createBinding(result);
+  return true;
+}
+  
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
 ////////////////////////////////////////////////////////////////////////
@@ -1468,7 +1459,6 @@ static struct {
     { "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 },
     { "property-adjust", do_property_adjust },
@@ -1483,6 +1473,7 @@ static struct {
     { "dialog-close", do_dialog_close },
     { "dialog-update", do_dialog_update },
     { "dialog-apply", do_dialog_apply },
+    { "open-browser", do_open_browser },
     { "gui-redraw", do_gui_redraw },
     { "add-model", do_add_model },
     { "set-cursor", do_set_cursor },
@@ -1502,6 +1493,10 @@ static struct {
     { "dump-terrainbranch", do_dump_terrain_branch },
     { "print-visible-scene", do_print_visible_scene_info },
     { "reload-shaders", do_reload_shaders },
+  
+    { "find-navaid", do_nav_search },
+    { "find-comm", do_comm_search },
+  
     { 0, 0 }                   // zero-terminated
 };