SurveyItemEditor.qml 21.8 KB
Newer Older
1 2
import QtQuick                  2.2
import QtQuick.Controls         1.2
3
import QtQuick.Dialogs          1.2
4

5
import QGroundControl               1.0
6 7 8 9 10 11 12 13 14
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
15
    height:     visible ? (editorColumn.height + (_margin * 2)) : 0
16 17 18 19
    width:      availableWidth
    color:      qgcPal.windowShadeDark
    radius:     _radius

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

Don Gagne's avatar
Don Gagne committed
24
    property real _margin: ScreenTools.defaultFontPixelWidth / 2
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
    property int cameraIndex: 1

    ListModel {
           id: cameraModelList
           ListElement {
               text:           qsTr("Custom")
               sensorWidth:    0
               sensorHeight:   0
               imageWidth:     0
               imageHeight:    0
               focalLength:    0
           }
           ListElement {
               text:           qsTr("Sony ILCE-QX1") //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-qx1-body-kit/specifications
               sensorWidth:    23.2                  //http://www.sony.com/electronics/camera-lenses/sel16f28/specifications
               sensorHeight:   15.4
               imageWidth:     5456
               imageHeight:    3632
               focalLength:    16
           }
           ListElement {
               text:           qsTr("Canon S100 PowerShot")
               sensorWidth:    7.6
               sensorHeight:   5.7
               imageWidth:     4000
               imageHeight:    3000
               focalLength:    5.2
           }
           ListElement {
Andre Kjellstrup's avatar
Andre Kjellstrup committed
55
               text:           qsTr("Canon SX260 HS PowerShot")
56 57 58 59 60 61
               sensorWidth:    6.17
               sensorHeight:   4.55
               imageWidth:     4000
               imageHeight:    3000
               focalLength:    4.5
           }
62 63
           ListElement {
               text:           qsTr("Canon EOS-M 22mm")
64 65
               sensorWidth:    22.3
               sensorHeight:   14.9
66 67
               imageWidth:     5184
               imageHeight:    3456
68
               focalLength:    22
69
           }
70 71 72 73 74 75 76 77
           ListElement {
               text:           qsTr("Sony a6000 16mm") //http://www.sony.co.uk/electronics/interchangeable-lens-cameras/ilce-6000-body-kit#product_details_default
               sensorWidth:    23.5
               sensorHeight:   15.6
               imageWidth:     6000
               imageHeight:    4000
               focalLength:    16
           }
78
   }
Don Gagne's avatar
Don Gagne committed
79 80

    function recalcFromCameraValues() {
81 82 83 84 85 86 87 88 89 90 91 92 93 94
        var focalLength = cameraModelList.get(cameraIndex).focalLength
        var sensorWidth = cameraModelList.get(cameraIndex).sensorWidth
        var sensorHeight = cameraModelList.get(cameraIndex).sensorHeight
        var imageWidth = cameraModelList.get(cameraIndex).imageWidth
        var imageHeight = cameraModelList.get(cameraIndex).imageHeight

        var gsd = Number(gsdField.text)
        var frontalOverlap = Number(frontalOverlapField.text)
        var sideOverlap = Number(sideOverlapField.text)

        if (focalLength <= 0.0 || sensorWidth <= 0.0 || sensorHeight <= 0.0 || imageWidth < 0 || imageHeight < 0 || gsd < 0.0 || frontalOverlap < 0 || sideOverlap < 0) {
            missionItem.gridAltitude.rawValue = 0
            missionItem.gridSpacing.rawValue = 0
            missionItem.cameraTriggerDistance.rawValue = 0
Don Gagne's avatar
Don Gagne committed
95 96 97
            return
        }

98 99 100
        var altitude
        var imageSizeSideGround //size in side (non flying) direction of the image on the ground
        var imageSizeFrontGround //size in front (flying) direction of the image on the ground
Don Gagne's avatar
Don Gagne committed
101 102
        var gridSpacing
        var cameraTriggerDistance
103 104 105

        altitude = (imageWidth * gsd * focalLength) / (sensorWidth * 100)

Don Gagne's avatar
Don Gagne committed
106
        if (cameraOrientationLandscape.checked) {
107 108
            imageSizeSideGround = (imageWidth * gsd) / 100
            imageSizeFrontGround = (imageHeight * gsd) / 100
Don Gagne's avatar
Don Gagne committed
109
        } else {
110 111
            imageSizeSideGround = (imageHeight * gsd) / 100
            imageSizeFrontGround = (imageWidth * gsd) / 100
Don Gagne's avatar
Don Gagne committed
112 113
        }

114 115 116 117
        gridSpacing = imageSizeSideGround * ( (100-sideOverlap) / 100 )
        cameraTriggerDistance = imageSizeFrontGround * ( (100-frontalOverlap) / 100 )

        missionItem.gridAltitude.rawValue = altitude
Don Gagne's avatar
Don Gagne committed
118 119 120 121
        missionItem.gridSpacing.rawValue = gridSpacing
        missionItem.cameraTriggerDistance.rawValue = cameraTriggerDistance
    }

