Ref T111, swift driver plugin

This commit is contained in:
Klaus Basan
2017-07-26 15:18:52 +02:00
committed by Mathew Sutcliffe
parent c8d6ebb318
commit 52805965cd
12 changed files with 959 additions and 3 deletions

View File

@@ -267,15 +267,17 @@ namespace BlackCore
// We assume we run in the same process as the own aircraft context
// Hence we pass in memory reference to own aircraft object
Q_ASSERT(this->getIContextOwnAircraft()->isUsingImplementingObject());
Q_ASSERT(this->getIContextNetwork()->isUsingImplementingObject());
Q_ASSERT_X(this->getIContextOwnAircraft()->isUsingImplementingObject(), Q_FUNC_INFO, "Need implementing object");
Q_ASSERT_X(this->getIContextNetwork()->isUsingImplementingObject(), Q_FUNC_INFO, "Need implementing object");
IOwnAircraftProvider *ownAircraftProvider = this->getRuntime()->getCContextOwnAircraft();
IRemoteAircraftProvider *renderedAircraftProvider = this->getRuntime()->getCContextNetwork();
ISimulator *simulator = factory->create(simulatorPluginInfo, ownAircraftProvider, renderedAircraftProvider, &m_weatherManager);
Q_ASSERT_X(simulator, Q_FUNC_INFO, "no simulator driver can be created");
setRemoteAircraftProvider(renderedAircraftProvider);
const CSimulatorInfo simInfo(simulatorPluginInfo.getIdentifier());
// use sim info from ISimulator as it can access the swift driver settings
const CSimulatorInfo simInfo = simulator->getSimulatorInfo();
m_modelSetLoader.changeSimulator(simInfo);
m_aircraftMatcher.setModelSet(m_modelSetLoader.getAircraftModels(), simInfo);
m_aircraftMatcher.setDefaultModel(simulator->getDefaultModel());

View File

@@ -82,6 +82,9 @@ namespace BlackCore
//! Get the simulator info (metadata of plugin)
virtual const BlackMisc::Simulation::CSimulatorPluginInfo &getSimulatorPluginInfo() const = 0;
//! Get simulator info (default implementation)
virtual BlackMisc::Simulation::CSimulatorInfo getSimulatorInfo() const;
//! Get the setup (simulator environemnt)
virtual const BlackMisc::Simulation::CSimulatorInternals &getSimulatorInternals() const = 0;

View File

