mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
refs #358, added utility function to mapping rules reader
* renamed load to read * functions for problematic files, number of files etc. * some style fixes
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "vpilotmodelmappings.h"
|
||||
#include "blackmisc/nwaircraftmapping.h"
|
||||
|
||||
@@ -13,6 +22,12 @@ namespace BlackSim
|
||||
namespace FsCommon
|
||||
{
|
||||
|
||||
CVPilotModelMappings::CVPilotModelMappings(bool standardDirectory, QObject *parent) :
|
||||
ISimulatorModelMappings(parent)
|
||||
{
|
||||
if (standardDirectory) { this->addDirectory(CVPilotModelMappings::standardMappingsDirectory()); }
|
||||
}
|
||||
|
||||
void CVPilotModelMappings::addFilename(const QString &fileName)
|
||||
{
|
||||
if (this->m_fileList.contains(fileName)) return;
|
||||
@@ -43,12 +58,16 @@ namespace BlackSim
|
||||
return directory;
|
||||
}
|
||||
|
||||
bool CVPilotModelMappings::load()
|
||||
bool CVPilotModelMappings::read()
|
||||
{
|
||||
bool success = true;
|
||||
this->m_loadedFiles = 0;
|
||||
this->m_fileListWithProblems.clear();
|
||||
foreach(QString fn, this->m_fileList)
|
||||
{
|
||||
this->m_loadedFiles++;
|
||||
bool s = this->loadFile(fn);
|
||||
if (!s) { this->m_fileListWithProblems.append(fn); }
|
||||
success = s && success;
|
||||
}
|
||||
return success;
|
||||
@@ -57,38 +76,50 @@ namespace BlackSim
|
||||
bool CVPilotModelMappings::loadFile(const QString &fileName)
|
||||
{
|
||||
QFile f(fileName);
|
||||
if (!f.exists()) return false;
|
||||
if (!f.open(QFile::ReadOnly | QFile::Text)) return false;
|
||||
if (!f.exists()) { return false; }
|
||||
if (!f.open(QFile::ReadOnly | QFile::Text)) { return false; }
|
||||
QByteArray fc = f.readAll();
|
||||
if (fc.isEmpty()) return false;
|
||||
if (fc.isEmpty()) { return false; }
|
||||
QDomDocument doc;
|
||||
if (!doc.setContent(fc)) return false;
|
||||
if (!doc.setContent(fc)) { return false; }
|
||||
QDomNodeList rules = doc.elementsByTagName("ModelMatchRule");
|
||||
if (rules.isEmpty()) return false;
|
||||
int size = rules.size();
|
||||
for (int i = 0; i < size; i++)
|
||||
if (rules.isEmpty()) { return false; }
|
||||
|
||||
QString folder;
|
||||
QString updated;
|
||||
QDomNodeList mmRuleSet = doc.elementsByTagName("ModelMatchRuleSet");
|
||||
if (mmRuleSet.size() > 0)
|
||||
{
|
||||
QDomNamedNodeMap attributes = mmRuleSet.at(0).attributes();
|
||||
folder = attributes.namedItem("Folder").nodeValue();
|
||||
updated = attributes.namedItem("UpdatedOn").nodeValue();
|
||||
}
|
||||
int rulesSize = rules.size();
|
||||
for (int i = 0; i < rulesSize; i++)
|
||||
{
|
||||
QDomNamedNodeMap attributes = rules.at(i).attributes();
|
||||
const QString typeCode = attributes.namedItem("TypeCode").nodeValue();
|
||||
const QString modelName = attributes.namedItem("ModelName").nodeValue();
|
||||
const QString callsignPrefix = attributes.namedItem("CallsignPrefix").nodeValue();
|
||||
if (modelName.isEmpty()) continue;
|
||||
// remark, callsign prefix is airline ICAO code
|
||||
const QString airlineCode = attributes.namedItem("CallsignPrefix").nodeValue();
|
||||
if (modelName.isEmpty()) { continue; }
|
||||
|
||||
// split if we have multiple models
|
||||
if (modelName.contains("//"))
|
||||
{
|
||||
// multiple models
|
||||
QStringList models = modelName.split("//");
|
||||
foreach(QString model, models)
|
||||
{
|
||||
if (model.isEmpty()) continue;
|
||||
CAircraftMapping mapping(typeCode, callsignPrefix, model);
|
||||
if (model.isEmpty()) { continue; }
|
||||
CAircraftMapping mapping("vpilot", folder, typeCode, airlineCode, model);
|
||||
this->m_mappings.push_back(mapping);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// single model
|
||||
CAircraftMapping mapping(typeCode, callsignPrefix, modelName);
|
||||
CAircraftMapping mapping("vpilot", folder, typeCode, airlineCode, modelName);
|
||||
this->m_mappings.push_back(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace BlackSim
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CVPilotModelMappings(QObject *parent = nullptr) : ISimulatorModelMappings(parent) {}
|
||||
CVPilotModelMappings(bool standardDirectory, QObject *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CVPilotModelMappings() {}
|
||||
@@ -35,15 +35,20 @@ namespace BlackSim
|
||||
//! Directory with .vmr files
|
||||
void addDirectory(const QString &directory);
|
||||
|
||||
//! Loaded files (number)
|
||||
int countFilesLoaded() const { return m_loadedFiles; }
|
||||
|
||||
//! The standard directory for vPilot mappings
|
||||
static const QString &standardMappingsDirectory();
|
||||
|
||||
public slots:
|
||||
//! Load data
|
||||
virtual bool load() override;
|
||||
virtual bool read() override;
|
||||
|
||||
private:
|
||||
QStringList m_fileList; //!< list of file names
|
||||
QStringList m_fileListWithProblems; //!< problems during parsing
|
||||
int m_loadedFiles = 0; //!< loaded files
|
||||
|
||||
//! Single file read and parsing
|
||||
bool loadFile(const QString &fileName);
|
||||
|
||||
Reference in New Issue
Block a user