GeoFenceEditor.qml 14.5 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 113 114 115
                    SectionHeader {
                        id:     insertSection
                        text:   qsTr("Insert GeoFence")
                    }
116

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

Don Gagne's avatar
Don Gagne committed
121 122 123 124 125
                        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)
126
                        }
Don Gagne's avatar
Don Gagne committed
127
                    }
128

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

Don Gagne's avatar
Don Gagne committed
133 134 135 136 137
                        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)
138
                        }
Don Gagne's avatar
Don Gagne committed
139
                    }
140

Don Gagne's avatar
Don Gagne committed
141 142 143 144 145 146 147 148 149 150 151
                    SectionHeader {
                        id:     polygonSection
                        text:   qsTr("Polygon Fences")
                    }

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

                    GridLayout {
152 153 154 155
                        Layout.fillWidth:   true
                        columns:            3
                        flow:               GridLayout.TopToBottom
                        visible:            polygonSection.checked && myGeoFenceController.polygons.count > 0
156 157

                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
158 159 160
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
161 162
                        }

Don Gagne's avatar
Don Gagne committed
163 164
                        Repeater {
                            model: myGeoFenceController.polygons
165

Don Gagne's avatar
Don Gagne committed
166 167 168
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
169 170
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
171
                        }
172

Don Gagne's avatar
Don Gagne committed
173 174 175 176 177
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
178

Don Gagne's avatar
Don Gagne committed
179 180
                        Repeater {
                            model: myGeoFenceController.polygons
181

Don Gagne's avatar
Don Gagne committed
182 183
                            QGCRadioButton {
                                checked:            _interactive
184 185
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
Don Gagne committed
186
                                property bool _interactive: object.interactive
187

Don Gagne's avatar
Don Gagne committed
188
                                on_InteractiveChanged: checked = _interactive
189

Don Gagne's avatar
Don Gagne committed
190 191 192
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
193 194
                                }
                            }
Don Gagne's avatar
Don Gagne committed
195
                        }
196

Don Gagne's avatar
Don Gagne committed
197 198 199 200 201
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
202

Don Gagne's avatar
Don Gagne committed
203 204
                        Repeater {
                            model: myGeoFenceController.polygons
205

Don Gagne's avatar
Don Gagne committed
206 207 208 209 210 211 212
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deletePolygon(index)
                            }
                        }
                    } // GridLayout
213

Don Gagne's avatar
Don Gagne committed
214 215 216 217
                    SectionHeader {
                        id:     circleSection
                        text:   qsTr("Circular Fences")
                    }
218

Don Gagne's avatar
Don Gagne committed
219 220 221 222
                    QGCLabel {
                        text:       qsTr("None")
                        visible:    circleSection.checked && myGeoFenceController.circles.count === 0
                    }
223

Don Gagne's avatar
Don Gagne committed
224
                    GridLayout {
225 226 227 228 229
                        anchors.left:       parent.left
                        anchors.right:      parent.right
                        columns:            4
                        flow:               GridLayout.TopToBottom
                        visible:            polygonSection.checked && myGeoFenceController.circles.count > 0
230 231

                        QGCLabel {
Don Gagne's avatar
Don Gagne committed
232 233 234
                            text:               qsTr("Inclusion")
                            Layout.column:      0
                            Layout.alignment:   Qt.AlignHCenter
235 236
                        }

Don Gagne's avatar
Don Gagne committed
237 238
                        Repeater {
                            model: myGeoFenceController.circles
239

Don Gagne's avatar
Don Gagne committed
240 241 242
                            QGCCheckBox {
                                checked:            object.inclusion
                                onClicked:          object.inclusion = checked
243 244
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
245
                        }
246

Don Gagne's avatar
Don Gagne committed
247 248 249 250 251
                        QGCLabel {
                            text:               qsTr("Edit")
                            Layout.column:      1
                            Layout.alignment:   Qt.AlignHCenter
                        }
252

Don Gagne's avatar
Don Gagne committed
253 254
                        Repeater {
                            model: myGeoFenceController.circles
255

Don Gagne's avatar
Don Gagne committed
256 257
                            QGCRadioButton {
                                checked:            _interactive
258 259
                                Layout.alignment:   Qt.AlignHCenter

Don Gagne's avatar
Don Gagne committed
260
                                property bool _interactive: object.interactive
261

Don Gagne's avatar
Don Gagne committed
262
                                on_InteractiveChanged: checked = _interactive
263

Don Gagne's avatar
Don Gagne committed
264 265 266
                                onClicked: {
                                    myGeoFenceController.clearAllInteractive()
                                    object.interactive = checked
267 268
                                }
                            }
Don Gagne's avatar
Don Gagne committed
269
                        }
270

Don Gagne's avatar
Don Gagne committed
271 272 273 274 275
                        QGCLabel {
                            text:               qsTr("Radius")
                            Layout.column:      2
                            Layout.alignment:   Qt.AlignHCenter
                        }
276

Don Gagne's avatar
Don Gagne committed
277 278
                        Repeater {
                            model: myGeoFenceController.circles
279

Don Gagne's avatar
Don Gagne committed
280 281 282
                            FactTextField {
                                fact:               object.radius
                                Layout.fillWidth:   true
283 284
                                Layout.alignment:   Qt.AlignHCenter
                            }
Don Gagne's avatar
Don Gagne committed
285
                        }
286

Don Gagne's avatar
Don Gagne committed
287 288 289 290 291
                        QGCLabel {
                            text:               qsTr("Delete")
                            Layout.column:      3
                            Layout.alignment:   Qt.AlignHCenter
                        }
292

Don Gagne's avatar
Don Gagne committed
293 294
                        Repeater {
                            model: myGeoFenceController.circles
295

Don Gagne's avatar
Don Gagne committed
296 297 298 299
                            QGCButton {
                                text:               qsTr("Del")
                                Layout.alignment:   Qt.AlignHCenter
                                onClicked:          myGeoFenceController.deleteCircle(index)
300
                            }
Don Gagne's avatar
Don Gagne committed
301 302
                        }
                    } // GridLayout
303 304 305 306 307 308 309 310 311 312 313 314 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

                    SectionHeader {
                        id:     breachReturnSection
                        text:   qsTr("Breach Return Point")
                    }

                    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
                        }
                    }

343
                }
344
            }
Don Gagne's avatar
Don Gagne committed
345 346
        }
    } // Rectangle
347
}