@@ -3,6 +3,9 @@ load(common_pre)
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS += swift
SUBDIRS += swiftconfig
contains(BLACK_CONFIG,FSX|FS9|P3D) {
SUBDIRS += fsuipc32
SUBDIRS += fsuipc64

View File

@@ -0,0 +1,302 @@
/* Copyright (C) 2017
* 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 "simulatorswift.h"
#include "blackgui/guiapplication.h"
#include "blackcore/context/contextsimulator.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include <QApplication>
using namespace BlackGui;
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Simulation::Settings;
using namespace BlackMisc::Weather;
using namespace BlackCore;
using namespace BlackCore::Context;
namespace BlackSimPlugin
{
namespace Swift
{
CSimulatorSwift::CSimulatorSwift(const CSimulatorPluginInfo &info,
IOwnAircraftProvider *ownAircraftProvider,
IRemoteAircraftProvider *remoteAircraftProvider,
IWeatherGridProvider *weatherGridProvider,
QObject *parent) :
CSimulatorCommon(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, parent)
{
Q_ASSERT_X(sApp && sApp->getIContextSimulator(), Q_FUNC_INFO, "Need context");
CSimulatorSwift::registerHelp();
m_monitorWidget.reset(new CSimulatorSwiftMonitorDialog(this, sGui->mainApplicationWindow()));
connect(qApp, &QApplication::aboutToQuit, this, &CSimulatorSwift::closeMonitor);
this->onSettingsChanged();
}
CSimulatorInfo CSimulatorSwift::getSimulatorInfo() const
{
const CSwiftPluginSettings s = m_settings.get();
return s.getEmulatedSimulator();
}
bool CSimulatorSwift::isTimeSynchronized() const
{
return m_timeSyncronized;
}
bool CSimulatorSwift::connectTo()
{
QTimer::singleShot(1000, this, [ = ]
{
this->emitSimulatorCombinedStatus();
m_monitorWidget->show();
});
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return true;
}
bool CSimulatorSwift::disconnectFrom()
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
m_renderedAircraft.clear();
return true;
}
bool CSimulatorSwift::logicallyAddRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, remoteAircraft.toQString());
return CSimulatorCommon::logicallyAddRemoteAircraft(remoteAircraft);
}
bool CSimulatorSwift::logicallyRemoveRemoteAircraft(const CCallsign &callsign)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, callsign.toQString());
return CSimulatorCommon::logicallyRemoveRemoteAircraft(callsign);
}
int CSimulatorSwift::physicallyRemoveMultipleRemoteAircraft(const CCallsignSet &callsigns)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, callsigns.toQString());
return CSimulatorCommon::physicallyRemoveMultipleRemoteAircraft(callsigns);
}
bool CSimulatorSwift::changeRemoteAircraftModel(const CSimulatedAircraft &aircraft)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, aircraft.toQString());
return true;
}
bool CSimulatorSwift::changeRemoteAircraftEnabled(const CSimulatedAircraft &aircraft)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, aircraft.toQString());
const int c = m_renderedAircraft.setEnabled(aircraft.getCallsign(), aircraft.isEnabled(), true);
emit this->aircraftRenderingChanged(m_renderedAircraft.findFirstByCallsign(aircraft.getCallsign(), aircraft));
return c > 0;
}
bool CSimulatorSwift::updateOwnSimulatorCockpit(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, aircraft.toQString(), originator.toQString());
return true;
}
void CSimulatorSwift::displayStatusMessage(const CStatusMessage &message) const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, message.toQString());
}
void CSimulatorSwift::displayTextMessage(const CTextMessage &message) const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, message.toQString());
}
bool CSimulatorSwift::setTimeSynchronization(bool enable, const CTime &offset)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, boolToTrueFalse(enable), offset.toQString());
m_timeSyncronized = enable;
m_offsetTime = offset;
return enable;
}
CTime CSimulatorSwift::getTimeSynchronizationOffset() const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return m_offsetTime;
}
bool CSimulatorSwift::isPhysicallyRenderedAircraft(const CCallsign &callsign) const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, callsign.toQString());
return m_renderedAircraft.containsCallsign(callsign);
}
CCallsignSet CSimulatorSwift::physicallyRenderedAircraft() const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return m_renderedAircraft.getCallsigns();
}
void CSimulatorSwift::highlightAircraft(const CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const CTime &displayTime)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, aircraftToHighlight.toQString(), boolToTrueFalse(enableHighlight), displayTime.toQString());
CSimulatorCommon::highlightAircraft(aircraftToHighlight, enableHighlight, displayTime);
}
bool CSimulatorSwift::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, commandLine, originator.toQString());
return CSimulatorCommon::parseCommandLine(commandLine, originator);
}
void CSimulatorSwift::registerHelp()
{
if (BlackMisc::CSimpleCommandParser::registered("BlackSimPlugin::Swift::CSimulatorSwift")) { return; }
BlackMisc::CSimpleCommandParser::registerCommand({".drv", "alias: .driver .plugin"});
BlackMisc::CSimpleCommandParser::registerCommand({".drv show", "show swift driver window"});
BlackMisc::CSimpleCommandParser::registerCommand({".drv hide", "hide swift driver window"});
}
void CSimulatorSwift::setCombinedStatus(bool connected, bool simulating, bool paused)
{
m_connected = connected;
m_simulating = simulating;
m_paused = paused;
this->emitSimulatorCombinedStatus();
}
bool CSimulatorSwift::isConnected() const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return m_connected;
}
bool CSimulatorSwift::isPaused() const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return m_paused;
}
bool CSimulatorSwift::isSimulating() const
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return m_simulating;
}
bool CSimulatorSwift::physicallyAddRemoteAircraft(const CSimulatedAircraft &remoteAircraft)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, remoteAircraft.toQString());
CSimulatedAircraft aircraft(remoteAircraft);
aircraft.setRendered(true);
m_renderedAircraft.push_back(aircraft);
emit this->aircraftRenderingChanged(aircraft);
return true;
}
bool CSimulatorSwift::physicallyRemoveRemoteAircraft(const CCallsign &callsign)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, callsign.toQString());
const int c = m_renderedAircraft.removeByCallsign(callsign);
return c > 0;
}
bool CSimulatorSwift::setInterpolatorMode(CInterpolatorMulti::Mode mode, const CCallsign &callsign)
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO, CInterpolatorMulti::modeToString(mode), callsign.toQString());
return false;
}
int CSimulatorSwift::physicallyRemoveAllRemoteAircraft()
{
if (canLog()) m_monitorWidget->appendFunctionCall(Q_FUNC_INFO);
return CSimulatorCommon::physicallyRemoveAllRemoteAircraft();
}
bool CSimulatorSwift::parseDetails(const CSimpleCommandParser &parser)
{
if (m_monitorWidget && parser.isKnownCommand())
{
if (parser.matchesPart(1, "show")) { this->m_monitorWidget->show(); return true; }
if (parser.matchesPart(1, "hide")) { this->m_monitorWidget->hide(); return true; }
}
return false;
}
bool CSimulatorSwift::canLog() const
{
return sApp && !sApp->isShuttingDown() && m_log && m_monitorWidget;
}
void CSimulatorSwift::closeMonitor()
{
if (m_monitorWidget)
{
m_monitorWidget->close();
}
}
void CSimulatorSwift::setOwnAircraftPosition(const QString &wgsLatitude, const QString &wgsLongitude, const CAltitude &altitude)
{
const CCoordinateGeodetic coordinate(
CLatitude::fromWgs84(wgsLatitude),
CLongitude::fromWgs84(wgsLongitude),
CAltitude(0, CLengthUnit::m()));
CAircraftSituation s = this->getOwnAircraftSituation();
s.setPosition(coordinate);
s.setAltitude(altitude);
this->updateOwnSituation(s);
}
void CSimulatorSwift::onSettingsChanged()
{
const CSwiftPluginSettings settings(m_settings.get());
m_log = settings.isLoggingFunctionCalls();
const CSimulatorPluginInfoList plugins = sApp->getIContextSimulator()->getAvailableSimulatorPlugins();
const CSimulatorPluginInfo plugin = plugins.findBySimulator(settings.getEmulatedSimulator());
if (plugin.isValid())
{
// ? restart driver, disconnect/reconnect
this->setNewPluginInfo(plugin, settings.getDefaultModel());
}
else
{
CLogMessage(this).validationError("No valid plugin for %1") << settings.getEmulatedSimulator().getSimulator();
}
// update provider
this->updateOwnModel(settings.getOwnModel());
}
CSimulatorSwiftListener::CSimulatorSwiftListener(const CSimulatorPluginInfo &info)
: ISimulatorListener(info)
{ }
void CSimulatorSwiftListener::startImpl()
{
if (this->isShuttingDown()) { return; }
QTimer::singleShot(2000, this, [ = ]
{
Q_ASSERT_X(this->getPluginInfo().isValid(), Q_FUNC_INFO, "Invalid plugin");
emit this->simulatorStarted(this->getPluginInfo());
});
}
void CSimulatorSwiftListener::stopImpl()
{ }
} // ns
} // ns

View File

@@ -0,0 +1,143 @@
/* Copyright (C) 2017
* 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.
*/
//! \file
#ifndef BLACKSIMPLUGIN_SWIFT_SIMULATORSWIFT_H
#define BLACKSIMPLUGIN_SWIFT_SIMULATORSWIFT_H
#include "blackcore/simulatorcommon.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include "blackmisc/simulation/settings/swiftpluginsettings.h"
#include "blackmisc/pq/time.h"
#include "simulatorswiftmonitordialog.h"
#include <QScopedPointer>
namespace BlackSimPlugin
{
namespace Swift
{
//! swift simulator implementation
class CSimulatorSwift : public BlackCore::CSimulatorCommon
{
Q_OBJECT
friend class CSimulatorSwiftMonitorDialog; //!< the monitor widget represents the simulator and needs access to internals (i.e. private/protected)
public:
//! Constructor, parameters as in \sa BlackCore::ISimulatorFactory::create
CSimulatorSwift(
const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider,
QObject *parent = nullptr);
//! \copydoc BlackCore::CSimulatorCommon::getSimulatorInfo
virtual BlackMisc::Simulation::CSimulatorInfo getSimulatorInfo() const override;
// functions implemented
virtual bool isTimeSynchronized() const override;
virtual bool connectTo() override;
virtual bool disconnectFrom() override;
virtual bool changeRemoteAircraftModel(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) override;
virtual bool changeRemoteAircraftEnabled(const BlackMisc::Simulation::CSimulatedAircraft &aircraft) override;
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator) override;
virtual void displayStatusMessage(const BlackMisc::CStatusMessage &message) const override;
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override;
virtual bool setTimeSynchronization(bool enable, const BlackMisc::PhysicalQuantities::CTime &offset) override;
virtual BlackMisc::PhysicalQuantities::CTime getTimeSynchronizationOffset() const override;
virtual bool isPhysicallyRenderedAircraft(const BlackMisc::Aviation::CCallsign &callsign) const override;
virtual BlackMisc::Aviation::CCallsignSet physicallyRenderedAircraft() const override;
virtual bool setInterpolatorMode(BlackMisc::Simulation::CInterpolatorMulti::Mode mode, const BlackMisc::Aviation::CCallsign &callsign) override;
// functions just logged
virtual void highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime) override;
virtual bool logicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
virtual bool logicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual int physicallyRemoveMultipleRemoteAircraft(const BlackMisc::Aviation::CCallsignSet &callsigns) override;
// functions logged and used
//! \addtogroup swiftdotcommands
//! @{
//! <pre>
//! .drv show show swift driver window BlackSimPlugin::Swift::CSimulatorSwift
//! .drv hide hide swift driver window BlackSimPlugin::Swift::CSimulatorSwift
//! </pre>
//! @}
//! \copydoc BlackCore::ISimulator::parseCommandLine
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;
//! Register help
static void registerHelp();
//! UI setter
void setCombinedStatus(bool connected, bool simulating, bool paused);
protected:
virtual bool isConnected() const override;
virtual bool isPaused() const override;
virtual bool isSimulating() const override;
virtual bool physicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
virtual bool physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
// just logged
virtual int physicallyRemoveAllRemoteAircraft() override;
//! \copydoc BlackCore::CSimulatorCommon::parseDetails
virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser) override;
private:
//! Can append log messages?
bool canLog() const;
//! Close window
void closeMonitor();
//! Set own aircraft position
void setOwnAircraftPosition(const QString &wgsLatitude, const QString &wgsLongitude, const BlackMisc::Aviation::CAltitude &altitude);
//! Settings changed
void onSettingsChanged();
//! Values from UI
void onSimulatorStatusChanged();
bool m_log = false; //!< from settings
bool m_paused = false;
bool m_connected = true;
bool m_simulating = true;
bool m_timeSyncronized = false;
BlackMisc::PhysicalQuantities::CTime m_offsetTime;
BlackMisc::Simulation::CSimulatedAircraftList m_renderedAircraft;
QScopedPointer<CSimulatorSwiftMonitorDialog> m_monitorWidget; //!< parent will be main window, so we need to destroy widget when destroyed
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSwiftPlugin> m_settings { this, &CSimulatorSwift::onSettingsChanged };
};
//! Listener for swift
class CSimulatorSwiftListener : public BlackCore::ISimulatorListener
{
Q_OBJECT
public:
//! Constructor
CSimulatorSwiftListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info);
protected:
//! \copydoc BlackCore::ISimulatorListener::startImpl
virtual void startImpl() override;
//! \copydoc BlackCore::ISimulatorListener::stopImpl
virtual void stopImpl() override;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,7 @@
{
"identifier" : "org.swift-project.plugins.simulator.swift",
"name" : "swift pseudo simulator",
"simulator" : "swift",
"description" : "swift testing driver",
"config" : "org.swift-project.plugins.simulator.swift.config"
}

