-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapted database writers for MSFS 2024 changes.
- Loading branch information
Showing
5 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/***************************************************************************** | ||
* Copyright 2015-2023 Alexander Barthel [email protected] | ||
* Copyright 2015-2024 Alexander Barthel [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -208,6 +208,16 @@ QString DataWriter::getSurface(const QUuid& key) | |
return QString(); | ||
} | ||
|
||
int DataWriter::getNextSceneryId() const | ||
{ | ||
return sceneryAreaWriter->getNextId(); | ||
} | ||
|
||
int DataWriter::getNextFileId() const | ||
{ | ||
return bglFileWriter->getNextId(); | ||
} | ||
|
||
QString DataWriter::getLanguage(const QString& key) | ||
{ | ||
if(languageIndex != nullptr) | ||
|
@@ -241,7 +251,10 @@ void DataWriter::writeSceneryArea(const SceneryArea& area) | |
for(int i = 0; i < filepaths.size(); i++) | ||
{ | ||
progressHandler->setNumFiles(numFiles); | ||
progressHandler->setNumAirports(airportIdents.size()); | ||
|
||
// Do not reset airport counter which was read before from MSFS 2024 SimConnect | ||
if(options.getSimulatorType() != FsPaths::MSFS_2024) | ||
progressHandler->setNumAirports(airportIdents.size()); | ||
progressHandler->setNumNamelists(numNamelists); | ||
progressHandler->setNumVors(numVors); | ||
progressHandler->setNumIls(numIls); | ||
|
@@ -367,67 +380,72 @@ void DataWriter::writeSceneryArea(const SceneryArea& area) | |
} | ||
} | ||
|
||
void DataWriter::readMagDeclBgl(const QString& fileScenery) | ||
void DataWriter::readMagDeclBgl(const QString& fileScenery, bool forceWmm) | ||
{ | ||
QString fileSettings = atools::buildPath({atools::settings::Settings::getPath(), "magdec.bgl"}); | ||
QString fileApp = atools::buildPath({QCoreApplication::applicationDirPath(), "magdec", "magdec.bgl"}); | ||
|
||
QString file; | ||
if(QFileInfo::exists(fileScenery) && QFileInfo(fileScenery).isFile()) | ||
// Check if there is a file in the simulator scenery directory | ||
file = fileScenery; | ||
else if(QFileInfo::exists(fileSettings) && QFileInfo(fileSettings).isFile()) | ||
// Check if there is a file in the settings directory | ||
file = fileSettings; | ||
else if(QFileInfo::exists(fileApp) && QFileInfo(fileApp).isFile()) | ||
// Check if there is a file in the application directory | ||
file = fileApp; | ||
|
||
qInfo() << "Reading" << file; | ||
|
||
bool loaded = false; | ||
|
||
if(!file.isEmpty()) | ||
if(!forceWmm) | ||
{ | ||
try | ||
{ | ||
magDecReader->readFromBgl(file); | ||
} | ||
catch(atools::Exception& e) | ||
// Try to read from various places ================================================= | ||
QString fileSettings = atools::buildPath({atools::settings::Settings::getPath(), "magdec.bgl"}); | ||
QString fileApp = atools::buildPath({QCoreApplication::applicationDirPath(), "magdec", "magdec.bgl"}); | ||
|
||
if(QFileInfo::exists(fileScenery) && QFileInfo(fileScenery).isFile()) | ||
// Check if there is a file in the simulator scenery directory | ||
file = fileScenery; | ||
else if(QFileInfo::exists(fileSettings) && QFileInfo(fileSettings).isFile()) | ||
// Check if there is a file in the settings directory | ||
file = fileSettings; | ||
else if(QFileInfo::exists(fileApp) && QFileInfo(fileApp).isFile()) | ||
// Check if there is a file in the application directory | ||
file = fileApp; | ||
|
||
qInfo() << "Reading" << file; | ||
|
||
if(!file.isEmpty()) | ||
{ | ||
qCritical() << "Caught exception reading" << file << ":" << e.what(); | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({file, QString(e.what()), 0}); | ||
} | ||
catch(...) | ||
{ | ||
qCritical() << "Caught unknown exception reading" << file; | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({file, tr("Cannot read file. Falling back to world magnetic model."), 0}); | ||
} | ||
try | ||
{ | ||
magDecReader->readFromBgl(file); | ||
} | ||
catch(atools::Exception& e) | ||
{ | ||
qCritical() << "Caught exception reading" << file << ":" << e.what(); | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({file, QString(e.what()), 0}); | ||
} | ||
catch(...) | ||
{ | ||
qCritical() << "Caught unknown exception reading" << file; | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({file, tr("Cannot read file. Falling back to world magnetic model."), 0}); | ||
} | ||
|
||
if(magDecReader->isValid()) | ||
{ | ||
magDecReader->writeToTable(db); | ||
db.commit(); | ||
loaded = true; | ||
if(magDecReader->isValid()) | ||
{ | ||
magDecReader->writeToTable(db); | ||
db.commit(); | ||
loaded = true; | ||
} | ||
else | ||
{ | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({file, tr("File not valid. Falling back to world magnetic model."), 0}); | ||
} | ||
} | ||
else | ||
{ | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({file, tr("File not valid. Falling back to world magnetic model."), 0}); | ||
sceneryErrors->fileErrors.append({"magdec.bgl", tr("File not found. Falling back to world magnetic model."), 0}); | ||
} | ||
} | ||
else | ||
{ | ||
progressHandler->reportError(); | ||
if(sceneryErrors != nullptr) | ||
sceneryErrors->fileErrors.append({"magdec.bgl", tr("File not found. Falling back to world magnetic model."), 0}); | ||
} | ||
|
||
// Eiter no file found above or reading of WMM forced ========================================== | ||
if(!loaded) | ||
{ | ||
magDecReader->readFromWmm(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/***************************************************************************** | ||
* Copyright 2015-2020 Alexander Barthel [email protected] | ||
* Copyright 2015-2024 Alexander Barthel [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -97,7 +97,7 @@ class DataWriter | |
*/ | ||
void writeSceneryArea(const atools::fs::scenery::SceneryArea& area); | ||
|
||
void readMagDeclBgl(const QString& fileScenery); | ||
void readMagDeclBgl(const QString& fileScenery, bool forceWmm = false); | ||
|
||
/* | ||
* Log written record number, etc. to the log/console. | ||
|
@@ -290,6 +290,10 @@ class DataWriter | |
return db; | ||
} | ||
|
||
/* Get next ids from writers */ | ||
int getNextSceneryId() const; | ||
int getNextFileId() const; | ||
|
||
private: | ||
int numFiles = 0, numNamelists = 0, numVors = 0, numIls = 0, | ||
numNdbs = 0, numMarker = 0, numWaypoints = 0, numBoundaries = 0, numObjectsWritten = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/***************************************************************************** | ||
* Copyright 2015-2020 Alexander Barthel [email protected] | ||
* Copyright 2015-2024 Alexander Barthel [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -16,12 +16,13 @@ | |
*****************************************************************************/ | ||
|
||
#include "fs/db/nav/vorwriter.h" | ||
|
||
#include "atools.h" | ||
#include "fs/bgl/nav/dme.h" | ||
#include "fs/db/meta/bglfilewriter.h" | ||
#include "fs/db/datawriter.h" | ||
#include "fs/bgl/util.h" | ||
#include "fs/db/meta/bglfilewriter.h" | ||
#include "fs/util/tacanfrequencies.h" | ||
#include "geo/calculations.h" | ||
#include "atools.h" | ||
|
||
namespace atools { | ||
namespace fs { | ||
|
@@ -49,12 +50,18 @@ void VorWriter::writeObject(const Vor *type) | |
bind(":ident", type->getIdent()); | ||
bind(":name", type->getName()); | ||
bind(":region", type->getRegion()); | ||
bind(":type", bgl::IlsVor::ilsVorTypeToStr(type->getType())); | ||
|
||
if(type->isTacan()) // Only MFSF 2024 - P3D uses TacanWriter | ||
bind(":type", "TC"); | ||
else | ||
bind(":type", bgl::IlsVor::ilsVorTypeToStr(type->getType())); | ||
|
||
bind(":airport_ident", type->getAirportIdent()); | ||
bindNullInt(":airport_id"); | ||
|
||
bind(":frequency", type->getFrequency()); | ||
if(type->isTacan()) // Only MFSF 2024 | ||
bind(":channel", util::tacanChannelForFrequency(type->getFrequency() / 10)); | ||
bind(":range", roundToInt(meterToNm(type->getRange()))); | ||
|
||
if(type->isDmeOnly()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters