WaypointViewOnlyView.cc 16.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <QDebug>
#include "WaypointViewOnlyView.h"
#include "ui_WaypointViewOnlyView.h"

WaypointViewOnlyView::WaypointViewOnlyView(Waypoint* wp, QWidget *parent) :
    QWidget(parent),
    m_ui(new Ui::WaypointViewOnlyView)
{
    m_ui->setupUi(this);
    this->wp = wp;
    updateValues();

    connect(m_ui->current, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
    connect(m_ui->autoContinue, SIGNAL(stateChanged(int)),this, SLOT(changedAutoContinue(int)));
}

void WaypointViewOnlyView::changedAutoContinue(int state)
18
{    
19 20 21 22 23
    bool new_value = false;
    if (state != 0)
    {
        new_value = true;
    }
24
    wp->setAutocontinue(new_value);    
25
    emit changeAutoContinue(wp->getId(),new_value);
26
}
27 28

void WaypointViewOnlyView::changedCurrent(int state)
29
//This is a slot receiving signals from QCheckBox m_ui->current. The state given here is whatever the user has clicked and not the true "current" value onboard.
30
{
31
    Q_UNUSED(state);
pixhawk's avatar
pixhawk committed
32
    //qDebug() << "Trof: WaypointViewOnlyView::changedCurrent(" << state << ") ID:" << wp->getId();
33
    m_ui->current->blockSignals(true);    
34

35 36 37
    if (m_ui->current->isChecked() == false)
    {
        if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current. Box stays checked
38 39
        {
            m_ui->current->setCheckState(Qt::Checked);
pixhawk's avatar
pixhawk committed
40
            //qDebug() << "Trof: WaypointViewOnlyView::changedCurrent. Rechecked true. stay true " << m_ui->current->isChecked();
41
        }
42
        else // Strange case, unchecking the box which was not checked to start with
43
        {
44
            m_ui->current->setCheckState(Qt::Unchecked);
pixhawk's avatar
pixhawk committed
45
            //qDebug() << "Trof: WaypointViewOnlyView::changedCurrent. Unchecked false. set false " << m_ui->current->isChecked();
46 47 48
        }
    }
    else
49 50 51
    {
        hightlightDesiredCurrent(true);
        m_ui->current->setCheckState(Qt::Unchecked);
pixhawk's avatar
pixhawk committed
52
        //qDebug() << "Trof: WaypointViewOnlyView::changedCurrent. Checked new. Sending set_current request to Manager " << m_ui->current->isChecked();
53
        emit changeCurrentWaypoint(wp->getId());   //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
54

55
    }
56
    m_ui->current->blockSignals(false);
57 58 59
}

void WaypointViewOnlyView::setCurrent(bool state)
60
//This is a slot receiving signals from UASWaypointManager. The state given here is the true representation of what the "current" waypoint on UAV is.
61
{
62 63 64 65 66 67 68 69 70 71 72 73 74
    m_ui->current->blockSignals(true);    
    if (state == true)
    {
        wp->setCurrent(true);
        hightlightDesiredCurrent(true);
        m_ui->current->setCheckState(Qt::Checked);
    }
    else
    {
        wp->setCurrent(false);
        hightlightDesiredCurrent(false);
        m_ui->current->setCheckState(Qt::Unchecked);
    }
75 76 77 78 79 80 81 82 83 84 85 86 87
    m_ui->current->blockSignals(false);
}

void WaypointViewOnlyView::updateValues()
{
    qDebug() << "Trof: WaypointViewOnlyView::updateValues() ID:" << wp->getId();
    // Check if we just lost the wp, delete the widget
    // accordingly
    if (!wp)
    {
        deleteLater();
        return;
    }
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

    // Update style

    QColor backGroundColor = QGC::colorBackground;

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

    if (currId != lastId)
    {

        // qDebug() << "COLOR ID: " << currId;
        if (currId == 1)
        {
            backGroundColor = QColor("#252528").lighter(150);
        }
        else
        {
            backGroundColor = QColor("#252528").lighter(250);
        }

        // Update color based on id
        QString groupBoxStyle = QString("QGroupBox {padding: 0px; margin: 0px; border: 0px; background-color: %1; min-height: 12px; }").arg(backGroundColor.name());
        QString labelStyle = QString("QWidget {background-color: %1; color: #DDDDDF; border-color: #EEEEEE; }").arg(backGroundColor.name());
        QString displayBarStyle = QString("QWidget {background-color: %1; color: #DDDDDF; border: none; }").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->current->setStyleSheet(checkBoxStyle);
        m_ui->idLabel->setStyleSheet(labelStyle);
        m_ui->displayBar->setStyleSheet(displayBarStyle);
        m_ui->groupBox->setStyleSheet(groupBoxStyle);
        lastId = currId;
    }

123 124 125
    // update frame

    m_ui->idLabel->setText(QString("%1").arg(wp->getId()));
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
    switch (wp->getFrame())
    {
    case MAV_FRAME_GLOBAL:
    {
        m_ui->frameLabel->setText(QString("GAA"));
        break;
    }
    case MAV_FRAME_LOCAL_NED:
    {
        m_ui->frameLabel->setText(QString("NED"));
        break;
    }
    case MAV_FRAME_MISSION:
    {
        m_ui->frameLabel->setText(QString("MIS"));
        break;
    }
    case MAV_FRAME_GLOBAL_RELATIVE_ALT:
    {
        m_ui->frameLabel->setText(QString("GRA"));
        break;
    }
    case MAV_FRAME_LOCAL_ENU:
    {
        m_ui->frameLabel->setText(QString("ENU"));
        break;
    }
    default:
    {
        m_ui->frameLabel->setText(QString(""));
        break;
    }
    }

160
    hightlightDesiredCurrent(wp->getCurrent());
161 162
    if (m_ui->current->isChecked() != wp->getCurrent())
    {
163
        m_ui->current->blockSignals(true);
164
        m_ui->current->setChecked(wp->getCurrent());        
165
        m_ui->current->blockSignals(false);
166 167 168
    }
    if (m_ui->autoContinue->isChecked() != wp->getAutoContinue())
    {
169
        m_ui->autoContinue->blockSignals(true);
170
        m_ui->autoContinue->setChecked(wp->getAutoContinue());
171
        m_ui->autoContinue->blockSignals(false);
172 173
    }

174 175 176
    switch (wp->getAction())
    {
    case MAV_CMD_NAV_WAYPOINT:
177
    {
178
        switch (wp->getFrame())
179
        {
180 181 182 183 184 185 186 187 188 189 190 191
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            if (wp->getParam1()>0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and wait there for %4 sec; yaw: %5; rad: %6").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam1()).arg(wp->getParam4()).arg(wp->getParam2()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>,lon <b>%2<sup>o</sup></b>,alt <b>%3)</b>; yaw: %4; rad: %5").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam4()).arg(wp->getParam2()));
            }
            break;
192
        }
193 194
        case MAV_FRAME_LOCAL_NED:
        default:
195
        {
196 197 198 199 200 201 202 203 204
            if (wp->getParam1()>0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and wait there for %4 sec; yaw: %5; rad: %6").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f',2).arg(wp->getParam1()).arg(wp->getParam4()).arg(wp->getParam2()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b>; yaw: %4; rad: %5").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam4()).arg(wp->getParam2()));
            }
            break;