View File

@@ -0,0 +1,33 @@
/* Copyright (C) 2017
* 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 "simulatorswiftfactory.h"
#include "simulatorswift.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include <QTimer>
namespace BlackSimPlugin
{
namespace Swift
{
BlackCore::ISimulator *CSimulatorSwiftFactory::create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider)
{
Q_ASSERT(ownAircraftProvider);
return new CSimulatorSwift(info, ownAircraftProvider, remoteAircraftProvider, weatherGridProvider, this);
}
BlackCore::ISimulatorListener *CSimulatorSwiftFactory::createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info)
{
return new CSimulatorSwiftListener(info);
}
} // namespace
} // namespace

View File

@@ -0,0 +1,47 @@
/* Copyright (C) 2017
* 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.
*/
//! \file
#ifndef BLACKSIMPLUGIN_SIMULATOR_SWIFTFACTORY_H
#define BLACKSIMPLUGIN_SIMULATOR_SWIFTFACTORY_H
#include "blackcore/simulator.h"
#include "blackmisc/simulation/simulatorplugininfo.h"
#include <QObject>
#include <QtPlugin>
namespace BlackSimPlugin
{
namespace Swift
{
//! Factory implementation to create CSimulatorSwift instances
class CSimulatorSwiftFactory :
public QObject,
public BlackCore::ISimulatorFactory
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.swift-project.blackcore.simulatorinterface" FILE "simulatorswift.json")
Q_INTERFACES(BlackCore::ISimulatorFactory)
public:
//! \copydoc BlackCore::ISimulatorFactory::create
virtual BlackCore::ISimulator *create(const BlackMisc::Simulation::CSimulatorPluginInfo &info,
BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider,
BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider,
BlackMisc::Weather::IWeatherGridProvider *weatherGridProvider) override;
//! \copydoc BlackCore::ISimulatorFactory::createListener
virtual BlackCore::ISimulatorListener *createListener(const BlackMisc::Simulation::CSimulatorPluginInfo &info) override;
};
} // namespace
} // namespace
#endif // guard

View File

@@ -0,0 +1,103 @@
/* Copyright (C) 2017
* 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 "simulatorswiftmonitordialog.h"
#include "simulatorswift.h"
#include "ui_simulatorswiftmonitordialog.h"
using namespace BlackMisc;
namespace BlackSimPlugin
{
namespace Swift
{
const CLogCategoryList &CSimulatorSwiftMonitorDialog::getLogCategories()
{
static const BlackMisc::CLogCategoryList cats { CLogCategory::driver(), CLogCategory::plugin() };
return cats;
}
CSimulatorSwiftMonitorDialog::CSimulatorSwiftMonitorDialog(CSimulatorSwift *simulator, QWidget *parent) :
QDialog(parent),
ui(new Ui::CSimulatorSwiftMonitorDialog)
{
Q_ASSERT_X(simulator, Q_FUNC_INFO, "Need simulator");
m_simulator = simulator;
ui->setupUi(this);
ui->tw_SwiftMonitorDialog->setCurrentIndex(0);
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
connect(ui->cb_Connected, &QCheckBox::released, this, &CSimulatorSwiftMonitorDialog::onSimulatorValuesChanged);
connect(ui->cb_Paused, &QCheckBox::released, this, &CSimulatorSwiftMonitorDialog::onSimulatorValuesChanged);
connect(ui->cb_Simulating, &QCheckBox::released, this, &CSimulatorSwiftMonitorDialog::onSimulatorValuesChanged);
this->setSimulatorUiValues();
ui->comp_Position->setCoordinate(m_simulator->getOwnAircraftSituation());
}
CSimulatorSwiftMonitorDialog::~CSimulatorSwiftMonitorDialog()
{ }
void CSimulatorSwiftMonitorDialog::appendStatusMessageToList(const BlackMisc::CStatusMessage &statusMessage)
{
ui->comp_LogComponent->appendStatusMessagesToList(statusMessage);
}
void CSimulatorSwiftMonitorDialog::appendStatusMessagesToList(const BlackMisc::CStatusMessageList &statusMessages)
{
ui->comp_LogComponent->appendStatusMessagesToList(statusMessages);
}
void CSimulatorSwiftMonitorDialog::appendFunctionCall(const QString &function, const QString &p1, const QString &p2, const QString &p3)
{
static const QString c1("%1 %2");
static const QString c2("%1 %2 %3");
static const QString c3("%1 %2 %3 %4");
CStatusMessage msg;
if (!p3.isEmpty())
{
msg = CStatusMessage(this, CStatusMessage::SeverityInfo, c3.arg(function, p1, p2, p3));
}
else if (!p2.isEmpty())
{
msg = CStatusMessage(this, CStatusMessage::SeverityInfo, c2.arg(function, p1, p2));
}
else if (!p1.isEmpty())
{
msg = CStatusMessage(this, CStatusMessage::SeverityInfo, c1.arg(function, p1));
}
else
{
msg = CStatusMessage(this, CStatusMessage::SeverityInfo, function);
}
this->appendStatusMessageToList(msg);
}
void CSimulatorSwiftMonitorDialog::onSimulatorValuesChanged()
{
m_simulator->setCombinedStatus(
ui->cb_Connected->isChecked(),
ui->cb_Simulating->isChecked(),
ui->cb_Paused->isChecked()
);
}
void CSimulatorSwiftMonitorDialog::setSimulatorUiValues()
{
ui->cb_Connected->setChecked(m_simulator->isConnected());
ui->cb_Paused->setChecked(m_simulator->isPaused());
ui->cb_Simulating->setChecked(m_simulator->isSimulating());
ui->le_Simulator->setText(m_simulator->getSimulatorInfo().toQString(true));
ui->le_SimulatorPlugin->setText(m_simulator->getSimulatorPluginInfo().toQString(true));
}
} // ns
} // ns

View File

@@ -0,0 +1,66 @@
/* Copyright (C) 2017
* 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.
*/
//! \file
#ifndef BLACKSIMPLUGIN_SWIFT_SIMULATORSWIFTMONITORDIALOG_H
#define BLACKSIMPLUGIN_SWIFT_SIMULATORSWIFTMONITORDIALOG_H
#include <QDialog>
#include <QScopedPointer>
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/logcategorylist.h"
namespace Ui { class CSimulatorSwiftMonitorDialog; }
namespace BlackSimPlugin
{
namespace Swift
{
class CSimulatorSwift;
/**
* Monitor widget for the pseudo driver
*/
class CSimulatorSwiftMonitorDialog : public QDialog
{
Q_OBJECT
public:
//! Log categories
static const BlackMisc::CLogCategoryList &getLogCategories();
//! Ctor
explicit CSimulatorSwiftMonitorDialog(CSimulatorSwift *simulator, QWidget *parent = nullptr);
//! Dtor
virtual ~CSimulatorSwiftMonitorDialog();
//! \copydoc BlackGui::Components::CLogComponent::appendStatusMessageToList
void appendStatusMessageToList(const BlackMisc::CStatusMessage &statusMessage);
//! \copydoc BlackGui::Components::CLogComponent::appendStatusMessagesToList
void appendStatusMessagesToList(const BlackMisc::CStatusMessageList &statusMessages);
//! Append a function call as status message
void appendFunctionCall(const QString &function, const QString &p1 = {}, const QString &p2 = {}, const QString &p3 = {});
private:
//! UI values changed
void onSimulatorValuesChanged();
//! UI values
void setSimulatorUiValues();
QScopedPointer<Ui::CSimulatorSwiftMonitorDialog> ui;
CSimulatorSwift *m_simulator = nullptr;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,218 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSimulatorSwiftMonitorDialog</class>
<widget class="QDialog" name="CSimulatorSwiftMonitorDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<height>402</height>
</rect>
</property>
<property name="windowTitle">
<string>swift driver monitor</string>
</property>
<layout class="QVBoxLayout" name="vl_Settings">
<item>
<widget class="QTabWidget" name="tw_SwiftMonitorDialog">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="tb_AircraftSituation">
<attribute name="title">
<string>Situation</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="BlackGui::Components::CCoordinateSelector" name="comp_Position">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="vs_Situation">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_Simulator">
<attribute name="title">
<string>Simulator</string>
</attribute>
<layout class="QFormLayout" name="formLayout">
<item row="9" column="0">
<widget class="QLabel" name="lbl_Paused">
<property name="text">
<string>Paused:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="cb_Paused">
<property name="text">
<string>simulator paused?</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lbl_Connected">
<property name="text">
<string>Connected:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="cb_Connected">
<property name="text">
<string>simulator connected?</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="lbl_Simulating">
<property name="text">
<string>Simulating:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QCheckBox" name="cb_Simulating">
<property name="text">
<string>simulator simulating?</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_SimulatorPlugin">
<property name="text">
<string>Simulator plugin:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lbl_Simulator">
<property name="text">
<string>Simulator:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="le_SimulatorPlugin">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="le_Simulator">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_LogMessages">
<attribute name="title">
<string>Log information</string>
</attribute>
<layout class="QVBoxLayout" name="vl_LogInformation">
<item>
<widget class="BlackGui::Components::CLogComponent" name="comp_LogComponent"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_Settings">
<attribute name="title">
<string>Settings</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="BlackGui::Components::CSettingsSwiftPlugin" name="comp_Settings"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="bb_SwiftMonitorDialog">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CSettingsSwiftPlugin</class>
<extends>QFrame</extends>
<header>blackgui/components/settingsswiftplugin.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CLogComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/logcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CCoordinateSelector</class>
<extends>QFrame</extends>
<header>blackgui/components/coordinateselector.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>bb_SwiftMonitorDialog</sender>
<signal>accepted()</signal>
<receiver>CSimulatorSwiftMonitorDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bb_SwiftMonitorDialog</sender>
<signal>rejected()</signal>
<receiver>CSimulatorSwiftMonitorDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,29 @@
load(common_pre)
QT += core dbus gui widgets network xml
TARGET = simulatorswift
TEMPLATE = lib
CONFIG += plugin shared
CONFIG += blackmisc blackcore blackgui
DEPENDPATH += . $$SourceRoot/src
INCLUDEPATH += . $$SourceRoot/src
SOURCES += *.cpp
HEADERS += *.h
FORMS += *.ui
DISTFILES += simulatorswift.json
DESTDIR = $$DestRoot/bin/plugins/simulator
win32 {
dlltarget.path = $$PREFIX/bin/plugins/simulator
INSTALLS += dlltarget
} else {
target.path = $$PREFIX/bin/plugins/simulator
INSTALLS += target
}
load(common_post)