Skip to content

Commit

Permalink
Correctly handle large numbers of waypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Feb 12, 2016
1 parent 4aff412 commit e7c8878
Show file tree
Hide file tree
Showing 9 changed files with 16,000 additions and 162 deletions.
31 changes: 24 additions & 7 deletions src/MissionEditor/MissionEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ QGCView {
spacing: _margin / 2
orientation: ListView.Vertical
model: controller.missionItems

property real _maxItemHeight: 0
cacheBuffer: height * 2

delegate: MissionItemEditor {
missionItem: object
Expand All @@ -399,11 +398,6 @@ QGCView {
controller.removeMissionItem(object.sequenceNumber)
}

onRemoveAll: {
itemDragger.clearItem()
controller.removeAllMissionItems()
}

onInsert: {
controller.insertMissionItem(editorMap.center, i)
setCurrentItem(i)
Expand Down Expand Up @@ -601,6 +595,20 @@ QGCView {
}
}

Component {
id: removeAllPromptDialog

QGCViewMessage {
message: "Are you sure you want to delete all mission items?"

function accept() {
itemDragger.clearItem()
controller.removeAllMissionItems()
hideDialog()
}
}
}

Component {
id: syncDropDownComponent

Expand Down Expand Up @@ -671,6 +679,15 @@ QGCView {
}
}
}

QGCButton {
text: "Remove all"
onClicked: {
syncButton.hideDropDown()
_root.showDialog(removeAllPromptDialog, "Delete all", _root.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
}
}

/*
FIXME: autoSync is temporarily disconnected since it's still buggy
Expand Down
64 changes: 34 additions & 30 deletions src/MissionManager/MissionController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void MissionController::start(bool editMode)

// We start with an empty mission
_missionItems = new QmlObjectListModel(this);
_addPlannedHomePosition(false /* addToCenter */);
_addPlannedHomePosition(_missionItems, false /* addToCenter */);
_initAllMissionItems();
}

Expand All @@ -94,7 +94,7 @@ void MissionController::_newMissionItemsAvailableFromVehicle(void)
qCDebug(MissionControllerLog) << "loading from vehicle count"<< _missionItems->count();

if (!_activeVehicle->firmwarePlugin()->sendHomePositionToVehicle() || _missionItems->count() == 0) {
_addPlannedHomePosition(true /* addToCenter */);
_addPlannedHomePosition(_missionItems,true /* addToCenter */);
}

_missionItemsRequested = false;
Expand Down Expand Up @@ -176,14 +176,16 @@ void MissionController::removeMissionItem(int index)
void MissionController::removeAllMissionItems(void)
{
if (_missionItems) {
while (_missionItems->count() != 1) {
removeMissionItem(_missionItems->count() - 1);
}
QmlObjectListModel* oldItems = _missionItems;
_missionItems = new QmlObjectListModel(this);
_addPlannedHomePosition(_missionItems, false /* addToCenter */);
_initAllMissionItems();
oldItems->deleteLater();
}
}

#ifndef __mobile__
bool MissionController::_loadJsonMissionFile(const QByteArray& bytes, QString& errorString)
bool MissionController::_loadJsonMissionFile(const QByteArray& bytes, QmlObjectListModel* missionItems, QString& errorString)
{
QJsonParseError jsonParseError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(bytes, &jsonParseError));
Expand Down Expand Up @@ -219,7 +221,7 @@ bool MissionController::_loadJsonMissionFile(const QByteArray& bytes, QString& e

MissionItem* item = new MissionItem(_activeVehicle, this);
if (item->load(itemValue.toObject(), errorString)) {
_missionItems->append(item);
missionItems->append(item);
} else {
return false;
}
Expand All @@ -230,20 +232,20 @@ bool MissionController::_loadJsonMissionFile(const QByteArray& bytes, QString& e
MissionItem* item = new MissionItem(_activeVehicle, this);

if (item->load(json[_jsonPlannedHomePositionKey].toObject(), errorString)) {
_missionItems->insert(0, item);
missionItems->insert(0, item);
} else {
return false;
}
} else {
_addPlannedHomePosition(true /* addToCenter */);
_addPlannedHomePosition(missionItems, true /* addToCenter */);
}

return true;
}
#endif

#ifndef __mobile__
bool MissionController::_loadTextMissionFile(QTextStream& stream, QString& errorString)
bool MissionController::_loadTextMissionFile(QTextStream& stream, QmlObjectListModel* missionItems, QString& errorString)
{
bool addPlannedHomePosition = false;

Expand All @@ -267,7 +269,7 @@ bool MissionController::_loadTextMissionFile(QTextStream& stream, QString& error
MissionItem* item = new MissionItem(_activeVehicle, this);

if (item->load(stream)) {
_missionItems->append(item);
missionItems->append(item);
} else {
errorString = QStringLiteral("The mission file is corrupted.");
return false;
Expand All @@ -278,12 +280,12 @@ bool MissionController::_loadTextMissionFile(QTextStream& stream, QString& error
return false;
}

if (addPlannedHomePosition || _missionItems->count() == 0) {
_addPlannedHomePosition(true /* addToCenter */);
if (addPlannedHomePosition || missionItems->count() == 0) {
_addPlannedHomePosition(missionItems, true /* addToCenter */);

// Update sequence numbers in DO_JUMP commands to take into account added home position
for (int i=1; i<_missionItems->count(); i++) {
MissionItem* item = qobject_cast<MissionItem*>(_missionItems->get(i));
for (int i=1; i<missionItems->count(); i++) {
MissionItem* item = qobject_cast<MissionItem*>(missionItems->get(i));
if (item->command() == MavlinkQmlSingleton::MAV_CMD_DO_JUMP) {
// Home is in position 0
item->setParam1((int)item->param1() + 1);
Expand All @@ -305,11 +307,7 @@ void MissionController::loadMissionFromFile(void)
return;
}

if (_missionItems) {
_deinitAllMissionItems();
_missionItems->deleteLater();
}
_missionItems = new QmlObjectListModel(this);
QmlObjectListModel* newMissionItems = new QmlObjectListModel(this);

QFile file(filename);

Expand All @@ -322,19 +320,25 @@ void MissionController::loadMissionFromFile(void)
QString firstLine = stream.readLine();
if (firstLine.contains(QRegExp("QGC.*WPL"))) {
stream.seek(0);
_loadTextMissionFile(stream, errorString);
_loadTextMissionFile(stream, newMissionItems, errorString);
} else {
_loadJsonMissionFile(bytes, errorString);
_loadJsonMissionFile(bytes, newMissionItems, errorString);
}
}

if (!errorString.isEmpty()) {
_missionItems->clear();
delete newMissionItems;
qgcApp()->showMessage(errorString);
return;
}

if (_missionItems) {
_deinitAllMissionItems();
_missionItems->deleteLater();
}
_missionItems = newMissionItems;
if (_missionItems->count() == 0) {
_addPlannedHomePosition(true /* addToCenter */);
_addPlannedHomePosition(_missionItems, true /* addToCenter */);
}

_initAllMissionItems();
Expand Down Expand Up @@ -786,21 +790,21 @@ double MissionController::_normalizeLon(double lon)
}

/// Add the home position item to the front of the list
void MissionController::_addPlannedHomePosition(bool addToCenter)
void MissionController::_addPlannedHomePosition(QmlObjectListModel* missionItems, bool addToCenter)
{
MissionItem* homeItem = new MissionItem(_activeVehicle, this);
_missionItems->insert(0, homeItem);
missionItems->insert(0, homeItem);

if (_missionItems->count() > 1 && addToCenter) {
MissionItem* item = qobject_cast<MissionItem*>(_missionItems->get(1));
if (missionItems->count() > 1 && addToCenter) {
MissionItem* item = qobject_cast<MissionItem*>(missionItems->get(1));

double north = _normalizeLat(item->coordinate().latitude());
double south = north;
double east = _normalizeLon(item->coordinate().longitude());
double west = east;

for (int i=2; i<_missionItems->count(); i++) {
item = qobject_cast<MissionItem*>(_missionItems->get(i));
for (int i=2; i<missionItems->count(); i++) {
item = qobject_cast<MissionItem*>(missionItems->get(i));

double lat = _normalizeLat(item->coordinate().latitude());
double lon = _normalizeLon(item->coordinate().longitude());
Expand Down
6 changes: 3 additions & 3 deletions src/MissionManager/MissionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ private slots:
void _calcPrevWaypointValues(double homeAlt, MissionItem* currentItem, MissionItem* prevItem, double* azimuth, double* distance, double* altDifference);
bool _findLastAltitude(double* lastAltitude);
bool _findLastAcceptanceRadius(double* lastAcceptanceRadius);
void _addPlannedHomePosition(bool addToCenter);
void _addPlannedHomePosition(QmlObjectListModel* missionItems, bool addToCenter);
double _normalizeLat(double lat);
double _normalizeLon(double lon);
#ifndef __mobile__
bool _loadJsonMissionFile(const QByteArray& bytes, QString& errorString);
bool _loadTextMissionFile(QTextStream& stream, QString& errorString);
bool _loadJsonMissionFile(const QByteArray& bytes, QmlObjectListModel* missionItems, QString& errorString);
bool _loadTextMissionFile(QTextStream& stream, QmlObjectListModel* missionItems, QString& errorString);
#endif

private:
Expand Down
Loading

0 comments on commit e7c8878

Please sign in to comment.