From fb32766eb9bc00c45db5b30632a0678b5c84018c Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Tue, 30 Oct 2018 22:28:11 -0400 Subject: [PATCH] Fix fitMapViewportToMissionItems --- src/FlightMap/FlightMap.qml | 1 + src/FlightMap/MapItems/MissionLineView.qml | 4 +- src/FlightMap/Widgets/MapFitFunctions.qml | 48 +++++++++++----- src/MissionManager/ComplexMissionItem.h | 4 -- src/MissionManager/QGCMapCircle.h | 6 +- src/MissionManager/QGCMapPolygon.h | 4 +- .../StructureScanComplexItem.cc | 26 ++++++++- .../TransectStyleComplexItem.cc | 13 +---- src/MissionManager/TransectStyleComplexItem.h | 4 -- src/MissionManager/VisualMissionItem.cc | 11 +++- src/MissionManager/VisualMissionItem.h | 11 ++++ src/PlanView/PlanToolBar.qml | 10 ++-- src/QGCApplication.cc | 57 ++++++++++--------- src/QmlControls/QGCGeoBoundingCube.cc | 11 +++- src/QmlControls/QGCGeoBoundingCube.h | 12 ++-- 15 files changed, 140 insertions(+), 82 deletions(-) diff --git a/src/FlightMap/FlightMap.qml b/src/FlightMap/FlightMap.qml index 1da578c54..635acab5f 100644 --- a/src/FlightMap/FlightMap.qml +++ b/src/FlightMap/FlightMap.qml @@ -49,6 +49,7 @@ Map { property var activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate() function setVisibleRegion(region) { + // TODO: Is this still necessary with Qt 5.11? // This works around a bug on Qt where if you set a visibleRegion and then the user moves or zooms the map // and then you set the same visibleRegion the map will not move/scale appropriately since it thinks there // is nothing to do. diff --git a/src/FlightMap/MapItems/MissionLineView.qml b/src/FlightMap/MapItems/MissionLineView.qml index 2704e41be..39382391f 100644 --- a/src/FlightMap/MapItems/MissionLineView.qml +++ b/src/FlightMap/MapItems/MissionLineView.qml @@ -26,9 +26,9 @@ MapItemView { line.color: "#be781c" // Hack, can't get palette to work in here z: QGroundControl.zOrderWaypointLines - path: [ + path: object ? [ object.coordinate1, object.coordinate2, - ] + ] : [] } } diff --git a/src/FlightMap/Widgets/MapFitFunctions.qml b/src/FlightMap/Widgets/MapFitFunctions.qml index c6336514f..cec946938 100644 --- a/src/FlightMap/Widgets/MapFitFunctions.qml +++ b/src/FlightMap/Widgets/MapFitFunctions.qml @@ -10,7 +10,8 @@ import QtQuick 2.3 import QtPositioning 5.3 -import QGroundControl 1.0 +import QGroundControl 1.0 +import QGroundControl.FlightMap 1.0 /// Set of functions for fitting the map viewpoer to a specific constraint Item { @@ -62,38 +63,46 @@ Item { var south = north var east = normalizeLon(coordList[0].longitude) var west = east - for (var i=1; i vertices = _flightPolygon.coordinateList(); + for (int i = 0; i < vertices.count(); i++) { + QGeoCoordinate vertex = vertices[i]; + double lat = vertex.latitude() + 90.0; + double lon = vertex.longitude() + 180.0; + north = fmax(north, lat); + south = fmin(south, lat); + east = fmax(east, lon); + west = fmin(west, lon); + bottom = fmin(bottom, vertex.altitude()); + top = fmax(top, vertex.altitude()); + } + //-- Update bounding cube for airspace management control + _setBoundingCube(QGCGeoBoundingCube( + QGeoCoordinate(north - 90.0, west - 180.0, bottom), + QGeoCoordinate(south - 90.0, east - 180.0, top))); + emit coordinateChanged(coordinate()); emit exitCoordinateChanged(exitCoordinate()); emit greatestDistanceToChanged(); @@ -458,7 +482,7 @@ void StructureScanComplexItem::_recalcCameraShots(void) return; } - int cameraShots = distance / triggerDistance; + int cameraShots = static_cast(distance / triggerDistance); _setCameraShots(cameraShots * _layersFact.rawValue().toInt()); } diff --git a/src/MissionManager/TransectStyleComplexItem.cc b/src/MissionManager/TransectStyleComplexItem.cc index 7005d9a5e..c8c4f3d21 100644 --- a/src/MissionManager/TransectStyleComplexItem.cc +++ b/src/MissionManager/TransectStyleComplexItem.cc @@ -41,14 +41,13 @@ const int TransectStyleComplexItem::_terrainQueryTimeoutMsecs = 1000 TransectStyleComplexItem::TransectStyleComplexItem(Vehicle* vehicle, bool flyView, QString settingsGroup, QObject* parent) : ComplexMissionItem (vehicle, flyView, parent) , _sequenceNumber (0) - , _dirty (false) - , _terrainPolyPathQuery (NULL) + , _terrainPolyPathQuery (nullptr) , _ignoreRecalc (false) , _complexDistance (0) , _cameraShots (0) , _cameraCalc (vehicle, settingsGroup) , _followTerrain (false) - , _loadedMissionItemsParent (NULL) + , _loadedMissionItemsParent (nullptr) , _metaDataMap (FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/TransectStyle.SettingsGroup.json"), this)) , _turnAroundDistanceFact (settingsGroup, _metaDataMap[_vehicle->multiRotor() ? turnAroundDistanceMultiRotorName : turnAroundDistanceName]) , _cameraTriggerInTurnAroundFact (settingsGroup, _metaDataMap[cameraTriggerInTurnAroundName]) @@ -401,14 +400,6 @@ void TransectStyleComplexItem::_rebuildTransects(void) emit timeBetweenShotsChanged(); } -void TransectStyleComplexItem::_setBoundingCube(QGCGeoBoundingCube bc) -{ - if (bc != _boundingCube) { - _boundingCube = bc; - emit boundingCubeChanged(); - } -} - void TransectStyleComplexItem::_queryTransectsPathHeightInfo(void) { _transectsPathHeightInfo.clear(); diff --git a/src/MissionManager/TransectStyleComplexItem.h b/src/MissionManager/TransectStyleComplexItem.h index de84be6c4..d392f6ea7 100644 --- a/src/MissionManager/TransectStyleComplexItem.h +++ b/src/MissionManager/TransectStyleComplexItem.h @@ -77,7 +77,6 @@ public: int lastSequenceNumber (void) const final; QString mapVisualQML (void) const override = 0; bool load (const QJsonObject& complexObject, int sequenceNumber, QString& errorString) override = 0; - QGCGeoBoundingCube boundingCube (void) const override { return _boundingCube; } double complexDistance (void) const final { return _complexDistance; } double greatestDistanceTo (const QGeoCoordinate &other) const final; @@ -147,14 +146,11 @@ protected: double _triggerDistance (void) const; bool _hasTurnaround (void) const; double _turnaroundDistance (void) const; - void _setBoundingCube (QGCGeoBoundingCube bc); int _sequenceNumber; - bool _dirty; QGeoCoordinate _coordinate; QGeoCoordinate _exitCoordinate; QGCMapPolygon _surveyAreaPolygon; - QGCGeoBoundingCube _boundingCube; enum CoordType { CoordTypeInterior, ///< Interior waypoint for flight path only diff --git a/src/MissionManager/VisualMissionItem.cc b/src/MissionManager/VisualMissionItem.cc index 654fd0018..7d6e566c1 100644 --- a/src/MissionManager/VisualMissionItem.cc +++ b/src/MissionManager/VisualMissionItem.cc @@ -45,7 +45,7 @@ VisualMissionItem::VisualMissionItem(Vehicle* vehicle, bool flyView, QObject* pa VisualMissionItem::VisualMissionItem(const VisualMissionItem& other, bool flyView, QObject* parent) : QObject (parent) - , _vehicle (NULL) + , _vehicle (nullptr) , _flyView (flyView) , _isCurrentItem (false) , _dirty (false) @@ -203,3 +203,12 @@ void VisualMissionItem::_terrainDataReceived(bool success, QList heights emit terrainAltitudeChanged(_terrainAltitude); sender()->deleteLater(); } + +void VisualMissionItem::_setBoundingCube(QGCGeoBoundingCube bc) +{ + if (bc != _boundingCube) { + _boundingCube = bc; + emit boundingCubeChanged(); + } +} + diff --git a/src/MissionManager/VisualMissionItem.h b/src/MissionManager/VisualMissionItem.h index 38471507f..16679f9c0 100644 --- a/src/MissionManager/VisualMissionItem.h +++ b/src/MissionManager/VisualMissionItem.h @@ -68,6 +68,8 @@ public: Q_PROPERTY(double missionVehicleYaw READ missionVehicleYaw NOTIFY missionVehicleYawChanged) ///< Expected vehicle yaw at this point in mission Q_PROPERTY(bool flyView READ flyView CONSTANT) + Q_PROPERTY(QGCGeoBoundingCube* boundingCube READ boundingCube NOTIFY boundingCubeChanged) + // The following properties are calculated/set by the MissionController recalc methods Q_PROPERTY(double altDifference READ altDifference WRITE setAltDifference NOTIFY altDifferenceChanged) ///< Change in altitude from previous waypoint @@ -121,6 +123,9 @@ public: virtual double specifiedGimbalYaw (void) = 0; virtual double specifiedGimbalPitch (void) = 0; + //-- Default implementation returns an invalid bounding cube + virtual QGCGeoBoundingCube* boundingCube (void) { return &_boundingCube; } + /// Update item to mission flight status at point where this item appears in mission. /// IMPORTANT: Overrides must call base class implementation virtual void setMissionFlightStatus(MissionController::MissionFlightStatus_t& missionFlightStatus); @@ -192,6 +197,7 @@ signals: void missionVehicleYawChanged (double missionVehicleYaw); void terrainAltitudeChanged (double terrainAltitude); void additionalTimeDelayChanged (void); + void boundingCubeChanged (void); void coordinateHasRelativeAltitudeChanged (bool coordinateHasRelativeAltitude); void exitCoordinateHasRelativeAltitudeChanged (bool exitCoordinateHasRelativeAltitude); @@ -214,11 +220,16 @@ protected: double _missionGimbalYaw; double _missionVehicleYaw; + QGCGeoBoundingCube _boundingCube; ///< The bounding "cube" of this element. + MissionController::MissionFlightStatus_t _missionFlightStatus; /// This is used to reference any subsequent mission items which do not specify a coordinate. QmlObjectListModel _childItems; +protected: + void _setBoundingCube (QGCGeoBoundingCube bc); + private slots: void _updateTerrainAltitude (void); void _reallyUpdateTerrainAltitude (void); diff --git a/src/PlanView/PlanToolBar.qml b/src/PlanView/PlanToolBar.qml index e6616f5e8..f6cfca0c5 100644 --- a/src/PlanView/PlanToolBar.qml +++ b/src/PlanView/PlanToolBar.qml @@ -46,12 +46,12 @@ Rectangle { property real _smallValueWidth: ScreenTools.defaultFontPixelWidth * 3 property real _labelToValueSpacing: ScreenTools.defaultFontPixelWidth property real _rowSpacing: ScreenTools.isMobile ? 1 : 0 - property real _distance: _statusValid ? currentMissionItem.distance : NaN - property real _altDifference: _statusValid ? currentMissionItem.altDifference : NaN - property real _gradient: _statusValid && currentMissionItem.distance > 0 ? Math.atan(currentMissionItem.altDifference / currentMissionItem.distance) : NaN + property real _distance: _statusValid && currentMissionItem ? currentMissionItem.distance : NaN + property real _altDifference: _statusValid && currentMissionItem ? currentMissionItem.altDifference : NaN + property real _gradient: _statusValid && currentMissionItem && currentMissionItem.distance > 0 ? Math.atan(currentMissionItem.altDifference / currentMissionItem.distance) : NaN property real _gradientPercent: isNaN(_gradient) ? NaN : _gradient * 100 - property real _azimuth: _statusValid ? currentMissionItem.azimuth : NaN - property real _heading: _statusValid ? currentMissionItem.missionVehicleYaw : NaN + property real _azimuth: _statusValid && currentMissionItem ? currentMissionItem.azimuth : NaN + property real _heading: _statusValid && currentMissionItem ? currentMissionItem.missionVehicleYaw : NaN property real _missionDistance: _missionValid ? missionDistance : NaN property real _missionMaxTelemetry: _missionValid ? missionMaxTelemetry : NaN property real _missionTime: _missionValid ? missionTime : NaN diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 099e8385c..426c69f9c 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -377,6 +377,7 @@ QGCApplication::~QGCApplication() void QGCApplication::_initCommon(void) { + static const char* kRefOnly = "Reference only"; QSettings settings; // Register our Qml objects @@ -384,31 +385,35 @@ void QGCApplication::_initCommon(void) qmlRegisterType ("QGroundControl.Palette", 1, 0, "QGCPalette"); qmlRegisterType ("QGroundControl.Palette", 1, 0, "QGCMapPalette"); - qmlRegisterUncreatableType ("QGroundControl", 1, 0, "CoordinateVector", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl", 1, 0, "QmlObjectListModel", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl", 1, 0, "MissionCommandTree", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl", 1, 0, "CameraCalc", "Reference only"); - - qmlRegisterUncreatableType ("QGroundControl.AutoPilotPlugin", 1, 0, "AutoPilotPlugin", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.AutoPilotPlugin", 1, 0, "VehicleComponent", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "Vehicle", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "MissionItem", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "MissionManager", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "ParameterManager", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "QGCCameraManager", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "QGCCameraControl", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "LinkInterface", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "JoystickManager", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "Joystick", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.QGCPositionManager", 1, 0, "QGCPositionManager", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.FlightMap", 1, 0, "QGCMapPolygon", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Controllers", 1, 0, "MissionController", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Controllers", 1, 0, "GeoFenceController", "Reference only"); - qmlRegisterUncreatableType("QGroundControl.Controllers", 1, 0, "RallyPointController", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl.Controllers", 1, 0, "VisualMissionItem", "Reference only"); - qmlRegisterUncreatableType("QGroundControl.FactControls", 1, 0, "FactValueSliderListModel","Reference only"); - - qmlRegisterType ("QGroundControl", 1, 0, "QGCGeoBoundingCube"); + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "CoordinateVector", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "QmlObjectListModel", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "MissionCommandTree", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "CameraCalc", kRefOnly); + + qmlRegisterUncreatableType ("QGroundControl.AutoPilotPlugin", 1, 0, "AutoPilotPlugin", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.AutoPilotPlugin", 1, 0, "VehicleComponent", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "Vehicle", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "MissionItem", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "MissionManager", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "ParameterManager", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "QGCCameraManager", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "QGCCameraControl", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Vehicle", 1, 0, "LinkInterface", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "JoystickManager", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "Joystick", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.QGCPositionManager", 1, 0, "QGCPositionManager", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Controllers", 1, 0, "MissionController", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Controllers", 1, 0, "GeoFenceController", kRefOnly); + qmlRegisterUncreatableType("QGroundControl.Controllers", 1, 0, "RallyPointController", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.Controllers", 1, 0, "VisualMissionItem", kRefOnly); + qmlRegisterUncreatableType("QGroundControl.FactControls", 1, 0, "FactValueSliderListModel", kRefOnly); + + qmlRegisterUncreatableType ("QGroundControl.FlightMap", 1, 0, "QGCMapPolygon", kRefOnly); + qmlRegisterUncreatableType ("QGroundControl.FlightMap", 1, 0, "QGCGeoBoundingCube", kRefOnly); + +// qRegisterMetaType("QGCGeoBoundingCube"); + + qmlRegisterType ("QGroundControl.FlightMap", 1, 0, "QGCMapCircle"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ESP8266ComponentController"); @@ -421,7 +426,7 @@ void QGCApplication::_initCommon(void) qmlRegisterType ("QGroundControl.Controllers", 1, 0, "LogDownloadController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "SyslinkComponentController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "EditPositionDialogController"); - qmlRegisterType ("QGroundControl.FlightMap", 1, 0, "QGCMapCircle"); + #ifndef __mobile__ qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "CustomCommandWidgetController"); diff --git a/src/QmlControls/QGCGeoBoundingCube.cc b/src/QmlControls/QGCGeoBoundingCube.cc index acddeefb0..ea20edcc0 100644 --- a/src/QmlControls/QGCGeoBoundingCube.cc +++ b/src/QmlControls/QGCGeoBoundingCube.cc @@ -18,6 +18,13 @@ double QGCGeoBoundingCube::MaxSouth = -90.0; double QGCGeoBoundingCube::MaxWest = -180.0; double QGCGeoBoundingCube::MaxEast = 180.0; +//----------------------------------------------------------------------------- +QGCGeoBoundingCube::QGCGeoBoundingCube(QObject* parent) + : QObject(parent) +{ + reset(); +} + //----------------------------------------------------------------------------- bool QGCGeoBoundingCube::isValid() const @@ -30,8 +37,8 @@ QGCGeoBoundingCube::isValid() const void QGCGeoBoundingCube::reset() { - pointSE = QGeoCoordinate(); - pointNW = QGeoCoordinate(); + pointNW = QGeoCoordinate(MaxSouth, MaxEast, MaxAlt); + pointSE = QGeoCoordinate(MaxNorth, MaxWest, MinAlt); } //----------------------------------------------------------------------------- diff --git a/src/QmlControls/QGCGeoBoundingCube.h b/src/QmlControls/QGCGeoBoundingCube.h index d8e4e14a1..bba5db9a3 100644 --- a/src/QmlControls/QGCGeoBoundingCube.h +++ b/src/QmlControls/QGCGeoBoundingCube.h @@ -18,6 +18,8 @@ class QGCGeoBoundingCube : public QObject { Q_OBJECT public: + QGCGeoBoundingCube(QObject* parent = nullptr); + QGCGeoBoundingCube(const QGCGeoBoundingCube& other) : QObject() { @@ -25,12 +27,6 @@ public: pointSE = other.pointSE; } - QGCGeoBoundingCube() - : pointNW(QGeoCoordinate(MaxSouth, MaxEast, MaxAlt)) - , pointSE(QGeoCoordinate(MaxNorth, MaxWest, MinAlt)) - { - } - QGCGeoBoundingCube(QGeoCoordinate p1, QGeoCoordinate p2) : pointNW(p1) , pointSE(p2) @@ -38,7 +34,7 @@ public: } Q_PROPERTY(QGeoCoordinate pointNW MEMBER pointNW CONSTANT) - Q_PROPERTY(QGeoCoordinate pointSE MEMBER pointNW CONSTANT) + Q_PROPERTY(QGeoCoordinate pointSE MEMBER pointSE CONSTANT) Q_INVOKABLE void reset (); Q_INVOKABLE bool isValid () const; @@ -64,7 +60,7 @@ public: } //-- 2D - QList polygon2D(double clipTo = 0.0) const; + Q_INVOKABLE QList polygon2D(double clipTo = 0.0) const; Q_INVOKABLE double width () const; Q_INVOKABLE double height () const; -- 2.22.0