122 123 124 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 156 157 158 159 160 161
    function recalcFromMissionValues() {
        var focalLength = cameraModelList.get(cameraIndex).focalLength
        var sensorWidth = cameraModelList.get(cameraIndex).sensorWidth
        var sensorHeight = cameraModelList.get(cameraIndex).sensorHeight
        var imageWidth = cameraModelList.get(cameraIndex).imageWidth
        var imageHeight = cameraModelList.get(cameraIndex).imageHeight

        var altitude = missionItem.gridAltitude.rawValue
        var gridSpacing = missionItem.gridSpacing.rawValue
        var cameraTriggerDistance = missionItem.cameraTriggerDistance.rawValue

        if (focalLength <= 0.0 || sensorWidth <= 0.0 || sensorHeight <= 0.0 || imageWidth < 0 || imageHeight < 0 || altitude < 0.0 || gridSpacing < 0.0 || cameraTriggerDistance < 0.0) {
            gsdField.text = "0.0"
            sideOverlapField.text = "0"
            frontalOverlapField.text = "0"
            return
        }

        var gsd
        var imageSizeSideGround //size in side (non flying) direction of the image on the ground
        var imageSizeFrontGround //size in front (flying) direction of the image on the ground

        gsd = (altitude * sensorWidth * 100) / (imageWidth * focalLength)

        if (cameraOrientationLandscape.checked) {
            imageSizeSideGround = (imageWidth * gsd) / 100
            imageSizeFrontGround = (imageHeight * gsd) / 100
        } else {
            imageSizeSideGround = (imageHeight * gsd) / 100
            imageSizeFrontGround = (imageWidth * gsd) / 100
        }

        var sideOverlap = (imageSizeSideGround == 0 ? 0 : 100 - (gridSpacing*100 / imageSizeSideGround))
        var frontOverlap = (imageSizeFrontGround == 0 ? 0 : 100 - (cameraTriggerDistance*100 / imageSizeFrontGround))

        gsdField.text = gsd.toFixed(1)
        sideOverlapField.text = sideOverlap.toFixed(0)
        frontalOverlapField.text = frontOverlap.toFixed(0)
    }

162
    function polygonCaptureStarted() {
163
    	missionItem.clearPolygon()
164
    }
Don Gagne's avatar
Don Gagne committed
165

166 167 168
    function polygonCaptureFinished(coordinates) {
        for (var i=0; i<coordinates.length; i++) {
            missionItem.addPolygonCoordinate(coordinates[i])
Don Gagne's avatar
Don Gagne committed
169
        }
170
    }
Don Gagne's avatar
Don Gagne committed
171

172 173
    function polygonAdjustVertex(vertexIndex, vertexCoordinate) {
        missionItem.adjustPolygonCoordinate(vertexIndex, vertexCoordinate)
Don Gagne's avatar
Don Gagne committed
174 175
    }

