mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T658, matching script
This commit is contained in:
@@ -10,11 +10,13 @@
|
||||
#include "blackcore/application.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackmisc/simulation/simulatedaircraft.h"
|
||||
#include "blackmisc/simulation/matchingscript.h"
|
||||
#include "blackmisc/simulation/matchingutils.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
@@ -26,6 +28,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <QPair>
|
||||
#include <QStringBuilder>
|
||||
#include <QJSEngine>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Aviation;
|
||||
@@ -270,14 +273,69 @@ namespace BlackCore
|
||||
return matchedModel;
|
||||
}
|
||||
|
||||
CAircraftModel CAircraftMatcher::reverseLookupModel(const CCallsign &callsign, const CAircraftIcaoCode &networkAircraftIcao, const CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, CAircraftModel::ModelType type, CStatusMessageList *log)
|
||||
CAircraftModel CAircraftMatcher::reverseLookupModel(const CCallsign &callsign, const CAircraftIcaoCode &networkAircraftIcao, const CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, const CAircraftMatcherSetup &setup, CAircraftModel::ModelType type, CStatusMessageList *log)
|
||||
{
|
||||
CLivery livery;
|
||||
livery.setAirlineIcaoCode(networkAirlineIcao);
|
||||
CAircraftModel model(networkModelString, type, "", networkAircraftIcao, livery);
|
||||
CAircraftModel model(networkModelString, type, {}, networkAircraftIcao, livery);
|
||||
model.setCallsign(callsign);
|
||||
model = CAircraftMatcher::reverseLookupModel(model, networkLiveryInfo, log);
|
||||
model.setModelType(CAircraftModel::TypeReverseLookup);
|
||||
|
||||
// matching script
|
||||
while (setup.doRunMsNetworkEntryScript())
|
||||
{
|
||||
const QString js = CFileUtils::readFileToString(setup.getMsNetworkEntryFile());
|
||||
if (js.isEmpty()) { break; }
|
||||
|
||||
static const QString logFile = CFileUtils::appendFilePaths(CDirectoryUtils::logDirectory(), "logMatchingSriptEntry.log");
|
||||
QJSEngine engine;
|
||||
// engine.installExtensions(QJSEngine::ConsoleExtension);
|
||||
QJSValue jsMetaObject = engine.newQMetaObject(&MSSwiftValues::staticMetaObject);
|
||||
engine.globalObject().setProperty("SwiftValues", jsMetaObject);
|
||||
MSSwiftValues networkObject(
|
||||
callsign.asString(),
|
||||
networkAircraftIcao.getDesignator(), networkAircraftIcao.getDbKey(),
|
||||
networkAirlineIcao.getDesignator(), networkAirlineIcao.getDbKey(),
|
||||
networkLiveryInfo, -1
|
||||
);
|
||||
MSSwiftValues reverseModel(
|
||||
model.getCallsign().asString(),
|
||||
model.getAircraftIcaoCode().getDesignator(), model.getAircraftIcaoCode().getDbKey(),
|
||||
model.getAirlineIcaoCode().getDesignator(), model.getAirlineIcaoCode().getDbKey(),
|
||||
model.getLivery().getCombinedCode(), model.getLivery().getDbKey()
|
||||
);
|
||||
MSSwiftValues returnObject;
|
||||
|
||||
QJSValue jsNetworkObject = engine.newQObject(&networkObject);
|
||||
engine.globalObject().setProperty("networkObject", jsNetworkObject);
|
||||
QJSValue jsReverseObject = engine.newQObject(&networkObject);
|
||||
engine.globalObject().setProperty("reverseObject", jsNetworkObject);
|
||||
QJSValue jsReturnObject = engine.newQObject(&returnObject);
|
||||
engine.globalObject().setProperty("returnObject", jsNetworkObject);
|
||||
|
||||
QJSValue ms = engine.evaluate(js, logFile);
|
||||
ms = ms.call();
|
||||
if (ms.isError())
|
||||
{
|
||||
CLogMessage(getLogCategories()).warning(u"Matching script error: %1 '%2'") << ms.property("lineNumber").toInt() << ms.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ms.isString())
|
||||
{
|
||||
const QString r = ms.toString();
|
||||
if (!r.isEmpty())
|
||||
{
|
||||
CLogMessage(getLogCategories()).info(u"Matching script: '%1'") << ms.property("lineNumber").toInt() << ms.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// end this
|
||||
break;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,12 +89,12 @@ namespace BlackCore
|
||||
//! Try to find the corresponding data in DB and get best information for given data
|
||||
//! \threadsafe
|
||||
//! \ingroup reverselookup
|
||||
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(
|
||||
const BlackMisc::Aviation::CCallsign &callsign,
|
||||
const BlackMisc::Aviation::CAircraftIcaoCode &networkAircraftIcao,
|
||||
const BlackMisc::Aviation::CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString,
|
||||
BlackMisc::Simulation::CAircraftModel::ModelType type,
|
||||
BlackMisc::CStatusMessageList *log = nullptr);
|
||||
static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Aviation::CCallsign &callsign,
|
||||
const BlackMisc::Aviation::CAircraftIcaoCode &networkAircraftIcao,
|
||||
const BlackMisc::Aviation::CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString,
|
||||
const BlackMisc::Simulation::CAircraftMatcherSetup &setup,
|
||||
BlackMisc::Simulation::CAircraftModel::ModelType type,
|
||||
BlackMisc::CStatusMessageList *log = nullptr);
|
||||
|
||||
//! Try to find the corresponding data in DB and get best information for following matching
|
||||
//! \threadsafe
|
||||
|
||||
@@ -2,7 +2,7 @@ load(common_pre)
|
||||
|
||||
# GUI is required for the matrix classes
|
||||
# Network for host info etc.
|
||||
QT += network dbus xml multimedia
|
||||
QT += network dbus xml multimedia qml
|
||||
|
||||
TARGET = blackcore
|
||||
TEMPLATE = lib
|
||||
|
||||
@@ -35,7 +35,6 @@ namespace BlackGui
|
||||
{
|
||||
/**
|
||||
* Handle validation result
|
||||
* \sa BlackMisc::Views::
|
||||
*/
|
||||
class BLACKGUI_EXPORT CAircraftModelValidationComponent : public COverlayMessagesFrame
|
||||
{
|
||||
|
||||
@@ -32,6 +32,14 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="qw_MatchingForm">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>296</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_ScrollAreaContent">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
@@ -50,7 +58,7 @@
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>550</height>
|
||||
<height>600</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
|
||||
@@ -44,6 +44,16 @@ namespace BlackMisc
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CAircraftMatcherSetup::doRunMsNetworkEntryScript() const
|
||||
{
|
||||
return m_msNetworkEnabled && !m_msNetworkEntryFile.isEmpty();
|
||||
}
|
||||
|
||||
bool CAircraftMatcherSetup::doRunMsMatchingStageScript() const
|
||||
{
|
||||
return m_msMatchingEnabled && !m_msMatchingStageFile.isEmpty();
|
||||
}
|
||||
|
||||
void CAircraftMatcherSetup::setVerificationAtStartup(bool verify)
|
||||
{
|
||||
MatchingMode m = this->getMatchingMode();
|
||||
@@ -115,7 +125,7 @@ namespace BlackMisc
|
||||
this->reset(MatchingStepwiseReducePlusScoreBased);
|
||||
m_msNetworkEntryFile.clear();
|
||||
m_msMatchingStageFile.clear();
|
||||
m_msNetworkEnabled = false;
|
||||
m_msNetworkEnabled = false;
|
||||
m_msMatchingEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +137,11 @@ namespace BlackMisc
|
||||
bool isMsMatchingStageEnabled() const { return m_msMatchingEnabled; }
|
||||
//! @}
|
||||
|
||||
//! Run the scripts @{
|
||||
bool doRunMsNetworkEntryScript() const;
|
||||
bool doRunMsMatchingStageScript() const;
|
||||
//! @}
|
||||
|
||||
//! Is matching script enabled @{
|
||||
void setMsNetworkEntryEnabled(bool enabled) { m_msNetworkEnabled = enabled; }
|
||||
void setMsMatchingStageEnabled(bool enabled) { m_msMatchingEnabled = enabled; }
|
||||
|
||||
@@ -12,49 +12,49 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
void MSNetworkValues::setCallsign(const QString &callsign)
|
||||
void MSSwiftValues::setCallsign(const QString &callsign)
|
||||
{
|
||||
if (m_callsign == callsign) { return; }
|
||||
m_callsign = callsign;
|
||||
emit this->callsignChanged();
|
||||
}
|
||||
|
||||
void MSNetworkValues::setDbAircraftIcaoId(int id)
|
||||
void MSSwiftValues::setDbAircraftIcaoId(int id)
|
||||
{
|
||||
if (id == m_dbAircraftIcaoId) { return; }
|
||||
m_dbAircraftIcaoId = id;
|
||||
emit this->dbAircraftIcaoIdChanged();
|
||||
}
|
||||
|
||||
void MSNetworkValues::setDbAirlineIcaoId(int id)
|
||||
void MSSwiftValues::setDbAirlineIcaoId(int id)
|
||||
{
|
||||
if (id == m_dbAirlineIcaoId) { return; }
|
||||
m_dbAirlineIcaoId = id;
|
||||
emit this->dbAirlineIcaoIdChanged();
|
||||
}
|
||||
|
||||
void MSNetworkValues::setDbLiveryId(int id)
|
||||
void MSSwiftValues::setDbLiveryId(int id)
|
||||
{
|
||||
if (id == m_dbLiveryId) { return; }
|
||||
m_dbLiveryId = id;
|
||||
emit this->dbLiveryIdChanged();
|
||||
}
|
||||
|
||||
void MSNetworkValues::setAircraftIcao(const QString &aircraftIcao)
|
||||
void MSSwiftValues::setAircraftIcao(const QString &aircraftIcao)
|
||||
{
|
||||
if (aircraftIcao == m_aircraftIcao) { return; }
|
||||
m_aircraftIcao = aircraftIcao;
|
||||
emit this->aircraftIcaoChanged();
|
||||
}
|
||||
|
||||
void MSNetworkValues::setAirlineIcao(const QString &airlineIcao)
|
||||
void MSSwiftValues::setAirlineIcao(const QString &airlineIcao)
|
||||
{
|
||||
if (airlineIcao == m_airlineIcao) { return; }
|
||||
m_airlineIcao = airlineIcao;
|
||||
emit this->airlineIcaoChanged();
|
||||
}
|
||||
|
||||
void MSNetworkValues::setLivery(const QString &livery)
|
||||
void MSSwiftValues::setLivery(const QString &livery)
|
||||
{
|
||||
if (livery == m_livery) { return; }
|
||||
m_livery = livery;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace BlackMisc
|
||||
namespace Simulation
|
||||
{
|
||||
//! The network values
|
||||
class BLACKMISC_EXPORT MSNetworkValues : public QObject
|
||||
class BLACKMISC_EXPORT MSSwiftValues : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -37,7 +37,19 @@ namespace BlackMisc
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
Q_INVOKABLE MSNetworkValues() {}
|
||||
Q_INVOKABLE MSSwiftValues() {}
|
||||
|
||||
//! Ctor
|
||||
Q_INVOKABLE MSSwiftValues(const QString &cs,
|
||||
const QString &aircraftIcao, int idAircraftIcao,
|
||||
const QString &airlineIcao, int idAirlineIcao,
|
||||
const QString &livery, int liveryId) :
|
||||
m_callsign(cs.trimmed().toUpper()),
|
||||
m_aircraftIcao(aircraftIcao.trimmed().toUpper()),
|
||||
m_airlineIcao(airlineIcao.trimmed().toUpper()),
|
||||
m_livery(livery.trimmed().toUpper()),
|
||||
m_dbAircraftIcaoId(idAircraftIcao), m_dbAirlineIcaoId(idAirlineIcao), m_dbLiveryId(liveryId)
|
||||
{}
|
||||
|
||||
//! Get callsign
|
||||
const QString &getCallsign() const { return m_callsign; }
|
||||
|
||||
Reference in New Issue
Block a user