205
        }
206
        } //end Frame switch
207 208
        break;
    }
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 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 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    case MAV_CMD_NAV_LOITER_UNLIM:
    {
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            if (wp->getParam3()>=0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and loiter there indefinitely (clockwise); rad: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam3()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and loiter there indefinitely (counter-clockwise); rad: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(-wp->getParam3()));
            }
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            if (wp->getParam3()>=0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there indefinitely (clockwise); rad: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f',2).arg(wp->getParam3()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there indefinitely (counter-clockwise); rad: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f', 2).arg(-wp->getParam3()));
            }
            break;
        }
        } //end Frame switch
        break;
    }
    case MAV_CMD_NAV_LOITER_TURNS:
    {
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            if (wp->getParam3()>=0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and loiter there for %5 turns (clockwise); rad: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam3()).arg(wp->getParam1()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and loiter there for %5 turns (counter-clockwise); rad: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
            }
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            if (wp->getParam3()>=0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5 turns (clockwise); rad: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f',2).arg(wp->getParam3()).arg(wp->getParam1()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5 turns (counter-clockwise); rad: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
            }
            break;
        }
        } //end Frame switch
        break;
    }
    case MAV_CMD_NAV_LOITER_TIME:
    {
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            if (wp->getParam3()>=0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and loiter there for %5s (clockwise); rad: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam3()).arg(wp->getParam1()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and loiter there for %5s (counter-clockwise); rad: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
            }
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            if (wp->getParam3()>=0)
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5s (clockwise); rad: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f',2).arg(wp->getParam3()).arg(wp->getParam1()));
            }
            else
            {
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5s (counter-clockwise); rad: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
            }
            break;
        }
        } //end Frame switch
        break;
    }
    case MAV_CMD_NAV_RETURN_TO_LAUNCH:
    {
        m_ui->displayBar->setText(QString("Return to launch location"));
        break;
    }
