CircularSurveyMapVisual.qml 5.89 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
/****************************************************************************
 *
 *   (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
29
    property var _generator: _missionItem.generator
30

31 32 33 34
    property var _transectsComponent: undefined
    property var _entryCoordinate: undefined
    property var _exitCoordinate: undefined
    property var _generatorVisuals: undefined
35

36
    property bool _isCurrentItem: _missionItem.isCurrentItem
37

38
    signal clicked(int sequenceNumber)
39 40

    Component.onCompleted: {
41 42 43
        _addEntryCoordinate()
        _addExitCoordinate()
        _addTransectsComponent()
44
        _addGeneratorVisuals()
45 46 47
    }

    Component.onDestruction: {
48 49 50
        _destroyEntryCoordinate()
        _destroyExitCoordinate()
        _destroyTransectsComponent()
51 52 53 54 55 56
        _destroyGeneratorVisuals()
    }

    on_GeneratorChanged: {
        _destroyGeneratorVisuals()
        _addGeneratorVisuals()
57 58
    }

59 60 61 62 63
    // Transect lines
    Component {
        id: visualTransectsComponent

        MapPolyline {
64
            property var transects: _missionItem.visualTransectPoints
65 66
            line.color: "white"
            line.width: 2
67
            path:       transects.length > 0 ? transects : []
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
        }
    }

    // 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)
            }
        }
    }
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

    // Generator visuals
    function _addGeneratorVisuals(){
        if (_generator.mapVisualQml && !_generatorVisuals) {
            var component = Qt.createComponent(_generator.mapVisualQml)
            if (component.status === Component.Error) {
                console.log("Error loading Qml: ",
                            _generator.mapVisualQml, component.errorString())
            } else {
                _generatorVisuals =
                        component.createObject(_root, {
                                                   "map": _root.map,
                                                   "qgcView": _root.qgcView ,
                                                   "generator": _root._generator,
                                                   "checked": Qt.binding(
                                                                  function(){
                                                                      return _root._isCurrentItem
                                                                  })
                                               })
                _generatorVisuals.clicked.connect(
                            function(){_root.clicked(_missionItem.sequenceNumber)})
            }
        }
    }

    function _destroyGeneratorVisuals(){
        if(_generatorVisuals){
            _generatorVisuals.destroy()
            _generatorVisuals = undefined
        }
    }

    function _addTransectsComponent(){
        if (!_transectsComponent){
            _transectsComponent = visualTransectsComponent.createObject(_root)
            map.addMapItem(_transectsComponent)
        }
    }

    function _addExitCoordinate(){
        if (!_exitCoordinate){
            _exitCoordinate = exitPointComponent.createObject(_root)
            map.addMapItem(_exitCoordinate)
        }
    }

    function _addEntryCoordinate(){
        if (!_entryCoordinate){
            _entryCoordinate = entryPointComponent.createObject(_root)
            map.addMapItem(_entryCoordinate)
        }
    }

    function _destroyEntryCoordinate(){
        if (_entryCoordinate){
            map.removeMapItem(_entryCoordinate)
            _entryCoordinate.destroy()
            _entryCoordinate = undefined
        }
    }

    function _destroyExitCoordinate(){
        if (_exitCoordinate){
            map.removeMapItem(_exitCoordinate)
            _exitCoordinate.destroy()
            _exitCoordinate = undefined
        }
    }

    function _destroyTransectsComponent(){
        if (_transectsComponent){
            map.removeMapItem(_transectsComponent)
            _transectsComponent.destroy()
            _transectsComponent = undefined
        }
    }


188
}