176 177 178
    function polygonAdjustStarted() { }
    function polygonAdjustFinished() { }

179 180
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

Don Gagne's avatar
Don Gagne committed
181 182
    ExclusiveGroup {
        id:                 cameraOrientationGroup
183 184 185
        onCurrentChanged:   {
            recalcFromMissionValues()
        }
Don Gagne's avatar
Don Gagne committed
186 187
    }

188 189 190 191 192
    Column {
        id:                 editorColumn
        anchors.margins:    _margin
        anchors.top:        parent.top
        anchors.left:       parent.left
193
        anchors.right:      parent.right
194 195 196
        spacing:            _margin

        QGCLabel {
197 198 199
            wrapMode:       Text.WordWrap
            font.pointSize: ScreenTools.smallFontPointSize
            text:           qsTr("Work in progress, be careful!")
200 201
        }

202
        Repeater {
203
            model: [ missionItem.gridAngle, missionItem.gridSpacing, missionItem.gridAltitude, missionItem.turnaroundDist ]
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

            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
222 223
                    onEditingFinished: recalcFromMissionValues()
                    validator:      DoubleValidator{bottom:0.0; decimals:2}
224 225 226 227
                }
            }
        }

Don Gagne's avatar
Don Gagne committed
228 229
        QGCCheckBox {
            anchors.left:   parent.left
230
            text:           qsTr("Relative altitude")
Don Gagne's avatar
Don Gagne committed
231 232 233 234
            checked:        missionItem.gridAltitudeRelative
            onClicked:      missionItem.gridAltitudeRelative = checked
        }

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
        Grid {
            columns: 2
            columnSpacing:  ScreenTools.defaultFontPixelWidth
            rowSpacing:     _margin
            verticalItemAlignment: Grid.AlignVCenter

            QGCLabel {
                text: qsTr("GSD:")
                width:      _editFieldWidth
            }
            QGCTextField {
                id:         gsdField
                width:      _editFieldWidth
                unitsLabel: "cm/px"
                showUnits:  true
                onEditingFinished:  recalcFromCameraValues()
                validator:  DoubleValidator{bottom:0.0; decimals:2}
            }

            QGCLabel { text: qsTr("Frontal Overlap:") }
            QGCTextField {
                id:         frontalOverlapField
                width:      _editFieldWidth
                unitsLabel: "%"
                showUnits:  true
                onEditingFinished: recalcFromCameraValues()
                validator:  IntValidator {bottom:0}
            }

            QGCLabel { text: qsTr("Side Overlap:") }
            QGCTextField {
                id:         sideOverlapField
                width:      _editFieldWidth
                unitsLabel: "%"
                showUnits:  true
                onEditingFinished: recalcFromCameraValues()
                validator:  IntValidator {bottom:0}
            }

            Component.onCompleted: recalcFromMissionValues()
        }

Don Gagne's avatar
Don Gagne committed
277 278 279 280 281 282 283 284 285
        QGCLabel { text: qsTr("Camera:") }

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

286 287
        Grid {
            columns: 2
Don Gagne's avatar
Don Gagne committed
288
            spacing: ScreenTools.defaultFontPixelWidth
289
            verticalItemAlignment: Grid.AlignVCenter
Don Gagne's avatar
Don Gagne committed
290 291 292

            QGCRadioButton {
                id:             cameraOrientationLandscape
293
                width:          _editFieldWidth
Don Gagne's avatar
Don Gagne committed
294 295 296 297 298 299 300 301 302 303 304
                text:           "Landscape"
                checked:        true
                exclusiveGroup: cameraOrientationGroup
            }

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

Don Gagne's avatar
Don Gagne committed
305 306
            QGCCheckBox {
                id:         cameraTrigger
307
                width:      _editFieldWidth
Don Gagne's avatar
Don Gagne committed
308 309 310 311 312 313 314 315 316 317
                text:       qsTr("Trigger:")
                checked:    missionItem.cameraTrigger
                onClicked:  missionItem.cameraTrigger = checked
            }

            FactTextField {
                width:      _editFieldWidth
                showUnits:  true
                fact:       missionItem.cameraTriggerDistance
                enabled:    missionItem.cameraTrigger
318 319
                onEditingFinished: recalcFromMissionValues()
                validator:  DoubleValidator{bottom:0.0; decimals:2}
Don Gagne's avatar
Don Gagne committed
320
            }
321
        }
