Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
7795737d
Unverified
Commit
7795737d
authored
Feb 01, 2019
by
Don Gagne
Committed by
GitHub
Feb 01, 2019
Browse files
Merge pull request #7198 from DonLakeFlyer/PolygonWinding
QGCMapPolygon: Preserve clockwise winding when adjusting vertices
parents
e6c49d97
7abbe1b9
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/KMLFileHelper.cc
View file @
7795737d
...
@@ -100,7 +100,7 @@ bool KMLFileHelper::loadPolygonFromFile(const QString& kmlFile, QList<QGeoCoordi
...
@@ -100,7 +100,7 @@ bool KMLFileHelper::loadPolygonFromFile(const QString& kmlFile, QList<QGeoCoordi
rgCoords
.
append
(
coord
);
rgCoords
.
append
(
coord
);
}
}
// Determine winding, reverse if needed
// Determine winding, reverse if needed
. QGC wants clockwise winding
double
sum
=
0
;
double
sum
=
0
;
for
(
int
i
=
0
;
i
<
rgCoords
.
count
();
i
++
)
{
for
(
int
i
=
0
;
i
<
rgCoords
.
count
();
i
++
)
{
QGeoCoordinate
coord1
=
rgCoords
[
i
];
QGeoCoordinate
coord1
=
rgCoords
[
i
];
...
...
src/MissionManager/QGCMapPolygon.cc
View file @
7795737d
...
@@ -94,7 +94,7 @@ void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinat
...
@@ -94,7 +94,7 @@ void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinat
_polygonPath
[
vertexIndex
]
=
QVariant
::
fromValue
(
coordinate
);
_polygonPath
[
vertexIndex
]
=
QVariant
::
fromValue
(
coordinate
);
_polygonModel
.
value
<
QGCQGeoCoordinate
*>
(
vertexIndex
)
->
setCoordinate
(
coordinate
);
_polygonModel
.
value
<
QGCQGeoCoordinate
*>
(
vertexIndex
)
->
setCoordinate
(
coordinate
);
if
(
!
_centerDrag
)
{
if
(
!
_centerDrag
)
{
// When dragging center we don't signal path changed until a
dd
vertices are updated
// When dragging center we don't signal path changed until a
ll
vertices are updated
emit
pathChanged
();
emit
pathChanged
();
}
}
setDirty
(
true
);
setDirty
(
true
);
...
@@ -340,7 +340,7 @@ void QGCMapPolygon::setCenter(QGeoCoordinate newCenter)
...
@@ -340,7 +340,7 @@ void QGCMapPolygon::setCenter(QGeoCoordinate newCenter)
}
}
if
(
_centerDrag
)
{
if
(
_centerDrag
)
{
// When center dragging signals
are delayed until all vertices are upda
te
d
// When center dragging
,
signals
from adjustVertext are not sent. So we need to signal here when all adjusting is comple
te
.
emit
pathChanged
();
emit
pathChanged
();
}
}
...
@@ -486,3 +486,30 @@ double QGCMapPolygon::area(void) const
...
@@ -486,3 +486,30 @@ double QGCMapPolygon::area(void) const
}
}
return
0.5
*
fabs
(
coveredArea
);
return
0.5
*
fabs
(
coveredArea
);
}
}
void
QGCMapPolygon
::
verifyClockwiseWinding
(
void
)
{
if
(
_polygonPath
.
count
()
<=
2
)
{
return
;
}
double
sum
=
0
;
for
(
int
i
=
0
;
i
<
_polygonPath
.
count
();
i
++
)
{
QGeoCoordinate
coord1
=
_polygonPath
[
i
].
value
<
QGeoCoordinate
>
();
QGeoCoordinate
coord2
=
(
i
==
_polygonPath
.
count
()
-
1
)
?
_polygonPath
[
0
].
value
<
QGeoCoordinate
>
()
:
_polygonPath
[
i
+
1
].
value
<
QGeoCoordinate
>
();
sum
+=
(
coord2
.
longitude
()
-
coord1
.
longitude
())
*
(
coord2
.
latitude
()
+
coord1
.
latitude
());
}
if
(
sum
<
0.0
)
{
// Winding is counter-clockwise and needs reversal
QList
<
QGeoCoordinate
>
rgReversed
;
for
(
const
QVariant
&
varCoord
:
_polygonPath
)
{
rgReversed
.
prepend
(
varCoord
.
value
<
QGeoCoordinate
>
());
}
clear
();
appendVertices
(
rgReversed
);
}
}
src/MissionManager/QGCMapPolygon.h
View file @
7795737d
...
@@ -66,6 +66,9 @@ public:
...
@@ -66,6 +66,9 @@ public:
/// Returns the QGeoCoordinate for the vertex specified
/// Returns the QGeoCoordinate for the vertex specified
Q_INVOKABLE
QGeoCoordinate
vertexCoordinate
(
int
vertex
)
const
;
Q_INVOKABLE
QGeoCoordinate
vertexCoordinate
(
int
vertex
)
const
;
/// Adjust polygon winding order to be clockwise (if needed)
Q_INVOKABLE
void
verifyClockwiseWinding
(
void
);
/// Saves the polygon to the json object.
/// Saves the polygon to the json object.
/// @param json Json object to save to
/// @param json Json object to save to
void
saveToJson
(
QJsonObject
&
json
);
void
saveToJson
(
QJsonObject
&
json
);
...
...
src/MissionManager/QGCMapPolygonVisuals.qml
View file @
7795737d
...
@@ -344,6 +344,7 @@ Item {
...
@@ -344,6 +344,7 @@ Item {
mapControl
:
_root
.
mapControl
mapControl
:
_root
.
mapControl
z
:
_zorderDragHandle
z
:
_zorderDragHandle
visible
:
!
_circle
visible
:
!
_circle
onDragStop
:
mapPolygon
.
verifyClockwiseWinding
()
property
int
polygonVertex
property
int
polygonVertex
...
@@ -466,7 +467,10 @@ Item {
...
@@ -466,7 +467,10 @@ Item {
EditPositionDialog
{
EditPositionDialog
{
coordinate
:
mapPolygon
.
vertexCoordinate
(
menu
.
_editingVertexIndex
)
coordinate
:
mapPolygon
.
vertexCoordinate
(
menu
.
_editingVertexIndex
)
onCoordinateChanged
:
mapPolygon
.
adjustVertex
(
menu
.
_editingVertexIndex
,
coordinate
)
onCoordinateChanged
:
{
mapPolygon
.
adjustVertex
(
menu
.
_editingVertexIndex
,
coordinate
)
mapPolygon
.
verifyClockwiseWinding
()
}
}
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment