Skip to content

Commit

Permalink
Now extracting ICAO airport idents for waypoints, NDB and VOR for MSF…
Browse files Browse the repository at this point in the history
…S export. PLN element "ICAOAirport" was missing before.

Closes #614
  • Loading branch information
albar965 committed Feb 5, 2021
1 parent e2bab24 commit 7de144e
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 19 deletions.
53 changes: 35 additions & 18 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,46 @@ For example: #3 is https://github.com/albar965/littlenavmap/issues/3.

# Version 2.6.8

* Fixed crash on startup which can appear with Mercator projection zoomed far out.
* Fixed procedure display issues for turn bow after circular legs.
Example: LGSR VOR-B transition BINKI.
## Known Issues

* No SID and STAR yet from MSFS scenery library. This will come with a future update.
* MSFS multiplayer traffic is not shown in *Little Navmap*.

See user manual for further known problems:
https://www.littlenavmap.org/manuals/littlenavmap/release/2.6/en/APPENDIX.html#problems .

## Changes from 2.6.7 to 2.6.8

### General

* Fixed unrecoverable crash on startup which can appear with Mercator projection zoomed far out.
* Added error handling for missing layout file on startup if `Load window layout from last used
file` in `Options` on page `Startup and Updates` is checked. Removing or renaming the layout file
resulted in an unrecoverable crash on startup.
* Fixed procedure display issues for turn bow after circular legs. Example: LGSR VOR-B
transition BINKI.
* Fixed issue where weather to FSX and P3D was not transferred across networked connections.
* Various drawing and user interface corrections.

### Flight Plan

* Fixed issue where waypoints inserted for procedure endpoints received wrong altitude when saving
or exporting flight plans right after calculation. This causes error messages when loading the
resulting LNMPLN files. #608
* Now extracting ICAO airport idents for waypoints, NDB and VOR for MSFS export. PLN element
`ICAOAirport` was missing before and caused crashes when loading flight plans in MSFS. #614
* Added verbose logging option for X-Plane compiler based on navdatareader.cfg. Added warnings if
rows are not written to the database when loading scenery library.
* Corrections to X-Plane FMS export. Using DEP and DES keywords now instead of truncating ident.
This allows to reload the plan in *Little Navmap*.
* Added verbose logging option for X-Plane compiler based on navdatareader.cfg.
Added warnings if rows are not written to the database.
* Fixed flight plan export for FSX and MSFS which used the wrong coordinates for
destination element `DestinationLLA` in flight plan. This confused third party programs.
* Fixed flight plan export for FSX and MSFS which used the wrong coordinates for destination
element `DestinationLLA` in flight plan. This confused third party programs.
* Corrected wrong departure position for saved LNMPLN and FSX/P3D PLN flight plans. Now uses
position from parking, helipad or runway/start for PLN `DepartureLLA` and LNMPLN `Start` element.
albar965/littlenavmap#613
* Added error handling for missing layout file on startup if `Load window layout from last used file`
in `Options` on page `Startup and Updates` is checked.
Removing or renaming the layout file resulted in an unrecoverable crash on startup.
* Fixed issue where waypoints inserted for procedure endpoints received wrong altitude when saving
or exporting flight plans right after calculation. This causes error messages when loading the resulting
LNMPLN files. albar965/littlenavmap#608
* Fixed issue where LNMPLN flight plan procedures were replaced with waypoints inadvertently
if enabled in export options menu. This happened when saving LNMPLN plans with multiexport.
#613
* Fixed issue where LNMPLN flight plan procedures were replaced with waypoints inadvertently if
enabled in export options menu. This happened when saving LNMPLN plans with multiexport.
* Removed extra space to fix flight plan export for iFly (`.FLTPLAN`).
* Fixed issue where weather to FSX and P3D was not transferred across networked connections.
* Various drawing and user interface corrections.

===============================================================================

Expand Down
64 changes: 64 additions & 0 deletions src/query/mapquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ static double queryRectInflationFactor = 0.2;
static double queryRectInflationIncrement = 0.1;
int MapQuery::queryMaxRows = map::MAX_MAP_OBJECTS;

// Queries only used for export ================================================
// Get assigned airport for navaid by name, region and coordinate closest to position
static QLatin1String AIRPORTIDENT_FROM_WAYPOINT("select a.ident, w.lonx, w.laty "
"from waypoint w join airport a on a.airport_id = w.airport_id "
"where w. ident = :ident and w.region like :region "
"order by (abs(w.lonx - :lonx) + abs(w.laty - :laty)) limit 1");

static QLatin1String AIRPORTIDENT_FROM_VOR("select a.ident, v.lonx, v.laty "
"from vor v join airport a on a.airport_id = v.airport_id "
"where v.ident = :ident and v.region like :region "
"order by (abs(v.lonx - :lonx) + abs(v.laty - :laty)) limit 1");

static QLatin1String AIRPORTIDENT_FROM_NDB("select a.ident, n.lonx, n.laty "
"from ndb n join airport a on a.airport_id = n.airport_id "
"where n.ident = :ident and n.region like :region "
"order by (abs(n.lonx - :lonx) + abs(n.laty - :laty)) limit 1");
static float MAX_AIRPORT_IDENT_DISTANCE_M = atools::geo::nmToMeter(5.f);

