TransectStyleMapVisuals.qml 7.15 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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

/// Base control for both Survey and Corridor Scan map visuals
Item {
    id: _root

25 26
    property var    map                                                 ///< Map control to place item in
    property bool   polygonInteractive: true
27
    property bool   interactive: true
28 29 30 31 32

    property var    _missionItem:               object
    property var    _mapPolygon:                object.surveyAreaPolygon
    property bool   _currentItem:               object.isCurrentItem
    property var    _transectPoints:            _missionItem.visualTransectPoints
33 34 35 36 37 38
    property int    _transectCount:             _transectPoints.length / (_hasTurnaround ? 4 : 2)
    property bool   _hasTurnaround:             _missionItem.turnAroundDistance.rawValue !== 0
    property int    _firstTrueTransectIndex:    _hasTurnaround ? 1 : 0
    property int    _lastTrueTransectIndex:     _transectPoints.length - (_hasTurnaround ? 2 : 1)
    property int    _lastPointIndex:            _transectPoints.length - 1
    property bool   _showPartialEntryExit:      !_currentItem && _hasTurnaround &&_transectPoints.length >= 2
39 40 41 42 43 44 45 46 47
    property var    _fullTransectsComponent:    null
    property var    _entryTransectsComponent:   null
    property var    _exitTransectsComponent:    null
    property var    _entryCoordinate
    property var    _exitCoordinate

    signal clicked(int sequenceNumber)

    function _addVisualElements() {
48 49
        var toAdd = [ fullTransectsComponent, entryTransectComponent, exitTransectComponent, entryPointComponent, exitPointComponent,
                     entryArrow1Component, entryArrow2Component, exitArrow1Component, exitArrow2Component ]
50
        objMgr.createObjects(toAdd, map, true /* parentObjectIsMap */)
51 52 53
    }

    function _destroyVisualElements() {
54
        objMgr.destroyObjects()
55 56 57 58 59 60 61 62 63 64
    }

    Component.onCompleted: {
        _addVisualElements()
    }

    Component.onDestruction: {
        _destroyVisualElements()
    }

65 66 67 68
    QGCDynamicObjectManager {
        id: objMgr
    }

69 70 71 72 73
    // Area polygon
    QGCMapPolygonVisuals {
        id:                 mapPolygonVisuals
        mapControl:         map
        mapPolygon:         _mapPolygon
74
        interactive:        polygonInteractive && _missionItem.isCurrentItem && _root.interactive
75 76
        borderWidth:        1
        borderColor:        "black"
77
        interiorColor:      QGroundControl.globalPalette.surveyPolygonInterior
78
        altColor:           QGroundControl.globalPalette.surveyPolygonTerrainCollision
79
        interiorOpacity:    0.5 * _root.opacity
80 81 82 83 84 85 86 87 88 89 90
    }

    // Full set of transects lines. Shown when item is selected.
    Component {
        id: fullTransectsComponent

        MapPolyline {
            line.color: "white"
            line.width: 2
            path:       _transectPoints
            visible:    _currentItem
91
            opacity:    _root.opacity
92 93 94 95 96 97 98 99 100 101 102 103
        }
    }

    // Entry and exit transect lines only. Used when item is not selected.
    Component {
        id: entryTransectComponent

        MapPolyline {
            line.color: "white"
            line.width: 2
            path:       _showPartialEntryExit ? [ _transectPoints[0], _transectPoints[1] ] : []
            visible:    _showPartialEntryExit
104
            opacity:    _root.opacity
105 106 107 108 109 110 111 112
        }
    }
    Component {
        id: exitTransectComponent

        MapPolyline {
            line.color: "white"
            line.width: 2
113
            path:       _showPartialEntryExit ? [ _transectPoints[_lastPointIndex - 1], _transectPoints[_lastPointIndex] ] : []
114
            visible:    _showPartialEntryExit
115
            opacity:    _root.opacity
116 117 118 119 120 121 122 123 124 125 126 127 128
        }
    }

    // Entry point
    Component {
        id: entryPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.coordinate
            visible:        _missionItem.exitCoordinate.isValid
129
            opacity:        _root.opacity
130 131 132 133

            sourceItem: MissionItemIndexLabel {
                index:      _missionItem.sequenceNumber
                checked:    _missionItem.isCurrentItem
134
                onClicked:  if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
135 136 137 138
            }
        }
    }

139 140 141 142 143 144
    Component {
        id: entryArrow1Component

        MapLineArrow {
            fromCoord:      _transectPoints[_firstTrueTransectIndex]
            toCoord:        _transectPoints[_firstTrueTransectIndex + 1]
145
            arrowPosition:  1
146
            visible:        _currentItem
147
            opacity:        _root.opacity
148 149 150 151 152 153 154 155 156
        }
    }

    Component {
        id: entryArrow2Component

        MapLineArrow {
            fromCoord:      _transectPoints[nextTrueTransectIndex]
            toCoord:        _transectPoints[nextTrueTransectIndex + 1]
157
            arrowPosition:  1
158
            visible:        _currentItem && _transectCount > 3
159
            opacity:        _root.opacity
160 161 162 163 164 165 166 167 168 169 170

            property int nextTrueTransectIndex: _firstTrueTransectIndex + (_hasTurnaround ? 4 : 2)
        }
    }

    Component {
        id: exitArrow1Component

        MapLineArrow {
            fromCoord:      _transectPoints[_lastTrueTransectIndex - 1]
            toCoord:        _transectPoints[_lastTrueTransectIndex]
171
            arrowPosition:  3
172
            visible:        _currentItem
173
            opacity:        _root.opacity
174 175 176 177 178 179 180 181 182
        }
    }

    Component {
        id: exitArrow2Component

        MapLineArrow {
            fromCoord:      _transectPoints[prevTrueTransectIndex - 1]
            toCoord:        _transectPoints[prevTrueTransectIndex]
183
            arrowPosition:  13
184
            visible:        _currentItem && _transectCount > 3
185
            opacity:        _root.opacity
186 187 188 189 190

            property int prevTrueTransectIndex: _lastTrueTransectIndex - (_hasTurnaround ? 4 : 2)
        }
    }

191 192 193 194 195 196 197 198 199 200
    // Exit point
    Component {
        id: exitPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.exitCoordinate
            visible:        _missionItem.exitCoordinate.isValid
201
            opacity:        _root.opacity
202 203 204 205

            sourceItem: MissionItemIndexLabel {
                index:      _missionItem.lastSequenceNumber
                checked:    _missionItem.isCurrentItem
206
                onClicked:  if(_root.interactive) _root.clicked(_missionItem.sequenceNumber)
207 208 209 210
            }
        }
    }
}