WaypointViewOnlyView.cc 13.8 KB
Newer Older
1
#include <QDebug>
2 3

#include "MainWindow.h"
4 5 6
#include "WaypointViewOnlyView.h"
#include "ui_WaypointViewOnlyView.h"

7
WaypointViewOnlyView::WaypointViewOnlyView(MissionItem* wp, QWidget *parent) :
8
    QWidget(parent),
9
    wp(wp),
10 11 12 13 14 15 16 17 18 19
    m_ui(new Ui::WaypointViewOnlyView)
{
    m_ui->setupUi(this);
    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)
20
{
21 22 23 24 25
    bool new_value = false;
    if (state != 0)
    {
        new_value = true;
    }
26
    wp->setAutocontinue(new_value);
Don Gagne's avatar
Don Gagne committed
27
    emit changeAutoContinue(wp->sequenceNumber(),new_value);
28
}
29 30

void WaypointViewOnlyView::changedCurrent(int state)
31
//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.
32
{
33
    Q_UNUSED(state);
Don Gagne's avatar
Don Gagne committed
34
    //qDebug() << "Trof: WaypointViewOnlyView::changedCurrent(" << state << ") ID:" << wp->sequenceNumber();
35
    m_ui->current->blockSignals(true);
36

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

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

void WaypointViewOnlyView::setCurrent(bool state)
61
//This is a slot receiving signals from UASWaypointManager. The state given here is the true representation of what the "current" waypoint on UAV is.
62
{
63 64 65 66
    if (!wp) {
        return;
    }

67
    m_ui->current->blockSignals(true);
68 69
    if (state == true)
    {
Don Gagne's avatar
Don Gagne committed
70
        wp->setIsCurrentItem(true);
71 72 73 74
        m_ui->current->setCheckState(Qt::Checked);
    }
    else
    {
Don Gagne's avatar
Don Gagne committed
75
        wp->setIsCurrentItem(false);
76 77
        m_ui->current->setCheckState(Qt::Unchecked);
    }
78 79 80 81 82 83 84 85 86 87 88 89
    m_ui->current->blockSignals(false);
}

void WaypointViewOnlyView::updateValues()
{
    // Check if we just lost the wp, delete the widget
    // accordingly
    if (!wp)
    {
        deleteLater();
        return;
    }
90

91
    // Style alternating rows of Missions as lighter/darker.
92
    static int lastId = -1;
Don Gagne's avatar
Don Gagne committed
93
    int currId = wp->sequenceNumber() % 2;
94 95 96 97
    if (currId != lastId)
    {
        if (currId == 1)
        {
98
            this->setProperty("RowColoring", "odd");
99 100 101
        }
        else
        {
102
            this->setProperty("RowColoring", "even");
103 104 105 106 107
        }

        lastId = currId;
    }

108 109
    // update frame

Don Gagne's avatar
Don Gagne committed
110
    m_ui->idLabel->setText(QString("%1").arg(wp->sequenceNumber()));
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    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;
    }
    }

Don Gagne's avatar
Don Gagne committed
145
    if (m_ui->current->isChecked() != wp->isCurrentItem())
146
    {
147
        m_ui->current->blockSignals(true);
Don Gagne's avatar
Don Gagne committed
148
        m_ui->current->setChecked(wp->isCurrentItem());
149
        m_ui->current->blockSignals(false);
150 151 152
    }
    if (m_ui->autoContinue->isChecked() != wp->getAutoContinue())
    {
153
        m_ui->autoContinue->blockSignals(true);
154
        m_ui->autoContinue->setChecked(wp->getAutoContinue());
155
        m_ui->autoContinue->blockSignals(false);
156 157
    }

158 159 160
    switch (wp->getAction())
    {
    case MAV_CMD_NAV_WAYPOINT:
161
    {
162
        switch (wp->getFrame())
163
        {
164 165 166 167 168
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            if (wp->getParam1()>0)
            {
Don Gagne's avatar
Don Gagne committed
169
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam1()).arg(wp->getParam4()).arg(wp->getParam2()));
170 171 172
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
173
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam4()).arg(wp->getParam2()));
174 175
            }
            break;
176
        }
177 178
        case MAV_FRAME_LOCAL_NED:
        default:
179
        {
180 181
            if (wp->getParam1()>0)
            {
Don Gagne's avatar
Don Gagne committed
182
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and wait there for %4 sec; yaw: %5; rad: %6").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f',2).arg(wp->getParam1()).arg(wp->getParam4()).arg(wp->getParam2()));
183 184 185
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
186
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b>; yaw: %4; rad: %5").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f', 2).arg(wp->getParam4()).arg(wp->getParam2()));
187 188
            }
            break;
189
        }
190
        } //end Frame switch
191 192
        break;
    }