Don Gagne's avatar
Don Gagne committed
322

323 324
        Component {
            id: cameraFields
Don Gagne's avatar
Don Gagne committed
325

326
            QGCViewDialog {
Don Gagne's avatar
Don Gagne committed
327

328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
                Column {
                    id:                 dialogColumn
                    anchors.margins:    _margin
                    anchors.top:        parent.top
                    anchors.left:       parent.left
                    anchors.right:      parent.right
                    spacing:            _margin * 5

                    Row {
                        spacing: ScreenTools.defaultFontPixelWidth

                        QGCLabel {
                            id:                 selectCameraModelText
                            text:               qsTr("Select Camera Model:")
                        }

                        QGCComboBox {
                            id:                 cameraModelCombo
                            model:              cameraModelList
                            width:              dialogColumn.width - selectCameraModelText.width - ScreenTools.defaultFontPixelWidth

                            onActivated: {
                                cameraIndex = index
                            }

                            Component.onCompleted: {
                                var index = cameraIndex
                                if (index === -1) {
                                    console.warn("Active camera model name not in combo", cameraIndex)
                                } else {
                                    cameraModelCombo.currentIndex = index
                                }
                            }
                        }
                    }

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

                        QGCLabel { text: qsTr("Sensor Width:") }
                        QGCTextField {
                            id:                 sensorWidthField
                            unitsLabel:         "mm"
                            showUnits:          true
                            text:               cameraModelList.get(cameraIndex).sensorWidth.toFixed(2)
                            readOnly:           cameraIndex != 0
                            enabled:            cameraIndex == 0
                            validator:          DoubleValidator{bottom:0.0; decimals:2}
                            onEditingFinished:  {
                                if (cameraIndex == 0) {
                                    cameraModelList.setProperty(cameraIndex, "sensorWidth", Number(text))
                                }
                            }
                        }

                        QGCLabel { text: qsTr("Sensor Height:") }
                        QGCTextField {
                            id:                 sensorHeightField
                            unitsLabel:         "mm"
                            showUnits:          true
                            text:               cameraModelList.get(cameraIndex).sensorHeight.toFixed(2)
                            readOnly:           cameraIndex != 0
                            enabled:            cameraIndex == 0
                            validator:          DoubleValidator{bottom:0.0; decimals:2}
                            onEditingFinished:  {
                                if (cameraIndex == 0) {
                                    cameraModelList.setProperty(cameraIndex, "sensorHeight", Number(text))
                                }
                            }
                        }

                        QGCLabel { text: qsTr("Image Width:") }
                        QGCTextField {
                            id:                 imageWidthField
                            unitsLabel:         "px"
                            showUnits:          true
                            text:               cameraModelList.get(cameraIndex).imageWidth.toFixed(0)
                            readOnly:           cameraIndex != 0
                            enabled:            cameraIndex == 0
                            validator:          IntValidator {bottom:0}
                            onEditingFinished:  {
                                if (cameraIndex == 0) {
                                    cameraModelList.setProperty(cameraIndex, "imageWidth", Number(text))
                                }
                            }
                        }

                        QGCLabel { text: qsTr("Image Height:") }
                        QGCTextField {
                            id:                 imageHeightField
                            unitsLabel:         "px"
                            showUnits:          true
                            text:               cameraModelList.get(cameraIndex).imageHeight.toFixed(0)
                            readOnly:           cameraIndex != 0
                            enabled:            cameraIndex == 0
                            validator:          IntValidator {bottom:0}
                            onEditingFinished:  {
                                if (cameraIndex == 0) {
                                    cameraModelList.setProperty(cameraIndex, "imageHeight", Number(text))
                                }
                            }
                        }

                        QGCLabel { text: qsTr("Focal Length:") }
                        QGCTextField {
                            id:                 focalLengthField
                            unitsLabel:         "mm"
                            showUnits:          true
                            text:               cameraModelList.get(cameraIndex).focalLength.toFixed(2)
                            readOnly:           cameraIndex != 0
                            enabled:            cameraIndex == 0
                            validator:          DoubleValidator{bottom:0.0; decimals:2}
                            onEditingFinished:  {
                                if (cameraIndex == 0) {
                                    cameraModelList.setProperty(cameraIndex, "focalLength", Number(text))
                                }
                            }
                        }
                    }
                }
Don Gagne's avatar
Don Gagne committed
450

451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
                function accept() {
                    hideDialog()
                    recalcFromCameraValues()
                }
            }//QGCViewDialog
        }//Component

        Column {
            spacing: ScreenTools.defaultFontPixelHeight*0.01

            Row {
                spacing: ScreenTools.defaultFontPixelWidth

                QGCLabel { text: qsTr("Model:") }
                QGCLabel { text: cameraModelList.get(cameraIndex).text }
Don Gagne's avatar
Don Gagne committed
466 467
            }

468 469 470 471
            Grid {
                columns: 2
                columnSpacing: ScreenTools.defaultFontPixelWidth
                rowSpacing: ScreenTools.defaultFontPixelHeight*0.01
Don Gagne's avatar
Don Gagne committed
472

473 474 475 476 477 478 479 480 481 482 483 484 485 486
                QGCLabel {
                    text: qsTr("Sensor Size:")
                    width: _editFieldWidth
                }
                QGCLabel {
                    text: cameraModelList.get(cameraIndex).sensorWidth.toFixed(2) + qsTr(" x ") +  cameraModelList.get(cameraIndex).sensorHeight.toFixed(2)
                    width: _editFieldWidth
                }

                QGCLabel { text: qsTr("Image Size:") }
                QGCLabel { text: cameraModelList.get(cameraIndex).imageWidth.toFixed(0) + qsTr(" x ") +  cameraModelList.get(cameraIndex).imageHeight.toFixed(0) }

                QGCLabel { text: qsTr("Focal length:") }
                QGCLabel { text: cameraModelList.get(cameraIndex).focalLength.toFixed(2) }
Don Gagne's avatar
Don Gagne committed
487
            }
488
        }
Don Gagne's avatar
Don Gagne committed
489

490 491 492
        QGCButton {
            id:         cameraModelChange
            text:       qsTr("Change")
Don Gagne's avatar
Don Gagne committed
493

494 495
            onClicked: {
                qgcView.showDialog(cameraFields, qsTr("Set Camera Model"), qgcView.showDialogDefaultWidth, StandardButton.Save)
Don Gagne's avatar
Don Gagne committed
496 497 498
            }
        }

499

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

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
        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 {
521
                        editorMap.polygonDraw.startCapturePolygon(_root)
522
                    }
523 524 525
                }
            }

526 527 528
            QGCButton {
                text:       editorMap.polygonDraw.adjustingPolygon ? qsTr("Finish Adjust") : qsTr("Adjust")
                visible:    missionItem.polygonPath.length > 0 && !editorMap.polygonDraw.drawingPolygon
529

530 531 532 533
                onClicked: {
                    if (editorMap.polygonDraw.adjustingPolygon) {
                        editorMap.polygonDraw.finishAdjustPolygon()
                    } else {
534
                        editorMap.polygonDraw.startAdjustPolygon(_root, missionItem.polygonPath)
535
                    }
536 537 538
                }
            }
        }
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

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