WaypointView.cc 19.2 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
/*===================================================================
pixhawk's avatar
pixhawk committed
2 3 4 5 6 7 8 9
======================================================================*/

/**
 * @file
 *   @brief Displays one waypoint
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *   @author Benjamin Knecht <mavteam@student.ethz.ch>
10
 *   @author Petri Tanskanen <mavteam@student.ethz.ch>
pixhawk's avatar
pixhawk committed
11 12 13 14 15 16
 *
 */

#include <QDoubleSpinBox>
#include <QDebug>

17 18
#include <cmath>
#include <qmath.h>
pixhawk's avatar
pixhawk committed
19

pixhawk's avatar
pixhawk committed
20 21
#include "WaypointView.h"
#include "ui_WaypointView.h"
22
#include "ui_QGCCustomWaypointAction.h"
pixhawk's avatar
pixhawk committed
23 24

WaypointView::WaypointView(Waypoint* wp, QWidget* parent) :
25 26 27 28
    QWidget(parent),
    customCommand(new Ui_QGCCustomWaypointAction),
    viewMode(QGC_WAYPOINTVIEW_MODE_NAV),
    m_ui(new Ui::WaypointView)
pixhawk's avatar
pixhawk committed
29 30 31 32
{
    m_ui->setupUi(this);

    this->wp = wp;
pixhawk's avatar
pixhawk committed
33
    connect(wp, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*)));
34

35 36 37
    // CUSTOM COMMAND WIDGET
    customCommand->setupUi(m_ui->customActionWidget);

38
    // add actions
39 40 41 42 43 44 45
    m_ui->comboBox_action->addItem(tr("NAV: Waypoint"),MAV_CMD_NAV_WAYPOINT);
    m_ui->comboBox_action->addItem(tr("NAV: TakeOff"),MAV_CMD_NAV_TAKEOFF);
    m_ui->comboBox_action->addItem(tr("NAV: Loiter Unlim."),MAV_CMD_NAV_LOITER_UNLIM);
    m_ui->comboBox_action->addItem(tr("NAV: Loiter Time"),MAV_CMD_NAV_LOITER_TIME);
    m_ui->comboBox_action->addItem(tr("NAV: Loiter Turns"),MAV_CMD_NAV_LOITER_TURNS);
    m_ui->comboBox_action->addItem(tr("NAV: Ret. to Launch"),MAV_CMD_NAV_RETURN_TO_LAUNCH);
    m_ui->comboBox_action->addItem(tr("NAV: Land"),MAV_CMD_NAV_LAND);
lm's avatar
lm committed
46 47 48 49
//    m_ui->comboBox_action->addItem(tr("NAV: Target"),MAV_CMD_NAV_TARGET);
    //m_ui->comboBox_action->addItem(tr("IF: Delay over"),MAV_CMD_CONDITION_DELAY);
    //m_ui->comboBox_action->addItem(tr("IF: Yaw angle is"),MAV_CMD_CONDITION_YAW);
    //m_ui->comboBox_action->addItem(tr("DO: Jump to Index"),MAV_CMD_DO_JUMP);
50
    m_ui->comboBox_action->addItem(tr("Other"), MAV_CMD_ENUM_END);
51

52
    // add frames
53 54 55
    m_ui->comboBox_frame->addItem("Abs. Alt/Global",MAV_FRAME_GLOBAL);
    m_ui->comboBox_frame->addItem("Rel. Alt/Global", MAV_FRAME_GLOBAL_RELATIVE_ALT);
    m_ui->comboBox_frame->addItem("Local/Abs. Alt.",MAV_FRAME_LOCAL);
56 57 58 59 60
    m_ui->comboBox_frame->addItem("Mission",MAV_FRAME_MISSION);

    // Initialize view correctly
    updateActionView(wp->getAction());
    updateFrameView(wp->getFrame());
61

pixhawk's avatar
pixhawk committed
62
    // Read values and set user interface
63
    updateValues();
pixhawk's avatar
pixhawk committed
64

65
    // Check for mission frame
66
    if (wp->getFrame() == MAV_FRAME_MISSION) {
67 68 69
        m_ui->comboBox_action->setCurrentIndex(m_ui->comboBox_action->count()-1);
    }

