]> git.mxchange.org Git - flightgear.git/commitdiff
Improvements to exposing FGPositioned via commands - support frequency searches.
authorJames Turner <zakalawe@mac.com>
Wed, 1 Jun 2011 22:55:04 +0000 (23:55 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 1 Jun 2011 22:55:04 +0000 (23:55 +0100)
src/Main/fg_commands.cxx
src/Navaids/PositionedBinding.cxx
src/Navaids/positioned.cxx

index c2058ba1978b06b80a38ac4c481e535a5727d735..f9933243d055cf6598b802ea37950e9a181ee085 100644 (file)
@@ -34,6 +34,9 @@
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.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"
@@ -1349,7 +1352,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.
 ////////////////////////////////////////////////////////////////////////
@@ -1421,6 +1480,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
 };
 
index c1ecdf0aa122643ea4ad30921b312bef2e5aeb39..8a2f23f6f66bb40442b6585502f551a29ae68ad3 100644 (file)
@@ -148,12 +148,27 @@ AirportBinding::AirportBinding(const FGAirport* apt, SGPropertyNode* nd) :
     for (unsigned int c=0; c<apt->commStations().size(); ++c) {
         flightgear::CommStation* comm = apt->commStations()[c];
         std::string tynm = FGPositioned::nameForType(comm->type());
-        int count = nd->getChildren(tynm).size();
         
-        SGPropertyNode* commNode = nd->getChild(tynm, count, true);
-        commNode->setStringValue("ident", comm->ident());
-        commNode->setDoubleValue("frequency-mhz", comm->freqMHz());
-    }
+      // for some standard frequence types, we don't care about the ident,
+      // so just list the frequencies under one group.
+        if ((comm->type() == FGPositioned::FREQ_ATIS) ||
+            (comm->type() == FGPositioned::FREQ_AWOS) ||
+            (comm->type() == FGPositioned::FREQ_TOWER) ||
+            (comm->type() == FGPositioned::FREQ_GROUND))
+        {
+          SGPropertyNode* commNode = nd->getChild(tynm, 0, true);
+          int count = nd->getChildren("frequency-mhz").size();
+          SGPropertyNode* freqNode = commNode->getChild("frequency-mhz", count, true);
+          freqNode->setDoubleValue(comm->freqMHz());
+        } else {
+      // for other kinds of frequency, there's more variation, so list the ID too
+          int count = nd->getChildren(tynm).size();
+          SGPropertyNode* commNode = nd->getChild(tynm, count, true);
+          commNode->setStringValue("ident", comm->ident());
+          commNode->setDoubleValue("frequency-mhz", comm->freqMHz());
+
+        }
+      } // of airprot comm stations iteration
 }
 
 CommStationBinding::CommStationBinding(const CommStation* sta, SGPropertyNode* node) :
index b67e9c75d70b96bc3b47bc057f5f1986d0c19876..88613881bf96e88aa7b30f462488286cb69464d3 100644 (file)
@@ -861,7 +861,7 @@ FGPositioned::Filter* createSearchFilter(const SGPropertyNode* arg)
     return NULL;
 }
 
-SGGeod commandSearchPos(const SGPropertyNode* arg)
+static SGGeod commandSearchPos(const SGPropertyNode* arg)
 {
     if (arg->hasChild("longitude-deg") && arg->hasChild("latitude-deg")) {
         return SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),