Skip to content

Commit 2519a87

Browse files
tzoblerltoenning
authored andcommitted
refactor: Extend aircraft model classes for MSFS24
1 parent 5273273 commit 2519a87

7 files changed

Lines changed: 107 additions & 10 deletions

File tree

src/core/aircraftmatcher.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,10 @@ namespace swift::core
16571657
if (modelsCleaned.isEmpty())
16581658
{
16591659
// error to force popup
1660-
CLogMessage(this).error(u"No models for matching ('%1'), swift without a model set will not work!")
1660+
// TODO TZ extend commend
1661+
CLogMessage(this).error(
1662+
u"No models for matching ('%1'), swift without a model set will not work! Note: If you are using "
1663+
u"MSFS2024 and starting the GUI for the first time, it may take some time for the model set to load.")
16611664
<< simulator.toQString();
16621665
}
16631666
else if (!duplicateModels.isEmpty())

src/core/airspacemonitor.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ namespace swift::core
547547
if (!this->isConnectedAndNotShuttingDown()) { return; }
548548
Q_ASSERT_X(!callsign.isEmpty(), Q_FUNC_INFO, "missing callsign");
549549

550+
CStatusMessageList reverseLookupMessages;
551+
CCallsign::addLogDetailsToList(&reverseLookupMessages, callsign,
552+
QStringLiteral("CAirspaceMonitor::sendReadyForModelMatching Flag: %1").arg(rf),
553+
CAirspaceMonitor::getLogCategories());
554+
// TODO remove
555+
550556
// set flag and init ts
551557
Readiness &readiness = this->addMatchingReadinessFlag(callsign, rf);
552558

@@ -863,13 +869,18 @@ namespace swift::core
863869
CAirspaceMonitor::getLogCategories());
864870

865871
const CClient client = this->getClientOrDefaultForCallsign(callsign);
866-
this->addOrUpdateAircraftInRange(callsign, aircraftIcaoDesignator, airlineIcaoDesignator, livery,
867-
client.getQueriedModelString(), CAircraftModel::TypeQueriedFromNetwork,
868-
pReverseLookupMessages);
869-
this->addReverseLookupMessages(callsign, reverseLookupMessages);
870-
this->sendReadyForModelMatching(callsign, ReceivedIcaoCodes); // ICAO codes received
872+
const CSimulatedAircraft aircraft = this->addOrUpdateAircraftInRange(
873+
callsign, aircraftIcaoDesignator, airlineIcaoDesignator, livery, client.getQueriedModelString(),
874+
CAircraftModel::TypeQueriedFromNetwork, pReverseLookupMessages);
871875

872-
emit this->requestedNewAircraft(callsign, aircraftIcaoDesignator, airlineIcaoDesignator, livery);
876+
// we do not change manually assigned models
877+
if (aircraft.getModel().getModelType() != CAircraftModel::TypeManuallySet)
878+
{
879+
this->addReverseLookupMessages(callsign, reverseLookupMessages);
880+
this->sendReadyForModelMatching(callsign, ReceivedIcaoCodes); // ICAO codes received
881+
882+
emit this->requestedNewAircraft(callsign, aircraftIcaoDesignator, airlineIcaoDesignator, livery);
883+
}
873884
}
874885

875886
CAircraftModel CAirspaceMonitor::reverseLookupModelWithFlightplanData(
@@ -1176,8 +1187,8 @@ namespace swift::core
11761187
const CSimulatedAircraft aircraft = this->getAircraftInRangeForCallsign(callsign);
11771188
if (aircraft.hasValidCallsign())
11781189
{
1179-
// only if we do not have a DB model yet
1180-
if (!aircraft.getModel().hasValidDbKey())
1190+
// we do not change manually assigned models (msfs2024)
1191+
if (!aircraft.getModel().hasValidDbKey() && aircraft.getModelType() != CAircraftModel::TypeManuallySet)
11811192
{
11821193
CAircraftModel model = this->reverseLookupModelWithFlightplanData(callsign, aircraftIcao, airlineIcao,
11831194
livery, modelString, modelType, log);

src/misc/simulation/aircraftmodel.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ namespace swift::misc::simulation
4242
: m_modelString(model.trimmed().toUpper()), m_modelType(type)
4343
{}
4444

45+
CAircraftModel::CAircraftModel(const QString &model, const QString &livery, CAircraftModel::ModelType type)
46+
: m_modelString(model.trimmed().toUpper()), m_modelLivery(livery.trimmed().toUpper()), m_modelType(type)
47+
{}
48+
4549
CAircraftModel::CAircraftModel(const QString &model, CAircraftModel::ModelType type, const CAircraftIcaoCode &icao,
4650
const CLivery &livery)
4751
: m_aircraftIcao(icao), m_livery(livery), m_modelString(model.trimmed().toUpper()), m_modelType(type)
@@ -241,6 +245,12 @@ namespace swift::misc::simulation
241245
return this->getAllModelStringsAndAliases() % " " % this->getDbKeyAsStringInParentheses();
242246
}
243247

248+
QString CAircraftModel::getMsfs2024ModelString()
249+
{
250+
m_modelString = m_modelString.trimmed().toUpper() % u" " % m_modelLivery.trimmed().toUpper();
251+
return m_modelString;
252+
}
253+
244254
bool CAircraftModel::isVtol() const { return this->getAircraftIcaoCode().isVtol(); }
245255

246256
QVariant CAircraftModel::propertyByIndex(swift::misc::CPropertyIndexRef index) const
@@ -588,6 +598,23 @@ namespace swift::misc::simulation
588598
return (sim.isFG()) ? this->getSwiftLiveryString(true, false, false) : this->getSwiftLiveryString();
589599
}
590600

601+
QString CAircraftModel::getShortModelString() const
602+
{
603+
604+
QString shortModelString = m_modelString;
605+
if (m_modelString.contains(m_modelLivery))
606+
{
607+
int lastIndex = m_modelString.lastIndexOf(m_modelLivery);
608+
609+
if (lastIndex != -1)
610+
{
611+
const QString newModelString = m_modelString.left(lastIndex);
612+
shortModelString = newModelString;
613+
}
614+
}
615+
return shortModelString;
616+
}
617+
591618
DBTripleIds CAircraftModel::parseNetworkLiveryString(const QString &liveryString)
592619
{
593620
// "swift_m22l33a11"
@@ -770,6 +797,13 @@ namespace swift::misc::simulation
770797
return (p.contains(path, cs));
771798
}
772799

800+
bool CAircraftModel::matchesModelStringAndLivery(const QString &modelString, const QString &modelLivery,
801+
Qt::CaseSensitivity sensitivity) const
802+
{
803+
return (stringCompare(modelString, m_modelString, sensitivity) &&
804+
stringCompare(modelLivery, m_modelLivery, sensitivity));
805+
}
806+
773807
bool CAircraftModel::matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const
774808
{
775809
return stringCompare(modelString, m_modelString, sensitivity);
@@ -1003,6 +1037,7 @@ namespace swift::misc::simulation
10031037
const QString modelName(json.value(prefix % u"name").toString());
10041038
const QString modelMode(json.value(prefix % u"mode").toString());
10051039
const QString parts(json.value(prefix % u"parts").toString());
1040+
const QString modelLivery(json.value(prefix % u"modellivery").toString());
10061041

10071042
// check for undefined to rule out 0ft values
10081043
const QJsonValue cgjv = json.value(prefix % u"cgft");
@@ -1012,6 +1047,7 @@ namespace swift::misc::simulation
10121047
const CSimulatorInfo simInfo = CSimulatorInfo::fromDatabaseJson(json, prefix);
10131048
CAircraftModel model(modelString, CAircraftModel::TypeDatabaseEntry, simInfo, modelName, modelDescription);
10141049
model.setModelStringAlias(modelStringAlias);
1050+
model.setModelLivery(modelLivery); // msfs2024
10151051
model.setModelModeAsString(modelMode);
10161052
model.setSupportedParts(parts);
10171053
model.setCG(cg);

src/misc/simulation/aircraftmodel.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ namespace swift::misc
8383
TypeManuallySet, //!< manually set, e.g. from GUI
8484
TypeOwnSimulatorModel, //!< represents own simulator model (AI model, model on disk)
8585
TypeVPilotRuleBased, //!< based on a vPilot rule
86-
TypeTerrainProbe //!< peudo aircraft used for terrain probing (FSX)
86+
TypeTerrainProbe, //!< peudo aircraft used for terrain probing (FSX)
87+
TypeOwnSimulatorLivery //!< represents own simulator model livery (msfs2024)
8788
};
8889

8990
//! Mode, decides if a model is supposed to be used in the model set for model matching
@@ -136,6 +137,9 @@ namespace swift::misc
136137
//! Constructor.
137138
CAircraftModel(const QString &model, ModelType type);
138139

140+
//! Constructor.
141+
CAircraftModel(const QString &model, const QString &livery, ModelType type);
142+
139143
//! Constructor.
140144
CAircraftModel(const QString &model, ModelType type, const aviation::CAircraftIcaoCode &icao,
141145
const aviation::CLivery &livery);
@@ -181,12 +185,21 @@ namespace swift::misc
181185
//! Model key, either queried or loaded from simulator model
182186
const QString &getModelString() const { return m_modelString; }
183187

188+
//! Model Livery, part of model string in MSFS 2024
189+
const QString &getModelLivery() const { return m_modelLivery; }
190+
184191
//! Model string and DB key (if available)
185192
QString getModelStringAndDbKey() const;
186193

187194
//! Model string
188195
void setModelString(const QString &modelString) { m_modelString = modelString.trimmed().toUpper(); }
189196

197+
//! Model livery msfs2024
198+
void setModelLivery(const QString &modelLivery) { m_modelLivery = modelLivery.trimmed().toUpper(); }
199+
200+
//! Model livery whitout part for lifery msfs2024
201+
QString getShortModelString() const;
202+
190203
//! Model key, either queried or loaded from simulator model
191204
const QString &getModelStringAlias() const { return m_modelStringAlias; }
192205

@@ -196,6 +209,9 @@ namespace swift::misc
196209
//! Get model string and aliases
197210
QString getAllModelStringsAliasesAndDbKey() const;
198211

212+
//! Get model string and Livery
213+
QString getMsfs2024ModelString();
214+
199215
//! Model string alias
200216
void setModelStringAlias(const QString &alias) { m_modelStringAlias = alias.trimmed().toUpper(); }
201217

@@ -419,6 +435,10 @@ namespace swift::misc
419435
//! Matches model string?
420436
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
421437

438+
//! Matches model string and livery?
439+
bool matchesModelStringAndLivery(const QString &modelString, const QString &modelLivery,
440+
Qt::CaseSensitivity sensitivity) const;
441+
422442
//! Matches model string or alias?
423443
bool matchesModelStringOrAlias(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
424444

@@ -567,11 +587,13 @@ namespace swift::misc
567587
CSimulatorInfo m_simulator; //!< model for given simulator
568588
CDistributor m_distributor; //!< who designed or distributed the model
569589
QString m_modelString; //!< Simulator model key, unique
590+
QString m_modelLivery; //!< Simulator livery (msfs2024)
570591
QString m_modelStringAlias; //!< Simulator model key alias, unique
571592
QString m_name; //!< Model name
572593
QString m_description; //!< descriptive text
573594
QString m_fileName; //!< file name
574595
QString m_supportedParts; //!< supported parts
596+
QString m_shortModelString; //!< cached short model string
575597
qint64 m_fileTimestamp = -1; //!< file timestamp of originating file (if applicable)
576598
ModelType m_modelType = TypeUnknown; //!< model string is coming representing ...?
577599
ModelMode m_modelMode = Include; //!< model mode (include / exclude)
@@ -591,6 +613,7 @@ namespace swift::misc
591613
SWIFT_METAMEMBER(supportedParts),
592614
SWIFT_METAMEMBER(modelString, 0, CaseInsensitiveComparison),
593615
SWIFT_METAMEMBER(modelStringAlias, 0, CaseInsensitiveComparison),
616+
SWIFT_METAMEMBER(modelLivery, 0, CaseInsensitiveComparison),
594617
SWIFT_METAMEMBER(name),
595618
SWIFT_METAMEMBER(description, 0, DisabledForComparison),
596619
SWIFT_METAMEMBER(fileName, 0, DisabledForComparison),

src/misc/simulation/aircraftmodellist.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,18 @@ namespace swift::misc::simulation
901901
return ms;
902902
}
903903

904+
QStringList CAircraftModelList::getModelStringAndLiveryList(bool sort) const
905+
{
906+
QStringList ms;
907+
for (const CAircraftModel &model : *this)
908+
{
909+
if (!model.hasModelString()) { continue; }
910+
ms.append(model.getModelString() + "{" + model.getModelLivery() + "}");
911+
}
912+
if (sort) { ms.sort(Qt::CaseInsensitive); }
913+
return ms;
914+
}
915+
904916
QSet<QString> CAircraftModelList::getModelStringSet() const
905917
{
906918
CSetBuilder<QString> ms;

src/misc/simulation/aircraftmodellist.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ namespace swift::misc
393393
//! Model strings
394394
QStringList getModelStringList(bool sort = true) const;
395395

396+
//! Model strings and Livery codes
397+
QStringList getModelStringAndLiveryList(bool sort = true) const;
398+
396399
//! Model strings as set
397400
QSet<QString> getModelStringSet() const;
398401

src/misc/simulation/simulatedaircraft.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ namespace swift::misc
406406
//! Get model string
407407
const QString &getModelString() const { return m_models[CurrentModel].getModelString(); }
408408

409+
//! Get model Livery MSFS2024
410+
const QString &getLiveryString() const { return m_models[CurrentModel].getModelLivery(); }
411+
412+
//! Get short model string (without livery msfs2024)
413+
const QString getShortModelString() const { return m_models[CurrentModel].getShortModelString(); }
414+
409415
//! Set model string
410416
void setModelString(const QString &modelString);
411417

@@ -483,6 +489,9 @@ namespace swift::misc
483489
//! \copydoc swift::misc::mixin::Icon::toIcon()
484490
CIcons::IconIndex toIcon() const { return m_callsign.toIcon(); }
485491

492+
//! Get model type
493+
int getModelType() const { return m_models[CurrentModel].getModelType(); }
494+
486495
private:
487496
static constexpr int CurrentModel = 0; //!< m_models
488497
static constexpr int NetworkModel = 1; //!< m_models

0 commit comments

Comments
 (0)