WimaGlobalMeasurementPolygon.cc 3.83 KB
Newer Older
1 2 3
#include "WimaGlobalMeasurementPolygon.h"


Valentin Platzgummer's avatar
Valentin Platzgummer committed
4
const char* WimaGlobalMeasurementPolygon::settingsGroup =                   "OperatingArea";
5 6 7
const char* WimaGlobalMeasurementPolygon::bottomLayerAltitudeName =         "BottomLayerAltitude";
const char* WimaGlobalMeasurementPolygon::numberOfLayersName =              "NumberOfLayers";
const char* WimaGlobalMeasurementPolygon::layerDistanceName =               "LayerDistance";
8

9 10 11 12 13 14
WimaGlobalMeasurementPolygon::WimaGlobalMeasurementPolygon(QObject *parent)
  : WimaPolygon (parent)
  , _metaDataMap            (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/WimaGlobalMeasurementPolygon.SettingsGroup.json"), this /* QObject parent */))
  , _bottomLayerAltitude    (settingsGroup, _metaDataMap[bottomLayerAltitudeName])
  , _numberOfLayers         (settingsGroup, _metaDataMap[numberOfLayersName])
  , _layerDistance          (settingsGroup, _metaDataMap[layerDistanceName])
Valentin Platzgummer's avatar
Valentin Platzgummer committed
15 16
  , _vehicleList            (new QmlObjectListModel(this))
  , _vehiclePolygons        (new QmlObjectListModel(this))
17
{
18
    this->setObjectName("Operating Area");
Valentin Platzgummer's avatar
Valentin Platzgummer committed
19
    _polyline.bindPolygon(this->polygon());
20 21
}

Valentin Platzgummer's avatar
Valentin Platzgummer committed
22 23 24 25 26 27 28 29
WimaGlobalMeasurementPolygon::WimaGlobalMeasurementPolygon(QGCMapPolygon *other, QObject *parent)
  : WimaPolygon (other, parent)
  , _metaDataMap            (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/WimaGlobalMeasurementPolygon.SettingsGroup.json"), this /* QObject parent */))
  , _bottomLayerAltitude    (settingsGroup, _metaDataMap[bottomLayerAltitudeName])
  , _numberOfLayers         (settingsGroup, _metaDataMap[numberOfLayersName])
  , _layerDistance          (settingsGroup, _metaDataMap[layerDistanceName])
  , _vehicleList            (new QmlObjectListModel(this))
  , _vehiclePolygons        (new QmlObjectListModel(this))
30
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
31 32
    this->setObjectName("Operating Area");
    _polyline.bindPolygon(this->polygon());
33 34
}

35 36 37
void WimaGlobalMeasurementPolygon::addVehicle(Vehicle *vehicle)
{
    if(vehicle != nullptr){
38 39
        _vehicleList->append(vehicle);
        emit vehicleListChanged();
40 41 42 43 44
    }
}

void WimaGlobalMeasurementPolygon::removeVehicle(int vehicleIndex)
{
45 46 47
    if(vehicleIndex >= 0 && vehicleIndex < _vehicleList->count()){
        _vehicleList->removeAt(vehicleIndex);
        emit vehicleListChanged();
48 49 50
    }
}

51
void WimaGlobalMeasurementPolygon::recalculatesubPolygons()
52 53
{
    int vehicleCount = _vehicleList->count();
54
    QScopedPointer<QList<QGCMapPolygon*>> listQGCPoly(this->splitPolygonArea(vehicleCount));
55

56
    int polyCount = listQGCPoly->size();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
57
    _vehiclePolygons->clear();
58 59
    for(int i = 0; i < polyCount; i++){
        WimaVehicleMeasurementPolygon* subPoly = new WimaVehicleMeasurementPolygon(listQGCPoly->takeAt(i), this);
Valentin Platzgummer's avatar
Valentin Platzgummer committed
60
        _vehiclePolygons->append(subPoly);
61
    }
62 63 64 65
}

void WimaGlobalMeasurementPolygon::removeAllVehicles()
{
Valentin Platzgummer's avatar
Valentin Platzgummer committed
66
    int count = _vehicleList->count();
67

Valentin Platzgummer's avatar
Valentin Platzgummer committed
68 69 70 71 72 73 74
    if(count > 0){
        do{
            _vehicleList->removeAt(0);
            count--;
        }while(count > 0);

        emit vehicleListChanged();
75 76 77 78 79
    }

}


Valentin Platzgummer's avatar
Valentin Platzgummer committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
void WimaGlobalMeasurementPolygon::addVehiclePolygon()
{
    _vehiclePolygons->append(new WimaVehicleMeasurementPolygon(this));

    emit vehiclePolygonsChanged();
}

void WimaGlobalMeasurementPolygon::removeVehiclePolygon(int polygonIndex)
{
    if(polygonIndex >= 0 && polygonIndex < _vehiclePolygons->count()){
        _vehiclePolygons->removeAt(polygonIndex);

        emit vehiclePolygonsChanged();
    }else {
        qWarning("Index out of bounds!");
    }
}

void WimaGlobalMeasurementPolygon::removeVehiclePolygon(WimaVehicleMeasurementPolygon *wimaPolygon)
{
    if(wimaPolygon != nullptr){
        QObject* removedPolygon = _vehiclePolygons->removeOne(wimaPolygon);
        if(removedPolygon){
            emit vehiclePolygonsChanged();
        }else {
            qWarning("Polygon not inside polygon list.");
        }
    }else {
        qWarning("Not a valid Polygon.");
    }
}