|
|
|
@ -21,6 +21,8 @@
@@ -21,6 +21,8 @@
|
|
|
|
|
#include "QGCQGeoCoordinate.h" |
|
|
|
|
#include "AppSettings.h" |
|
|
|
|
#include "PlanMasterController.h" |
|
|
|
|
#include "SettingsManager.h" |
|
|
|
|
#include "AppSettings.h" |
|
|
|
|
|
|
|
|
|
#ifndef __mobile__ |
|
|
|
|
#include "MainWindow.h" |
|
|
|
@ -32,24 +34,43 @@
@@ -32,24 +34,43 @@
|
|
|
|
|
|
|
|
|
|
QGC_LOGGING_CATEGORY(GeoFenceControllerLog, "GeoFenceControllerLog") |
|
|
|
|
|
|
|
|
|
QMap<QString, FactMetaData*> GeoFenceController::_metaDataMap; |
|
|
|
|
|
|
|
|
|
const char* GeoFenceController::_jsonFileTypeValue = "GeoFence"; |
|
|
|
|
const char* GeoFenceController::_jsonBreachReturnKey = "breachReturn"; |
|
|
|
|
const char* GeoFenceController::_jsonPolygonsKey = "polygons"; |
|
|
|
|
const char* GeoFenceController::_jsonCirclesKey = "circles"; |
|
|
|
|
|
|
|
|
|
const char* GeoFenceController::_breachReturnAltitudeFactName = "Altitude"; |
|
|
|
|
|
|
|
|
|
const char* GeoFenceController::_px4ParamCircularFence = "GF_MAX_HOR_DIST"; |
|
|
|
|
|
|
|
|
|
GeoFenceController::GeoFenceController(PlanMasterController* masterController, QObject* parent) |
|
|
|
|
: PlanElementController (masterController, parent) |
|
|
|
|
, _geoFenceManager (_managerVehicle->geoFenceManager()) |
|
|
|
|
, _dirty (false) |
|
|
|
|
: PlanElementController (masterController, parent) |
|
|
|
|
, _geoFenceManager (_managerVehicle->geoFenceManager()) |
|
|
|
|
, _dirty (false) |
|
|
|
|
, _breachReturnAltitudeFact (0, _breachReturnAltitudeFactName, FactMetaData::valueTypeDouble) |
|
|
|
|
, _breachReturnDefaultAltitude (qgcApp()->toolbox()->settingsManager()->appSettings()->defaultMissionItemAltitude()->rawValue().toDouble()) |
|
|
|
|
|
|
|
|
|
, _itemsRequested (false) |
|
|
|
|
, _px4ParamCircularFenceFact(NULL) |
|
|
|
|
, _px4ParamCircularFenceFact(nullptr) |
|
|
|
|
{ |
|
|
|
|
if (_metaDataMap.isEmpty()) { |
|
|
|
|
_metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/BreachReturn.FactMetaData.json"), nullptr /* metaDataParent */); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_breachReturnAltitudeFact.setMetaData(_metaDataMap[_breachReturnAltitudeFactName]); |
|
|
|
|
_breachReturnAltitudeFact.setRawValue(_breachReturnDefaultAltitude); |
|
|
|
|
|
|
|
|
|
connect(&_polygons, &QmlObjectListModel::countChanged, this, &GeoFenceController::_updateContainsItems); |
|
|
|
|
connect(&_circles, &QmlObjectListModel::countChanged, this, &GeoFenceController::_updateContainsItems); |
|
|
|
|
|
|
|
|
|
managerVehicleChanged(_managerVehicle); |
|
|
|
|
|
|
|
|
|
connect(this, &GeoFenceController::breachReturnPointChanged, this, &GeoFenceController::_setDirty); |
|
|
|
|
connect(&_breachReturnAltitudeFact, &Fact::rawValueChanged, this, &GeoFenceController::_setDirty); |
|
|
|
|
connect(&_polygons, &QmlObjectListModel::dirtyChanged, this, &GeoFenceController::_setDirty); |
|
|
|
|
connect(&_circles, &QmlObjectListModel::dirtyChanged, this, &GeoFenceController::_setDirty); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GeoFenceController::~GeoFenceController() |
|
|
|
@ -79,26 +100,19 @@ void GeoFenceController::setBreachReturnPoint(const QGeoCoordinate& breachReturn
@@ -79,26 +100,19 @@ void GeoFenceController::setBreachReturnPoint(const QGeoCoordinate& breachReturn
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GeoFenceController::_signalAll(void) |
|
|
|
|
{ |
|
|
|
|
emit breachReturnPointChanged(breachReturnPoint()); |
|
|
|
|
emit dirtyChanged(dirty()); |
|
|
|
|
emit supportedChanged(supported()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GeoFenceController::managerVehicleChanged(Vehicle* managerVehicle) |
|
|
|
|
{ |
|
|
|
|
if (_managerVehicle) { |
|
|
|
|
_geoFenceManager->disconnect(this); |
|
|
|
|
_managerVehicle->disconnect(this); |
|
|
|
|
_managerVehicle->parameterManager()->disconnect(this); |
|
|
|
|
_managerVehicle = NULL; |
|
|
|
|
_geoFenceManager = NULL; |
|
|
|
|
_managerVehicle = nullptr; |
|
|
|
|
_geoFenceManager = nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_managerVehicle = managerVehicle; |
|
|
|
|
if (!_managerVehicle) { |
|
|
|
|
qWarning() << "GeoFenceController::managerVehicleChanged managerVehicle=NULL"; |
|
|
|
|
qWarning() << "GeoFenceController::managerVehicleChanged managerVehicle=nullptr"; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -114,7 +128,6 @@ void GeoFenceController::managerVehicleChanged(Vehicle* managerVehicle)
@@ -114,7 +128,6 @@ void GeoFenceController::managerVehicleChanged(Vehicle* managerVehicle)
|
|
|
|
|
_parametersReady(); |
|
|
|
|
|
|
|
|
|
emit supportedChanged(supported()); |
|
|
|
|
_signalAll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool GeoFenceController::load(const QJsonObject& json, QString& errorString) |
|
|
|
@ -133,6 +146,7 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
@@ -133,6 +146,7 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
|
|
|
|
|
{ JsonHelper::jsonVersionKey, QJsonValue::Double, true }, |
|
|
|
|
{ _jsonCirclesKey, QJsonValue::Array, true }, |
|
|
|
|
{ _jsonPolygonsKey, QJsonValue::Array, true }, |
|
|
|
|
{ _jsonBreachReturnKey, QJsonValue::Array, false }, |
|
|
|
|
}; |
|
|
|
|
if (!JsonHelper::validateKeys(json, keyInfoList, errorString)) { |
|
|
|
|
return false; |
|
|
|
@ -144,7 +158,7 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
@@ -144,7 +158,7 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QJsonArray jsonPolygonArray = json[_jsonPolygonsKey].toArray(); |
|
|
|
|
for (const QJsonValue& jsonPolygonValue: jsonPolygonArray) { |
|
|
|
|
for (const QJsonValue jsonPolygonValue: jsonPolygonArray) { |
|
|
|
|
if (jsonPolygonValue.type() != QJsonValue::Object) { |
|
|
|
|
errorString = tr("GeoFence polygon not stored as object"); |
|
|
|
|
return false; |
|
|
|
@ -158,7 +172,7 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
@@ -158,7 +172,7 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QJsonArray jsonCircleArray = json[_jsonCirclesKey].toArray(); |
|
|
|
|
for (const QJsonValue& jsonCircleValue: jsonCircleArray) { |
|
|
|
|
for (const QJsonValue jsonCircleValue: jsonCircleArray) { |
|
|
|
|
if (jsonCircleValue.type() != QJsonValue::Object) { |
|
|
|
|
errorString = tr("GeoFence circle not stored as object"); |
|
|
|
|
return false; |
|
|
|
@ -171,8 +185,18 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
@@ -171,8 +185,18 @@ bool GeoFenceController::load(const QJsonObject& json, QString& errorString)
|
|
|
|
|
_circles.append(fenceCircle); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (json.contains(_jsonBreachReturnKey)) { |
|
|
|
|
if (!JsonHelper::loadGeoCoordinate(json[_jsonBreachReturnKey], true /* altitudeRequred */, _breachReturnPoint, errorString)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
_breachReturnAltitudeFact.setRawValue(_breachReturnPoint.altitude()); |
|
|
|
|
} else { |
|
|
|
|
_breachReturnPoint = QGeoCoordinate(); |
|
|
|
|
_breachReturnAltitudeFact.setRawValue(_breachReturnDefaultAltitude); |
|
|
|
|
} |
|
|
|
|
emit breachReturnPointChanged(_breachReturnPoint); |
|
|
|
|
|
|
|
|
|
setDirty(false); |
|
|
|
|
_signalAll(); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -198,6 +222,14 @@ void GeoFenceController::save(QJsonObject& json)
@@ -198,6 +222,14 @@ void GeoFenceController::save(QJsonObject& json)
|
|
|
|
|
jsonCircleArray.append(jsonCircle); |
|
|
|
|
} |
|
|
|
|
json[_jsonCirclesKey] = jsonCircleArray; |
|
|
|
|
|
|
|
|
|
if (_breachReturnPoint.isValid()) { |
|
|
|
|
QJsonValue jsonCoordinate; |
|
|
|
|
|
|
|
|
|
_breachReturnPoint.setAltitude(_breachReturnAltitudeFact.rawValue().toDouble()); |
|
|
|
|
JsonHelper::saveGeoCoordinate(_breachReturnPoint, true /* writeAltitude */, jsonCoordinate); |
|
|
|
|
json[_jsonBreachReturnKey] = jsonCoordinate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GeoFenceController::removeAll(void) |
|
|
|
@ -305,6 +337,11 @@ void GeoFenceController::_setReturnPointFromManager(QGeoCoordinate breachReturnP
@@ -305,6 +337,11 @@ void GeoFenceController::_setReturnPointFromManager(QGeoCoordinate breachReturnP
|
|
|
|
|
{ |
|
|
|
|
_breachReturnPoint = breachReturnPoint; |
|
|
|
|
emit breachReturnPointChanged(_breachReturnPoint); |
|
|
|
|
if (_breachReturnPoint.isValid()) { |
|
|
|
|
_breachReturnAltitudeFact.setRawValue(_breachReturnPoint.altitude()); |
|
|
|
|
} else { |
|
|
|
|
_breachReturnAltitudeFact.setRawValue(_breachReturnDefaultAltitude); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void GeoFenceController::_managerLoadComplete(void) |
|
|
|
@ -315,7 +352,6 @@ void GeoFenceController::_managerLoadComplete(void)
@@ -315,7 +352,6 @@ void GeoFenceController::_managerLoadComplete(void)
|
|
|
|
|
_setReturnPointFromManager(_geoFenceManager->breachReturnPoint()); |
|
|
|
|
_setFenceFromManager(_geoFenceManager->polygons(), _geoFenceManager->circles()); |
|
|
|
|
setDirty(false); |
|
|
|
|
_signalAll(); |
|
|
|
|
emit loadComplete(); |
|
|
|
|
} |
|
|
|
|
_itemsRequested = false; |
|
|
|
@ -476,7 +512,7 @@ void GeoFenceController::_parametersReady(void)
@@ -476,7 +512,7 @@ void GeoFenceController::_parametersReady(void)
|
|
|
|
|
{ |
|
|
|
|
if (_px4ParamCircularFenceFact) { |
|
|
|
|
_px4ParamCircularFenceFact->disconnect(this); |
|
|
|
|
_px4ParamCircularFenceFact = NULL; |
|
|
|
|
_px4ParamCircularFenceFact = nullptr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (_managerVehicle->isOfflineEditingVehicle() || !_managerVehicle->parameterManager()->parameterExists(FactSystem::defaultComponentId, _px4ParamCircularFence)) { |
|
|
|
|