GeoFenceEditor.qml 15 KB
Newer Older
1 2
import QtQuick          2.3
import QtQuick.Controls 1.2
3
import QtQuick.Layouts  1.2
4
import QtPositioning    5.2
5 6 7 8

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
9 10
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
11 12 13

QGCFlickable {
    id:             root
Don Gagne's avatar
Don Gagne committed
14
    contentHeight:  geoFenceEditorRect.height
15 16
    clip:           true

17 18 19
    property var    myGeoFenceController
    property var    flightMap

20
    readonly property real  _editFieldWidth:    Math.min(width - _margin * 2, ScreenTools.defaultFontPixelWidth * 15)
21 22 23
    readonly property real  _margin:            ScreenTools.defaultFontPixelWidth / 2
    readonly property real  _radius:            ScreenTools.defaultFontPixelWidth / 2

Don Gagne's avatar
Don Gagne committed
24 25
    Rectangle {
        id:     geoFenceEditorRect
26 27
        anchors.left:   parent.left
        anchors.right:  parent.right
Don Gagne's avatar
Don Gagne committed
28 29 30 31 32 33 34 35 36 37 38 39
        height: geoFenceItems.y + geoFenceItems.height + (_margin * 2)
        radius: _radius
        color:  qgcPal.missionItemEditor

        QGCLabel {
            id:                 geoFenceLabel
            anchors.margins:    _margin
            anchors.left:       parent.left
            anchors.top:        parent.top
            text:               qsTr("GeoFence")
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
        }
40

41
        Rectangle {
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48 49 50 51 52
            id:                 geoFenceItems
            anchors.margins:    _margin
            anchors.left:       parent.left
            anchors.right:      parent.right
            anchors.top:        geoFenceLabel.bottom
            height:             fenceColumn.y + fenceColumn.height + (_margin * 2)
            color:              qgcPal.windowShadeDark
            radius:             _radius

            Column {
                id:                 fenceColumn
53 54
                anchors.margins:    _margin
                anchors.top:        parent.top
55 56
                anchors.left:       parent.left
                anchors.right:      parent.right
57
                spacing:            _margin
58

Don Gagne's avatar
Don Gagne committed
59
                QGCLabel {
60 61
                    anchors.left:       parent.left
                    anchors.right:      parent.right
Don Gagne's avatar
Don Gagne committed
62 63 64 65 66 67
                    wrapMode:           Text.WordWrap
                    font.pointSize:     myGeoFenceController.supported ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
                    text:               myGeoFenceController.supported ?
                                            qsTr("GeoFencing allows you to set a virtual ‘fence’ around the area you want to fly in.") :
                                            qsTr("This vehicle does not support GeoFence.")
                }
68

Don Gagne's avatar
Don Gagne committed
69
                Column {
70 71 72 73
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    spacing:            _margin
                    visible:            myGeoFenceController.supported
74

Don Gagne's avatar
Don Gagne committed
75 76
                    Repeater {
                        model: myGeoFenceController.params
77

Don Gagne's avatar
Don Gagne committed
78 79 80
                        Item {
                            width:  fenceColumn.width
                            height: textField.height
81

Don Gagne's avatar
Don Gagne committed
82
                            property bool showCombo: modelData.enumStrings.length > 0
83

Don Gagne's avatar
Don Gagne committed
84 85 86 87 88
                            QGCLabel {
                                id:                 textFieldLabel
                                anchors.baseline:   textField.baseline
                                text:               myGeoFenceController.paramLabels[index]
                            }
89

Don Gagne's avatar
Don Gagne committed
90 91 92 93 94 95 96 97
                            FactTextField {
                                id:             textField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                showUnits:      true
                                fact:           modelData
                                visible:        !parent.showCombo
                            }
98

Don Gagne's avatar
Don Gagne committed
99 100 101 102 103 104 105
                            FactComboBox {
                                id:             comboField
                                anchors.right:  parent.right
                                width:          _editFieldWidth
                                indexModel:     false
                                fact:           showCombo ? modelData : _nullFact
                                visible:        parent.showCombo
106

Don Gagne's avatar
Don Gagne committed
107
                                property var _nullFact: Fact { }
108 109
                            }
                        }
Don Gagne's avatar
Don Gagne committed
110
                    }
111

Don Gagne's avatar
Don Gagne committed
112
                    SectionHeader {
113 114 115 116
                        id:             insertSection
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Insert GeoFence")
Don Gagne's avatar
Don Gagne committed
117
                    }
118

Don Gagne's avatar
Don Gagne committed
119
                    QGCButton {
120 121
                        Layout.fillWidth:   true
                        text:               qsTr("Polygon Fence")
122

Don Gagne's avatar
Don Gagne committed
123 124 125 126 127
                        onClicked: {
                            var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
                            var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
                            var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
                            myGeoFenceController.addInclusionPolygon(topLeftCoord, bottomRightCoord)
128
                        }
Don Gagne's avatar
Don Gagne committed
129
                    }
130

Don Gagne's avatar
Don Gagne committed
131
                    QGCButton {
132 133
                        Layout.fillWidth:   true
                        text:               qsTr("Circular Fence")
134

Don Gagne's avatar
Don Gagne committed
135 136 137 138 139
                        onClicked: {
                            var rect = Qt.rect(flightMap.centerViewport.x, flightMap.centerViewport.y, flightMap.centerViewport.width, flightMap.centerViewport.height)
                            var topLeftCoord = flightMap.toCoordinate(Qt.point(rect.x, rect.y), false /* clipToViewPort */)
                            var bottomRightCoord = flightMap.toCoordinate(Qt.point(rect.x + rect.width, rect.y + rect.height), false /* clipToViewPort */)
                            myGeoFenceController.addInclusionCircle(topLeftCoord, bottomRightCoord)
140
                        }
Don Gagne's avatar
Don Gagne committed
141
                    }
142

Don Gagne's avatar
Don Gagne committed
143
                    SectionHeader {
144 145 146 147
                        id:             polygonSection
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Polygon Fences")
Don Gagne's avatar
Don Gagne committed
148 149 150 151 152 153 154 155
                    }

                    QGCLabel {
                        text:       qsTr("None")
                        visible:    polygonSection.checked && myGeoFenceController.polygons.count === 0
                    }

                    GridLayout {
156 157 158 159
                        Layout.fillWidth:   true
                        columns:            3
                        flow:               GridLayout.TopToBottom
                        visible:            polygonSection.checked && myGeoFenceController.polygons.count > 0
160 161

                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
162 163 164
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
165 166
                        }

Don Gagne's avatar
Don Gagne committed
167 168
                        Repeater {
                            model: myGeoFenceController.polygons
169

Don Gagne's avatar
Don Gagne committed
170 171 172
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
173 174
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
175
                        }
176

Don Gagne's avatar
Don Gagne committed
177 178 179 180 181
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
182

Don Gagne's avatar
Don Gagne committed
183 184
                        Repeater {
                            model: myGeoFenceController.polygons
185

Don Gagne's avatar
Don Gagne committed
186 187
                            QGCRadioButton {
                                checked:            _interactive
188 189
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
Don Gagne committed
190
                                property bool _interactive: object.interactive
191

Don Gagne's avatar
Don Gagne committed
192
                                on_InteractiveChanged: checked = _interactive
193

Don Gagne's avatar
Don Gagne committed
194 195 196
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
197 198
                                }
                            }
Don Gagne's avatar
Don Gagne committed
199
                        }
200

Don Gagne's avatar
Don Gagne committed
201 202 203 204 205
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
206

Don Gagne's avatar
Don Gagne committed
207 208
                        Repeater {
                            model: myGeoFenceController.polygons
209

Don Gagne's avatar
Don Gagne committed
210 211 212 213 214 215 216
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deletePolygon(index)
                            }
                        }
                    } // GridLayout
217

Don Gagne's avatar
Don Gagne committed
218
                    SectionHeader {
219 220 221 222
                        id:             circleSection
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Circular Fences")
Don Gagne's avatar
Don Gagne committed
223
                    }
224

Don Gagne's avatar
Don Gagne committed
225 226 227 228
                    QGCLabel {
                        text:       qsTr("None")
                        visible:    circleSection.checked && myGeoFenceController.circles.count === 0
                    }
229

Don Gagne's avatar
Don Gagne committed
230
                    GridLayout {
231 232 233 234 235
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        columns:            4
                        flow:               GridLayout.TopToBottom
                        visible:            polygonSection.checked && myGeoFenceController.circles.count > 0
236 237

                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
238 239 240
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
241 242
                        }

Don Gagne's avatar
Don Gagne committed
243 244
                        Repeater {
                            model: myGeoFenceController.circles
245

Don Gagne's avatar
Don Gagne committed
246 247 248
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
249 250
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
251
                        }
252

Don Gagne's avatar
Don Gagne committed
253 254 255 256 257
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
258

Don Gagne's avatar
Don Gagne committed
259 260
                        Repeater {
                            model: myGeoFenceController.circles
261

Don Gagne's avatar
Don Gagne committed
262 263
                            QGCRadioButton {
                                checked:            _interactive
264 265
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
Don Gagne committed
266
                                property bool _interactive: object.interactive
267

Don Gagne's avatar
Don Gagne committed
268
                                on_InteractiveChanged: checked = _interactive
269

Don Gagne's avatar
Don Gagne committed
270 271 272
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
273 274
                                }
                            }
Don Gagne's avatar
Don Gagne committed
275
                        }
276

Don Gagne's avatar
Don Gagne committed
277 278 279 280 281
                        QGCLabel {
                            text:               qsTr("Radius")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
282

Don Gagne's avatar
Don Gagne committed
283 284
                        Repeater {
                            model: myGeoFenceController.circles
285

Don Gagne's avatar
Don Gagne committed
286 287 288
                            FactTextField {
                                fact:               object.radius
                                Layout.fillWidth:   true
289 290
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
291
                        }
292

Don Gagne's avatar
Don Gagne committed
293 294 295 296 297
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      3
                            Layout.alignment:   Qt.AlignHCenter
                        }
298

Don Gagne's avatar
Don Gagne committed
299 300
                        Repeater {
                            model: myGeoFenceController.circles
301

Don Gagne's avatar
Don Gagne committed
302 303 304 305
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deleteCircle(index)
306
                            }
Don Gagne's avatar
Don Gagne committed
307 308
                        }
                    } // GridLayout
309 310

                    SectionHeader {
311 312 313 314
                        id:             breachReturnSection
                        anchors.left:   parent.left
                        anchors.right:  parent.right
                        text:           qsTr("Breach Return Point")
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
                    }

                    QGCButton {
                        text:               qsTr("Add Breach Return Point")
                        visible:            breachReturnSection.visible && !myGeoFenceController.breachReturnPoint.isValid
                        anchors.left:       parent.left
                        anchors.right:      parent.right

                        onClicked: myGeoFenceController.breachReturnPoint = flightMap.center
                    }

                    QGCButton {
                        text:               qsTr("Remove Breach Return Point")
                        visible:            breachReturnSection.visible && myGeoFenceController.breachReturnPoint.isValid
                        anchors.left:       parent.left
                        anchors.right:      parent.right

                        onClicked: myGeoFenceController.breachReturnPoint = QtPositioning.coordinate()
                    }

                    ColumnLayout {
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        spacing:            _margin
                        visible:            breachReturnSection.visible && myGeoFenceController.breachReturnPoint.isValid

                        QGCLabel {
                            text: qsTr("Altitude")
                        }

                        AltitudeFactTextField {
                            fact:           myGeoFenceController.breachReturnAltitude
                            altitudeMode:   QGroundControl.AltitudeModeRelative
                        }
                    }

351
                }
352
            }
Don Gagne's avatar
Don Gagne committed
353 354
        }
    } // Rectangle
355
}