Ref T259, Ref T243 simulator environment provider

* access to elevation
* future: more data such as airport info
This commit is contained in:
Klaus Basan
2018-03-07 02:04:21 +01:00
parent 8021cf76fd
commit 3346a92b56
5 changed files with 169 additions and 7 deletions

View File

@@ -25,6 +25,13 @@
#include "blackcore/blackcoreexport.h"
#include "blackcore/network.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
#include "blackmisc/simulation/ownaircraftprovider.h"
#include "blackmisc/simulation/remoteaircraftprovider.h"
#include "blackmisc/simulation/simulationenvironmentprovider.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/aviation/aircraftpartslist.h"
#include "blackmisc/aviation/aircraftsituationlist.h"
#include "blackmisc/aviation/atcstation.h"
@@ -40,12 +47,6 @@
#include "blackmisc/pq/frequency.h"
#include "blackmisc/pq/length.h"
#include "blackmisc/pq/angle.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
#include "blackmisc/simulation/ownaircraftprovider.h"
#include "blackmisc/simulation/remoteaircraftprovider.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
namespace BlackMisc
{
@@ -69,7 +70,8 @@ namespace BlackCore
class BLACKCORE_EXPORT CAirspaceMonitor :
public QObject,
public BlackMisc::Simulation::IRemoteAircraftProvider, // those data will be provided from the class CAirspaceMonitor
public BlackMisc::Simulation::COwnAircraftAware, // used to obtain in memory information about own aircraft
public BlackMisc::Simulation::COwnAircraftAware, // used to obtain in memory information about own aircraft
public BlackMisc::Simulation::CSimulationEnvironmentAware, // elevation info etc.
public BlackMisc::CIdentifiable
{
Q_OBJECT

View File

@@ -0,0 +1,73 @@
/* Copyright (C) 2018
* 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 "simulationenvironmentprovider.h"
using namespace BlackMisc::Geo;
namespace BlackMisc
{
namespace Simulation
{
bool ISimulationEnvironmentProvider::rememberGroundElevation(const ICoordinateGeodetic &elevationCoordinate, const PhysicalQuantities::CLength &epsilon)
{
{
QReadLocker l(&m_lockElvCoordinates);
if (m_elvCoordinates.containsObjectInRange(elevationCoordinate, epsilon)) { return false; }
}
{
QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinates.push_back(elevationCoordinate);
}
return true;
}
bool ISimulationEnvironmentProvider::rememberGroundElevation(const CElevationPlane &elevationPlane)
{
if (!elevationPlane.hasMSLGeodeticHeight()) { return false; }
return this->rememberGroundElevation(elevationPlane, elevationPlane.getRadius());
}
CCoordinateGeodeticList ISimulationEnvironmentProvider::getElevationCoordinates() const
{
QReadLocker l(&m_lockElvCoordinates);
return m_elvCoordinates;
}
int ISimulationEnvironmentProvider::cleanUpElevations(const ICoordinateGeodetic &referenceCoordinate, int maxNumber)
{
CCoordinateGeodeticList coordinates(this->getElevationCoordinates());
const int size = coordinates.size();
if (size <= maxNumber) { return 0; }
coordinates.sortByEuclideanDistanceSquared(referenceCoordinate);
coordinates.truncate(maxNumber);
const int delta = size - coordinates.size();
QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinates = coordinates;
return delta;
}
CElevationPlane ISimulationEnvironmentProvider::findClosestElevationWithinRange(const ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range)
{
return this->getElevationCoordinates().findClosestWithinRange(reference, range);
}
void ISimulationEnvironmentProvider::clearSimulationEnvironmentData()
{
QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinates.clear();
}
CElevationPlane CSimulationEnvironmentAware::findClosestElevationWithinRange(const ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range)
{
if (!m_simEnvironmentProvider) { return CElevationPlane::null(); }
return m_simEnvironmentProvider->findClosestElevationWithinRange(reference, range);
}
} // namespace
} // namespace

View File

@@ -0,0 +1,83 @@
/* Copyright (C) 2018
* 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 BLACKMISC_SIMULATION_SIMULATIONENVIRONMENTPROVIDER_H
#define BLACKMISC_SIMULATION_SIMULATIONENVIRONMENTPROVIDER_H
#include "blackmisc/geo/coordinategeodeticlist.h"
#include "blackmisc/geo/elevationplane.h"
namespace BlackMisc
{
namespace Simulation
{
//! Direct in memory access to elevation data
//! \remark we are interested in elevations of airports
class BLACKMISC_EXPORT ISimulationEnvironmentProvider
{
public:
//! All remembered coordiantes
//! \remark might be a relatively large list
//! \threadsafe
Geo::CCoordinateGeodeticList getElevationCoordinates() const;
//! Only keep closest ones
//! \threadsafe
int cleanUpElevations(const Geo::ICoordinateGeodetic &referenceCoordinate, int maxNumber = MaxElevations);
//! Find closest elevation
//! \threadsafe
Geo::CElevationPlane findClosestElevationWithinRange(const Geo::ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range);
//! Clear data
//! \threadsafe
void clearSimulationEnvironmentData();
protected:
static constexpr int MaxElevations = 1000; //!< How many elevations we keep
//! Remember a given elevation
//! \threadsafe
bool rememberGroundElevation(const Geo::ICoordinateGeodetic &elevationCoordinate, const PhysicalQuantities::CLength &epsilon = Geo::CElevationPlane::singlePointRadius()) ;
//! Remember a given elevation
//! \threadsafe
bool rememberGroundElevation(const Geo::CElevationPlane &elevationPlane) ;
private:
Geo::CCoordinateGeodeticList m_elvCoordinates;
mutable QReadWriteLock m_lockElvCoordinates; //!< lock m_coordinates
};
//! Class which can be directly used to access an \sa ISimulationEnvironmentProvider object
class BLACKMISC_EXPORT CSimulationEnvironmentAware
{
public:
//! Elevations, can be changed over time as it comes from simulator
void setSimulationEnvironmentProvider(ISimulationEnvironmentProvider *provider) { m_simEnvironmentProvider = provider; }
//! Find closest elevation
Geo::CElevationPlane findClosestElevationWithinRange(const Geo::ICoordinateGeodetic &reference, const PhysicalQuantities::CLength &range);
protected:
//! Default constructor
CSimulationEnvironmentAware() {}
//! Constructor
CSimulationEnvironmentAware(ISimulationEnvironmentProvider *simEnvProvider) : m_simEnvironmentProvider(simEnvProvider) { Q_ASSERT(simEnvProvider); }
ISimulationEnvironmentProvider *m_simEnvironmentProvider = nullptr; //!< access to object
};
} // namespace
} // namespace
Q_DECLARE_INTERFACE(BlackMisc::Simulation::ISimulationEnvironmentProvider, "BlackMisc::Simulation::ISimulationEnvironmentProvider")
#endif // guard

View File

@@ -496,6 +496,9 @@ namespace BlackSimPlugin
// set it in the remote aircraft provider
this->updateAircraftGroundElevation(simObject.getCallsign(), elevation);
// and in elevation provider
this->rememberGroundElevation(elevation);
}
void CSimulatorFsxCommon::updateOwnAircraftFromSimulator(const DataDefinitionClientAreaSb &sbDataArea)

View File

@@ -1027,6 +1027,7 @@ namespace BlackSimPlugin
// set it in the remote aircraft provider
this->updateAircraftGroundElevation(cs, elevation);
this->rememberGroundElevation(elevation);
}
BlackCore::ISimulator *CSimulatorXPlaneFactory::create(const CSimulatorPluginInfo &info,