From: James Turner Date: Wed, 1 Jun 2011 22:55:04 +0000 (+0100) Subject: Improvements to exposing FGPositioned via commands - support frequency searches. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fc7e9740c3e34e1725ac28563285b7e6fa41972b;p=flightgear.git Improvements to exposing FGPositioned via commands - support frequency searches. --- diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index c2058ba19..f9933243d 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -34,6 +34,9 @@ #include #include #include +#include +#include +#include #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(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 }; diff --git a/src/Navaids/PositionedBinding.cxx b/src/Navaids/PositionedBinding.cxx index c1ecdf0aa..8a2f23f6f 100644 --- a/src/Navaids/PositionedBinding.cxx +++ b/src/Navaids/PositionedBinding.cxx @@ -148,12 +148,27 @@ AirportBinding::AirportBinding(const FGAirport* apt, SGPropertyNode* nd) : for (unsigned int c=0; ccommStations().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) : diff --git a/src/Navaids/positioned.cxx b/src/Navaids/positioned.cxx index b67e9c75d..88613881b 100644 --- a/src/Navaids/positioned.cxx +++ b/src/Navaids/positioned.cxx @@ -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"),