/** * Telegrams toJSON * $Id$ * $HeadURL$ * $Author$ * Created by Norbert Thoden, NLE, 2020-06-29 */ #pragma once #include #include #include #include #include namespace TargetManagement { class JsonException final : public std::exception { public: JsonException(const QJsonObject &obj, const QString &key); const char *what() const noexcept override { return m_what.data(); } private: QJsonObject m_obj; QString m_key; QByteArray m_what; }; template struct Constraints; // // Enumerations // // // Structs // // ------------------------------------------------------------------ // ------------------------------------------------------------------ struct Target { virtual ~Target() = default; virtual QJsonObject toJson() const = 0; virtual QString type() const = 0; }; struct GeoPosition2D { GeoPosition2D() = default; explicit GeoPosition2D(const Core::GeoPosition2D pos) : lat(pos.lat()), lon(pos.lon()) {} double lat = 0; // in degree, WGS-84 double lon = 0; // in degree, WGS-84 static GeoPosition2D fromJson(const QJsonObject &obj); QJsonObject toJson() const; // Core::GeoPosition2D toCoreGeoPosition2D() const { return {lon, lat}; } }; // ------------------------------------------------------------------ template struct TargetBaseTmpl : Target { QString type() const override final { return Constraints::type(); } }; // ------------------------------------------------------------------ struct ShootbackTargetData final : public TargetBaseTmpl { // use simple members and not generated dds struct to be independent int32_t id{-1}; int32_t targetDataId{-1}; QString name; int32_t targetParticipantEquipmentNumber{-1}; bool activateLaserDesignation{false}; bool permanentInstalledTarget{false}; bool activateLights{false}; int32_t hitsToKill{-1}; bool activatePopupAutomatic{false}; // conversion functions QJsonObject toJson() const override; static ShootbackTargetData fromJson(const QJsonObject &obj); }; template <> struct Constraints { static QString type() { return QStringLiteral("ShootbackTargetData"); } }; // ------------------------------------------------------------------ struct ShootbackAreaData final : public TargetBaseTmpl { // use simple members and not generated dds struct to be independent int32_t id{-1}; QString name; GeoPosition2D position; double width{.0}; double height{.0}; // conversion functions QJsonObject toJson() const override; static ShootbackAreaData fromJson(const QJsonObject &obj); }; template <> struct Constraints { static QString type() { return QStringLiteral("ShootbackAreaData"); } }; // ------------------------------------------------------------------ struct ShootbackConfigurationData final : public TargetBaseTmpl { // use simple members and not generated dds struct to be independent int interval1{-1}; bool flash1{false}; TargetManagement::Effect effect1{TargetManagement::Effect_def::NearMiss}; int interval2{-1}; bool flash2{false}; TargetManagement::Effect effect2{TargetManagement::Effect_def::NearMiss}; // conversion functions QJsonObject toJson() const override; static ShootbackConfigurationData fromJson(const QJsonObject &obj); }; template <> struct Constraints { static QString type() { return QStringLiteral("ShootbackConfigurationData"); } }; // ------------------------------------------------------------------ struct TargetAreaAssignmentData final : public TargetBaseTmpl { // use simple members and not generated dds struct to be independent int32_t id{-1}; QString name; int areaId; int targetParticipantId; ShootbackConfigurationData configuration; bool isActive{false}; // conversion functions QJsonObject toJson() const override; static TargetAreaAssignmentData fromJson(const QJsonObject &obj); }; template <> struct Constraints { static QString type() { return QStringLiteral("TargetAreaAssignmentData"); } }; }