mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 21:20:31 -05:00 
			
		
		
		
	ADS-B: Use randomized livery and model for aircraft not in database
This commit is contained in:
		
							parent
							
								
									c0adffb25c
								
							
						
					
					
						commit
						0591ae8378
					
				@ -910,6 +910,7 @@ void ADSBDemodGUI::handleADSB(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    bool newAircraft = false;
 | 
					    bool newAircraft = false;
 | 
				
			||||||
    bool updatedCallsign = false;
 | 
					    bool updatedCallsign = false;
 | 
				
			||||||
 | 
					    bool resetAnimation = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int df = (data[0] >> 3) & ADS_B_DF_MASK; // Downlink format
 | 
					    int df = (data[0] >> 3) & ADS_B_DF_MASK; // Downlink format
 | 
				
			||||||
    int ca = data[0] & 0x7; // Capability
 | 
					    int ca = data[0] & 0x7; // Capability
 | 
				
			||||||
@ -1174,11 +1175,13 @@ void ADSBDemodGUI::handleADSB(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                if (!aircraft->m_emitterCategory.compare("Heavy"))
 | 
					                if (!aircraft->m_emitterCategory.compare("Heavy"))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    aircraftType = "B744";  // Or B77W, B788, A350, A388
 | 
					                    QStringList heavy = {"B744", "B77W", "B788", "A388"};
 | 
				
			||||||
 | 
					                    aircraftType = heavy[m_random.bounded(heavy.size())];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (!aircraft->m_emitterCategory.compare("Large"))
 | 
					                else if (!aircraft->m_emitterCategory.compare("Large"))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    aircraftType = "A320";  // Or B737
 | 
					                    QStringList large = {"A319", "A320", "A321", "B737", "B738", "B739"};
 | 
				
			||||||
 | 
					                    aircraftType = large[m_random.bounded(large.size())];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                else if (!aircraft->m_emitterCategory.compare("Small"))
 | 
					                else if (!aircraft->m_emitterCategory.compare("Small"))
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
@ -1256,6 +1259,9 @@ void ADSBDemodGUI::handleADSB(
 | 
				
			|||||||
                        aircraft->m_labelAltitudeOffset = m_labelAltitudeOffset.value(aircraftType);
 | 
					                        aircraft->m_labelAltitudeOffset = m_labelAltitudeOffset.value(aircraftType);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					                // As we're changing the model, we need to reset animations to
 | 
				
			||||||
 | 
					                // ensure gear/flaps are in correct position on new model
 | 
				
			||||||
 | 
					                resetAnimation = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if (((tc >= 5) && (tc <= 18)) || ((tc >= 20) && (tc <= 22)))
 | 
					        else if (((tc >= 5) && (tc <= 18)) || ((tc >= 20) && (tc <= 22)))
 | 
				
			||||||
@ -1661,6 +1667,16 @@ void ADSBDemodGUI::handleADSB(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            // Send to Map feature
 | 
					            // Send to Map feature
 | 
				
			||||||
            sendToMap(aircraft, animations);
 | 
					            sendToMap(aircraft, animations);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (resetAnimation)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // Wait until after model has changed before reseting
 | 
				
			||||||
 | 
					                // otherwise animation might play on old model
 | 
				
			||||||
 | 
					                aircraft->m_gearDown = false;
 | 
				
			||||||
 | 
					                aircraft->m_flaps = 0.0;
 | 
				
			||||||
 | 
					                aircraft->m_engineStarted = false;
 | 
				
			||||||
 | 
					                aircraft->m_rotorStarted = false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (df == 18)
 | 
					    else if (df == 18)
 | 
				
			||||||
@ -2928,10 +2944,15 @@ QString ADSBDemodGUI::get3DModel(const QString &aircraftType, const QString &ope
 | 
				
			|||||||
    return "";
 | 
					    return "";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString ADSBDemodGUI::get3DModel(const QString &aircraftType) const
 | 
					QString ADSBDemodGUI::get3DModel(const QString &aircraftType)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (m_3DModels.contains(aircraftType)) {
 | 
					    if (m_3DModelsByType.contains(aircraftType))
 | 
				
			||||||
        return m_3DModels.value(aircraftType);
 | 
					    {
 | 
				
			||||||
 | 
					        // Choose a random livery
 | 
				
			||||||
 | 
					        QStringList models = m_3DModelsByType.value(aircraftType);
 | 
				
			||||||
 | 
					        int size = models.size();
 | 
				
			||||||
 | 
					        int idx = m_random.bounded(size);
 | 
				
			||||||
 | 
					        return models[idx];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (m_settings.m_verboseModelMatching) {
 | 
					    if (m_settings.m_verboseModelMatching) {
 | 
				
			||||||
        qDebug() << "ADS-B: No aircraft for " << aircraftType;
 | 
					        qDebug() << "ADS-B: No aircraft for " << aircraftType;
 | 
				
			||||||
@ -2998,6 +3019,7 @@ void ADSBDemodGUI::update3DModels()
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            QDir aircraftDir(dir.filePath(aircraft));
 | 
					            QDir aircraftDir(dir.filePath(aircraft));
 | 
				
			||||||
            QStringList gltfs = aircraftDir.entryList({"*.gltf"});
 | 
					            QStringList gltfs = aircraftDir.entryList({"*.gltf"});
 | 
				
			||||||
 | 
					            QStringList allAircraft;
 | 
				
			||||||
            for (auto gltf : gltfs)
 | 
					            for (auto gltf : gltfs)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                QStringList filenameParts = gltf.split(".")[0].split("_");
 | 
					                QStringList filenameParts = gltf.split(".")[0].split("_");
 | 
				
			||||||
@ -3008,13 +3030,13 @@ void ADSBDemodGUI::update3DModels()
 | 
				
			|||||||
                        qDebug() << "Aircraft " << aircraft << "Livery " << livery;
 | 
					                        qDebug() << "Aircraft " << aircraft << "Livery " << livery;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    // Only use relative path, as Map feature will add the prefix
 | 
					                    // Only use relative path, as Map feature will add the prefix
 | 
				
			||||||
                    m_3DModels.insert(aircraft + "_" + livery, subDir + "/" + aircraft + "/" + gltf);
 | 
					                    QString filename = subDir + "/" + aircraft + "/" + gltf;
 | 
				
			||||||
 | 
					                    m_3DModels.insert(aircraft + "_" + livery, filename);
 | 
				
			||||||
 | 
					                    allAircraft.append(filename);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // Also add an entry just using aircraft type, for when we can't find a operator specific livery
 | 
					 | 
				
			||||||
            // Just use first from the list for now
 | 
					 | 
				
			||||||
            if (gltfs.size() > 0) {
 | 
					            if (gltfs.size() > 0) {
 | 
				
			||||||
                m_3DModels.insert(aircraft, subDir + "/" + aircraft + "/" + gltfs[0]);
 | 
					                m_3DModelsByType.insert(aircraft, allAircraft);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -26,6 +26,7 @@
 | 
				
			|||||||
#include <QAbstractListModel>
 | 
					#include <QAbstractListModel>
 | 
				
			||||||
#include <QProgressDialog>
 | 
					#include <QProgressDialog>
 | 
				
			||||||
#include <QTextToSpeech>
 | 
					#include <QTextToSpeech>
 | 
				
			||||||
 | 
					#include <QRandomGenerator>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "channel/channelgui.h"
 | 
					#include "channel/channelgui.h"
 | 
				
			||||||
#include "dsp/dsptypes.h"
 | 
					#include "dsp/dsptypes.h"
 | 
				
			||||||
@ -757,7 +758,7 @@ public:
 | 
				
			|||||||
    bool useSIUints() const { return m_settings.m_siUnits; }
 | 
					    bool useSIUints() const { return m_settings.m_siUnits; }
 | 
				
			||||||
    Q_INVOKABLE void clearHighlighted();
 | 
					    Q_INVOKABLE void clearHighlighted();
 | 
				
			||||||
    QString get3DModel(const QString &aircraft, const QString &operatorICAO) const;
 | 
					    QString get3DModel(const QString &aircraft, const QString &operatorICAO) const;
 | 
				
			||||||
    QString get3DModel(const QString &aircraft) const;
 | 
					    QString get3DModel(const QString &aircraft);
 | 
				
			||||||
    void get3DModel(Aircraft *aircraft);
 | 
					    void get3DModel(Aircraft *aircraft);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public slots:
 | 
					public slots:
 | 
				
			||||||
@ -816,7 +817,9 @@ private:
 | 
				
			|||||||
    quint16 m_osmPort;
 | 
					    quint16 m_osmPort;
 | 
				
			||||||
    OpenAIP m_openAIP;
 | 
					    OpenAIP m_openAIP;
 | 
				
			||||||
    ADSBOSMTemplateServer *m_templateServer;
 | 
					    ADSBOSMTemplateServer *m_templateServer;
 | 
				
			||||||
 | 
					    QRandomGenerator m_random;
 | 
				
			||||||
    QHash<QString, QString> m_3DModels; // Hashed aircraft_icao or just aircraft
 | 
					    QHash<QString, QString> m_3DModels; // Hashed aircraft_icao or just aircraft
 | 
				
			||||||
 | 
					    QHash<QString, QStringList> m_3DModelsByType; // Hashed aircraft to list of all of that type
 | 
				
			||||||
    QList<ModelMatch *> m_3DModelMatch; // Map of database aircraft names to 3D model names
 | 
					    QList<ModelMatch *> m_3DModelMatch; // Map of database aircraft names to 3D model names
 | 
				
			||||||
    QHash<QString, float> m_modelAltitudeOffset;
 | 
					    QHash<QString, float> m_modelAltitudeOffset;
 | 
				
			||||||
    QHash<QString, float> m_labelAltitudeOffset;
 | 
					    QHash<QString, float> m_labelAltitudeOffset;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user