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


4 5 6 7
const char* WimaGlobalMeasurementPolygon::settingsGroup =               "OperatingArea";
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])
15
{
16
    this->setObjectName("Operating Area");
17 18
}

19 20 21 22 23 24
WimaGlobalMeasurementPolygon::WimaGlobalMeasurementPolygon(QGCMapPolygon *other, QObject *parent):
    WimaPolygon (other, parent)
{

}

25 26 27
void WimaGlobalMeasurementPolygon::addVehicle(Vehicle *vehicle)
{
    if(vehicle != nullptr){
28 29
        _vehicleList->append(vehicle);
        emit vehicleListChanged();
30 31 32 33 34
    }
}

void WimaGlobalMeasurementPolygon::removeVehicle(int vehicleIndex)
{
35 36 37
    if(vehicleIndex >= 0 && vehicleIndex < _vehicleList->count()){
        _vehicleList->removeAt(vehicleIndex);
        emit vehicleListChanged();
38 39 40
    }
}

41
void WimaGlobalMeasurementPolygon::recalculatesubPolygons()
42 43
{
    int vehicleCount = _vehicleList->count();
44
    QScopedPointer<QList<QGCMapPolygon*>> listQGCPoly(this->splitPolygonArea(vehicleCount));
45

46 47 48 49 50 51
    int polyCount = listQGCPoly->size();
    _subPolygons->clear();
    for(int i = 0; i < polyCount; i++){
        WimaVehicleMeasurementPolygon* subPoly = new WimaVehicleMeasurementPolygon(listQGCPoly->takeAt(i), this);
        _subPolygons->append(subPoly);
    }
52 53 54 55 56 57 58 59 60 61 62
}

void WimaGlobalMeasurementPolygon::removeAllVehicles()
{
    int counter = _vehicleList->count()-1;

    while(counter >= 0){
        _vehicleList->removeAt(0);
        counter--;
    }

63
    emit vehicleListChanged();
64 65 66
}