SurveyItemEditor.qml 8.94 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
    }

Don Gagne's avatar
Don Gagne committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    Connections {
        target: editorMap.polygonDraw

        onPolygonCaptureStarted: {
            missionItem.clearPolygon()
        }

        onPolygonCaptureFinished: {
            for (var i=0; i<coordinates.length; i++) {
                missionItem.addPolygonCoordinate(coordinates[i])
            }
        }

        onPolygonAdjustVertex: missionItem.adjustPolygonCoordinate(vertexIndex, vertexCoordinate)
    }

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

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

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

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

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

            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
118 119
        QGCCheckBox {
            anchors.left:   parent.left
120
            text:           qsTr("Relative altitude")
Don Gagne's avatar
Don Gagne committed
121 122 123 124
            checked:        missionItem.gridAltitudeRelative
            onClicked:      missionItem.gridAltitudeRelative = checked
        }

Don Gagne's avatar
Don Gagne committed
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
        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
156 157 158 159 160 161 162 163 164 165 166 167 168 169
            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
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
            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()
            }
        }

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

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
        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()
                    }
234 235 236
                }
            }

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

241 242 243 244 245 246
                onClicked: {
                    if (editorMap.polygonDraw.adjustingPolygon) {
                        editorMap.polygonDraw.finishAdjustPolygon()
                    } else {
                        editorMap.polygonDraw.startAdjustPolygon(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

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