70 71 72 73
    connect(m_ui->posNSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setX(double)));
    connect(m_ui->posESpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setY(double)));
    connect(m_ui->posDSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setZ(double)));

74 75 76
    connect(m_ui->latSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setLatitude(double)));
    connect(m_ui->lonSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setLongitude(double)));
    connect(m_ui->altSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setAltitude(double)));
lm's avatar
lm committed
77
    connect(m_ui->yawSpinBox, SIGNAL(valueChanged(int)), wp, SLOT(setYaw(int)));
pixhawk's avatar
pixhawk committed
78 79 80 81 82

    connect(m_ui->upButton, SIGNAL(clicked()), this, SLOT(moveUp()));
    connect(m_ui->downButton, SIGNAL(clicked()), this, SLOT(moveDown()));
    connect(m_ui->removeButton, SIGNAL(clicked()), this, SLOT(remove()));

pixhawk's avatar
pixhawk committed
83 84
    connect(m_ui->autoContinue, SIGNAL(stateChanged(int)), this, SLOT(changedAutoContinue(int)));
    connect(m_ui->selectedBox, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
85 86
    connect(m_ui->comboBox_action, SIGNAL(activated(int)), this, SLOT(changedAction(int)));
    connect(m_ui->comboBox_frame, SIGNAL(activated(int)), this, SLOT(changedFrame(int)));
pixhawk's avatar
pixhawk committed
87

88 89
    connect(m_ui->orbitSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setLoiterOrbit(double)));
    connect(m_ui->acceptanceSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setAcceptanceRadius(double)));
lm's avatar
lm committed
90
    connect(m_ui->holdTimeSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setHoldTime(double)));
91
    connect(m_ui->turnsSpinBox, SIGNAL(valueChanged(int)), wp, SLOT(setTurns(int)));
92
    connect(m_ui->takeOffAngleSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam1(double)));
93 94 95 96 97 98 99

    // Connect actions
    connect(customCommand->commandSpinBox, SIGNAL(valueChanged(int)),   wp, SLOT(setAction(int)));
    connect(customCommand->param1SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam1(double)));
    connect(customCommand->param2SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam2(double)));
    connect(customCommand->param3SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam3(double)));
    connect(customCommand->param4SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam4(double)));
100 101
    connect(customCommand->param5SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam5(double)));
    connect(customCommand->param6SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam6(double)));
lm's avatar
lm committed
102
    connect(customCommand->param7SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam7(double)));
pixhawk's avatar
pixhawk committed
103 104
}

pixhawk's avatar
pixhawk committed
105 106 107 108 109 110 111 112 113 114
void WaypointView::moveUp()
{
    emit moveUpWaypoint(wp);
}

void WaypointView::moveDown()
{
    emit moveDownWaypoint(wp);
}

Alejandro's avatar
Alejandro committed
115

pixhawk's avatar
pixhawk committed
116 117 118
void WaypointView::remove()
{
    emit removeWaypoint(wp);
119
    deleteLater();
pixhawk's avatar
pixhawk committed
120 121
}

pixhawk's avatar
pixhawk committed
122
void WaypointView::changedAutoContinue(int state)
pixhawk's avatar
pixhawk committed
123 124
{
    if (state == 0)
125
        wp->setAutocontinue(false);
pixhawk's avatar
pixhawk committed
126
    else
127
        wp->setAutocontinue(true);
pixhawk's avatar
pixhawk committed
128 129
}

130
void WaypointView::updateActionView(int action)
131 132
{
    // expose ui based on action
133

134
    switch(action) {
135
    case MAV_CMD_NAV_TAKEOFF:
136 137 138 139 140 141 142
        m_ui->orbitSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
143 144
        m_ui->takeOffAngleSpinBox->show();
        break;
145
    case MAV_CMD_NAV_LAND:
146 147 148 149 150 151 152 153 154
        m_ui->orbitSpinBox->hide();
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
        break;
155
    case MAV_CMD_NAV_RETURN_TO_LAUNCH:
156 157 158 159 160 161 162 163
        m_ui->orbitSpinBox->hide();
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
164
        break;
165
    case MAV_CMD_NAV_WAYPOINT:
166 167 168
        m_ui->orbitSpinBox->hide();
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->turnsSpinBox->hide();
lm's avatar
lm committed
169
        m_ui->holdTimeSpinBox->show();
170 171
        m_ui->customActionWidget->hide();

172
        m_ui->autoContinue->show();
173 174
        m_ui->acceptanceSpinBox->show();
        m_ui->yawSpinBox->show();
175
        break;
176
    case MAV_CMD_NAV_LOITER_UNLIM:
177 178 179 180 181 182 183 184 185
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
        m_ui->orbitSpinBox->show();
        break;
186
    case MAV_CMD_NAV_LOITER_TURNS:
187 188 189 190 191 192 193 194 195
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
        m_ui->orbitSpinBox->show();
        m_ui->turnsSpinBox->show();
        break;
196
    case MAV_CMD_NAV_LOITER_TIME:
197 198 199 200 201 202
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
203 204 205
        m_ui->orbitSpinBox->show();
        m_ui->holdTimeSpinBox->show();
        break;
LM's avatar
LM committed
206 207 208 209 210 211 212 213 214 215 216
//    case MAV_CMD_NAV_ORIENTATION_TARGET:
//        m_ui->orbitSpinBox->hide();
//        m_ui->takeOffAngleSpinBox->hide();
//        m_ui->turnsSpinBox->hide();
//        m_ui->holdTimeSpinBox->show();
//        m_ui->customActionWidget->hide();

//        m_ui->autoContinue->show();
//        m_ui->acceptanceSpinBox->hide();
//        m_ui->yawSpinBox->hide();
//        break;
217
    default:
218
        break;
219 220 221
    }
}

222 223 224 225
/**
 * @param index The index of the combo box of the action entry, NOT the action ID
 */
void WaypointView::changedAction(int index)
226 227
{
    // set waypoint action
228
    int actionIndex = m_ui->comboBox_action->itemData(index).toUInt();
229
    if (actionIndex < MAV_CMD_ENUM_END && actionIndex >= 0) {
230
        MAV_CMD action = (MAV_CMD) actionIndex;
231 232 233 234 235 236 237
        wp->setAction(action);
    }

    // Expose ui based on action
    // Change to mission frame
    // if action is unknown

238
    switch(actionIndex) {
239 240 241 242 243 244 245
    case MAV_CMD_NAV_TAKEOFF:
    case MAV_CMD_NAV_LAND:
    case MAV_CMD_NAV_RETURN_TO_LAUNCH:
    case MAV_CMD_NAV_WAYPOINT:
    case MAV_CMD_NAV_LOITER_UNLIM:
    case MAV_CMD_NAV_LOITER_TURNS:
    case MAV_CMD_NAV_LOITER_TIME:
246 247 248
        changeViewMode(QGC_WAYPOINTVIEW_MODE_NAV);
        // Update frame view
        updateFrameView(m_ui->comboBox_frame->currentIndex());
249 250
        // Update view
        updateActionView(actionIndex);
251
        break;
252
    case MAV_CMD_ENUM_END:
253 254
    default:
        // Switch to mission frame
255
        changeViewMode(QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING);
256 257 258
        break;
    }
}
259

260
void WaypointView::changeViewMode(QGC_WAYPOINTVIEW_MODE mode)
261
{
lm's avatar
lm committed
262
    viewMode = mode;
263
    switch (mode) {
264
    case QGC_WAYPOINTVIEW_MODE_NAV:
265 266 267 268
    case QGC_WAYPOINTVIEW_MODE_CONDITION:
        // Hide everything, show condition widget
        // TODO
    case QGC_WAYPOINTVIEW_MODE_DO:
269

270
        break;
271
    case QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING:
272 273 274 275 276 277 278 279 280 281 282 283 284 285
        // Hide almost everything
        m_ui->orbitSpinBox->hide();
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->posDSpinBox->hide();
        m_ui->posESpinBox->hide();
        m_ui->posNSpinBox->hide();
        m_ui->latSpinBox->hide();
        m_ui->lonSpinBox->hide();
        m_ui->altSpinBox->hide();

lm's avatar
lm committed
286 287 288
        int action_index = m_ui->comboBox_action->findData(MAV_CMD_ENUM_END);
        m_ui->comboBox_action->setCurrentIndex(action_index);

289
        // Show action widget
290
        if (!m_ui->customActionWidget->isVisible()) {
291 292
            m_ui->customActionWidget->show();
        }
293
        if (!m_ui->autoContinue->isVisible()) {
294 295
            m_ui->autoContinue->show();
        }
296
        break;
297
    }
lm's avatar
lm committed
298

299 300 301 302
}