193 194 195 196 197 198 199 200 201
    case MAV_CMD_NAV_LOITER_UNLIM:
    {
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
            if (wp->getParam3()>=0)
            {
Don Gagne's avatar
Don Gagne committed
202
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam3()));
203 204 205
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
206
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(-wp->getParam3()));
207 208 209 210 211 212 213 214
            }
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            if (wp->getParam3()>=0)
            {
Don Gagne's avatar
Don Gagne committed
215
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there indefinitely (clockwise); rad: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f',2).arg(wp->getParam3()));
216 217 218
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
219
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there indefinitely (counter-clockwise); rad: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f', 2).arg(-wp->getParam3()));
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
            }
            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)
            {
Don Gagne's avatar
Don Gagne committed
235
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam3()).arg(wp->getParam1()));
236 237 238
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
239
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
240 241 242 243 244 245 246 247
            }
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            if (wp->getParam3()>=0)
            {
Don Gagne's avatar
Don Gagne committed
248
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5 turns (clockwise); rad: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f',2).arg(wp->getParam3()).arg(wp->getParam1()));
249 250 251
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
252
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5 turns (counter-clockwise); rad: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
            }
            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)
            {
Don Gagne's avatar
Don Gagne committed
268
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam3()).arg(wp->getParam1()));
269 270 271
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
272
                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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
273 274 275 276 277 278 279 280
            }
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
            if (wp->getParam3()>=0)
            {
Don Gagne's avatar
Don Gagne committed
281
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5s (clockwise); rad: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f',2).arg(wp->getParam3()).arg(wp->getParam1()));
282 283 284
            }
            else
            {
Don Gagne's avatar
Don Gagne committed
285
                m_ui->displayBar->setText(QString("Go to <b>(%1, %2, %3)</b> and loiter there for %5s (counter-clockwise); rad: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f', 2).arg(-wp->getParam3()).arg(wp->getParam1()));
286 287 288 289 290 291 292 293 294 295 296
            }
            break;
        }
        } //end Frame switch
        break;
    }
    case MAV_CMD_NAV_RETURN_TO_LAUNCH:
    {
        m_ui->displayBar->setText(QString("Return to launch location"));
        break;
    }
297
    case MAV_CMD_NAV_LAND:
298
    {
299 300 301 302 303
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
Don Gagne's avatar
Don Gagne committed
304
            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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam4()));
305 306 307 308 309
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
Don Gagne's avatar
Don Gagne committed
310
            m_ui->displayBar->setText(QString("LAND. Go to <b>(%1, %2, %3)</b> and descent; yaw: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f', 2).arg(wp->getParam4()));
311 312 313
            break;
        }
        } //end Frame switch
314 315
        break;
    }
316
    case MAV_CMD_NAV_TAKEOFF:
317
    {
318 319 320 321 322
        switch (wp->getFrame())
        {
        case MAV_FRAME_GLOBAL_RELATIVE_ALT:
        case MAV_FRAME_GLOBAL:
        {
Don Gagne's avatar
Don Gagne committed
323
            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->x(),0, 'f', 7).arg(wp->y(),0, 'f', 7).arg(wp->z(),0, 'f', 2).arg(wp->getParam4()));
324 325 326 327 328
            break;
        }
        case MAV_FRAME_LOCAL_NED:
        default:
        {
Don Gagne's avatar
Don Gagne committed
329
            m_ui->displayBar->setText(QString("TAKEOFF. Go to <b>(%1, %2, %3)</b>; yaw: %4").arg(wp->x(),0, 'f', 2).arg(wp->y(),0, 'f', 2).arg(wp->z(),0, 'f', 2).arg(wp->getParam4()));
330 331 332 333
            break;
        }
        } //end Frame switch
        break;
334 335
        break;
    }
336
    case MAV_CMD_DO_JUMP:
337 338 339 340 341 342 343 344 345 346 347
    {
        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;
    }
348
    case MAV_CMD_CONDITION_DELAY:
349 350 351 352
    {
        m_ui->displayBar->setText(QString("Delay: %1 sec").arg(wp->getParam1()));
        break;
    }
353
    default:
354 355 356 357
    {
        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;
    }
358
    }
359 360
}

361
WaypointViewOnlyView::~WaypointViewOnlyView()
362
{
363
    delete m_ui;
364 365
}

366
void WaypointViewOnlyView::changeEvent(QEvent *e)
367
{
368 369 370 371 372 373 374
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
375
}
376 377 378 379 380 381 382 383 384 385 386

/**
 * Implement paintEvent() so that stylesheets work for our custom widget.
 */
void WaypointViewOnlyView::paintEvent(QPaintEvent *)
 {
     QStyleOption opt;
     opt.init(this);
     QPainter p(this);
     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
 }