SurveyItemEditor.qml 9.52 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 19 20 21 22
    width:      availableWidth
    color:      qgcPal.windowShadeDark
    radius:     _radius

    // The following properties must be available up the hierachy chain
    //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
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

Don Gagne's avatar
Don Gagne committed
59 60 61 62 63
    ExclusiveGroup {
        id:                 cameraOrientationGroup
        onCurrentChanged:   recalcFromCameraValues()
    }

64 65 66 67 68
    Column {
        id:                 editorColumn
        anchors.margins:    _margin
        anchors.top:        parent.top
        anchors.left:       parent.left
69
        anchors.right:      parent.right
70 71 72
        spacing:            _margin

        QGCLabel {
73 74 75
            wrapMode:       Text.WordWrap
            font.pointSize: ScreenTools.smallFontPointSize
            text:           qsTr("Work in progress, be careful!")
76 77
        }

78
        Repeater {
79
            model: [ missionItem.gridAngle, missionItem.gridSpacing, missionItem.gridAltitude ]
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

            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
102 103
        QGCCheckBox {
            anchors.left:   parent.left
104
            text:           qsTr("Relative altitude")
Don Gagne's avatar
Don Gagne committed
105 106 107 108
            checked:        missionItem.gridAltitudeRelative
            onClicked:      missionItem.gridAltitudeRelative = checked
        }

Don Gagne's avatar
Don Gagne committed
109 110 111
        QGCCheckBox {
            id:                 cameraTrigger
            anchors.left:       parent.left
112
            text:               qsTr("Camera trigger:")
Don Gagne's avatar
Don Gagne committed
113
            checked:            missionItem.cameraTrigger
Don Gagne's avatar
Don Gagne committed
114
            onClicked:          missionItem.cameraTrigger = checked
Don Gagne's avatar
Don Gagne committed
115 116 117 118 119 120 121 122 123 124 125 126
        }

        Item {
            id:             distanceItem
            anchors.left:   parent.left
            anchors.right:  parent.right
            height:         textField.height
            enabled:        cameraTrigger.checked

            QGCLabel {
                anchors.baseline:   textField.baseline
                anchors.left:       parent.left
127
                text:               qsTr("Distance:")
Don Gagne's avatar
Don Gagne committed
128 129 130 131 132 133 134 135 136 137 138
            }

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

Don Gagne's avatar
Don Gagne committed
139 140 141
        Connections {
            target: editorMap.polygonDraw

142
            onPolygonCaptureStarted: {
Don Gagne's avatar
Don Gagne committed
143 144 145
                missionItem.clearPolygon()
            }

146
            onPolygonCaptureFinished: {
Don Gagne's avatar
Don Gagne committed
147 148 149 150
                for (var i=0; i<coordinates.length; i++) {
                    missionItem.addPolygonCoordinate(coordinates[i])
                }
            }
151 152

            onPolygonAdjustVertex: missionItem.adjustPolygonCoordinate(vertexIndex, vertexCoordinate)
Don Gagne's avatar
Don Gagne committed
153 154
        }

Don Gagne's avatar
Don Gagne committed
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
        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

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

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

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
        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 {
                        editorMap.polygonDraw.startCapturePolygon()
                    }
251 252 253
                }
            }

254 255 256
            QGCButton {
                text:       editorMap.polygonDraw.adjustingPolygon ? qsTr("Finish Adjust") : qsTr("Adjust")
                visible:    missionItem.polygonPath.length > 0 && !editorMap.polygonDraw.drawingPolygon
257

258 259 260 261 262 263
                onClicked: {
                    if (editorMap.polygonDraw.adjustingPolygon) {
                        editorMap.polygonDraw.finishAdjustPolygon()
                    } else {
                        editorMap.polygonDraw.startAdjustPolygon(missionItem.polygonPath)
                    }
264 265 266
                }
            }
        }
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286

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