313
    case MAV_CMD_NAV_LAND:
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
    {        
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            m_ui->displayBar->setText(QString("LAND. Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b> and descent; yaw: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam4()));
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            m_ui->displayBar->setText(QString("LAND. Go to <b>(%1, %2, %3)</b> and descent; yaw: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam4()));
            break;
        }
        } //end Frame switch
330 331
        break;
    }
332
    case MAV_CMD_NAV_TAKEOFF:
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    {        
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            m_ui->displayBar->setText(QString("TAKEOFF. Go to <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup></b>, alt <b>%3)</b>; yaw: %4").arg(wp->getX(),0, 'f', 7).arg(wp->getY(),0, 'f', 7).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam4()));
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            m_ui->displayBar->setText(QString("TAKEOFF. Go to <b>(%1, %2, %3)</b>; yaw: %4").arg(wp->getX(),0, 'f', 2).arg(wp->getY(),0, 'f', 2).arg(wp->getZ(),0, 'f', 2).arg(wp->getParam4()));
            break;
        }
        } //end Frame switch
        break;
350 351
        break;
    }
352
    case MAV_CMD_DO_JUMP:
353 354 355 356 357 358 359 360 361 362 363
    {
        if (wp->getParam2()>0)
        {
            m_ui->displayBar->setText(QString("Jump to waypoint %1. Jumps left: %2").arg(wp->getParam1()).arg(wp->getParam2()));
        }
        else
        {
            m_ui->displayBar->setText(QString("No jumps left. Proceed to next waypoint."));
        }
        break;
    }
364
    case MAV_CMD_CONDITION_DELAY:
365 366 367 368
    {
        m_ui->displayBar->setText(QString("Delay: %1 sec").arg(wp->getParam1()));
        break;
    }
369 370
#ifdef MAVLINK_ENABLED_PIXHAWK
    case MAV_CMD_DO_START_SEARCH:
371 372 373 374
    {
        m_ui->displayBar->setText(QString("Start searching for pattern. Success when got more than %2 detections with confidence %1").arg(wp->getParam1()).arg(wp->getParam2()));
        break;
    }
375
    case MAV_CMD_DO_FINISH_SEARCH:
376 377 378 379
    {
        m_ui->displayBar->setText(QString("Check if search was successful. yes -> jump to %1, no -> jump to %2.  Jumps left: %3").arg(wp->getParam1()).arg(wp->getParam2()).arg(wp->getParam3()));
        break;
    }
380
    case MAV_CMD_NAV_SWEEP:
381
    {
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
        m_ui->displayBar->setText(QString("Sweep. Corners: <b>(</b>lat <b>%1<sup>o</sup></b>, lon <b>%2<sup>o</sup>)</b> and <b>(</b>lat <b>%3<sup>o</sup></b>, lon <b>%4<sup>o</sup>)</b>; alt: <b>%5</b>; scan radius: %6").arg(wp->getParam3(),0, 'f', 7).arg(wp->getParam4(),0, 'f', 7).arg(wp->getParam5(),0, 'f', 7).arg(wp->getParam6(),0, 'f', 7).arg(wp->getParam7(),0, 'f', 2).arg(wp->getParam1()));
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
        m_ui->displayBar->setText(QString("Sweep. Corners: <b>(%1, %2)</b> and <b>(%3, %4)</b>; z: <b>%5</b>; scan radius: %6").arg(wp->getParam3()).arg(wp->getParam4()).arg(wp->getParam5()).arg(wp->getParam6()).arg(wp->getParam7()).arg(wp->getParam1()));
            break;
        }
        } //end Frame switch
397 398
        break;
    }
399
#endif
400
    default:
401 402 403 404
    {
        m_ui->displayBar->setText(QString("Unknown Command ID (%1) : %2, %3, %4, %5, %6, %7, %8").arg(wp->getAction()).arg(wp->getParam1()).arg(wp->getParam2()).arg(wp->getParam3()).arg(wp->getParam4()).arg(wp->getParam5()).arg(wp->getParam6()).arg(wp->getParam7()));
        break;
    }
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
void WaypointViewOnlyView::hightlightDesiredCurrent(bool hightlight_on)
{
    QColor backGroundColor = QGC::colorBackground;
    QString checkBoxStyle;
    if (wp->getId() % 2 == 1)
    {
        backGroundColor = QColor("#252528").lighter(150);
    }
    else
    {
        backGroundColor = QColor("#252528").lighter(250);
    }

    if (hightlight_on)
    {
        checkBoxStyle = QString("QCheckBox {background-color: %1; color: #454545; border-color: #EEEEEE; } QCheckBox::indicator { border-color: #FFFFFF}").arg(backGroundColor.name());
    }
    else
    {
        checkBoxStyle = QString("QCheckBox {background-color: %1; color: #454545; border-color: #EEEEEE; } QCheckBox::indicator { border-color: QGC::colorBackground}").arg(backGroundColor.name());
    }
    m_ui->current->setStyleSheet(checkBoxStyle);
}

432 433 434 435
WaypointViewOnlyView::~WaypointViewOnlyView()
{
    delete m_ui;
}