SurveyItemEditor.qml 9.04 KB
Newer Older
1 2 3
import QtQuick                  2.2
import QtQuick.Controls         1.2

4
import QGroundControl               1.0
5 6 7 8 9 10 11 12 13
import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
import QGroundControl.Controls      1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0

// Editor for Survery mission items
Rectangle {
    id:         _root
14
    height:     visible ? (editorColumn.height + (_margin * 2)) : 0
15 16 17 18
    width:      availableWidth
    color:      qgcPal.windowShadeDark
    radius:     _radius

Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
19
    // The following properties must be available up the hierarchy chain
20 21 22
    //property real   availableWidth    ///< Width for control
    //property var    missionItem       ///< Mission Item for editor

Don Gagne's avatar
Don Gagne committed
23
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
24

Don Gagne's avatar
Don Gagne committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    property var _cameraInfoCanonSX260: { "focalLength": 4.5, "sensorHeight": 4.55, "sensorWidth": 6.17 }

    function recalcFromCameraValues() {
        var focalLength = Number(focalLengthField.text)
        var sensorWidth = Number(sensorWidthField.text)
        var sensorHeight = Number(sensorHeightField.text)
        var overlap = Number(imageOverlapField.text)

        if (focalLength <= 0.0 || sensorWidth <= 0.0 || sensorHeight <= 0.0) {
            return
        }

        var scaledFocalLengthMM = (1000.0 * missionItem.gridAltitude.rawValue) / focalLength
        var imageWidthM = (sensorWidth * scaledFocalLengthMM) / 1000.0;
        var imageHeightM = (sensorHeight * scaledFocalLengthMM) / 1000.0;

        var gridSpacing
        var cameraTriggerDistance
        if (cameraOrientationLandscape.checked) {
            gridSpacing = imageWidthM
            cameraTriggerDistance = imageHeightM
        } else {
            gridSpacing = imageHeightM
            cameraTriggerDistance = imageWidthM
        }
        gridSpacing = (1.0 - (overlap / 100.0)) * gridSpacing
        cameraTriggerDistance = (1.0 - (overlap / 100.0)) * cameraTriggerDistance

        missionItem.gridSpacing.rawValue = gridSpacing
        missionItem.cameraTriggerDistance.rawValue = cameraTriggerDistance
    }

57 58 59
    function polygonCaptureStarted() {
        missionItem.clearPolygon()
    }
Don Gagne's avatar
Don Gagne committed
60

61 62 63
    function polygonCaptureFinished(coordinates) {
        for (var i=0; i<coordinates.length; i++) {
            missionItem.addPolygonCoordinate(coordinates[i])
Don Gagne's avatar
Don Gagne committed
64
        }
65
    }
Don Gagne's avatar
Don Gagne committed
66

67 68
    function polygonAdjustVertex(vertexIndex, vertexCoordinate) {
        missionItem.adjustPolygonCoordinate(vertexIndex, vertexCoordinate)
Don Gagne's avatar
Don Gagne committed
69 70
    }

71 72 73
    function polygonAdjustStarted() { }
    function polygonAdjustFinished() { }

74 75
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

Don Gagne's avatar
Don Gagne committed
76 77 78 79 80
    ExclusiveGroup {
        id:                 cameraOrientationGroup
        onCurrentChanged:   recalcFromCameraValues()
    }

81 82 83 84 85
    Column {
        id:                 editorColumn
        anchors.margins:    _margin
        anchors.top:        parent.top
        anchors.left:       parent.left
86
        anchors.right:      parent.right
87 88 89
        spacing:            _margin

        QGCLabel {
90 91 92
            wrapMode:       Text.WordWrap
            font.pointSize: ScreenTools.smallFontPointSize
            text:           qsTr("Work in progress, be careful!")
93 94
        }

95
        Repeater {
96
            model: [ missionItem.gridAngle, missionItem.gridSpacing, missionItem.gridAltitude, missionItem.turnaroundDist ]
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

            Item {
                anchors.left:   parent.left
                anchors.right:  parent.right
                height:         textField.height

                QGCLabel {
                    anchors.baseline:   textField.baseline
                    anchors.left:       parent.left
                    text:               modelData.name
                }

                FactTextField {
                    id:             textField
                    anchors.right:  parent.right
                    width:          _editFieldWidth
                    showUnits:      true
                    fact:           modelData
                }
            }
        }

Don Gagne's avatar
Don Gagne committed
119 120
        QGCCheckBox {
            anchors.left:   parent.left
121
            text:           qsTr("Relative altitude")
Don Gagne's avatar
Don Gagne committed
122 123 124 125
            checked:        missionItem.gridAltitudeRelative
            onClicked:      missionItem.gridAltitudeRelative = checked
        }

Don Gagne's avatar
Don Gagne committed
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
        QGCLabel { text: qsTr("Camera:") }

        Rectangle {
            anchors.left:   parent.left
            anchors.right:  parent.right
            height:         1
            color:          qgcPal.text
        }

        Row {
            spacing: ScreenTools.defaultFontPixelWidth

            QGCRadioButton {
                id:             cameraOrientationLandscape
                text:           "Landscape"
                checked:        true
                exclusiveGroup: cameraOrientationGroup
            }

            QGCRadioButton {
                id:             cameraOrientationPortrait
                text:           "Portrait"
                exclusiveGroup: cameraOrientationGroup
            }
        }

        Grid {
            columns: 2
            spacing: ScreenTools.defaultFontPixelWidth
            verticalItemAlignment: Grid.AlignVCenter

Don Gagne's avatar
Don Gagne committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170
            QGCCheckBox {
                id:         cameraTrigger
                text:       qsTr("Trigger:")
                checked:    missionItem.cameraTrigger
                onClicked:  missionItem.cameraTrigger = checked
            }

            FactTextField {
                width:      _editFieldWidth
                showUnits:  true
                fact:       missionItem.cameraTriggerDistance
                enabled:    missionItem.cameraTrigger
            }

Don Gagne's avatar
Don Gagne committed
171 172 173 174 175 176 177 178 179 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
            QGCLabel { text: qsTr("Focal length:") }
            QGCTextField {
                id:         focalLengthField
                unitsLabel: "mm"
                showUnits:  true
                text:       _cameraInfoCanonSX260.focalLength.toString()

                onEditingFinished: recalcFromCameraValues()
            }

            QGCLabel { text: qsTr("Sensor Width:") }
            QGCTextField {
                id:         sensorWidthField
                unitsLabel: "mm"
                showUnits:  true
                text:       _cameraInfoCanonSX260.sensorWidth.toString()

                onEditingFinished: recalcFromCameraValues()
            }

            QGCLabel { text: qsTr("Sensor height:") }
            QGCTextField {
                id:         sensorHeightField
                unitsLabel: "mm"
                showUnits:  true
                text:       _cameraInfoCanonSX260.sensorHeight.toString()

                onEditingFinished: recalcFromCameraValues()
            }

            QGCLabel { text: qsTr("Image overlap:") }
            QGCTextField {
                id:         imageOverlapField
                unitsLabel: "%"
                showUnits:  true
                text:       "0"

                onEditingFinished: recalcFromCameraValues()
            }
        }

212
        QGCLabel { text: qsTr("Polygon:") }
Don Gagne's avatar
Don Gagne committed
213

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        Rectangle {
            anchors.left:   parent.left
            anchors.right:  parent.right
            height:         1
            color:          qgcPal.text
        }

        Row {
            spacing: ScreenTools.defaultFontPixelWidth

            QGCButton {
                text:       editorMap.polygonDraw.drawingPolygon ? qsTr("Finish Draw") : qsTr("Draw")
                visible:    !editorMap.polygonDraw.adjustingPolygon
                enabled:    ((editorMap.polygonDraw.drawingPolygon && editorMap.polygonDraw.polygonReady) || !editorMap.polygonDraw.drawingPolygon)

                onClicked: {
                    if (editorMap.polygonDraw.drawingPolygon) {
                        editorMap.polygonDraw.finishCapturePolygon()
                    } else {
233
                        editorMap.polygonDraw.startCapturePolygon(_root)
234
                    }
235 236 237
                }
            }

238 239 240
            QGCButton {
                text:       editorMap.polygonDraw.adjustingPolygon ? qsTr("Finish Adjust") : qsTr("Adjust")
                visible:    missionItem.polygonPath.length > 0 && !editorMap.polygonDraw.drawingPolygon
241

242 243 244 245
                onClicked: {
                    if (editorMap.polygonDraw.adjustingPolygon) {
                        editorMap.polygonDraw.finishAdjustPolygon()
                    } else {
246
                        editorMap.polygonDraw.startAdjustPolygon(_root, missionItem.polygonPath)
247
                    }
248 249 250
                }
            }
        }
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270

        QGCLabel { text: qsTr("Statistics:") }

        Rectangle {
            anchors.left:   parent.left
            anchors.right:  parent.right
            height:         1
            color:          qgcPal.text
        }

        Grid {
            columns: 2
            spacing: ScreenTools.defaultFontPixelWidth

            QGCLabel { text: qsTr("Survey area:") }
            QGCLabel { text: QGroundControl.squareMetersToAppSettingsAreaUnits(missionItem.coveredArea).toFixed(2) + " " + QGroundControl.appSettingsAreaUnitsString }

            QGCLabel { text: qsTr("# shots:") }
            QGCLabel { text: missionItem.cameraShots }
        }
271 272
    }
}