diff --git a/plugins/channelrx/demodadsb/adsbaircraft.cpp b/plugins/channelrx/demodadsb/adsbaircraft.cpp index 123460d4b..af57df39e 100644 --- a/plugins/channelrx/demodadsb/adsbaircraft.cpp +++ b/plugins/channelrx/demodadsb/adsbaircraft.cpp @@ -113,8 +113,9 @@ QString ADSBAircraft::getLiveryImage() const { // The 3D model matcher has already picked a model such as // BB_Airbus_png/A320/A320_BAW.gltf from the type and operator, and the livery icons - // are named after the models, so the icon just follows the model's basename - for (const QString& model : {m_aircraft3DModel, m_aircraftCat3DModel}) + // are named after the models, so the icon just follows the model's basename. Without + // the model pack, the matcher has picked from the icons themselves instead + for (const QString& model : {m_aircraft3DModel, m_liveryIcon, m_aircraftCat3DModel, m_catLiveryIcon}) { if (!model.isEmpty()) { diff --git a/plugins/channelrx/demodadsb/adsbaircraft.h b/plugins/channelrx/demodadsb/adsbaircraft.h index 391cef619..dca5eb4c0 100644 --- a/plugins/channelrx/demodadsb/adsbaircraft.h +++ b/plugins/channelrx/demodadsb/adsbaircraft.h @@ -149,6 +149,10 @@ struct ADSBAircraft { AircraftInformation *m_aircraftInfo; // Info about the aircraft from the database QString m_aircraft3DModel; // 3D model for map based on aircraft type QString m_aircraftCat3DModel; // 3D model based on aircraft category + // The same two choices made from the 2D livery icons, when there is no model pack to + // choose from: icon names, such as A320_BAW (see Aircraft3DModels::liveryIcons()) + QString m_liveryIcon; + QString m_catLiveryIcon; float m_modelAltitudeOffset; // Altitude adjustment so aircraft model doesn't go underground float m_labelAltitudeOffset; // How height to position label above aircraft QString m_flagName; // Country flag, for the GUI to resolve an icon from diff --git a/plugins/channelrx/demodadsb/adsbdemodtrackerdecode.cpp b/plugins/channelrx/demodadsb/adsbdemodtrackerdecode.cpp index ec1e16918..de8f357cb 100644 --- a/plugins/channelrx/demodadsb/adsbdemodtrackerdecode.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodtrackerdecode.cpp @@ -814,13 +814,21 @@ ADSBAircraft *ADSBDemodTracker::getAircraft(int icao, bool &newAircraft) } } - if (aircraft->m_aircraft3DModel.isEmpty()) + if (aircraft->m_aircraft3DModel.isEmpty() && aircraft->m_liveryIcon.isEmpty()) { - // Default to A320 until we get some more info - aircraft->m_aircraftCat3DModel = Aircraft3DModels::instance().modelForType("A320"); - Aircraft3DModels::instance().offsetsForType("A320", - aircraft->m_modelAltitudeOffset, aircraft->m_labelAltitudeOffset, - aircraft->m_aircraftCat3DModel); + // Default to A320 until we get some more info - its icon, with no model pack + // (see get3DModel()) + if (Aircraft3DModels::instance().isEmpty()) + { + aircraft->m_catLiveryIcon = Aircraft3DModels::liveryIcons().modelForType("A320"); + } + else + { + aircraft->m_aircraftCat3DModel = Aircraft3DModels::instance().modelForType("A320"); + Aircraft3DModels::instance().offsetsForType("A320", + aircraft->m_modelAltitudeOffset, aircraft->m_labelAltitudeOffset, + aircraft->m_aircraftCat3DModel); + } } // Check to see if we need to emit a notification about this new aircraft @@ -1159,8 +1167,9 @@ void ADSBDemodTracker::handleADSB( } // Select 3D model based on category, if we don't already have one based on ICAO - if ( aircraft->m_aircraft3DModel.isEmpty() - && ( aircraft->m_aircraftCat3DModel.isEmpty() + // (or its icon, with no model pack - chosen again each time, it would change) + if ( aircraft->m_aircraft3DModel.isEmpty() && aircraft->m_liveryIcon.isEmpty() + && ( (aircraft->m_aircraftCat3DModel.isEmpty() && aircraft->m_catLiveryIcon.isEmpty()) || (prevEmitterCategory != aircraft->m_emitterCategory) ) ) @@ -4660,7 +4669,12 @@ void ADSBDemodTracker::get3DModel(ADSBAircraft *aircraft) float altitudeOffset = aircraft->m_modelAltitudeOffset; float labelOffset = aircraft->m_labelAltitudeOffset; - const Aircraft3DModels &models = Aircraft3DModels::instance(); + const Aircraft3DModels &installed = Aircraft3DModels::instance(); + // With no model pack installed nothing matches, but the 2D livery icons are built in + // and named after the models, so the same choice is made from those - for the icon + // alone, as there is no model to send the map + const bool iconsOnly = installed.isEmpty(); + const Aircraft3DModels &models = iconsOnly ? Aircraft3DModels::liveryIcons() : installed; // Failing a model of its own type, a stand-in of the right shape for the type it is - // a business jet for a Premier, a twin turboprop for a King Air. That knows more than // the emitter category, so it is kept in preference to one: a category stand-in @@ -4670,9 +4684,16 @@ void ADSBDemodTracker::get3DModel(ADSBAircraft *aircraft) || models.defaultModel(aircraft->m_aircraftInfo->m_type.trimmed().toUpper(), model, altitudeOffset, labelOffset, true)) { - aircraft->m_aircraft3DModel = model; - aircraft->m_modelAltitudeOffset = altitudeOffset; - aircraft->m_labelAltitudeOffset = labelOffset; + if (iconsOnly) + { + aircraft->m_liveryIcon = model; + } + else + { + aircraft->m_aircraft3DModel = model; + aircraft->m_modelAltitudeOffset = altitudeOffset; + aircraft->m_labelAltitudeOffset = labelOffset; + } } } @@ -4682,6 +4703,12 @@ void ADSBDemodTracker::get3DModelBasedOnCategory(ADSBAircraft *aircraft) QStringList candidateTypes; // Any of these will do, for Heavy and Large static const QStringList large = {"A319", "A320", "A321", "B737", "B738", "B739", "A20N", "A21N"}; + // As in get3DModel(): with no model pack, the choice is made from the icons, for the icon + const Aircraft3DModels &installed = Aircraft3DModels::instance(); + const bool iconsOnly = installed.isEmpty(); + const Aircraft3DModels &models = iconsOnly ? Aircraft3DModels::liveryIcons() : installed; + aircraft->m_catLiveryIcon = ""; + if (!aircraft->m_emitterCategory.compare("Heavy")) { static const QStringList heavy = {"B744", "B77W", "B788", "A388", "B789", "A359", "B772", "A333", @@ -4702,11 +4729,18 @@ void ADSBDemodTracker::get3DModelBasedOnCategory(ADSBAircraft *aircraft) float altitudeOffset = aircraft->m_modelAltitudeOffset; float labelOffset = aircraft->m_labelAltitudeOffset; aircraft->m_aircraftCat3DModel = ""; - if (Aircraft3DModels::instance().defaultModel(light ? "C172" : "LJ45", model, altitudeOffset, labelOffset)) + if (models.defaultModel(light ? "C172" : "LJ45", model, altitudeOffset, labelOffset)) { - aircraft->m_aircraftCat3DModel = model; - aircraft->m_modelAltitudeOffset = altitudeOffset; - aircraft->m_labelAltitudeOffset = labelOffset; + if (iconsOnly) + { + aircraft->m_catLiveryIcon = model; + } + else + { + aircraft->m_aircraftCat3DModel = model; + aircraft->m_modelAltitudeOffset = altitudeOffset; + aircraft->m_labelAltitudeOffset = labelOffset; + } } } else if (!aircraft->m_emitterCategory.compare("Rotorcraft")) @@ -4767,7 +4801,6 @@ void ADSBDemodTracker::get3DModelBasedOnCategory(ADSBAircraft *aircraft) // and a 737-800 drawn, gave another airline's 737. An aircraft the database doesn't // know still has its operator in its callsign: the first three letters of an airline // callsign are its ICAO code - const Aircraft3DModels& models = Aircraft3DModels::instance(); QStringList operators; if (aircraft->m_aircraftInfo && !aircraft->m_aircraftInfo->m_operatorICAO.isEmpty()) { operators.append(aircraft->m_aircraftInfo->m_operatorICAO); @@ -4802,9 +4835,17 @@ void ADSBDemodTracker::get3DModelBasedOnCategory(ADSBAircraft *aircraft) aircraftType = type; } } - aircraft->m_aircraftCat3DModel = model; - if (!model.isEmpty()) { - models.offsetsForType(aircraftType, aircraft->m_modelAltitudeOffset, aircraft->m_labelAltitudeOffset, model); + if (iconsOnly) + { + aircraft->m_aircraftCat3DModel = ""; + aircraft->m_catLiveryIcon = model; + } + else + { + aircraft->m_aircraftCat3DModel = model; + if (!model.isEmpty()) { + models.offsetsForType(aircraftType, aircraft->m_modelAltitudeOffset, aircraft->m_labelAltitudeOffset, model); + } } } } diff --git a/plugins/feature/aircraft/aircrafttracker.cpp b/plugins/feature/aircraft/aircrafttracker.cpp index 61350ab02..c5715185a 100644 --- a/plugins/feature/aircraft/aircrafttracker.cpp +++ b/plugins/feature/aircraft/aircrafttracker.cpp @@ -405,10 +405,13 @@ void AircraftTracker::applySettings(const AircraftSettings& settings, const QLis { for (TrackedAircraft *item : m_aircraft) { - if (item->m_modelIsOurs) + if (item->m_modelIsOurs || !item->m_liveryIcon.isEmpty()) { - item->m_model3D = ""; + if (item->m_modelIsOurs) { + item->m_model3D = ""; + } item->m_modelIsOurs = false; + item->m_liveryIcon = ""; update3DModel(item); } } @@ -3166,11 +3169,17 @@ AircraftStatistics AircraftTracker::deserializeStatistics(const QByteArray& data // // Chosen ONCE and kept. The livery is picked at random where there is a choice, so asking // again on every report would change the aircraft's appearance as it flew. +// +// With no model pack installed nothing matches, but the 2D livery icons are built in and +// named after the models, so the same matching is done over those - for the icon alone, +// as there is no model to send the map. It is kept the same way. void AircraftTracker::update3DModel(TrackedAircraft *item) { - if (!item->m_model3D.isEmpty()) { + const bool iconsOnly = Aircraft3DModels::instance().isEmpty(); + if (!(iconsOnly ? item->m_liveryIcon : item->m_model3D).isEmpty()) { return; } + const Aircraft3DModels &models = iconsOnly ? Aircraft3DModels::liveryIcons() : Aircraft3DModels::instance(); const AircraftInformation *info = nullptr; if (m_aircraftInfo && !item->m_registration.isEmpty()) @@ -3184,7 +3193,7 @@ void AircraftTracker::update3DModel(TrackedAircraft *item) QString model; float altitudeOffset = 0.0f; float labelOffset = 0.0f; - bool matched = info && Aircraft3DModels::instance().modelFor( + bool matched = info && models.modelFor( info, m_settings.m_favourLivery, false, model, altitudeOffset, labelOffset); if (!matched) @@ -3192,11 +3201,15 @@ void AircraftTracker::update3DModel(TrackedAircraft *item) // Only a fraction of types have a model of their own, and an aircraft we know // nothing about has none either. Rather than leave it as a flat billboard among // modelled aircraft, stand in something of about the right shape and size - matched = Aircraft3DModels::instance().defaultModel( + matched = models.defaultModel( info ? info->m_type : QString(), model, altitudeOffset, labelOffset); } - if (matched) + if (matched && iconsOnly) + { + item->m_liveryIcon = model; + } + else if (matched) { item->m_model3D = model; item->m_modelAltitudeOffset = altitudeOffset; @@ -3474,7 +3487,7 @@ QString AircraftTracker::atcLabel(const TrackedAircraft *item) const // resources are process wide) QString AircraftTracker::aircraftImage(const TrackedAircraft *item) const { - return aircraftImage(item->m_registration, item->m_model3D); + return aircraftImage(item->m_registration, item->m_model3D.isEmpty() ? item->m_liveryIcon : item->m_model3D); } QString AircraftTracker::aircraftImage(const QString& registration, const QString& model3D) const @@ -3953,6 +3966,22 @@ void AircraftTracker::forwardMapItem(TrackedAircraft *item, SWGSDRangel::SWGMapI item->m_labelAltitudeOffset = swgMapItem->getLabelAltitudeOffset(); item->m_modelIsOurs = false; } + else if (swgMapItem->getImage()) + { + // With no model pack, ADS-B picks a livery icon in place of a model, and that is + // remembered the same way - otherwise the icon would switch to the one picked + // here whenever the pass-through went quiet. Not the plain icons in white, which + // are what it sends when it found nothing + static const QString liveries = QStringLiteral("qrc:///map/liveries/"); + const QString &image = *swgMapItem->getImage(); + if (image.startsWith(liveries)) + { + const QString icon = QFileInfo(image).completeBaseName(); + if (!icon.startsWith("aircraft_")) { + item->m_liveryIcon = icon; + } + } + } item->m_mapName = name; item->m_mapResync = false; m_mapResyncPending.remove(item); diff --git a/plugins/feature/aircraft/aircrafttracker.h b/plugins/feature/aircraft/aircrafttracker.h index 26bc87a94..6a7d95988 100644 --- a/plugins/feature/aircraft/aircrafttracker.h +++ b/plugins/feature/aircraft/aircrafttracker.h @@ -726,6 +726,10 @@ private: // be thrown away and chosen again when the livery preference changes - replacing // a pass-through model with our own would fight the demodulator for it. bool m_modelIsOurs = false; + // With no model pack installed, the 2D livery icon chosen in place of a model, by + // the same matching (see Aircraft3DModels::liveryIcons()) - or the one the ADS-B + // pass-through brought. An icon name, such as A320_BAW + QString m_liveryIcon; bool m_mapTrackChanged = true; //!< The track has only grown since it was last sent. The ADS-B pass-through sends //!< it at most every few seconds for that (see forwardMapItem()), where a change diff --git a/plugins/feature/aircraft/readme.md b/plugins/feature/aircraft/readme.md index 8a521518e..a9eac765a 100644 --- a/plugins/feature/aircraft/readme.md +++ b/plugins/feature/aircraft/readme.md @@ -15,7 +15,7 @@ continuous positions in VHF range, VDL-2 sees logons and CPDLC near airports, an can report an aircraft's position from thousands of kilometres away, hours after it left ADS-B range. The feature merges these into one aircraft with one track. -

Aircraft identity

+

Aircraft identity

Reports may identify an aircraft by any of: @@ -27,126 +27,13 @@ The feature merges reports under whichever identities it has seen, cross referen registration and ICAO address through the aircraft database. A flight number is remembered as the aircraft's most recent flight (flights change; the airframe does not). -

Tables and tabs

- -The upper half of the window holds the traffic: - -* **Aircraft** - every airframe currently being heard, one row each. See the column list - under Interface below -* **Old Aircraft** - airframes that have gone quiet for longer than the archive timeout. - They are not forgotten, only no longer current, and they come off the Map - -![Aircraft Table](../../../doc/img/AircraftFeature_aircraft_table.png) - -* **Flights** - the flights seen this session, current and past: flight number, aircraft, - departure and arrival, the four OOOI times, when it was first and last heard, which - documents it has produced, and which protocols heard it -* **Old Flights** - flights that have finished, and those restored from the last session - -![Flights Table](../../../doc/img/AircraftFeature_flights_table.png) - -* **Weather** - METARs, TAFs, D-ATIS, TWIPs, NOTAMs, PIREPs and SIGMETs carried by ACARS. - Selecting a row shows the full report. - -The lower half describes whatever is selected above: - -

Aircraft

- -Shows a photograph of the selected -aircraft from [planespotters.net](https://www.planespotters.net/) headed by its -registration and the country flag, with the airline's logo beneath it and a table of what -the aircraft database knows about the airframe beside it. Clicking the photograph opens it -on planespotters.net - -![Aircraft Tab](../../../doc/img/AircraftFeature_aircraft_tab.png) - -

Documents

- -Flight plans, oceanic clearances, loadsheets, logons and OOOI events, -collected against the flight number. Selecting one displays its full text -below the table. Plain ACARS messages are not collected. - -![Flight plan](../../../doc/img/AircraftFeature_flight_plan.png) - -![Loadsheet](../../../doc/img/AircraftFeature_loadsheet.png) - -![Clearance](../../../doc/img/AircraftFeature_clearance.png) - -

ATC

- -CPDLC (controller-pilot data link) messages across all channels, with the -protocol, direction (uplink from ATC, downlink from the aircraft), source and -recipient where known, and the concise message text (e.g. "WILCO"). SELCAL calls are -listed here too, with the frequency they were heard on as the source - see -[SELCAL](#selcal) below. With nothing selected, the table shows the SELCAL calls that -could not be attributed to an aircraft - -![ATC Tab](../../../doc/img/AircraftFeature_atc_tab.png) - -

Past Aircraft

- -Every airframe that has operated the selected **flight number**. -Shown only while a flight is selected. - -

Past Flights

- -Every flight the selected **aircraft** has operated. -Shown only while an aircraft is selected. -Selecting one of its rows charts that flight's profile and draws its track. - -

Flight profile

- -The Flight Profile tab charts the selected flight's altitude (left axis) and speed -(right axis) against time, showing the flight profile - climb, cruise and descent - built -from all protocols. - -![Flight Profile Tab](../../../doc/img/AircraftFeature_flight_profile.png) - -

SELCAL

- -A SELCAL call is a ground station calling an aircraft on an HF or VHF voice channel. It -carries only a code, and a code can be shared by several aircraft. - -An attributed call counts as a message from the aircraft: it adds "SELCAL" and the -frequency to the aircraft's protocols and updates when it was last seen. It carries no -position, so nothing moves on the Map. Every call, attributed or not, is listed in the ATC -tab. - -

Session persistence

+

Session persistence

The collated aircraft, flights, documents and ATC log are saved to a SQLite database (aircraft.db in the application data directory) every minute and on exit, and restored when the feature is next opened. -Tracks and flight profiles are **not** read at startup - only how many points each flight -has, which is what lets the save go on appending to them. The points themselves are -fetched a flight at a time, when something wants to draw or chart one. -On restore, aircraft that have not been heard within -the removal timeout are pruned, while the document and ATC logs are restored in full; -restored aircraft with positions reappear on the Map with their full tracks. - -Right clicking the statistics button offers to reset either half. Resetting the session -starts it again from that moment without touching the all time figures. Resetting all -time also clears the record of which airframes have been heard. - -

Finding things

- -The Find box highlights the next row matching what is typed, stepping through the matches -on each press of Enter. It searches the ICAO address, registration, type, flight number, -airline and departure and arrival airports at once, or a single one of them when the -column selector beside it is set to something other than All. The text turns red when -nothing matches. - -

Context menus

- -Right clicking a cell in any of the tables offers, as they apply to that cell: - -* **Copy** the cell's contents to the clipboard -* **Find on map** - centre the Map on that aircraft -* **Display flight** - jump to that flight in the Flights table, from the aircraft flying it -* **Display aircraft** - jump the other way, to the airframe operating a flight - -

Map

+

Map

Aircraft with a position are sent to the [Map feature](../map/readme.md), named by registration when known. @@ -190,11 +77,15 @@ without a report.

1: Find column

-Which field the Find box looks in - All, ICAO, Reg, Type or Flight. +Which field the Find box (2) looks in - All, ICAO, Reg, Type or Flight.

2: Find

-Highlights the next row matching the text. See Finding things above. +The Find box highlights the next row matching what is typed, stepping through the matches +on each press of Enter. It searches the ICAO address, registration, type, flight number, +airline and departure and arrival airports at once, or a single one of them when the +column selector (1) is set to something other than All. The text turns red when +nothing matches.

3: Delete aircraft

@@ -331,9 +222,13 @@ their airline's livery, instead of black icons. The icon follows the aircraft's 3D model, so this requires the 3D models to have been downloaded via the Map feature. Aircraft without a matching model are displayed with a white version of the plain icon. -

Aircraft table

+

Aircraft

+ +* **Aircraft** - every airframe currently being heard, one row each. +* **Old Aircraft** - airframes that have gone quiet for longer than the archive timeout. + They are not forgotten, only no longer current, and they come off the Map -The table shows one row per aircraft: +![Aircraft Table](../../../doc/img/AircraftFeature_aircraft_table.png) * ICAO - 24-bit ICAO address, when known * Reg - Aircraft registration @@ -364,10 +259,14 @@ The table shows one row per aircraft: SELCAL database assigns it, which can be more than one. The database is downloaded from the SELCAL demodulator -

Flights table

+

Flights

-The table shows one row per flight, and the Old Flights table the same columns for -flights that have finished: +* **Flights** - the flights seen this session, current and past: flight number, aircraft, + departure and arrival, the four OOOI times, when it was first and last heard, which + documents it has produced, and which protocols heard it +* **Old Flights** - flights that have finished, and those restored from the last session + +![Flights Table](../../../doc/img/AircraftFeature_flights_table.png) * Callsign - The ICAO form, as the transponder broadcasts it (e.g. TOM7BD). Where the flight has only ever been heard under its IATA number, that is shown here instead, so @@ -389,6 +288,82 @@ Columns in either table can be reordered by dragging, hidden via the right-click menu, and either table sorted by clicking a header. Widths and order are saved with the preset. +

Weather

+ +The Weather table shows METARs, TAFs, D-ATIS, TWIPs, NOTAMs, PIREPs and SIGMETs carried by ACARS. +Selecting a row shows the full report below. + +

Aircraft

+ +Shows a photograph of the selected +aircraft from [planespotters.net](https://www.planespotters.net/) headed by its +registration and the country flag, with the airline's logo beneath it and a table of what +the aircraft database knows about the airframe beside it. Clicking the photograph opens it +on planespotters.net + +![Aircraft Tab](../../../doc/img/AircraftFeature_aircraft_tab.png) + +

Documents

+ +Flight plans, oceanic clearances, loadsheets, logons and OOOI events, +collected against the flight number. Selecting one displays its full text +below the table. Plain ACARS messages are not collected. + +![Flight plan](../../../doc/img/AircraftFeature_flight_plan.png) + +![Loadsheet](../../../doc/img/AircraftFeature_loadsheet.png) + +![Clearance](../../../doc/img/AircraftFeature_clearance.png) + +

ATC

+ +CPDLC (controller-pilot data link) messages across all channels, with the +protocol, direction (uplink from ATC, downlink from the aircraft), source and +recipient where known, and the concise message text (e.g. "WILCO"). SELCAL calls are +listed here too, with the frequency they were heard on as the source - see +[SELCAL](#selcal) below. With nothing selected, the table shows the SELCAL calls that +could not be attributed to an aircraft + +![ATC Tab](../../../doc/img/AircraftFeature_atc_tab.png) + +

Past Aircraft

+ +Every airframe that has operated the selected **flight number**. +Shown only while a flight is selected. + +

Past Flights

+ +Every flight the selected **aircraft** has operated. +Shown only while an aircraft is selected. +Selecting one of its rows charts that flight's profile and draws its track. + +

Flight profile

+ +The Flight Profile tab charts the selected flight's altitude (left axis) and speed +(right axis) against time, showing the flight profile - climb, cruise and descent - built +from all protocols. + +![Flight Profile Tab](../../../doc/img/AircraftFeature_flight_profile.png) + +

SELCAL

+ +A SELCAL call is a ground station calling an aircraft on an HF or VHF voice channel. It +carries only a code, and a code can be shared by several aircraft. + +An attributed call counts as a message from the aircraft: it adds "SELCAL" and the +frequency to the aircraft's protocols and updates when it was last seen. It carries no +position, so nothing moves on the Map. Every call, attributed or not, is listed in the ATC +tab. + +

Context menus

+ +Right clicking a cell in any of the tables offers, as they apply to that cell: + +* **Copy** the cell's contents to the clipboard +* **Find on map** - centre the Map on that aircraft +* **Display flight** - jump to that flight in the Flights table, from the aircraft flying it +* **Display aircraft** - jump the other way, to the airframe operating a flight +

Web API

The feature's settings can be read and written at diff --git a/sdrbase/util/aircraft3dmodels.cpp b/sdrbase/util/aircraft3dmodels.cpp index 1a9153c3c..9322860b6 100644 --- a/sdrbase/util/aircraft3dmodels.cpp +++ b/sdrbase/util/aircraft3dmodels.cpp @@ -52,6 +52,12 @@ const Aircraft3DModels& Aircraft3DModels::instance() return models; } +const Aircraft3DModels& Aircraft3DModels::liveryIcons() +{ + static Aircraft3DModels icons(verboseFromEnvironment(), true); + return icons; +} + QString Aircraft3DModels::modelInfoCachePath() { return dataDir() + "/3d_model_info.json"; @@ -83,7 +89,7 @@ static QJsonObject gltfJson(const QString &path) bool Aircraft3DModels::hasAnimation(const QString &model, const QString &animation) const { - if (model.isEmpty()) { + if (model.isEmpty() || m_liveryIcons) { return true; } const ModelInfo info = modelInfo(model); @@ -92,7 +98,8 @@ bool Aircraft3DModels::hasAnimation(const QString &model, const QString &animati bool Aircraft3DModels::hasTextures(const QString &model) const { - if (model.isEmpty()) { + // An icon has no glTF to read, and is always complete + if (model.isEmpty() || m_liveryIcons) { return true; } const ModelInfo info = modelInfo(model); @@ -264,14 +271,45 @@ Aircraft3DModels::~Aircraft3DModels() qDeleteAll(m_3DModelMatch); } -Aircraft3DModels::Aircraft3DModels(bool verbose) +// The ICAO type and operator a model converted from FSLTL/MSFS is named after, with the +// FSLTL_ prefix and _cesium suffix already off: A20N_AAN, Asobo_208B_ACN, B744F_CLX. The +// operator is empty for a model of the type in no particular livery. False for a name +// that doesn't read as a type +static bool typeAndOperator(const QString &name, QString &type, QString &operatorICAO) { - // Timed and logged unconditionally: it runs once per session, reads a directory tree - // that can be well over a gigabyte, and is the first thing to suspect when start up - // is slow. A silent multi-second pause is precisely what makes that hard to find. - QElapsedTimer timer; - timer.start(); + const QStringList parts = name.split('_'); + + int typeIndex = 0; + if ((parts[typeIndex].compare("Asobo", Qt::CaseInsensitive) == 0) && (parts.size() > 1)) { + ++typeIndex; + } + type = parts[typeIndex].toUpper(); + // The Asobo aircraft FSLTL reuses are named after the product, not the designator + static const QHash asoboTypes = { + {"208B", "C208"}, {"TBM930", "TBM9"}, {"C172SP", "C172"}, {"G36", "BE36"}, {"DR400", "DR40"} + }; + type = asoboTypes.value(type, type); + if ((type.size() == 5) && type.endsWith('F')) { + type.chop(1); // FSLTL freighter suffix; the ICAO type remains four characters + } + if ((type.size() < 3) || (type.size() > 4)) { + return false; + } + operatorICAO.clear(); + if (parts.size() > typeIndex + 1) + { + const QString candidate = parts[typeIndex + 1].toUpper(); + if (candidate.size() == 3) { + operatorICAO = candidate; + } + } + return true; +} + +// The installed 3D models: the downloadable Bluebell set and any converted from FSLTL/MSFS +void Aircraft3DModels::findModels(bool verbose) +{ // Look for all aircraft gltfs in 3d directory QString modelDir = dataDir() + "/3d"; static const QStringList subDirs = {"BB_Airbus_png", "BB_Boeing_png", "BB_Jets_png", "BB_Props_png", "BB_GA_png", "BB_Mil_png", "BB_Heli_png"}; @@ -327,25 +365,11 @@ Aircraft3DModels::Aircraft3DModels(bool verbose) { const QString gltf = msfsModels.next(); const QString aircraft = QFileInfo(gltf).completeBaseName().chopped(QString("_cesium").size()); - const QStringList parts = aircraft.split('_'); - if ((parts.size() < 2) || (parts[0].compare("FSLTL", Qt::CaseInsensitive) != 0)) { - continue; - } - - int typeIndex = 1; - if ((parts[typeIndex].compare("Asobo", Qt::CaseInsensitive) == 0) && (parts.size() > 2)) { - ++typeIndex; - } - QString type = parts[typeIndex].toUpper(); - // The Asobo aircraft FSLTL reuses are named after the product, not the designator - static const QHash asoboTypes = { - {"208B", "C208"}, {"TBM930", "TBM9"}, {"C172SP", "C172"}, {"G36", "BE36"}, {"DR400", "DR40"} - }; - type = asoboTypes.value(type, type); - if ((type.size() == 5) && type.endsWith('F')) { - type.chop(1); // FSLTL freighter suffix; the ICAO type remains four characters - } - if ((type.size() < 3) || (type.size() > 4)) { + static const QString prefix = QStringLiteral("FSLTL_"); + QString type; + QString operatorICAO; + if (!aircraft.startsWith(prefix, Qt::CaseInsensitive) + || !typeAndOperator(aircraft.mid(prefix.size()), type, operatorICAO)) { continue; } @@ -355,13 +379,51 @@ Aircraft3DModels::Aircraft3DModels(bool verbose) if (lowDetailFiles.contains(lowDetail)) { m_lowDetailModels.insert(filename, QDir(modelDir).relativeFilePath(lowDetail)); } - if (parts.size() > typeIndex + 1) - { - const QString operatorICAO = parts[typeIndex + 1].toUpper(); - if (operatorICAO.size() == 3) { - m_3DModels.insert(type + "_" + operatorICAO, filename); - } + if (!operatorICAO.isEmpty()) { + m_3DModels.insert(type + "_" + operatorICAO, filename); + } + } +} + +// The 2D livery icons built into the ADS-B demodulator, standing in for the models. They +// were rendered from the models and are named after them (see liveryIconName()) - +// Bluebell's A320_BAW and FSLTL's A20N_AAN and Asobo_208B_ACN alike, all of which the +// FSLTL naming rules read - so the tables come out as if every model were installed, +// with an icon's name where a model's path would be. Of the plain stand-ins +// (aircraft_large, helicopter and the rest) only fire_truck passes for a type, as FIRE, +// which no aircraft is, so it is never asked for. Empty when the ADS-B demodulator, +// whose resources these are, isn't loaded +void Aircraft3DModels::findLiveryIcons() +{ + const QStringList icons = QDir(":/map/liveries").entryList({"*.png"}, QDir::Files); + for (const QString &icon : icons) + { + const QString name = QFileInfo(icon).completeBaseName(); + QString type; + QString operatorICAO; + if (!typeAndOperator(name, type, operatorICAO)) { + continue; } + m_3DModelsByType[type].append(name); + if (!operatorICAO.isEmpty()) { + m_3DModels.insert(type + "_" + operatorICAO, name); + } + } +} + +Aircraft3DModels::Aircraft3DModels(bool verbose, bool liveryIcons) : + m_liveryIcons(liveryIcons) +{ + // Timed and logged unconditionally: it runs once per session, reads a directory tree + // that can be well over a gigabyte, and is the first thing to suspect when start up + // is slow. A silent multi-second pause is precisely what makes that hard to find. + QElapsedTimer timer; + timer.start(); + + if (liveryIcons) { + findLiveryIcons(); + } else { + findModels(verbose); } const QHash &modelsByType = m_3DModelsByType; @@ -686,8 +748,8 @@ Aircraft3DModels::Aircraft3DModels(bool verbose) m_3DModelMatch.append(new ModelMatch("SAAB.2000.*", "SB20")); m_3DModelMatch.append(new ManufacturerModelMatch(".*340.*", "Saab.*", "SF34")); - qDebug() << "Aircraft3DModels: scanned" << dataDir() + "/3d" << "in" << timer.elapsed() - << "ms -" << m_3DModelsByType.size() << "types," << m_3DModels.size() + qDebug() << "Aircraft3DModels: scanned" << (liveryIcons ? QString(":/map/liveries") : dataDir() + "/3d") + << "in" << timer.elapsed() << "ms -" << m_3DModelsByType.size() << "types," << m_3DModels.size() << "liveries," << m_3DModelMatch.size() << "name matches"; (void) verbose; } diff --git a/sdrbase/util/aircraft3dmodels.h b/sdrbase/util/aircraft3dmodels.h index 3edfd48ea..3cab92d0d 100644 --- a/sdrbase/util/aircraft3dmodels.h +++ b/sdrbase/util/aircraft3dmodels.h @@ -106,6 +106,14 @@ public: // only afterwards. static const Aircraft3DModels& instance(); + // The same matching over the 2D livery icons built into the ADS-B demodulator, for + // when the model pack isn't installed and instance() matches nothing. The icons are + // named after the models they were rendered from, so what this picks is the icon the + // model that would have been picked has - its "models" are icon names, A320_BAW, to + // look up under :/map/liveries/, and never anything to send to the 3D map. Empty + // without the ADS-B demodulator, whose resources the icons are + static const Aircraft3DModels& liveryIcons(); + // A model for an aircraft in the OpenSky database, preferring the operator's livery. // False when nothing matches: no model pack, or a type with no model. bool modelFor(const AircraftInformation *info, bool favourLivery, bool verbose, @@ -178,7 +186,9 @@ private: QSet animations; }; - Aircraft3DModels(bool verbose); + Aircraft3DModels(bool verbose, bool liveryIcons = false); + void findModels(bool verbose); + void findLiveryIcons(); ~Aircraft3DModels(); ModelInfo modelInfo(const QString &model) const; @@ -198,6 +208,7 @@ private: static constexpr qint64 m_modelInfoRecheckMs = 30000; mutable QSet m_unreadableModels; // Not persisted: tried again next session + bool m_liveryIcons; // Built from the icons rather than the models QHash m_3DModels; // "TYPE_LIVERY" to model path QHash m_3DModelsByType; // Type to every livery of it QHash m_lowDetailModels; // Model path to its low detail sibling