Unverified Commit 98071529 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #6213 from DonLakeFlyer/StableMerge

Stable merge
parents 78be63ea ba0dce20
...@@ -38,10 +38,6 @@ public: ...@@ -38,10 +38,6 @@ public:
/// from mission start to resumeIndex in the generate mission. /// from mission start to resumeIndex in the generate mission.
void generateResumeMission(int resumeIndex); void generateResumeMission(int resumeIndex);
signals:
void currentIndexChanged (int currentIndex);
void lastCurrentIndexChanged (int lastCurrentIndex);
private slots: private slots:
void _mavlinkMessageReceived(const mavlink_message_t& message); void _mavlinkMessageReceived(const mavlink_message_t& message);
......
...@@ -258,6 +258,19 @@ void QGCMapPolygon::appendVertex(const QGeoCoordinate& coordinate) ...@@ -258,6 +258,19 @@ void QGCMapPolygon::appendVertex(const QGeoCoordinate& coordinate)
emit pathChanged(); emit pathChanged();
} }
void QGCMapPolygon::appendVertices(const QList<QGeoCoordinate>& coordinates)
{
QList<QObject*> objects;
foreach (const QGeoCoordinate& coordinate, coordinates) {
objects.append(new QGCQGeoCoordinate(coordinate, this));
_polygonPath.append(QVariant::fromValue(coordinate));
}
_polygonModel.append(objects);
emit pathChanged();
}
void QGCMapPolygon::_polygonModelDirtyChanged(bool dirty) void QGCMapPolygon::_polygonModelDirtyChanged(bool dirty)
{ {
if (dirty) { if (dirty) {
...@@ -509,9 +522,7 @@ bool QGCMapPolygon::loadKMLFile(const QString& kmlFile) ...@@ -509,9 +522,7 @@ bool QGCMapPolygon::loadKMLFile(const QString& kmlFile)
} }
clear(); clear();
for (int i=0; i<rgCoords.count(); i++) { appendVertices(rgCoords);
appendVertex(rgCoords[i]);
}
return true; return true;
} }
......
...@@ -40,6 +40,7 @@ public: ...@@ -40,6 +40,7 @@ public:
Q_INVOKABLE void clear(void); Q_INVOKABLE void clear(void);
Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate); Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
Q_INVOKABLE void removeVertex(int vertexIndex); Q_INVOKABLE void removeVertex(int vertexIndex);
Q_INVOKABLE void appendVertices(const QList<QGeoCoordinate>& coordinates);
/// Adjust the value for the specified coordinate /// Adjust the value for the specified coordinate
/// @param vertexIndex Polygon point index to modify (0-based) /// @param vertexIndex Polygon point index to modify (0-based)
......
...@@ -554,53 +554,6 @@ void SurveyMissionItem::_swapPoints(QList<QPointF>& points, int index1, int inde ...@@ -554,53 +554,6 @@ void SurveyMissionItem::_swapPoints(QList<QPointF>& points, int index1, int inde
points[index2] = temp; points[index2] = temp;
} }
QList<QPointF> SurveyMissionItem::_convexPolygon(const QList<QPointF>& polygon)
{
// We use the Graham scan algorithem to convert the possibly concave polygon to a convex polygon
// https://en.wikipedia.org/wiki/Graham_scan
QList<QPointF> workPolygon(polygon);
// First point must be lowest y-coordinate point
for (int i=1; i<workPolygon.count(); i++) {
if (workPolygon[i].y() < workPolygon[0].y()) {
_swapPoints(workPolygon, i, 0);
}
}
// Sort the points by angle with first point
for (int i=1; i<workPolygon.count(); i++) {
qreal angle = _dp(workPolygon[0], workPolygon[i]);
for (int j=i+1; j<workPolygon.count(); j++) {
if (_dp(workPolygon[0], workPolygon[j]) > angle) {
_swapPoints(workPolygon, i, j);
angle = _dp(workPolygon[0], workPolygon[j]);
}
}
}
// Perform the the Graham scan
workPolygon.insert(0, workPolygon.last()); // Sentinel for algo stop
int convexCount = 1; // Number of points on the convex hull.
for (int i=2; i<=polygon.count(); i++) {
while (_ccw(workPolygon[convexCount-1], workPolygon[convexCount], workPolygon[i]) <= 0) {
if (convexCount > 1) {
convexCount -= 1;
} else if (i == polygon.count()) {
break;
} else {
i++;
}
}
convexCount++;
_swapPoints(workPolygon, convexCount, i);
}
return workPolygon.mid(1, convexCount);
}
/// Returns true if the current grid angle generates north/south oriented transects /// Returns true if the current grid angle generates north/south oriented transects
bool SurveyMissionItem::_gridAngleIsNorthSouthTransects() bool SurveyMissionItem::_gridAngleIsNorthSouthTransects()
{ {
...@@ -695,8 +648,6 @@ void SurveyMissionItem::_generateGrid(void) ...@@ -695,8 +648,6 @@ void SurveyMissionItem::_generateGrid(void)
qCDebug(SurveyMissionItemLog) << "vertex:x:y" << vertex << polygonPoints.last().x() << polygonPoints.last().y(); qCDebug(SurveyMissionItemLog) << "vertex:x:y" << vertex << polygonPoints.last().x() << polygonPoints.last().y();
} }
polygonPoints = _convexPolygon(polygonPoints);
double coveredArea = 0.0; double coveredArea = 0.0;
for (int i=0; i<polygonPoints.count(); i++) { for (int i=0; i<polygonPoints.count(); i++) {
if (i != 0) { if (i != 0) {
...@@ -714,8 +665,6 @@ void SurveyMissionItem::_generateGrid(void) ...@@ -714,8 +665,6 @@ void SurveyMissionItem::_generateGrid(void)
_adjustTransectsToEntryPointLocation(_transectSegments); _adjustTransectsToEntryPointLocation(_transectSegments);
_appendGridPointsFromTransects(_transectSegments); _appendGridPointsFromTransects(_transectSegments);
if (_refly90Degrees) { if (_refly90Degrees) {
QVariantList reflyPointsGeo;
transectSegments.clear(); transectSegments.clear();
cameraShots += _gridGenerator(polygonPoints, transectSegments, true /* refly */); cameraShots += _gridGenerator(polygonPoints, transectSegments, true /* refly */);
_convertTransectToGeo(transectSegments, tangentOrigin, _reflyTransectSegments); _convertTransectToGeo(transectSegments, tangentOrigin, _reflyTransectSegments);
...@@ -844,28 +793,41 @@ void SurveyMissionItem::_intersectLinesWithRect(const QList<QLineF>& lineList, c ...@@ -844,28 +793,41 @@ void SurveyMissionItem::_intersectLinesWithRect(const QList<QLineF>& lineList, c
void SurveyMissionItem::_intersectLinesWithPolygon(const QList<QLineF>& lineList, const QPolygonF& polygon, QList<QLineF>& resultLines) void SurveyMissionItem::_intersectLinesWithPolygon(const QList<QLineF>& lineList, const QPolygonF& polygon, QList<QLineF>& resultLines)
{ {
resultLines.clear(); resultLines.clear();
for (int i=0; i<lineList.count(); i++) { for (int i=0; i<lineList.count(); i++) {
int foundCount = 0;
QLineF intersectLine;
const QLineF& line = lineList[i]; const QLineF& line = lineList[i];
QList<QPointF> intersections;
// Intersect the line with all the polygon edges
for (int j=0; j<polygon.count()-1; j++) { for (int j=0; j<polygon.count()-1; j++) {
QPointF intersectPoint; QPointF intersectPoint;
QLineF polygonLine = QLineF(polygon[j], polygon[j+1]); QLineF polygonLine = QLineF(polygon[j], polygon[j+1]);
if (line.intersect(polygonLine, &intersectPoint) == QLineF::BoundedIntersection) { if (line.intersect(polygonLine, &intersectPoint) == QLineF::BoundedIntersection) {
if (foundCount == 0) { intersections.append(intersectPoint);
foundCount++;
intersectLine.setP1(intersectPoint);
} else {
foundCount++;
intersectLine.setP2(intersectPoint);
break;
}
} }
} }
if (foundCount == 2) { // We now have one or more intersection points all along the same line. Find the two
resultLines += intersectLine; // which are furthest away from each other to form the transect.
if (intersections.count() > 1) {
QPointF firstPoint;
QPointF secondPoint;
double currentMaxDistance = 0;
for (int i=0; i<intersections.count(); i++) {
for (int j=0; j<intersections.count(); j++) {
QLineF lineTest(intersections[i], intersections[j]);
\
double newMaxDistance = lineTest.length();
if (newMaxDistance > currentMaxDistance) {
firstPoint = intersections[i];
secondPoint = intersections[j];
currentMaxDistance = newMaxDistance;
}
}
}
resultLines += QLineF(firstPoint, secondPoint);
} }
} }
} }
......
...@@ -217,7 +217,6 @@ private: ...@@ -217,7 +217,6 @@ private:
qreal _ccw(QPointF pt1, QPointF pt2, QPointF pt3); qreal _ccw(QPointF pt1, QPointF pt2, QPointF pt3);
qreal _dp(QPointF pt1, QPointF pt2); qreal _dp(QPointF pt1, QPointF pt2);
void _swapPoints(QList<QPointF>& points, int index1, int index2); void _swapPoints(QList<QPointF>& points, int index1, int index2);
QList<QPointF> _convexPolygon(const QList<QPointF>& polygon);
void _reverseTransectOrder(QList<QList<QGeoCoordinate>>& transects); void _reverseTransectOrder(QList<QList<QGeoCoordinate>>& transects);
void _reverseInternalTransectPoints(QList<QList<QGeoCoordinate>>& transects); void _reverseInternalTransectPoints(QList<QList<QGeoCoordinate>>& transects);
void _adjustTransectsToEntryPointLocation(QList<QList<QGeoCoordinate>>& transects); void _adjustTransectsToEntryPointLocation(QList<QList<QGeoCoordinate>>& transects);
......
...@@ -63,6 +63,7 @@ Rectangle { ...@@ -63,6 +63,7 @@ Rectangle {
} }
} }
} }
recalcFromCameraValues()
} }
function recalcFromCameraValues() { function recalcFromCameraValues() {
......
...@@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object) ...@@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object)
setDirty(true); setDirty(true);
} }
void QmlObjectListModel::insert(int i, QList<QObject*> objects)
{
if (i < 0 || i > _objectList.count()) {
qWarning() << "Invalid index index:count" << i << _objectList.count();
}
int j = i;
foreach (QObject* object, objects) {
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
// Look for a dirtyChanged signal on the object
if (object->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("dirtyChanged(bool)")) != -1) {
if (!_skipDirtyFirstItem || j != 0) {
QObject::connect(object, SIGNAL(dirtyChanged(bool)), this, SLOT(_childDirtyChanged(bool)));
}
}
j++;
_objectList.insert(i, object);
}
insertRows(i, objects.count());
setDirty(true);
}
void QmlObjectListModel::append(QObject* object) void QmlObjectListModel::append(QObject* object)
{ {
insert(_objectList.count(), object); insert(_objectList.count(), object);
} }
void QmlObjectListModel::append(QList<QObject*> objects)
{
insert(_objectList.count(), objects);
}
QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist) QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist)
{ {
QObjectList oldlist(_objectList); QObjectList oldlist(_objectList);
......
...@@ -37,11 +37,13 @@ public: ...@@ -37,11 +37,13 @@ public:
void setDirty(bool dirty); void setDirty(bool dirty);
void append(QObject* object); void append(QObject* object);
void append(QList<QObject*> objects);
QObjectList swapObjectList(const QObjectList& newlist); QObjectList swapObjectList(const QObjectList& newlist);
void clear(void); void clear(void);
QObject* removeAt(int i); QObject* removeAt(int i);
QObject* removeOne(QObject* object) { return removeAt(indexOf(object)); } QObject* removeOne(QObject* object) { return removeAt(indexOf(object)); }
void insert(int i, QObject* object); void insert(int i, QObject* object);
void insert(int i, QList<QObject*> objects);
QObject* operator[](int i); QObject* operator[](int i);
const QObject* operator[](int i) const; const QObject* operator[](int i) const;
bool contains(QObject* object) { return _objectList.indexOf(object) != -1; } bool contains(QObject* object) { return _objectList.indexOf(object) != -1; }
...@@ -63,12 +65,12 @@ private slots: ...@@ -63,12 +65,12 @@ private slots:
private: private:
// Overrides from QAbstractListModel // Overrides from QAbstractListModel
virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; int rowCount(const QModelIndex & parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
virtual QHash<int, QByteArray> roleNames(void) const; QHash<int, QByteArray> roleNames(void) const override;
virtual bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
virtual bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
private: private:
QList<QObject*> _objectList; QList<QObject*> _objectList;
......
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