void WaypointView::updateFrameView(int frame)
{
303
    switch(frame) {
304
    case MAV_FRAME_GLOBAL:
305
    case MAV_FRAME_GLOBAL_RELATIVE_ALT:
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
        m_ui->posNSpinBox->hide();
        m_ui->posESpinBox->hide();
        m_ui->posDSpinBox->hide();
        m_ui->lonSpinBox->show();
        m_ui->latSpinBox->show();
        m_ui->altSpinBox->show();
        // Coordinate frame
        m_ui->comboBox_frame->show();
        m_ui->customActionWidget->hide();
        break;
    case MAV_FRAME_LOCAL:
        m_ui->lonSpinBox->hide();
        m_ui->latSpinBox->hide();
        m_ui->altSpinBox->hide();
        m_ui->posNSpinBox->show();
        m_ui->posESpinBox->show();
        m_ui->posDSpinBox->show();
        // Coordinate frame
        m_ui->comboBox_frame->show();
        m_ui->customActionWidget->hide();
        break;
327 328 329 330 331
    default:
        std::cerr << "unknown frame" << std::endl;
    }
}

pixhawk's avatar
pixhawk committed
332 333
void WaypointView::deleted(QObject* waypoint)
{
334
    Q_UNUSED(waypoint);
lm's avatar
lm committed
335 336 337 338
//    if (waypoint == this->wp)
//    {
//        deleteLater();
//    }
pixhawk's avatar
pixhawk committed
339 340
}

341 342 343 344 345 346 347 348 349
void WaypointView::changedFrame(int index)
{
    // set waypoint action
    MAV_FRAME frame = (MAV_FRAME)m_ui->comboBox_frame->itemData(index).toUInt();
    wp->setFrame(frame);

    updateFrameView(frame);
}

pixhawk's avatar
pixhawk committed
350
void WaypointView::changedCurrent(int state)
pixhawk's avatar
pixhawk committed
351
{
352
    if (state == 0) {
pixhawk's avatar
pixhawk committed
353 354 355
        m_ui->selectedBox->setChecked(true);
        m_ui->selectedBox->setCheckState(Qt::Checked);
        wp->setCurrent(false);
356
    } else {
pixhawk's avatar
pixhawk committed
357
        wp->setCurrent(true);
358
        emit changeCurrentWaypoint(wp->getId());   //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
pixhawk's avatar
pixhawk committed
359
    }
pixhawk's avatar
pixhawk committed
360 361
}

362 363
void WaypointView::updateValues()
{
pixhawk's avatar
pixhawk committed
364 365
    // Check if we just lost the wp, delete the widget
    // accordingly
366
    if (!wp) {
pixhawk's avatar
pixhawk committed
367 368 369
        deleteLater();
        return;
    }
370 371
    // Deactivate signals from the WP
    wp->blockSignals(true);
372 373
    // update frame
    MAV_FRAME frame = wp->getFrame();
374
    int frame_index = m_ui->comboBox_frame->findData(frame);
375
    if (m_ui->comboBox_frame->currentIndex() != frame_index) {
376
        m_ui->comboBox_frame->setCurrentIndex(frame_index);
377
        updateFrameView(frame);
378
    }
379 380 381 382
    switch(frame) {
    case MAV_FRAME_LOCAL: {
        if (m_ui->posNSpinBox->value() != wp->getX()) {
            m_ui->posNSpinBox->setValue(wp->getX());
pixhawk's avatar
pixhawk committed
383
        }
384 385 386 387 388 389 390 391
        if (m_ui->posESpinBox->value() != wp->getY()) {
            m_ui->posESpinBox->setValue(wp->getY());
        }
        if (m_ui->posDSpinBox->value() != wp->getZ()) {
            m_ui->posDSpinBox->setValue(wp->getZ());
        }
    }
    break;
392
    case MAV_FRAME_GLOBAL:
393
    case MAV_FRAME_GLOBAL_RELATIVE_ALT: {
394 395 396 397 398 399
        if (m_ui->latSpinBox->value() != wp->getLatitude()) {
            // Rounding might occur, prevent spin box from
            // firing back changes
            m_ui->latSpinBox->blockSignals(true);
            m_ui->latSpinBox->setValue(wp->getLatitude());
            m_ui->latSpinBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
400
        }
401 402 403 404 405 406
        if (m_ui->lonSpinBox->value() != wp->getLongitude()) {
            // Rounding might occur, prevent spin box from
            // firing back changes
            m_ui->lonSpinBox->blockSignals(true);
            m_ui->lonSpinBox->setValue(wp->getLongitude());
            m_ui->lonSpinBox->blockSignals(false);
407
        }
408 409 410 411 412 413
        if (m_ui->altSpinBox->value() != wp->getAltitude()) {
            // Rounding might occur, prevent spin box from
            // firing back changes
            m_ui->altSpinBox->blockSignals(true);
            m_ui->altSpinBox->setValue(wp->getAltitude());
            m_ui->altSpinBox->blockSignals(false);
414 415 416
        }
    }
    break;
417 418
    default:
        // Do nothing
419
        break;
420 421
    }

422
    // Update action
423
    MAV_CMD action = wp->getAction();
424
    int action_index = m_ui->comboBox_action->findData(action);
425
    // Set to "Other" action if it was -1
426
    if (action_index == -1) {
427
        action_index = m_ui->comboBox_action->findData(MAV_CMD_ENUM_END);
428 429
    }
    // Only update if changed
430
    if (m_ui->comboBox_action->currentIndex() != action_index) {
431
        // If action is unknown, set direct editing mode
432
        if (wp->getAction() < 0 || wp->getAction() > MAV_CMD_NAV_TAKEOFF) {
433
            changeViewMode(QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING);
434 435
        } else {
            if (viewMode != QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING) {
lm's avatar
lm committed
436 437 438 439
                // Action ID known, update
                m_ui->comboBox_action->setCurrentIndex(action_index);
                updateActionView(action);
            }
440
        }
pixhawk's avatar
pixhawk committed
441
    }
442 443 444 445 446 447 448 449 450 451 452 453 454
    // Do something on actions - currently unused
//    switch(action) {
//    case MAV_CMD_NAV_TAKEOFF:
//        break;
//    case MAV_CMD_NAV_LAND:
//        break;
//    case MAV_CMD_NAV_WAYPOINT:
//        break;
//    case MAV_CMD_NAV_LOITER_UNLIM:
//        break;
//    default:
//        std::cerr << "unknown action" << std::endl;
//    }
455

456
    if (m_ui->yawSpinBox->value() != wp->getYaw()) {
lm's avatar
lm committed
457
        if (!m_ui->yawSpinBox->isVisible()) m_ui->yawSpinBox->blockSignals(true);
lm's avatar
lm committed
458
        m_ui->yawSpinBox->setValue(wp->getYaw());
lm's avatar
lm committed
459
        if (!m_ui->yawSpinBox->isVisible()) m_ui->yawSpinBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
460
    }
461
    if (m_ui->selectedBox->isChecked() != wp->getCurrent()) {
pixhawk's avatar
pixhawk committed
462 463
        m_ui->selectedBox->setChecked(wp->getCurrent());
    }
464
    if (m_ui->autoContinue->isChecked() != wp->getAutoContinue()) {
pixhawk's avatar
pixhawk committed
465 466
        m_ui->autoContinue->setChecked(wp->getAutoContinue());
    }
pixhawk's avatar
pixhawk committed
467
    m_ui->idLabel->setText(QString("%1").arg(wp->getId()));
468
    if (m_ui->orbitSpinBox->value() != wp->getLoiterOrbit()) {
lm's avatar
lm committed
469
        if (!m_ui->orbitSpinBox->isVisible()) m_ui->orbitSpinBox->blockSignals(true);
470
        m_ui->orbitSpinBox->setValue(wp->getLoiterOrbit());
lm's avatar
lm committed
471
        if (!m_ui->orbitSpinBox->isVisible()) m_ui->orbitSpinBox->blockSignals(false);
472
    }
473
    if (m_ui->acceptanceSpinBox->value() != wp->getAcceptanceRadius()) {
lm's avatar
lm committed
474
        if (!m_ui->acceptanceSpinBox->isVisible()) m_ui->acceptanceSpinBox->blockSignals(true);
475
        m_ui->acceptanceSpinBox->setValue(wp->getAcceptanceRadius());
lm's avatar
lm committed
476
        if (!m_ui->acceptanceSpinBox->isVisible()) m_ui->acceptanceSpinBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
477
    }
478
    if (m_ui->holdTimeSpinBox->value() != wp->getHoldTime()) {
lm's avatar
lm committed
479
        if (!m_ui->holdTimeSpinBox->isVisible()) m_ui->holdTimeSpinBox->blockSignals(true);
pixhawk's avatar
pixhawk committed
480
        m_ui->holdTimeSpinBox->setValue(wp->getHoldTime());
lm's avatar
lm committed
481
        if (!m_ui->holdTimeSpinBox->isVisible()) m_ui->holdTimeSpinBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
482
    }
483
    if (m_ui->turnsSpinBox->value() != wp->getTurns()) {
lm's avatar
lm committed
484
        if (!m_ui->turnsSpinBox->isVisible()) m_ui->turnsSpinBox->blockSignals(true);
485
        m_ui->turnsSpinBox->setValue(wp->getTurns());
lm's avatar
lm committed
486
        if (!m_ui->turnsSpinBox->isVisible()) m_ui->turnsSpinBox->blockSignals(false);
487
    }
488
    if (m_ui->takeOffAngleSpinBox->value() != wp->getParam1()) {
lm's avatar
lm committed
489
        if (!m_ui->takeOffAngleSpinBox->isVisible()) m_ui->takeOffAngleSpinBox->blockSignals(true);
490
        m_ui->takeOffAngleSpinBox->setValue(wp->getParam1());
lm's avatar
lm committed
491
        if (!m_ui->takeOffAngleSpinBox->isVisible()) m_ui->takeOffAngleSpinBox->blockSignals(false);
492
    }
493 494 495

    // UPDATE CUSTOM ACTION WIDGET

496
    if (customCommand->commandSpinBox->value() != wp->getAction()) {
497 498 499 500
        customCommand->commandSpinBox->setValue(wp->getAction());
        qDebug() << "Changed action";
    }
    // Param 1
501
    if (customCommand->param1SpinBox->value() != wp->getParam1()) {
502 503 504
        customCommand->param1SpinBox->setValue(wp->getParam1());
    }
    // Param 2
505
    if (customCommand->param2SpinBox->value() != wp->getParam2()) {
506 507 508
        customCommand->param2SpinBox->setValue(wp->getParam2());
    }
    // Param 3
509
    if (customCommand->param3SpinBox->value() != wp->getParam3()) {
510 511 512
        customCommand->param3SpinBox->setValue(wp->getParam3());
    }
    // Param 4
513
    if (customCommand->param4SpinBox->value() != wp->getParam4()) {
514 515
        customCommand->param4SpinBox->setValue(wp->getParam4());
    }
516
    // Param 5
517
    if (customCommand->param5SpinBox->value() != wp->getParam5()) {
518 519 520
        customCommand->param5SpinBox->setValue(wp->getParam5());
    }
    // Param 6
521
    if (customCommand->param6SpinBox->value() != wp->getParam6()) {
522 523
        customCommand->param6SpinBox->setValue(wp->getParam6());
    }
lm's avatar
lm committed
524
    // Param 7
525
    if (customCommand->param7SpinBox->value() != wp->getParam7()) {
lm's avatar
lm committed
526 527
        customCommand->param7SpinBox->setValue(wp->getParam7());
    }
528

529
    wp->blockSignals(false);
530 531
}

pixhawk's avatar
pixhawk committed
532
void WaypointView::setCurrent(bool state)
pixhawk's avatar
pixhawk committed
533
{
534
    m_ui->selectedBox->blockSignals(true);
535
    m_ui->selectedBox->setChecked(state);
536
    m_ui->selectedBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
}

WaypointView::~WaypointView()
{
    delete m_ui;
}

void WaypointView::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}