MapQuery::MapQuery(atools::sql::SqlDatabase *sqlDb, SqlDatabase *sqlDbNav, SqlDatabase *sqlDbUser)
: dbSim(sqlDb), dbNav(sqlDbNav), dbUser(sqlDbUser)
{
Expand Down Expand Up @@ -767,6 +785,52 @@ const QList<map::MapUserpoint> MapQuery::getUserdataPoints(const GeoDataLatLonBo
return retval;
}

QString MapQuery::getAirportIdentSimFromWaypoint(const QString& ident, const QString& region, const Pos& pos,
bool found)
{
return airportIdentSimFromQuery(AIRPORTIDENT_FROM_WAYPOINT, ident, region, pos, found);
}

QString MapQuery::getAirportIdentSimFromVor(const QString& ident, const QString& region, const Pos& pos, bool found)
{
return airportIdentSimFromQuery(AIRPORTIDENT_FROM_VOR, ident, region, pos, found);
}

QString MapQuery::getAirportIdentSimFromNdb(const QString& ident, const QString& region, const Pos& pos, bool found)
{
return airportIdentSimFromQuery(AIRPORTIDENT_FROM_NDB, ident, region, pos, found);
}

QString MapQuery::airportIdentSimFromQuery(const QString& queryStr, const QString& ident, const QString& region,
const Pos& pos, bool& found)
{
found = false;

// Query for nearest navaid
SqlQuery query(dbSim);
query.prepare(queryStr);
query.bindValue(":ident", ident);
query.bindValue(":region", region.isEmpty() ? "%" : region);
query.bindValue(":lonx", pos.getLonX());
query.bindValue(":laty", pos.getLatY());

QString airport;
query.exec();
if(query.next())
{
// Check if max distance is not exceeded
Pos navaidPos(query.valueFloat("lonx"), query.valueFloat("laty"));
if(pos.distanceMeterTo(pos) < MAX_AIRPORT_IDENT_DISTANCE_M)
{
// Get airport ident and record that a navaid was found
found = true;
airport = query.valueStr("ident");
}
}
query.finish();
return airport;
}

const QList<map::MapMarker> *MapQuery::getMarkers(const GeoDataLatLonBox& rect, const MapLayer *mapLayer,
bool lazy, bool& overflow)
{
Expand Down
11 changes: 11 additions & 0 deletions src/query/mapquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ class MapQuery
const QStringList& typesAll,
bool unknownType, float distance);

/* Get related airport for navaids from simulator database.
* found is true if navaid search was successful and max distance to pos is not exceeded. */
QString getAirportIdentSimFromWaypoint(const QString& ident, const QString& region, const atools::geo::Pos& pos,
bool found);
QString getAirportIdentSimFromVor(const QString& ident, const QString& region, const atools::geo::Pos& pos,
bool found);
QString getAirportIdentSimFromNdb(const QString& ident, const QString& region, const atools::geo::Pos& pos,
bool found);

/* Close all query objects thus disconnecting from the database */
void initQueries();

Expand All @@ -199,6 +208,8 @@ class MapQuery

void runwayEndByNameFuzzy(QList<map::MapRunwayEnd>& runwayEnds, const QString& name, const map::MapAirport& airport,
bool navData);
QString airportIdentSimFromQuery(const QString& queryStr, const QString& ident, const QString& region,
const atools::geo::Pos& pos, bool& found);

MapTypesFactory *mapTypesFactory;
atools::sql::SqlDatabase *dbSim, *dbNav, *dbUser;
Expand Down
37 changes: 37 additions & 0 deletions src/route/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,43 @@ Route Route::adjustedToOptions(const Route& origRoute, rf::RouteAdjustOptions op
route.createRouteLegsFromFlightplan();
route.updateAll();

// Assign airport idents to waypoints where available - for MSFS =======================================
if(msfs)
{
MapQuery *mapQuery = NavApp::getMapQuery();
bool found = false;
for(FlightplanEntry& entry : entries)
{
// Get airport for every navaid
QString airportIdent;
switch(entry.getWaypointType())
{
case atools::fs::pln::entry::WAYPOINT:
airportIdent =
mapQuery->getAirportIdentSimFromWaypoint(entry.getIdent(), entry.getRegion(), entry.getPosition(), found);
break;

case atools::fs::pln::entry::VOR:
airportIdent =
mapQuery->getAirportIdentSimFromVor(entry.getIdent(), entry.getRegion(), entry.getPosition(), found);
break;

case atools::fs::pln::entry::NDB:
airportIdent =
mapQuery->getAirportIdentSimFromNdb(entry.getIdent(), entry.getRegion(), entry.getPosition(), found);
break;

case atools::fs::pln::entry::UNKNOWN:
case atools::fs::pln::entry::AIRPORT:
case atools::fs::pln::entry::USER:
break;
}

if(!airportIdent.isEmpty())
entry.setAirport(airportIdent);
}
}

// Airways are updated in route controller

} // if(saveApproachWp || saveSidStarWp || msfs)
Expand Down
3 changes: 2 additions & 1 deletion src/route/routeflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ enum RouteAdjustOption
FIX_CIRCLETOLAND = 1 << 7, /* Add a dummy best guess runway for circle-to-land approaches for X-Plane */
FIX_PROC_ENTRY_EXIT = 1 << 8, /* Add any removed procedure entry and exit points back */
SAVE_MSFS = 1 << 9, /* Insert all SID/STAR waypoints and add procedure information for each waypoint.
* Add approach information to last waypoint/destination */
* Add approach information to last waypoint/destination.
* Also adds airport information to waypoints from simulator database. */
SAVE_LNMPLN = 1 << 10, /* Ignore menu options to save procedures or airways as waypoints */

/* Export adjust options for most export formats */
Expand Down

0 comments on commit 7de144e

Please sign in to comment.