CircularSurveyMapVisual.qml 8.22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.FlightMap     1.0

/// Survey Complex Mission Item visuals
Item {
    id: _root

    property var map        ///< Map control to place item in
    property var qgcView    ///< QGCView to use for popping dialogs

    property var _missionItem:      object
    property var _mapPolygon:       object.surveyAreaPolygon
30
    property var _transectsComponent
31 32
    property var _entryCoordinate
    property var _exitCoordinate
Valentin Platzgummer's avatar
Valentin Platzgummer committed
33
    property var _refPoint
34
    property bool showRefPoint: _missionItem.type.value === 0 // type == Circular
35 36 37

    signal clicked(int sequenceNumber)

38 39
    function _addTransectsComponent(){
        if (!_transectsComponent){
40
            _transectsComponent = visualTransectsComponent.createObject(_root)
41 42 43 44 45 46
            map.addMapItem(_transectsComponent)
        }
    }

    function _addExitCoordinate(){
        if (!_exitCoordinate){
47
            _exitCoordinate = exitPointComponent.createObject(_root)
48 49 50 51 52 53
            map.addMapItem(_exitCoordinate)
        }
    }

    function _addEntryCoordinate(){
        if (!_entryCoordinate){
54
            _entryCoordinate = entryPointComponent.createObject(_root)
55 56 57 58 59 60
            map.addMapItem(_entryCoordinate)
        }
    }

    function _addRefPoint(){
        if (!_refPoint){
61
            _refPoint = refPointComponent.createObject(_root)
62 63 64 65 66 67
            map.addMapItem(_refPoint)
        }
    }

    function _destroyEntryCoordinate(){
        if (_entryCoordinate){
68
            map.removeMapItem(_entryCoordinate)
69 70 71 72 73 74 75
            _entryCoordinate.destroy()
            _entryCoordinate = undefined
        }
    }

    function _destroyExitCoordinate(){
        if (_exitCoordinate){
76
            map.removeMapItem(_exitCoordinate)
77 78 79
            _exitCoordinate.destroy()
            _exitCoordinate = undefined
        }
80 81
    }

82 83
    function _destroyRefPoint(){
        if (_refPoint){
84
            map.removeMapItem(_refPoint)
85 86 87 88 89 90 91
            _refPoint.destroy()
            _refPoint = undefined
        }
    }

    function _destroyTransectsComponent(){
        if (_transectsComponent){
92
            map.removeMapItem(_transectsComponent)
93 94 95
            _transectsComponent.destroy()
            _transectsComponent = undefined
        }
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    }

    /// Add an initial 4 sided polygon if there is none
    function _addInitialPolygon() {
        if (_mapPolygon.count < 3) {
            // Initial polygon is inset to take 2/3rds space
            var rect = Qt.rect(map.centerViewport.x, map.centerViewport.y, map.centerViewport.width, map.centerViewport.height)
            rect.x += (rect.width * 0.25) / 2
            rect.y += (rect.height * 0.25) / 2
            rect.width *= 0.75
            rect.height *= 0.75

            var centerCoord =       map.toCoordinate(Qt.point(rect.x + (rect.width / 2), rect.y + (rect.height / 2)),   false /* clipToViewPort */)
            var topLeftCoord =      map.toCoordinate(Qt.point(rect.x, rect.y),                                          false /* clipToViewPort */)
            var topRightCoord =     map.toCoordinate(Qt.point(rect.x + rect.width, rect.y),                             false /* clipToViewPort */)
            var bottomLeftCoord =   map.toCoordinate(Qt.point(rect.x, rect.y + rect.height),                            false /* clipToViewPort */)
            var bottomRightCoord =  map.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height),               false /* clipToViewPort */)

            // Initial polygon has max width and height of 3000 meters
            var halfWidthMeters =   Math.min(topLeftCoord.distanceTo(topRightCoord), 3000) / 2
            var halfHeightMeters =  Math.min(topLeftCoord.distanceTo(bottomLeftCoord), 3000) / 2
            topLeftCoord =      centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 0)
            topRightCoord =     centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 0)
            bottomLeftCoord =   centerCoord.atDistanceAndAzimuth(halfWidthMeters, -90).atDistanceAndAzimuth(halfHeightMeters, 180)
            bottomRightCoord =  centerCoord.atDistanceAndAzimuth(halfWidthMeters, 90).atDistanceAndAzimuth(halfHeightMeters, 180)

            _mapPolygon.appendVertex(topLeftCoord)
            _mapPolygon.appendVertex(topRightCoord)
            _mapPolygon.appendVertex(bottomRightCoord)
            _mapPolygon.appendVertex(bottomLeftCoord)
