mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
refs #369, adjusted plugins
* common base class for FS drivers * moved mapper into common base class * reflect changes for own aircraft provider ** removed member functions ** removed unused members
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
/* 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 "simulator_xplane.h"
|
||||
#include "xbus_service_proxy.h"
|
||||
@@ -23,7 +27,8 @@ namespace BlackSimPlugin
|
||||
namespace XPlane
|
||||
{
|
||||
|
||||
CSimulatorXPlane::CSimulatorXPlane(QObject *parent) : BlackCore::ISimulator(parent)
|
||||
CSimulatorXPlane::CSimulatorXPlane(IOwnAircraftProvider *ownAircraft, QObject *parent) :
|
||||
BlackCore::ISimulator(parent), COwnAircraftProviderSupport(ownAircraft)
|
||||
{
|
||||
m_watcher = new QDBusServiceWatcher(this);
|
||||
m_watcher->setWatchMode(QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration);
|
||||
@@ -164,15 +169,14 @@ namespace BlackSimPlugin
|
||||
void CSimulatorXPlane::ps_emitOwnAircraftModelChanged(const QString &path, const QString &filename, const QString &livery, const QString &icao)
|
||||
{
|
||||
//! \todo change as appropriate
|
||||
CSimulatedAircraft aircraft(this->getOwnAircraft());
|
||||
CAircraftModel model(aircraft.getModel());
|
||||
CAircraftModel model(ownAircraft().getModel());
|
||||
model.setModelType(CAircraftModel::TypeOwnSimulatorModel);
|
||||
model.setFileName(path + "/" + filename);
|
||||
CAircraftIcao aircraftIcao(icao);
|
||||
aircraftIcao.setLivery(livery);
|
||||
aircraft.setModel(model);
|
||||
aircraft.setIcaoInfo(aircraftIcao);
|
||||
emit ownAircraftModelChanged(aircraft);
|
||||
ownAircraft().setIcaoInfo(aircraftIcao);
|
||||
ownAircraft().setModel(model);
|
||||
emit ownAircraftModelChanged(ownAircraft());
|
||||
}
|
||||
|
||||
// convert xplane squawk mode to swift squawk mode
|
||||
@@ -188,7 +192,7 @@ namespace BlackSimPlugin
|
||||
return mode == BlackMisc::Aviation::CTransponder::StateStandby ? 1 : 2;
|
||||
}
|
||||
|
||||
CSimulatedAircraft CSimulatorXPlane::getOwnAircraft() const
|
||||
CSimulatedAircraft CSimulatorXPlane::xplaneDataToSimulatedAircraft() const
|
||||
{
|
||||
if (! isConnected()) { return {}; }
|
||||
Aviation::CAircraftSituation situation;
|
||||
@@ -198,9 +202,8 @@ namespace BlackSimPlugin
|
||||
situation.setPitch({ m_xplaneData.pitch, CAngleUnit::deg() });
|
||||
situation.setBank({ m_xplaneData.roll, CAngleUnit::deg() });
|
||||
situation.setGroundspeed({ m_xplaneData.groundspeed, CSpeedUnit::m_s() });
|
||||
CSimulatedAircraft ac;
|
||||
CSimulatedAircraft ac(ownAircraft());
|
||||
ac.setSituation(situation);
|
||||
ac.setModel(this->getOwnAircraftModel());
|
||||
ac.setIcaoInfo(Aviation::CAircraftIcao { m_xplaneData.aircraftIcaoCode });
|
||||
ac.setCom1System(Aviation::CComSystem::getCom1System({ m_xplaneData.com1Active, CFrequencyUnit::kHz() }, { m_xplaneData.com1Standby, CFrequencyUnit::kHz() }));
|
||||
ac.setCom2System(Aviation::CComSystem::getCom2System({ m_xplaneData.com2Active, CFrequencyUnit::kHz() }, { m_xplaneData.com2Standby, CFrequencyUnit::kHz() }));
|
||||
@@ -222,12 +225,6 @@ namespace BlackSimPlugin
|
||||
Q_UNUSED(message);
|
||||
}
|
||||
|
||||
BlackMisc::Simulation::CAircraftModel CSimulatorXPlane::getOwnAircraftModel() const
|
||||
{
|
||||
if (! isConnected()) { return {}; }
|
||||
return { m_xplaneData.aircraftModelPath, CAircraftModel::TypeOwnSimulatorModel };
|
||||
}
|
||||
|
||||
BlackMisc::Simulation::CAircraftModelList CSimulatorXPlane::getInstalledModels() const
|
||||
{
|
||||
// TODO
|
||||
@@ -276,11 +273,10 @@ namespace BlackSimPlugin
|
||||
return CPixmap();
|
||||
}
|
||||
|
||||
bool CSimulatorXPlane::updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &aircraft)
|
||||
bool CSimulatorXPlane::updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator)
|
||||
{
|
||||
if (! isConnected()) { return false; }
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
if (originator == this->simulatorOriginator()) { return false; }
|
||||
if (!isConnected()) { return false; }
|
||||
auto com1 = Aviation::CComSystem::getCom1System({ m_xplaneData.com1Active, CFrequencyUnit::kHz() }, { m_xplaneData.com1Standby, CFrequencyUnit::kHz() });
|
||||
auto com2 = Aviation::CComSystem::getCom2System({ m_xplaneData.com2Active, CFrequencyUnit::kHz() }, { m_xplaneData.com2Standby, CFrequencyUnit::kHz() });
|
||||
auto xpdr = Aviation::CTransponder::getStandardTransponder(m_xplaneData.xpdrCode, xpdrMode(m_xplaneData.xpdrMode, m_xplaneData.xpdrIdent));
|
||||
@@ -345,5 +341,10 @@ namespace BlackSimPlugin
|
||||
//! \todo really update aircraft in SIM
|
||||
}
|
||||
|
||||
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(IOwnAircraftProvider *ownAircraft, QObject *parent)
|
||||
{
|
||||
return new CSimulatorXPlane(ownAircraft, parent);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKSIMPLUGIN_SIMULATOR_XPLANE_H
|
||||
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackmisc/simulation/simdirectaccessownaircraft.h"
|
||||
#include "blackmisc/pixmap.h"
|
||||
#include <QDBusConnection>
|
||||
|
||||
@@ -29,13 +30,13 @@ namespace BlackSimPlugin
|
||||
/*!
|
||||
* X-Plane ISimulator implementation
|
||||
*/
|
||||
class CSimulatorXPlane : public BlackCore::ISimulator
|
||||
class CSimulatorXPlane : public BlackCore::ISimulator, BlackMisc::Simulation::COwnAircraftProviderSupport
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
CSimulatorXPlane(QObject *parent = nullptr);
|
||||
CSimulatorXPlane(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent = nullptr);
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::isConnected
|
||||
virtual bool isConnected() const override;
|
||||
@@ -62,9 +63,6 @@ namespace BlackSimPlugin
|
||||
//! \copydoc BlackCore::ISimulator::disconnectFrom
|
||||
virtual bool disconnectFrom() override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::getOwnAircraft
|
||||
virtual BlackMisc::Simulation::CSimulatedAircraft getOwnAircraft() const override;
|
||||
|
||||
//! \copydoc ISimulator::addRemoteAircraft()
|
||||
virtual void addRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
|
||||
|
||||
@@ -82,7 +80,7 @@ namespace BlackSimPlugin
|
||||
virtual int changeRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &changedAircraft, const BlackMisc::CPropertyIndexVariantMap &changeValues) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::updateOwnSimulatorCockpit
|
||||
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &aircraft) override;
|
||||
virtual bool updateOwnSimulatorCockpit(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override { return BlackSim::CSimulatorInfo::XP(); }
|
||||
@@ -93,9 +91,6 @@ namespace BlackSimPlugin
|
||||
//! \copydoc ISimulator::displayTextMessage
|
||||
virtual void displayTextMessage(const BlackMisc::Network::CTextMessage &message) const override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::getAircraftModel
|
||||
virtual BlackMisc::Simulation::CAircraftModel getOwnAircraftModel() const override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulator::getInstalledModels
|
||||
virtual BlackMisc::Simulation::CAircraftModelList getInstalledModels() const override;
|
||||
|
||||
@@ -130,6 +125,8 @@ namespace BlackSimPlugin
|
||||
BlackMisc::Aviation::CAirportList m_airports;
|
||||
BlackMisc::Simulation::CSimulatedAircraftList m_remoteAircraft;
|
||||
|
||||
BlackMisc::Simulation::CSimulatedAircraft xplaneDataToSimulatedAircraft() const;
|
||||
|
||||
//! \todo Add units to members? pitchDeg?, altitudeFt?
|
||||
struct // data is written by DBus async method callbacks
|
||||
{
|
||||
@@ -166,7 +163,7 @@ namespace BlackSimPlugin
|
||||
|
||||
public:
|
||||
//! \copydoc BlackCore::ISimulatorFactory::create
|
||||
virtual BlackCore::ISimulator *create(QObject *parent = nullptr) override { return new CSimulatorXPlane(parent); }
|
||||
virtual BlackCore::ISimulator *create(BlackMisc::Simulation::IOwnAircraftProvider *ownAircraft, QObject *parent = nullptr) override;
|
||||
|
||||
//! \copydoc BlackCore::ISimulatorFactory::getSimulatorInfo
|
||||
virtual BlackSim::CSimulatorInfo getSimulatorInfo() const override { return BlackSim::CSimulatorInfo::XP(); }
|
||||
|
||||
Reference in New Issue
Block a user