WimaMeasurementArea.cc 5.03 KB
Newer Older
1 2
#include "WimaMeasurementArea.h"

Valentin Platzgummer's avatar
Valentin Platzgummer committed
3

4
const char* WimaMeasurementArea::settingsGroup =                   "MeasurementArea";
Valentin Platzgummer's avatar
Valentin Platzgummer committed
5 6 7
const char* WimaMeasurementArea::bottomLayerAltitudeName =         "BottomLayerAltitude";
const char* WimaMeasurementArea::numberOfLayersName =              "NumberOfLayers";
const char* WimaMeasurementArea::layerDistanceName =               "LayerDistance";
8
const char* WimaMeasurementArea::WimaMeasurementAreaName =         "Measurement Area";
Valentin Platzgummer's avatar
Valentin Platzgummer committed
9 10 11


WimaMeasurementArea::WimaMeasurementArea(QObject *parent)
12 13 14 15 16
  :     WimaArea (parent)
  ,     _metaDataMap            (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/WimaMeasurementArea.SettingsGroup.json"), this /* QObject parent */))
  ,     _bottomLayerAltitude    (SettingsFact(settingsGroup, _metaDataMap[bottomLayerAltitudeName], this /* QObject parent */))
  ,     _numberOfLayers         (SettingsFact(settingsGroup, _metaDataMap[numberOfLayersName], this /* QObject parent */))
  ,     _layerDistance          (SettingsFact(settingsGroup, _metaDataMap[layerDistanceName], this /* QObject parent */))
Valentin Platzgummer's avatar
Valentin Platzgummer committed
17 18 19 20 21
{
    init();
}

WimaMeasurementArea::WimaMeasurementArea(const WimaMeasurementArea &other, QObject *parent)
22 23 24 25 26
    :     WimaArea (other, parent)
    ,     _metaDataMap            (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/WimaMeasurementArea.SettingsGroup.json"), this /* QObject parent */))
    ,     _bottomLayerAltitude    (SettingsFact(settingsGroup, _metaDataMap[bottomLayerAltitudeName], this /* QObject parent */))
    ,     _numberOfLayers         (SettingsFact(settingsGroup, _metaDataMap[numberOfLayersName], this /* QObject parent */))
    ,     _layerDistance          (SettingsFact(settingsGroup, _metaDataMap[layerDistanceName], this /* QObject parent */))
Valentin Platzgummer's avatar
Valentin Platzgummer committed
27 28 29 30
{
    init();
}

31 32 33 34 35 36 37 38 39 40 41 42
/*!
 * \overload operator=()
 *
 * Calls the inherited operator WimaArea::operator=().
 */
WimaMeasurementArea &WimaMeasurementArea::operator=(const WimaMeasurementArea &other)
{
    WimaArea::operator=(other);

    return *this;
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
43 44 45 46 47 48 49 50 51 52
void WimaMeasurementArea::saveToJson(QJsonObject &json)
{
    this->WimaArea::saveToJson(json);
    json[bottomLayerAltitudeName]   = _bottomLayerAltitude.rawValue().toDouble();
    json[numberOfLayersName]        = _numberOfLayers.rawValue().toInt();
    json[layerDistanceName]         = _layerDistance.rawValue().toDouble();
    json[areaTypeName]              = WimaMeasurementAreaName;
}

bool WimaMeasurementArea::loadFromJson(const QJsonObject &json, QString& errorString)
53
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    if (this->WimaArea::loadFromJson(json, errorString)) {
        bool retVal = true;

        if ( json.contains(bottomLayerAltitudeName) && json[bottomLayerAltitudeName].isDouble() ) {
            _bottomLayerAltitude.setRawValue(json[bottomLayerAltitudeName].toDouble());
        } else {
            errorString.append(tr("Could not load Bottom Layer Altitude!\n"));
            retVal = false;
        }

        if ( json.contains(numberOfLayersName) && json[numberOfLayersName].isDouble() ) {
            _numberOfLayers.setRawValue(json[numberOfLayersName].toInt());
        } else {
            errorString.append(tr("Could not load Number of Layers!\n"));
            retVal = false;
        }
70

Valentin Platzgummer's avatar
Valentin Platzgummer committed
71 72 73 74 75 76 77 78 79 80 81
        if ( json.contains(layerDistanceName) && json[layerDistanceName].isDouble() ) {
            _layerDistance.setRawValue(json[layerDistanceName].toDouble());
        } else {
            errorString.append(tr("Could not load Layer Distance!\n"));
            retVal = false;
        }

        return retVal;
    } else {
        return false;
    }
82
}
Valentin Platzgummer's avatar
Valentin Platzgummer committed
83

84 85 86 87 88 89 90 91 92 93
void WimaMeasurementArea::setBottomLayerAltitude(double altitude)
{
    if ( !qFuzzyCompare(_bottomLayerAltitude.rawValue().toDouble(), altitude) ) {
        _bottomLayerAltitude.setRawValue(altitude);

        emit bottomLayerAltitudeChanged();
    }
}

void WimaMeasurementArea::setNumberOfLayers(double numLayers)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
94
{
95 96
    if ( !qFuzzyCompare(_numberOfLayers.rawValue().toDouble(), numLayers) ) {
        _numberOfLayers.setRawValue(numLayers);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
97

98 99 100 101 102 103 104 105
        emit numberOfLayersChanged();
    }
}

void WimaMeasurementArea::setLayerDistance(double layerDistance)
{
    if ( !qFuzzyCompare(_layerDistance.rawValue().toDouble(), layerDistance) ) {
        _layerDistance.setRawValue(layerDistance);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
106

107 108
        emit layerDistanceChanged();
    }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
}

void print(const WimaMeasurementArea &area)
{
    QString message;
    print(area, message);
    qWarning() << message;
}

void print(const WimaMeasurementArea &area, QString outputStr)
{
    print(static_cast<const WimaArea&>(area), outputStr);
    outputStr.append(QString("Bottom Layer Altitude: %1\n").arg(area._bottomLayerAltitude.rawValue().toDouble()));
    outputStr.append(QString("Number of Layers: %1\n").arg(area._numberOfLayers.rawValue().toInt()));
    outputStr.append(QString("Layer Distance: %1\n").arg(area._layerDistance.rawValue().toDouble()));
}

void WimaMeasurementArea::init()
{
    this->setObjectName(WimaMeasurementAreaName);
}

131 132 133 134 135 136 137
/*!
 * \class WimaMeasurementArea
 * \brief Class defining the area inside which the actual drone measurements are performed.
 *
 * \sa WimaArea, WimaController, WimaPlaner
 */

Valentin Platzgummer's avatar
Valentin Platzgummer committed
138