mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25: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 "vpilotmodelmappings.h"
|
||||||
#include "blackmisc/nwaircraftmapping.h"
|
#include "blackmisc/nwaircraftmapping.h"
|
||||||
|
|
||||||
@@ -13,6 +22,12 @@ namespace BlackSim
|
|||||||
namespace FsCommon
|
namespace FsCommon
|
||||||
{
|
{
|
||||||
|
|
||||||
|
CVPilotModelMappings::CVPilotModelMappings(bool standardDirectory, QObject *parent) :
|
||||||
|
ISimulatorModelMappings(parent)
|
||||||
|
{
|
||||||
|
if (standardDirectory) { this->addDirectory(CVPilotModelMappings::standardMappingsDirectory()); }
|
||||||
|
}
|
||||||
|
|
||||||
void CVPilotModelMappings::addFilename(const QString &fileName)
|
void CVPilotModelMappings::addFilename(const QString &fileName)
|
||||||
{
|
{
|
||||||
if (this->m_fileList.contains(fileName)) return;
|
if (this->m_fileList.contains(fileName)) return;
|
||||||
@@ -43,12 +58,16 @@ namespace BlackSim
|
|||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CVPilotModelMappings::load()
|
bool CVPilotModelMappings::read()
|
||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
this->m_loadedFiles = 0;
|
||||||
|
this->m_fileListWithProblems.clear();
|
||||||
foreach(QString fn, this->m_fileList)
|
foreach(QString fn, this->m_fileList)
|
||||||
{
|
{
|
||||||
|
this->m_loadedFiles++;
|
||||||
bool s = this->loadFile(fn);
|
bool s = this->loadFile(fn);
|
||||||
|
if (!s) { this->m_fileListWithProblems.append(fn); }
|
||||||
success = s && success;
|
success = s && success;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
@@ -57,38 +76,50 @@ namespace BlackSim
|
|||||||
bool CVPilotModelMappings::loadFile(const QString &fileName)
|
bool CVPilotModelMappings::loadFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QFile f(fileName);
|
QFile f(fileName);
|
||||||
if (!f.exists()) return false;
|
if (!f.exists()) { return false; }
|
||||||
if (!f.open(QFile::ReadOnly | QFile::Text)) return false;
|
if (!f.open(QFile::ReadOnly | QFile::Text)) { return false; }
|
||||||
QByteArray fc = f.readAll();
|
QByteArray fc = f.readAll();
|
||||||
if (fc.isEmpty()) return false;
|
if (fc.isEmpty()) { return false; }
|
||||||
QDomDocument doc;
|
QDomDocument doc;
|
||||||
if (!doc.setContent(fc)) return false;
|
if (!doc.setContent(fc)) { return false; }
|
||||||
QDomNodeList rules = doc.elementsByTagName("ModelMatchRule");
|
QDomNodeList rules = doc.elementsByTagName("ModelMatchRule");
|
||||||
if (rules.isEmpty()) return false;
|
if (rules.isEmpty()) { return false; }
|
||||||
int size = rules.size();
|
|
||||||
for (int i = 0; i < size; i++)
|
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();
|
QDomNamedNodeMap attributes = rules.at(i).attributes();
|
||||||
const QString typeCode = attributes.namedItem("TypeCode").nodeValue();
|
const QString typeCode = attributes.namedItem("TypeCode").nodeValue();
|
||||||
const QString modelName = attributes.namedItem("ModelName").nodeValue();
|
const QString modelName = attributes.namedItem("ModelName").nodeValue();
|
||||||
const QString callsignPrefix = attributes.namedItem("CallsignPrefix").nodeValue();
|
// remark, callsign prefix is airline ICAO code
|
||||||
if (modelName.isEmpty()) continue;
|
const QString airlineCode = attributes.namedItem("CallsignPrefix").nodeValue();
|
||||||
|
if (modelName.isEmpty()) { continue; }
|
||||||
|
|
||||||
|
// split if we have multiple models
|
||||||
if (modelName.contains("//"))
|
if (modelName.contains("//"))
|
||||||
{
|
{
|
||||||
// multiple models
|
// multiple models
|
||||||
QStringList models = modelName.split("//");
|
QStringList models = modelName.split("//");
|
||||||
foreach(QString model, models)
|
foreach(QString model, models)
|
||||||
{
|
{
|
||||||
if (model.isEmpty()) continue;
|
if (model.isEmpty()) { continue; }
|
||||||
CAircraftMapping mapping(typeCode, callsignPrefix, model);
|
CAircraftMapping mapping("vpilot", folder, typeCode, airlineCode, model);
|
||||||
this->m_mappings.push_back(mapping);
|
this->m_mappings.push_back(mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// single model
|
// single model
|
||||||
CAircraftMapping mapping(typeCode, callsignPrefix, modelName);
|
CAircraftMapping mapping("vpilot", folder, typeCode, airlineCode, modelName);
|
||||||
this->m_mappings.push_back(mapping);
|
this->m_mappings.push_back(mapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace BlackSim
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
CVPilotModelMappings(QObject *parent = nullptr) : ISimulatorModelMappings(parent) {}
|
CVPilotModelMappings(bool standardDirectory, QObject *parent = nullptr);
|
||||||
|
|
||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CVPilotModelMappings() {}
|
virtual ~CVPilotModelMappings() {}
|
||||||
@@ -35,15 +35,20 @@ namespace BlackSim
|
|||||||
//! Directory with .vmr files
|
//! Directory with .vmr files
|
||||||
void addDirectory(const QString &directory);
|
void addDirectory(const QString &directory);
|
||||||
|
|
||||||
|
//! Loaded files (number)
|
||||||
|
int countFilesLoaded() const { return m_loadedFiles; }
|
||||||
|
|
||||||
//! The standard directory for vPilot mappings
|
//! The standard directory for vPilot mappings
|
||||||
static const QString &standardMappingsDirectory();
|
static const QString &standardMappingsDirectory();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Load data
|
//! Load data
|
||||||
virtual bool load() override;
|
virtual bool read() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList m_fileList; //!< list of file names
|
QStringList m_fileList; //!< list of file names
|
||||||
|
QStringList m_fileListWithProblems; //!< problems during parsing
|
||||||
|
int m_loadedFiles = 0; //!< loaded files
|
||||||
|
|
||||||
//! Single file read and parsing
|
//! Single file read and parsing
|
||||||
bool loadFile(const QString &fileName);
|
bool loadFile(const QString &fileName);
|
||||||
|
|||||||
Reference in New Issue
Block a user