126
        }
127 128
    }

129 130

    Component.onCompleted: {
131
        if ( _mapPolygon.count === 0 ) {
132
            _addInitialPolygon()
133
            _missionItem.resetReference();
Valentin Platzgummer's avatar
Valentin Platzgummer committed
134
        }
135 136 137 138 139 140
        _addEntryCoordinate()
        _addExitCoordinate()
        if (showRefPoint){
            _addRefPoint()
        }
        _addTransectsComponent()
141 142 143
    }

    Component.onDestruction: {
144 145 146 147 148 149 150 151 152 153 154 155
        _destroyEntryCoordinate()
        _destroyExitCoordinate()
        _destroyRefPoint()
        _destroyTransectsComponent()
    }

    onShowRefPointChanged: {
        if (showRefPoint){
            _addRefPoint()
        } else {
            _destroyRefPoint()
        }
156 157
    }

158
    WimaMapPolygonVisuals {
159 160 161 162 163 164 165 166 167
        id:                 mapPolygonVisuals
        qgcView:            _root.qgcView
        mapControl:         map
        mapPolygon:         _mapPolygon
        interactive:        _missionItem.isCurrentItem
        borderWidth:        1
        borderColor:        "black"
        interiorColor:      "green"
        interiorOpacity:    0.5
168
        visible:  			!_missionItem.hidePolygon
169 170 171 172 173 174 175
    }

    // Transect lines
    Component {
        id: visualTransectsComponent

        MapPolyline {
176
            property var transects: _missionItem.visualTransectPoints
177 178
            line.color: "white"
            line.width: 2
179
            path:       transects.length > 0 ? transects : []
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
        }
    }

    // Entry point
    Component {
        id: entryPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.coordinate
            visible:        _missionItem.exitCoordinate.isValid

            sourceItem: MissionItemIndexLabel {
                index:      _missionItem.sequenceNumber
                label:      "Entry"
                checked:    _missionItem.isCurrentItem
                onClicked:  _root.clicked(_missionItem.sequenceNumber)
            }
        }
    }

    // Exit point
    Component {
        id: exitPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.exitCoordinate
            visible:        _missionItem.exitCoordinate.isValid

            sourceItem: MissionItemIndexLabel {
                index:      _missionItem.lastSequenceNumber
                label:      "Exit"
                checked:    _missionItem.isCurrentItem
                onClicked:  _root.clicked(_missionItem.sequenceNumber)
            }
        }
    }
222 223 224 225 226

    // Ref. point (Base Station)
    Component {
        id: refPointComponent

Valentin Platzgummer's avatar
Valentin Platzgummer committed
227 228 229
        DragCoordinate {
            map:        _root.map
            qgcView:    _root.qgcView
230
            z:          QGroundControl.zOrderMapItems
Valentin Platzgummer's avatar
Valentin Platzgummer committed
231
            checked:    _missionItem.isCurrentItem
Valentin Platzgummer's avatar
Valentin Platzgummer committed
232
            coordinate: _missionItem.refPoint
233

234 235 236 237
            onClicked:  {
                _root.clicked(_missionItem.sequenceNumber)
            }

238 239
            onDragReleased: {
                _missionItem.refPoint = coordinate
240
                coordinate = Qt.binding(function (){return _missionItem.refPoint})
241
            }
242 243
        }
    }
244
}