Skip to content

Commit

Permalink
Added new tab to show nearest map objects for airport:
Browse files Browse the repository at this point in the history
One list with radio navaids and one list with airports that have procedures.
#344
  • Loading branch information
albar965 committed Jul 23, 2019
1 parent 920362c commit 6fa6dff
Show file tree
Hide file tree
Showing 17 changed files with 655 additions and 156 deletions.
360 changes: 248 additions & 112 deletions src/common/htmlinfobuilder.cpp

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions src/common/htmlinfobuilder.h
Expand Up @@ -52,6 +52,8 @@ struct MapProcedurePoint;
struct MapProcedureRef;
struct MapUserpoint;
struct MapLogbookEntry;
struct MapBase;
struct MapSearchResultMixed;
}

namespace atools {
Expand Down Expand Up @@ -148,6 +150,10 @@ class HtmlInfoBuilder
*/
void procedureText(const map::MapAirport& airport, atools::util::HtmlBuilder& html) const;

/* Get information for navaids and airports near the currently displayed airport */
void nearestText(const map::MapAirport& airport, atools::util::HtmlBuilder& html) const;

/* Create HTML for decoded weather report for current airport */
void weatherText(const map::WeatherContext& context, const map::MapAirport& airport,
atools::util::HtmlBuilder& html) const;

Expand Down Expand Up @@ -175,6 +181,9 @@ class HtmlInfoBuilder
*/
void waypointText(const map::MapWaypoint& waypoint, atools::util::HtmlBuilder& html) const;

/* Get information for one ILS */
void ilsText(const map::MapIls& ils, atools::util::HtmlBuilder& html) const;

/* Description for user defined points */
void userpointText(map::MapUserpoint userpoint, atools::util::HtmlBuilder& html) const;

Expand Down Expand Up @@ -275,11 +284,18 @@ class HtmlInfoBuilder
symbolSizeTitle = value;
}

void ilsText(const map::MapIls& ils, atools::util::HtmlBuilder& html) const;

private:
void head(atools::util::HtmlBuilder& html, const QString& text) const;

void nearestMapObjectsText(const map::MapAirport& airport, atools::util::HtmlBuilder& html,
const map::MapSearchResultMixed *nearest, const QString& header, bool frequencyCol,
bool airportCol,
int maxRows) const;
void nearestMapObjectsTextRow(const map::MapAirport& airport, atools::util::HtmlBuilder& html, const QString& type,
const QString& ident, const QString& name, const QString& freq,
const map::MapBase *base,
float magVar, bool frequencyCol, bool airportCol) const;

/* Add scenery entries and links into table */
void addScenery(const atools::sql::SqlRecord *rec, atools::util::HtmlBuilder& html) const;
void addAirportScenery(const map::MapAirport& airport, atools::util::HtmlBuilder& html) const;
Expand Down Expand Up @@ -370,6 +386,7 @@ class HtmlInfoBuilder
atools::fs::util::MorseCode *morse;
bool info, print;
QLocale locale;

};

#endif // MAPHTMLINFOBUILDER
23 changes: 19 additions & 4 deletions src/common/maptypes.cpp
Expand Up @@ -1147,11 +1147,21 @@ QString vorText(const MapVor& vor)
return QObject::tr("%1 %2 (%3)").arg(vorType(vor)).arg(atools::capString(vor.name)).arg(vor.ident);
}

QString vorTextShort(const MapVor& vor)
{
return QObject::tr("%1 (%2)").arg(atools::capString(vor.name)).arg(vor.ident);
}

QString ndbText(const MapNdb& ndb)
{
return QObject::tr("NDB %1 (%2)").arg(atools::capString(ndb.name)).arg(ndb.ident);
}

QString ndbTextShort(const MapNdb& ndb)
{
return QObject::tr("%1 (%2)").arg(atools::capString(ndb.name)).arg(ndb.ident);
}

QString waypointText(const MapWaypoint& waypoint)
{
return QObject::tr("Waypoint %1").arg(waypoint.ident);
Expand Down Expand Up @@ -2023,19 +2033,24 @@ QString ilsText(const MapIls& ils)
QString::number(ils.frequency / 1000., 'f', 2) + " / " +
QString::number(atools::geo::normalizeCourse(ils.heading - ils.magvar), 'f', 0) + QObject::tr("°M");

if(ils.slope > 0)
if(ils.slope > 0.1f)
text += QObject::tr(" / GS ") + QString::number(ils.slope, 'f', 1) + QObject::tr("°");
if(ils.hasDme)
text += QObject::tr(" / DME");

return text;
}

QString ilsTextShort(map::MapIls& ils)
QString ilsTextShort(const map::MapIls& ils)
{
return ilsTextShort(ils.ident, ils.name, ils.slope > 0.f, ils.hasDme);
}

QString ilsType(const map::MapIls& ils)
{
return ils.slope > 0.f ? QObject::tr("ILS") : QObject::tr("LOC");
}

QString ilsTextShort(QString ident, QString name, bool gs, bool dme)
{
QString text;
Expand Down Expand Up @@ -2113,7 +2128,7 @@ void MapSearchResultMixed::addFromResult(const MapSearchResult& result, const Ma
addCopyAll(result.logbookEntries);
}

void MapSearchResultMixed::sortByDistance(const atools::geo::Pos& pos, bool reverse)
void MapSearchResultMixed::sortByDistance(const atools::geo::Pos& pos, bool sortNearToFar)
{
if(vector.isEmpty() || !pos.isValid())
return;
Expand All @@ -2122,7 +2137,7 @@ void MapSearchResultMixed::sortByDistance(const atools::geo::Pos& pos, bool reve
[ = ](const MapBase *obj1, const MapBase *obj2) -> bool
{
bool result = obj1->getPosition().distanceMeterTo(pos) < obj2->getPosition().distanceMeterTo(pos);
return reverse ? result : !result;
return sortNearToFar ? result : !result;
});
}

Expand Down
95 changes: 92 additions & 3 deletions src/common/maptypes.h
Expand Up @@ -104,12 +104,21 @@ bool isSoftSurface(const QString& surface);

// =====================================================================
/* Base struct for all map objects covering id and position
* Position is used to check for validity, i.e. not initialized objects */
* Position is used to check for validity, i.e. not initialized objects
* Object type can be NONE if no polymorphism is needed */
struct MapBase
{
MapBase(map::MapObjectType type)
: objType(type)
{
}

int id;
atools::geo::Pos position;

/* Use simple type information to avoid vtable and RTTI overhead. Avoid QFlags here. */
map::MapObjectType objType;

bool isValid() const
{
return position.isValid();
Expand All @@ -125,6 +134,15 @@ struct MapBase
return id;
}

template<typename TYPE>
const TYPE *asType(map::MapObjectTypes type) const
{
if(objType == type)
return static_cast<const TYPE *>(this);
else
return nullptr;
}

};

// =====================================================================
Expand All @@ -133,6 +151,10 @@ struct MapBase
struct MapAirport
: public MapBase
{
MapAirport() : MapBase(map::AIRPORT)
{
}

QString ident, /* ICAO ident*/ name, region;
int longestRunwayLength = 0, longestRunwayHeading = 0, transitionAltitude = 0;
int rating = -1;
Expand Down Expand Up @@ -192,6 +214,10 @@ struct MapAirport
struct MapRunway
: public MapBase
{
MapRunway() : MapBase(map::NONE)
{
}

QString surface, shoulder, primaryName, secondaryName, edgeLight;
int length /* ft */, primaryEndId, secondaryEndId;
float heading, patternAlt;
Expand Down Expand Up @@ -243,6 +269,10 @@ struct MapRunway
struct MapRunwayEnd
: public MapBase
{
MapRunwayEnd() : MapBase(map::RUNWAYEND)
{
}

QString name, leftVasiType, rightVasiType, pattern;
float heading, leftVasiPitch = 0.f, rightVasiPitch = 0.f;
bool secondary;
Expand All @@ -254,6 +284,10 @@ struct MapRunwayEnd
struct MapApron
: public MapBase
{
MapApron() : MapBase(map::NONE)
{
}

/* FSX/P3D simple geometry */
atools::geo::LineString vertices;

Expand Down Expand Up @@ -291,6 +325,10 @@ struct MapTaxiPath
struct MapParking
: public MapBase
{
MapParking() : MapBase(map::PARKING)
{
}

QString type, name, airlineCodes /* Comma separated list of airline codes */;
int airportId /* database id airport.airport_id */;
int number, /* -1 for X-Plane style free names. Otherwise FSX/P3D number */
Expand All @@ -304,6 +342,10 @@ struct MapParking
struct MapStart
: public MapBase
{
MapStart() : MapBase(map::NONE)
{
}

QString type /* RUNWAY, HELIPAD or WATER */, runwayName /* not empty if this is a runway start */;
int airportId /* database id airport.airport_id */;
int heading, helipadNumber /* -1 if not a helipad otherwise sequence number as it appeared in the BGL */;
Expand All @@ -314,6 +356,10 @@ struct MapStart
struct MapHelipad
: public MapBase
{
MapHelipad() : MapBase(map::HELIPAD)
{
}

QString surface, type, runwayName;
int startId, airportId, length, width, heading, start;
bool closed, transparent;
Expand All @@ -325,6 +371,10 @@ struct MapHelipad
struct MapVor
: public MapBase
{
MapVor() : MapBase(map::VOR)
{
}

QString ident, region, type /* HIGH, LOW, TERMINAL */, name /*, airportIdent*/;
float magvar;
int frequency /* MHz * 1000 */, range /* nm */;
Expand All @@ -348,6 +398,10 @@ struct MapVor
struct MapNdb
: public MapBase
{
MapNdb() : MapBase(map::NDB)
{
}

QString ident, region, type /* HH, H, COMPASS_POINT, etc. */, name /*, airportIdent*/;
float magvar;
int frequency /* kHz * 100 */, range /* nm */;
Expand All @@ -359,6 +413,10 @@ struct MapNdb
struct MapWaypoint
: public MapBase
{
MapWaypoint() : MapBase(map::WAYPOINT)
{
}

float magvar;
QString ident, region, type /* NAMED, UNAMED, etc. *//*, airportIdent*/;
int routeIndex = -1; /* Filled by the get nearest methods for building the context menu */
Expand All @@ -379,6 +437,10 @@ struct MapAirwayWaypoint
struct MapUserpointRoute
: public MapBase
{
MapUserpointRoute() : MapBase(map::USERPOINTROUTE)
{
}

QString name;
float magvar;
int routeIndex = -1; /* Filled by the get nearest methods for building the context menu */
Expand All @@ -389,6 +451,10 @@ struct MapUserpointRoute
struct MapUserpoint
: public MapBase
{
MapUserpoint() : MapBase(map::USERPOINT)
{
}

QString name, ident, region, type, description, tags;
bool temp = false;
};
Expand All @@ -398,6 +464,10 @@ struct MapUserpoint
struct MapLogbookEntry
: public MapBase
{
MapLogbookEntry() : MapBase(map::LOGBOOK)
{
}

QString departureName, departureIdent, departureRunway,
destinationName, destinationIdent, destinationRunway,
description, simulator, aircraftType,
Expand Down Expand Up @@ -443,6 +513,10 @@ enum MapAirwayDirection
struct MapAirway
: public MapBase
{
MapAirway() : MapBase(map::AIRWAY)
{
}

QString name;
map::MapAirwayType type;
int fromWaypointId, toWaypointId /* all database ids */;
Expand All @@ -461,6 +535,10 @@ struct MapAirway
struct MapMarker
: public MapBase
{
MapMarker() : MapBase(map::MARKER)
{
}

QString type, ident;
int heading;
};
Expand All @@ -471,6 +549,10 @@ struct MapMarker
struct MapIls
: public MapBase
{
MapIls() : MapBase(map::ILS)
{
}

QString ident, name, region;
float magvar, slope, heading, width;
int frequency /* MHz * 1000 */, range /* nm */;
Expand All @@ -487,6 +569,10 @@ struct MapIls
struct MapAirspace
: public MapBase
{
MapAirspace() : MapBase(map::AIRSPACE)
{
}

int minAltitude, maxAltitude;
QString name, /* Airspace name or callsign for online ATC */
comName, comType, minAltitudeType, maxAltitudeType,
Expand Down Expand Up @@ -679,7 +765,7 @@ struct MapSearchResultMixed
void addFromResult(const map::MapSearchResult& result, const MapObjectTypes& types = map::ALL);

/* Sort objects by distance to given position from closest to farthest */
void sortByDistance(const atools::geo::Pos& pos, bool reverse);
void sortByDistance(const atools::geo::Pos& pos, bool sortNearToFar);

/* Remove all objects which are more far away from pos than max distance */
void filterByDistance(const atools::geo::Pos& pos, float maxDistanceNm);
Expand Down Expand Up @@ -854,7 +940,8 @@ const QString& navTypeNameNdb(const QString& type);
const QString& navTypeNameWaypoint(const QString& type);

QString ilsText(const map::MapIls& ils);
QString ilsTextShort(map::MapIls& ils);
QString ilsType(const MapIls& ils);
QString ilsTextShort(const MapIls& ils);
QString ilsTextShort(QString ident, QString name, bool gs, bool dme);

QString edgeLights(const QString& type);
Expand Down Expand Up @@ -913,9 +1000,11 @@ QString airportText(const map::MapAirport& airport, int elideName = 1000);
QString airportTextShort(const map::MapAirport& airport);
QString vorFullShortText(const map::MapVor& vor);
QString vorText(const map::MapVor& vor);
QString vorTextShort(const MapVor& vor);
QString vorType(const map::MapVor& vor);
QString ndbFullShortText(const map::MapNdb& ndb);
QString ndbText(const map::MapNdb& ndb);
QString ndbTextShort(const MapNdb& ndb);
QString waypointText(const map::MapWaypoint& waypoint);
QString userpointRouteText(const map::MapUserpointRoute& userpoint);
QString userpointText(const MapUserpoint& userpoint);
Expand Down

0 comments on commit 6fa6dff

Please sign in to comment.