File indexing completed on 2024-04-28 04:42:41

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
0003  * SPDX-FileCopyrightText: 2021 Anjani Kumar <anjanik012@gmail.com>
0004  * SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #ifndef KWEATHERCORE_CAPAREA_H
0009 #define KWEATHERCORE_CAPAREA_H
0010 
0011 #include "capnamedvalue.h"
0012 #include <kweathercore/kweathercore_export.h>
0013 
0014 #include <QMetaType>
0015 #include <QSharedDataPointer>
0016 
0017 #include <cmath>
0018 
0019 namespace KWeatherCore
0020 {
0021 
0022 /** A geographic coordinate as part of a polygon. */
0023 class CAPCoordinate
0024 {
0025 public:
0026     float latitude = NAN;
0027     float longitude = NAN;
0028 };
0029 
0030 /** Geographic polygon describing the target area of a CAP alert message. */
0031 using CAPPolygon = std::vector<CAPCoordinate>;
0032 
0033 /** Geographic circle describing the target area of a CAP alert message. */
0034 class KWEATHERCORE_EXPORT CAPCircle
0035 {
0036     Q_GADGET
0037     Q_PROPERTY(float latitude MEMBER latitude)
0038     Q_PROPERTY(float longitude MEMBER longitude)
0039     Q_PROPERTY(float radius MEMBER radius)
0040 
0041 public:
0042     float latitude = NAN;
0043     float longitude = NAN;
0044     float radius = NAN;
0045 };
0046 
0047 class CAPAreaPrivate;
0048 
0049 /** Affected area of a CAP alert message.
0050  *  @see https://docs.oasis-open.org/emergency/cap/v1.2/CAP-v1.2.html ยง3.2.4
0051  */
0052 class KWEATHERCORE_EXPORT CAPArea
0053 {
0054     Q_GADGET
0055     Q_PROPERTY(QString description READ description)
0056     Q_PROPERTY(float altitude READ altitude)
0057     Q_PROPERTY(float ceiling READ ceiling)
0058 public:
0059     CAPArea();
0060     CAPArea(const CAPArea &other);
0061     CAPArea(CAPArea &&other);
0062     ~CAPArea();
0063     CAPArea &operator=(const CAPArea &other);
0064     CAPArea &operator=(CAPArea &&other);
0065 
0066     /** A text description of the message target area. */
0067     QString description() const;
0068     void setDescription(const QString &areaDesc);
0069 
0070     /** Geographic polygon(s) enclosing the message target area. */
0071     const std::vector<CAPPolygon> &polygons() const;
0072     void addPolygon(CAPPolygon &&polygon);
0073 
0074     /** Geographic circles(s) enclosing the message target area. */
0075     const std::vector<CAPCircle> &circles() const;
0076     void addCircle(CAPCircle &&circle);
0077 
0078     /** Any geographically-based code to describe a message target area, as key/value pair. */
0079     const std::vector<CAPNamedValue> &geoCodes() const;
0080     void addGeoCode(CAPNamedValue &&geoCode);
0081 
0082     /** The specific or minimum altitude of the affected area of the alert message.
0083      *  The altitude measure is in feet above mean sea level.
0084      *  If not set, NAN is returned.
0085      */
0086     float altitude() const;
0087     void setAltitude(float altitude);
0088 
0089     /** The maximum altitude of the affected area of the alert message.
0090      *  The altitude measure is in feet above mean sea level.
0091      *  If not set, NAN is returned.
0092      */
0093     float ceiling() const;
0094     void setCeiling(float ceiling);
0095 
0096 private:
0097     QSharedDataPointer<CAPAreaPrivate> d;
0098 };
0099 
0100 }
0101 
0102 Q_DECLARE_METATYPE(KWeatherCore::CAPCircle)
0103 Q_DECLARE_METATYPE(KWeatherCore::CAPArea)
0104 
0105 #endif // KWEATHERCORE_CAPAREA_H