EditPositionDialogController.cc 3.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "EditPositionDialogController.h"
#include "QGCGeo.h"

const char*  EditPositionDialogController::_latitudeFactName =      "Latitude";
const char*  EditPositionDialogController::_longitudeFactName =     "Longitude";
const char*  EditPositionDialogController::_zoneFactName =          "Zone";
const char*  EditPositionDialogController::_hemisphereFactName =    "Hemisphere";
const char*  EditPositionDialogController::_eastingFactName =       "Easting";
const char*  EditPositionDialogController::_northingFactName =      "Northing";

QMap<QString, FactMetaData*> EditPositionDialogController::_metaDataMap;

EditPositionDialogController::EditPositionDialogController(void)
    : _latitudeFact     (0, _latitudeFactName,      FactMetaData::valueTypeDouble)
    , _longitudeFact    (0, _longitudeFactName,     FactMetaData::valueTypeDouble)
    , _zoneFact         (0, _zoneFactName,          FactMetaData::valueTypeUint8)
    , _hemisphereFact   (0, _hemisphereFactName,    FactMetaData::valueTypeUint8)
    , _eastingFact      (0, _eastingFactName,       FactMetaData::valueTypeDouble)
    , _northingFact     (0, _northingFactName,      FactMetaData::valueTypeDouble)
{
    if (_metaDataMap.isEmpty()) {
        _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/EditPositionDialog.FactMetaData.json"), NULL /* QObject parent */);
    }

    _latitudeFact.setMetaData   (_metaDataMap[_latitudeFactName]);
    _longitudeFact.setMetaData  (_metaDataMap[_longitudeFactName]);
    _zoneFact.setMetaData       (_metaDataMap[_zoneFactName]);
    _hemisphereFact.setMetaData (_metaDataMap[_hemisphereFactName]);
    _eastingFact.setMetaData    (_metaDataMap[_eastingFactName]);
    _northingFact.setMetaData   (_metaDataMap[_northingFactName]);
}

void EditPositionDialogController::setCoordinate(QGeoCoordinate coordinate)
{
    if (coordinate != _coordinate) {
        _coordinate = coordinate;
        emit coordinateChanged(coordinate);
    }
}

void EditPositionDialogController::initValues(void)
{
    _latitudeFact.setRawValue(_coordinate.latitude());
    _longitudeFact.setRawValue(_coordinate.longitude());

    double easting, northing;
    int zone = convertGeoToUTM(_coordinate, easting, northing);
    _zoneFact.setRawValue(zone);
    _hemisphereFact.setRawValue(_coordinate.latitude() < 0);
    _eastingFact.setRawValue(easting);
    _northingFact.setRawValue(northing);
}

void EditPositionDialogController::setFromGeo(void)
{
    _coordinate.setLatitude(_latitudeFact.rawValue().toDouble());
    _coordinate.setLongitude(_longitudeFact.rawValue().toDouble());
    emit coordinateChanged(_coordinate);
}

void EditPositionDialogController::setFromUTM(void)
{
    qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1);
    convertUTMToGeo(_eastingFact.rawValue().toDouble(), _northingFact.rawValue().toDouble(), _zoneFact.rawValue().toInt(), _hemisphereFact.rawValue().toInt() == 1, _coordinate);
    qDebug() << _eastingFact.rawValue().toDouble() << _northingFact.rawValue().toDouble() << _zoneFact.rawValue().toInt() << (_hemisphereFact.rawValue().toInt() == 1) << _coordinate;
    emit coordinateChanged(_coordinate);
}