Commit ae0fb2c2 authored by Don Gagne's avatar Don Gagne

Calculate/Display distance between waypoints

parent 1aad419c
......@@ -38,7 +38,9 @@ import QGroundControl.Controllers 1.0
/// Mission Editor
QGCView {
viewPanel: panel
id: _root
viewPanel: panel
// zOrder comes from the Loader in MainWindow.qml
z: QGroundControl.zOrderTopMost
......@@ -85,6 +87,15 @@ QGCView {
}
}
function showDistance(missionItem) {
if (missionItem.distance < 0.0) {
waypointDistanceDisplay.visible = false
} else {
waypointDistanceDisplay.distance = missionItem.distance
waypointDistanceDisplay.visible = true
}
}
MissionController {
id: controller
......@@ -180,9 +191,9 @@ QGCView {
y: missionItemIndicator ? (missionItemIndicator.y + missionItemIndicator.anchorPoint.y - (itemDragger.height / 2)) : 100
width: _radius * 2
height: _radius * 2
radius: _radius
border.width: 2
border.color: "white"
//radius: _radius
//border.width: 2
//border.color: "white"
color: "transparent"
visible: false
z: QGroundControl.zOrderMapItems + 1 // Above item icons
......@@ -281,6 +292,7 @@ QGCView {
itemDragger.missionItem.coordinate = coordinate
editorMap.latitude = itemDragger.missionItem.coordinate.latitude
editorMap.longitude = itemDragger.missionItem.coordinate.longitude
_root.showDistance(itemDragger.missionItem)
}
}
}
......@@ -309,19 +321,22 @@ QGCView {
target: object
onIsCurrentItemChanged: {
if (object.isCurrentItem && object.specifiesCoordinate) {
// Setup our drag item
if (object.sequenceNumber != 0) {
itemDragger.visible = true
itemDragger.missionItem = Qt.binding(function() { return object })
itemDragger.missionItemIndicator = Qt.binding(function() { return itemIndicator })
} else {
itemDragger.clearItem()
}
if (object.isCurrentItem) {
_root.showDistance(object)
if (object.specifiesCoordinate) {
// Setup our drag item
if (object.sequenceNumber != 0) {
itemDragger.visible = true
itemDragger.missionItem = Qt.binding(function() { return object })
itemDragger.missionItemIndicator = Qt.binding(function() { return itemIndicator })
} else {
itemDragger.clearItem()
}
// Move to the new position
editorMap.latitude = object.coordinate.latitude
editorMap.longitude = object.coordinate.longitude
// Move to the new position
editorMap.latitude = object.coordinate.latitude
editorMap.longitude = object.coordinate.longitude
}
}
}
}
......@@ -1041,6 +1056,31 @@ QGCView {
z: QGroundControl.zOrderWidgets
checked: _showHelp
}
Rectangle {
id: waypointDistanceDisplay
anchors.margins: margins
anchors.left: parent.left
anchors.bottom: parent.bottom
width: distanceLabel.width + margins
height: distanceLabel.height + margins
radius: ScreenTools.defaultFontPixelWidth
color: qgcPal.window
opacity: 0.80
visible: false
property real distance: 0
readonly property real margins: ScreenTools.defaultFontPixelWidth
QGCLabel {
id: distanceLabel
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizonalCenter
color: qgcPal.text
text: "Distance: " + Math.round(parent.distance) + " meters"
}
}
} // FlightMap
} // Item - split view container
} // QGCViewPanel
......
......@@ -80,6 +80,7 @@ MissionItem::MissionItem(QObject* parent,
, _autocontinue(autocontinue)
, _isCurrentItem(isCurrentItem)
, _reachedTime(0)
, _distance(0.0)
, _headingDegreesFact(NULL)
, _dirty(false)
, _homePositionSpecialCase(false)
......@@ -189,6 +190,7 @@ const MissionItem& MissionItem::operator=(const MissionItem& other)
_command = other._command;
_autocontinue = other._autocontinue;
_reachedTime = other._reachedTime;
_distance = other._distance;
_altitudeRelativeToHomeFact = other._altitudeRelativeToHomeFact;
_dirty = other._dirty;
_homePositionSpecialCase = other._homePositionSpecialCase;
......@@ -916,3 +918,9 @@ void MissionItem::setHomePositionValid(bool homePositionValid)
_homePositionValid = homePositionValid;
emit homePositionValidChanged(_homePositionValid);
}
void MissionItem::setDistance(double distance)
{
_distance = distance;
emit distanceChanged(_distance);
}
......@@ -91,6 +91,9 @@ public:
/// true: home position should be shown
Q_PROPERTY(bool homePositionValid READ homePositionValid WRITE setHomePositionValid NOTIFY homePositionValidChanged)
/// Distance to previous waypoint, set by UI controller
Q_PROPERTY(double distance READ distance WRITE setDistance NOTIFY distanceChanged)
// Property accesors
int sequenceNumber(void) const { return _sequenceNumber; }
......@@ -134,6 +137,9 @@ public:
bool homePosition(void) { return _homePositionSpecialCase; }
bool homePositionValid(void) { return _homePositionValid; }
void setHomePositionValid(bool homePositionValid);
double distance(void) { return _distance; }
void setDistance(double distance);
// C++ only methods
......@@ -221,6 +227,7 @@ signals:
void headingDegreesChanged(double heading);
void dirtyChanged(bool dirty);
void homePositionValidChanged(bool homePostionValid);
void distanceChanged(float distance);
/** @brief Announces a change to the waypoint data */
void changed(MissionItem* wp);
......@@ -279,6 +286,7 @@ private:
bool _autocontinue;
bool _isCurrentItem;
quint64 _reachedTime;
double _distance;
Fact* _latitudeFact;
Fact* _longitudeFact;
......
......@@ -293,6 +293,9 @@ void MissionController::_recalcWaypointLines(void)
MissionItem* lastCoordinateItem = qobject_cast<MissionItem*>(_missionItems->get(0));
bool firstCoordinateItem = true;
// No distance for first item
lastCoordinateItem->setDistance(-1.0);
_waypointLines.clear();
for (int i=1; i<_missionItems->count(); i++) {
......@@ -305,18 +308,27 @@ void MissionController::_recalcWaypointLines(void)
// The first coordinate we hit is a takeoff command so link back to home position if valid
if (homeItem->homePositionValid()) {
_waypointLines.append(new CoordinateVector(qobject_cast<MissionItem*>(_missionItems->get(0))->coordinate(), item->coordinate()));
MissionItem* homeItem = qobject_cast<MissionItem*>(_missionItems->get(0));
item->setDistance(homeItem->coordinate().distanceTo(item->coordinate()));
_waypointLines.append(new CoordinateVector(homeItem->coordinate(), item->coordinate()));
} else {
item->setDistance(-1.0);
}
} else {
// First coordiante is not a takeoff command, it does not link backwards to anything
item->setDistance(-1.0);
}
firstCoordinateItem = false;
} else if (!lastCoordinateItem->homePosition() || lastCoordinateItem->homePositionValid()) {
// Subsequent coordinate items link to last coordinate item. If the last coordinate item
// is an invalid home position we skip the line
item->setDistance(lastCoordinateItem->coordinate().distanceTo(item->coordinate()));
_waypointLines.append(new CoordinateVector(lastCoordinateItem->coordinate(), item->coordinate()));
}
lastCoordinateItem = item;
} else {
item->setDistance(-1.0);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment