WaypointEditableView.cc 27.4 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

20 21
#include "WaypointEditableView.h"
#include "ui_WaypointEditableView.h"
22
#include "ui_QGCCustomWaypointAction.h"
23
#include "ui_QGCMissionDoWidget.h"
pixhawk's avatar
pixhawk committed
24

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

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

37 38
    // CUSTOM COMMAND WIDGET
    customCommand->setupUi(m_ui->customActionWidget);
39 40 41 42
    // DO COMMAND WIDGET
    //doCommand->setupUi(m_ui->customActionWidget);


43
    // add actions
44 45 46 47 48 49 50
    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);
51
    //m_ui->comboBox_action->addItem(tr("NAV: Target"),MAV_CMD_NAV_TARGET);
lm's avatar
lm committed
52 53 54
    //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);
55
    m_ui->comboBox_action->addItem(tr("Other"), MAV_CMD_ENUM_END);
56

57
    // add frames
58 59 60
    m_ui->comboBox_frame->addItem("Global/Abs. Alt",MAV_FRAME_GLOBAL);
    m_ui->comboBox_frame->addItem("Global/Rel. Alt", MAV_FRAME_GLOBAL_RELATIVE_ALT);
    m_ui->comboBox_frame->addItem("Local(NED)",MAV_FRAME_LOCAL_NED);
61 62 63 64 65
    m_ui->comboBox_frame->addItem("Mission",MAV_FRAME_MISSION);

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

pixhawk's avatar
pixhawk committed
67
    // Read values and set user interface
68
    updateValues();
pixhawk's avatar
pixhawk committed
69

70
    // Check for mission frame
71 72
    if (wp->getFrame() == MAV_FRAME_MISSION)
    {
73 74 75
        m_ui->comboBox_action->setCurrentIndex(m_ui->comboBox_action->count()-1);
    }

76 77 78 79
    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)));

80 81 82
    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
83
    connect(m_ui->yawSpinBox, SIGNAL(valueChanged(int)), wp, SLOT(setYaw(int)));
pixhawk's avatar
pixhawk committed
84 85 86 87 88

    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
89 90
    connect(m_ui->autoContinue, SIGNAL(stateChanged(int)), this, SLOT(changedAutoContinue(int)));
    connect(m_ui->selectedBox, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
91 92
    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
93

94 95
    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
96
    connect(m_ui->holdTimeSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setHoldTime(double)));
97
    connect(m_ui->turnsSpinBox, SIGNAL(valueChanged(int)), wp, SLOT(setTurns(int)));
98
    connect(m_ui->takeOffAngleSpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam1(double)));
99 100 101 102 103 104 105

    // 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)));
106 107
    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
108
    connect(customCommand->param7SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam7(double)));
pixhawk's avatar
pixhawk committed
109 110
}

111
void WaypointEditableView::moveUp()
pixhawk's avatar
pixhawk committed
112 113 114 115
{
    emit moveUpWaypoint(wp);
}

116
void WaypointEditableView::moveDown()
pixhawk's avatar
pixhawk committed
117 118 119 120
{
    emit moveDownWaypoint(wp);
}

Alejandro's avatar
Alejandro committed
121

122
void WaypointEditableView::remove()
pixhawk's avatar
pixhawk committed
123 124
{
    emit removeWaypoint(wp);
125
    deleteLater();
pixhawk's avatar
pixhawk committed
126 127
}

128
void WaypointEditableView::changedAutoContinue(int state)
pixhawk's avatar
pixhawk committed
129 130
{
    if (state == 0)
131
        wp->setAutocontinue(false);
pixhawk's avatar
pixhawk committed
132
    else
133
        wp->setAutocontinue(true);
pixhawk's avatar
pixhawk committed
134 135
}

136
void WaypointEditableView::updateActionView(int action)
137
{
138 139
    // Remove stretch item at index 17 (m_ui->removeSpacer)
    m_ui->horizontalLayout->takeAt(17);
140
    // expose ui based on action
141

142
    switch(action) {
143
    case MAV_CMD_NAV_TAKEOFF:
144 145 146 147 148 149 150
        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();
151 152
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
153
        m_ui->horizontalLayout->insertStretch(17, 82);
154 155
        m_ui->takeOffAngleSpinBox->show();
        break;
156
    case MAV_CMD_NAV_LAND:
157 158 159 160 161 162 163 164
        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();
165 166
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
167
        m_ui->horizontalLayout->insertStretch(17, 26);
168
        break;
169
    case MAV_CMD_NAV_RETURN_TO_LAUNCH:
170 171 172 173 174 175 176 177
        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();
178 179
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
180
        m_ui->horizontalLayout->insertStretch(17, 26);
181
        break;
182
    case MAV_CMD_NAV_WAYPOINT:
183 184 185
        m_ui->orbitSpinBox->hide();
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->turnsSpinBox->hide();
lm's avatar
lm committed
186
        m_ui->holdTimeSpinBox->show();
187
        m_ui->customActionWidget->hide();
188 189
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
190
        m_ui->horizontalLayout->insertStretch(17, 1);
191

192
        m_ui->autoContinue->show();
193 194
        m_ui->acceptanceSpinBox->show();
        m_ui->yawSpinBox->show();
195
        break;
196
    case MAV_CMD_NAV_LOITER_UNLIM:
197 198 199 200 201 202 203
        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();
204 205
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
206
        m_ui->horizontalLayout->insertStretch(17, 25);
207 208
        m_ui->orbitSpinBox->show();
        break;
209
    case MAV_CMD_NAV_LOITER_TURNS:
210 211 212 213 214 215
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->holdTimeSpinBox->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
216 217
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
218
        m_ui->horizontalLayout->insertStretch(17, 20);
219 220 221
        m_ui->orbitSpinBox->show();
        m_ui->turnsSpinBox->show();
        break;
222
    case MAV_CMD_NAV_LOITER_TIME:
223 224 225 226 227 228
        m_ui->takeOffAngleSpinBox->hide();
        m_ui->yawSpinBox->hide();
        m_ui->turnsSpinBox->hide();
        m_ui->autoContinue->hide();
        m_ui->acceptanceSpinBox->hide();
        m_ui->customActionWidget->hide();
229 230
        m_ui->missionDoWidgetSlot->hide();
        m_ui->missionConditionWidgetSlot->hide();
231
        m_ui->horizontalLayout->insertStretch(17, 20);
232 233 234
        m_ui->orbitSpinBox->show();
        m_ui->holdTimeSpinBox->show();
        break;
LM's avatar
LM committed
235 236 237 238 239 240
//    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();
241 242
//        m_ui->missionDoWidgetSlot->hide();
//        m_ui->missionConditionWidgetSlot->hide();
LM's avatar
LM committed
243 244 245 246
//        m_ui->autoContinue->show();
//        m_ui->acceptanceSpinBox->hide();
//        m_ui->yawSpinBox->hide();
//        break;
247
    default:
248
        break;
249 250 251
    }
}

252 253 254
/**
 * @param index The index of the combo box of the action entry, NOT the action ID
 */
255
void WaypointEditableView::changedAction(int index)
256
{
257
    MAV_FRAME cur_frame = (MAV_FRAME) m_ui->comboBox_frame->itemData(m_ui->comboBox_frame->currentIndex()).toUInt();
258
    // set waypoint action
259
    int actionIndex = m_ui->comboBox_action->itemData(index).toUInt();
260
    if (actionIndex < MAV_CMD_ENUM_END && actionIndex >= 0) {
261
        MAV_CMD action = (MAV_CMD) actionIndex;
262 263 264 265 266 267 268
        wp->setAction(action);
    }

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

269
    switch(actionIndex) {
270 271 272 273 274 275 276
    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:
277
        changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_NAV);
278 279
        // Update frame view        
        updateFrameView(cur_frame);
280 281
        // Update view
        updateActionView(actionIndex);
282
        break;
283 284 285 286 287
    case MAV_CMD_DO_JUMP:
        {
            changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DO);
            break;
        }
288
    case MAV_CMD_ENUM_END:
289 290
    default:
        // Switch to mission frame
291
        changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING);
292 293 294
        break;
    }
}
295

296
void WaypointEditableView::changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE mode)
297
{
lm's avatar
lm committed
298
    viewMode = mode;
299
    switch (mode) {
300 301
    case QGC_WAYPOINTEDITABLEVIEW_MODE_NAV:
    case QGC_WAYPOINTEDITABLEVIEW_MODE_CONDITION:
302 303
        // Hide everything, show condition widget
        // TODO
304
        break;
305
    case QGC_WAYPOINTEDITABLEVIEW_MODE_DO:
306 307 308 309 310 311 312 313 314 315 316 317 318 319
    {
        // 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();
320

321 322 323 324 325 326 327
        // Show action widget
        if (!m_ui->missionDoWidgetSlot->isVisible()) {
            m_ui->missionDoWidgetSlot->show();
        }
        if (!m_ui->autoContinue->isVisible()) {
            m_ui->autoContinue->show();
        }
328
        break;
329
    }
330
    case QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING:
331 332 333 334 335 336 337 338 339 340 341 342 343 344
        // 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
345 346 347
        int action_index = m_ui->comboBox_action->findData(MAV_CMD_ENUM_END);
        m_ui->comboBox_action->setCurrentIndex(action_index);

348
        // Show action widget
349
        if (!m_ui->customActionWidget->isVisible()) {
350 351
            m_ui->customActionWidget->show();
        }
352
        if (!m_ui->autoContinue->isVisible()) {
353 354
            m_ui->autoContinue->show();
        }
355
        break;
356
    }
lm's avatar
lm committed
357

358 359
}

360
void WaypointEditableView::updateFrameView(int frame)
361
{    
362
    switch(frame) {
363
    case MAV_FRAME_GLOBAL:
364
    case MAV_FRAME_GLOBAL_RELATIVE_ALT:
365 366 367 368 369 370 371 372 373 374 375
        if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
        {
            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();
376 377
            m_ui->missionDoWidgetSlot->hide();
            m_ui->missionConditionWidgetSlot->hide();
378 379 380 381 382
        }
        else // do not hide customActionWidget if Command is set to "Other"
        {
            m_ui->customActionWidget->show();
        }
383
        break;
384
    case MAV_FRAME_LOCAL_NED:
385 386 387 388 389 390 391 392 393 394 395
        if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
        {
            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();
396 397
            m_ui->missionDoWidgetSlot->hide();
            m_ui->missionConditionWidgetSlot->hide();
398 399 400 401 402
        }
        else // do not hide customActionWidget if Command is set to "Other"
        {
            m_ui->customActionWidget->show();
        }
403
        break;
404 405 406 407 408
    default:
        std::cerr << "unknown frame" << std::endl;
    }
}

409
void WaypointEditableView::deleted(QObject* waypoint)
pixhawk's avatar
pixhawk committed
410
{
411
    Q_UNUSED(waypoint);
lm's avatar
lm committed
412 413 414 415
//    if (waypoint == this->wp)
//    {
//        deleteLater();
//    }
pixhawk's avatar
pixhawk committed
416 417
}

418
void WaypointEditableView::changedFrame(int index)
419 420 421 422 423 424 425 426
{
    // set waypoint action
    MAV_FRAME frame = (MAV_FRAME)m_ui->comboBox_frame->itemData(index).toUInt();
    wp->setFrame(frame);

    updateFrameView(frame);
}

427
void WaypointEditableView::changedCurrent(int state)
pixhawk's avatar
pixhawk committed
428
{
429
    //m_ui->selectedBox->blockSignals(true);
430 431 432 433
    if (state == 0)
    {
        if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current
        {
434
            //qDebug() << "Editable " << wp->getId() << " changedCurrent: State 0, current true" ;
435 436 437 438 439
            m_ui->selectedBox->setChecked(true);
            m_ui->selectedBox->setCheckState(Qt::Checked);
        }
        else
        {
440
            //qDebug() << "Editable " << wp->getId() << " changedCurrent: State 0, current false";
441 442
            m_ui->selectedBox->setChecked(false);
            m_ui->selectedBox->setCheckState(Qt::Unchecked);
443
            //wp->setCurrent(false);
444 445 446 447
        }
    }
    else
    {
448
        //qDebug() << "Editable " << wp->getId() << " changedCurrent: State 2";
pixhawk's avatar
pixhawk committed
449
        wp->setCurrent(true);
450
        emit changeCurrentWaypoint(wp->getId());   //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
pixhawk's avatar
pixhawk committed
451
    }
452
    //m_ui->selectedBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
453 454
}

455
void WaypointEditableView::updateValues()
456
{
pixhawk's avatar
pixhawk committed
457 458
    // Check if we just lost the wp, delete the widget
    // accordingly
459
    if (!wp) {
pixhawk's avatar
pixhawk committed
460 461 462
        deleteLater();
        return;
    }
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529

    //wp->blockSignals(true);

    // Deactivate all QDoubleSpinBox signals due to
    // unwanted rounding effects
    for (int j = 0; j  < children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(children().at(j));
        if (spin)
        {
            //qDebug() << "DEACTIVATED SPINBOX #" << j;
            spin->blockSignals(true);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QWidget* item = dynamic_cast<QWidget*>(children().at(j));
            if (item)
            {
                //qDebug() << "FOUND WIDGET BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                        //qDebug() << "DEACTIVATED SPINBOX #" << k;
                        spin->blockSignals(true);
                    }
                }
            }
        }
    }

    // Block all custom action widget actions
    for (int j = 0; j  < m_ui->customActionWidget->children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(m_ui->customActionWidget->children().at(j));
        if (spin)
        {
            //qDebug() << "DEACTIVATED SPINBOX #" << j;
            spin->blockSignals(true);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QWidget* item = dynamic_cast<QWidget*>(m_ui->customActionWidget->children().at(j));
            if (item)
            {
                //qDebug() << "CUSTOM ACTIONS FOUND WIDGET BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                        //qDebug() << "DEACTIVATED SPINBOX #" << k;
                        spin->blockSignals(true);
                    }
                }
            }
        }
    }


530 531
    // update frame
    MAV_FRAME frame = wp->getFrame();
532
    int frame_index = m_ui->comboBox_frame->findData(frame);
533
    if (m_ui->comboBox_frame->currentIndex() != frame_index) {
534
        m_ui->comboBox_frame->setCurrentIndex(frame_index);
535
        updateFrameView(frame);
536
    }
537
    switch(frame) {
538
    case MAV_FRAME_LOCAL_NED: {
539 540
        if (m_ui->posNSpinBox->value() != wp->getX()) {
            m_ui->posNSpinBox->setValue(wp->getX());
pixhawk's avatar
pixhawk committed
541
        }
542 543 544 545 546 547
        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());
        }
548
    }      
549
    break;
550
    case MAV_FRAME_GLOBAL:
551
    case MAV_FRAME_GLOBAL_RELATIVE_ALT: {
552 553 554 555
        if (m_ui->latSpinBox->value() != wp->getLatitude()) {
            // Rounding might occur, prevent spin box from
            // firing back changes
            m_ui->latSpinBox->setValue(wp->getLatitude());
pixhawk's avatar
pixhawk committed
556
        }
557 558 559 560
        if (m_ui->lonSpinBox->value() != wp->getLongitude()) {
            // Rounding might occur, prevent spin box from
            // firing back changes
            m_ui->lonSpinBox->setValue(wp->getLongitude());
561
        }
562 563 564 565
        if (m_ui->altSpinBox->value() != wp->getAltitude()) {
            // Rounding might occur, prevent spin box from
            // firing back changes
            m_ui->altSpinBox->setValue(wp->getAltitude());
566 567 568
        }
    }
    break;
569 570
    default:
        // Do nothing
571
        break;
572 573
    }

574
    // Update action
575
    MAV_CMD action = wp->getAction();
576
    int action_index = m_ui->comboBox_action->findData(action);
577
    // Set to "Other" action if it was -1
578 579
    if (action_index == -1)
    {
580
        action_index = m_ui->comboBox_action->findData(MAV_CMD_ENUM_END);
581 582
    }
    // Only update if changed
583 584
    if (m_ui->comboBox_action->currentIndex() != action_index)
    {
585
        // If action is unknown, set direct editing mode
586 587
        if (wp->getAction() < 0 || wp->getAction() > MAV_CMD_NAV_TAKEOFF)
        {
588
            changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING);
589 590 591
        }
        else
        {
592
            if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
593
            {
lm's avatar
lm committed
594 595
                // Action ID known, update
                m_ui->comboBox_action->setCurrentIndex(action_index);
596
                updateActionView(action);                
lm's avatar
lm committed
597
            }
598
        }
pixhawk's avatar
pixhawk committed
599
    }
600

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
//    // 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;
////    }

    if (m_ui->yawSpinBox->value() != wp->getYaw())
    {
lm's avatar
lm committed
617
        m_ui->yawSpinBox->setValue(wp->getYaw());
pixhawk's avatar
pixhawk committed
618
    }
619 620
    if (m_ui->selectedBox->isChecked() != wp->getCurrent())
    {
pixhawk's avatar
pixhawk committed
621 622
        m_ui->selectedBox->setChecked(wp->getCurrent());
    }
623 624
    if (m_ui->autoContinue->isChecked() != wp->getAutoContinue())
    {
pixhawk's avatar
pixhawk committed
625 626
        m_ui->autoContinue->setChecked(wp->getAutoContinue());
    }
pixhawk's avatar
pixhawk committed
627
    m_ui->idLabel->setText(QString("%1").arg(wp->getId()));
628 629
    if (m_ui->orbitSpinBox->value() != wp->getLoiterOrbit())
    {
630 631
        m_ui->orbitSpinBox->setValue(wp->getLoiterOrbit());
    }
632 633
    if (m_ui->acceptanceSpinBox->value() != wp->getAcceptanceRadius())
    {
634
        m_ui->acceptanceSpinBox->setValue(wp->getAcceptanceRadius());
pixhawk's avatar
pixhawk committed
635
    }
636 637
    if (m_ui->holdTimeSpinBox->value() != wp->getHoldTime())
    {
pixhawk's avatar
pixhawk committed
638 639
        m_ui->holdTimeSpinBox->setValue(wp->getHoldTime());
    }
640 641
    if (m_ui->turnsSpinBox->value() != wp->getTurns())
    {
642 643
        m_ui->turnsSpinBox->setValue(wp->getTurns());
    }
644 645
    if (m_ui->takeOffAngleSpinBox->value() != wp->getParam1())
    {
646 647
        m_ui->takeOffAngleSpinBox->setValue(wp->getParam1());
    }
648

649
//    // UPDATE CUSTOM ACTION WIDGET
650

651 652
    if (customCommand->commandSpinBox->value() != wp->getAction())
    {
653
        customCommand->commandSpinBox->setValue(wp->getAction());
654
        // qDebug() << "Changed action";
655 656
    }
    // Param 1
657
    if (customCommand->param1SpinBox->value() != wp->getParam1()) {
658 659 660
        customCommand->param1SpinBox->setValue(wp->getParam1());
    }
    // Param 2
661
    if (customCommand->param2SpinBox->value() != wp->getParam2()) {
662 663 664
        customCommand->param2SpinBox->setValue(wp->getParam2());
    }
    // Param 3
665
    if (customCommand->param3SpinBox->value() != wp->getParam3()) {
666 667 668
        customCommand->param3SpinBox->setValue(wp->getParam3());
    }
    // Param 4
669
    if (customCommand->param4SpinBox->value() != wp->getParam4()) {
670 671
        customCommand->param4SpinBox->setValue(wp->getParam4());
    }
672
    // Param 5
673
    if (customCommand->param5SpinBox->value() != wp->getParam5()) {
674 675 676
        customCommand->param5SpinBox->setValue(wp->getParam5());
    }
    // Param 6
677
    if (customCommand->param6SpinBox->value() != wp->getParam6()) {
678 679
        customCommand->param6SpinBox->setValue(wp->getParam6());
    }
lm's avatar
lm committed
680
    // Param 7
681
    if (customCommand->param7SpinBox->value() != wp->getParam7()) {
lm's avatar
lm committed
682 683
        customCommand->param7SpinBox->setValue(wp->getParam7());
    }
684

685 686 687 688 689 690 691 692
    QColor backGroundColor = QGC::colorBackground;

    static int lastId = -1;
    int currId = wp->getId() % 2;

    if (currId != lastId)
    {

693
        // qDebug() << "COLOR ID: " << currId;
694 695 696 697 698 699 700 701 702
        if (currId == 1)
        {
            //backGroundColor = backGroundColor.lighter(150);
            backGroundColor = QColor("#252528").lighter(150);
        }
        else
        {
            backGroundColor = QColor("#252528").lighter(250);
        }
703
        // qDebug() << "COLOR:" << backGroundColor.name();
704 705 706 707 708 709 710 711 712 713 714 715

        // Update color based on id
        QString groupBoxStyle = QString("QGroupBox {padding: 0px; margin: 0px; border: 0px; background-color: %1; }").arg(backGroundColor.name());
        QString labelStyle = QString("QWidget {background-color: %1; color: #DDDDDF; border-color: #EEEEEE; }").arg(backGroundColor.name());
        QString checkBoxStyle = QString("QCheckBox {background-color: %1; color: #454545; border-color: #EEEEEE; }").arg(backGroundColor.name());

        m_ui->autoContinue->setStyleSheet(checkBoxStyle);
        m_ui->selectedBox->setStyleSheet(checkBoxStyle);
        m_ui->idLabel->setStyleSheet(labelStyle);
        m_ui->groupBox->setStyleSheet(groupBoxStyle);
        lastId = currId;
    }
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780

    // Activate all QDoubleSpinBox signals due to
    // unwanted rounding effects
    for (int j = 0; j  < children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(children().at(j));
        if (spin)
        {
            //qDebug() << "ACTIVATED SPINBOX #" << j;
            spin->blockSignals(false);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QGroupBox* item = dynamic_cast<QGroupBox*>(children().at(j));
            if (item)
            {
                //qDebug() << "FOUND GROUP BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                        //qDebug() << "ACTIVATED SPINBOX #" << k;
                        spin->blockSignals(false);
                    }
                }
            }
        }
    }

    // Unblock all custom action widget actions
    for (int j = 0; j  < m_ui->customActionWidget->children().size(); ++j)
    {
        // Store only QGCToolWidgetItems
        QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(m_ui->customActionWidget->children().at(j));
        if (spin)
        {
            //qDebug() << "ACTIVATED SPINBOX #" << j;
            spin->blockSignals(false);
        }
        else
        {
            // Store only QGCToolWidgetItems
            QWidget* item = dynamic_cast<QWidget*>(m_ui->customActionWidget->children().at(j));
            if (item)
            {
                //qDebug() << "FOUND WIDGET BOX";
                for (int k = 0; k  < item->children().size(); ++k)
                {
                    // Store only QGCToolWidgetItems
                    QDoubleSpinBox* spin = dynamic_cast<QDoubleSpinBox*>(item->children().at(k));
                    if (spin)
                    {
                       //qDebug() << "ACTIVATED SPINBOX #" << k;
                        spin->blockSignals(false);
                    }
                }
            }
        }
    }

//    wp->blockSignals(false);
781 782
}

783
void WaypointEditableView::setCurrent(bool state)
pixhawk's avatar
pixhawk committed
784
{
785
    m_ui->selectedBox->blockSignals(true);
786
    m_ui->selectedBox->setChecked(state);
787
    m_ui->selectedBox->blockSignals(false);
pixhawk's avatar
pixhawk committed
788 789
}

790
WaypointEditableView::~WaypointEditableView()
pixhawk's avatar
pixhawk committed
791 792 793 794
{
    delete m_ui;
}

795
void WaypointEditableView::changeEvent(QEvent *e)
pixhawk's avatar
pixhawk committed
796 797 798 799 800 801 802 803 804
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}