Files
aman-es/src/PlugIn.h

167 lines
7.1 KiB
C++

/*
* @brief Defines the EuroScope plug-in
* @file src/PlugIn.h
* @author Sven Czarnian <devel@svcz.de>
* @copyright Copyright 2021 Sven Czarnian
* @license This project is published under the GNU General Public License v3 (GPLv3)
*/
#pragma once
#include <functional>
#pragma warning(push, 0)
#include <EuroScopePlugIn.h>
#pragma warning(pop)
#include <aman/types/Communication.h>
#include <aman/types/Inbound.h>
#pragma warning(push, 0)
#include <protobuf/BaseTypes.pb.h>
#include <protobuf/AircraftReport.pb.h>
#include <protobuf/Communication.pb.h>
#pragma warning(pop)
#include "RadarScreen.h"
namespace aman {
/**
* @brief Defines the EuroScope plug-in
* @ingroup euroscope
*/
class PlugIn : public EuroScopePlugIn::CPlugIn {
public:
/**
* @brief Defines the different internal and external tag functions
*/
enum class TagItemFunction {
RunwaySelectMenu = 2, /**< Opens the runway selection menu */
RunwaySelect = 3, /**< Selects the runway */
DirectToMenu = 4, /**< Opens the direct to menu */
DirectTo = 5 /**< Selects the direct to */
};
private:
struct AirportData {
std::vector<std::string> arrivalRunways;
std::list<std::string> inboundUpdates;
};
struct InitialApproachFix {
std::string name;
GeoCoordinate coordinate;
};
enum class TagItemElement {
EstimatedTimeOfArrival = 0,
PlannedTimeOfArrival = 1,
DeltaTime = 2,
FixedPlanIndicator = 3
};
void validateBackendData();
void receiveConfiguration(const std::string& airport);
aman::Aircraft* generateAircraftMessage(const EuroScopePlugIn::CRadarTarget& target) const;
void generateAircraftReportMessage(EuroScopePlugIn::CRadarTarget& radarTarget, aman::AircraftReport* report);
void addUpdateQueue(EuroScopePlugIn::CRadarTarget& radarTarget);
void updateInbound(EuroScopePlugIn::CRadarTarget& radarTarget);
void updateSequence(std::shared_ptr<aman::AircraftSequence>& sequence);
static void distanceToPredictedIaf(const EuroScopePlugIn::CRadarTarget& radarTarget, const EuroScopePlugIn::CFlightPlan& flightPlan,
const EuroScopePlugIn::CPosition& iafPosition, aman::AircraftReport* report);
Communication m_configuration;
std::shared_ptr<RadarScreen> m_screen;
std::mutex m_updateQueueLock;
std::map<std::string, AirportData> m_updateQueue;
std::map<std::string, std::vector<InitialApproachFix>> m_initialApproachFixes;
std::mutex m_inboundsQueueLock;
std::map<std::string, Inbound> m_inbounds;
std::map<std::string, std::string> m_selectedRunway;
std::list<std::string> m_forcedToBackendCallsigns;
bool m_compatible;
bool m_connectedToNetwork;
bool m_sweatboxValid;
bool m_playbackValid;
public:
/**
* @brief Creates a new plug-in
*/
PlugIn();
/**
* @brief Destroys all internal strcutures
*/
~PlugIn();
PlugIn(const PlugIn&) = delete;
PlugIn(PlugIn&&) = delete;
PlugIn& operator=(const PlugIn&) = delete;
PlugIn& operator=(PlugIn&&) = delete;
/**
* @brief Called as soon as a new RADAR screen needs to be created
* @param[in] displayName The display's name
* @param[in] needsRadarContent True of the screen needs RADAR content
* @param[in] geoReferenced True if the positions are geo referenced
* @param[in] canBeSaved True if the configurations can be saved
* @param[in] canBeCreated True if the configuration can be created
* @return The created RADAR screen
*/
EuroScopePlugIn::CRadarScreen* OnRadarScreenCreated(const char* displayName, bool needsRadarContent, bool geoReferenced,
bool canBeSaved, bool canBeCreated) override;
/**
* @brief Called as soon as a controller writes down a command
* @param[in] cmdline The commandline
* @return True if the command was parsed, else false
*/
bool OnCompileCommand(const char* cmdline) override;
/**
* @brief Called as soon as a function is triggered
* @param[in] functionId The triggered ID
* @param[in] itemString The content of the message
* @param[in] pt The click position
* @param[in] area The clicked area
*/
void OnFunctionCall(int functionId, const char* itemString, POINT pt, RECT area) override;
/**
* @brief Called as soon as a tag entry needs to be updated
* @param[in] flightPlan The requested flight plan
* @param[in] radarTarget The corresponding RADAR target
* @param[in] itemCode The requested item
* @param[in] tagData The requested tag data
* @param[in] itemString The buffer to store the data
* @param[in] colorCode The color code of the entry
* @param[in] rgb The colorization of the entry
* @param[in] fontSize The size of the text
*/
void OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlugIn::CRadarTarget radarTarget,
int itemCode, int tagData, char itemString[16], int* colorCode, COLORREF* rgb,
double* fontSize) override;
/**
* @brief Called every second
* @param[in] counter The counter that indicates the seconds
*/
void OnTimer(int counter) override;
/**
* @brief Called as soon as a controller updated the flight plan
* @param[in] flightPlan The updated flight plan
* @param[in] type The changed information
*/
void OnFlightPlanControllerAssignedDataUpdate(EuroScopePlugIn::CFlightPlan flightPlan, int type) override;
/**
* @brief Called as soon as a radar target position is updated
* @param[in] radarTarget The updated radar target
*/
void OnRadarTargetPositionUpdate(EuroScopePlugIn::CRadarTarget radarTarget) override;
/**
* @brief Called as soon as a flight plan is offline
* @param[in] flightPlan The disconnected flight plan
*/
void OnFlightPlanDisconnect(EuroScopePlugIn::CFlightPlan flightPlan) override;
/**
* @brief Called as soon as a runway configuration changed
*/
void OnAirportRunwayActivityChanged() override;
};
}