Newer
Older
/*===================================================================
======================================================================*/
/**
* @file
* @brief Displays one waypoint
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
* @author Benjamin Knecht <mavteam@student.ethz.ch>
* @author Petri Tanskanen <mavteam@student.ethz.ch>
#include <cmath>
#include <qmath.h>
pixhawk
committed
#include "WaypointEditableView.h"
#include "ui_WaypointEditableView.h"
#include "MainWindow.h"
#include "mission/QGCMissionNavWaypoint.h"
#include "mission/QGCMissionNavLoiterUnlim.h"
#include "mission/QGCMissionNavLoiterTurns.h"
#include "mission/QGCMissionNavLoiterTime.h"
#include "mission/QGCMissionNavReturnToLaunch.h"
#include "mission/QGCMissionNavLand.h"
#include "mission/QGCMissionNavTakeoff.h"
#include "mission/QGCMissionNavSweep.h"
#include "mission/QGCMissionConditionDelay.h"
#include "mission/QGCMissionDoJump.h"
#include "mission/QGCMissionDoStartSearch.h"
#include "mission/QGCMissionDoFinishSearch.h"
#include "mission/QGCMissionOther.h"
pixhawk
committed
WaypointEditableView::WaypointEditableView(Waypoint* wp, QWidget* parent) :
pixhawk
committed
m_ui(new Ui::WaypointEditableView)
connect(wp, SIGNAL(destroyed(QObject*)), this, SLOT(deleted(QObject*)));
pixhawk
committed
// CUSTOM COMMAND WIDGET
pixhawk
committed
layout->setSpacing(2);
layout->setContentsMargins(4, 0 ,4 ,0);
pixhawk
committed
m_ui->customActionWidget->setLayout(layout);
pixhawk
committed
MissionNavWaypointWidget = NULL;
MissionNavLoiterUnlimWidget = NULL;
MissionNavLoiterTurnsWidget = NULL;
MissionNavLoiterTimeWidget = NULL;
MissionNavReturnToLaunchWidget = NULL;
MissionNavLandWidget = NULL;
MissionNavTakeoffWidget = NULL;
MissionNavSweepWidget = NULL;
pixhawk
committed
MissionConditionDelayWidget = NULL;
MissionDoJumpWidget = NULL;
MissionDoStartSearchWidget = NULL;
MissionDoFinishSearchWidget = NULL;
pixhawk
committed
MissionOtherWidget = NULL;
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);
//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);
m_ui->comboBox_action->addItem(tr("Other"), MAV_CMD_ENUM_END);
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);
m_ui->comboBox_frame->addItem("Local Offset(NED)",MAV_FRAME_LOCAL_OFFSET_NED);
m_ui->comboBox_frame->addItem("Mission",MAV_FRAME_MISSION);
Lorenz Meier
committed
// We do not want users to mess with the current waypoint in missions -
// they have to use the one downloaded from the MAV to change the current WP.
m_ui->selectedBox->setVisible(false);
connect(m_ui->selectedBox, SIGNAL(stateChanged(int)), this, SLOT(changedCurrent(int)));
// Initialize view correctly
int actionID = wp->getAction();
initializeActionView(actionID);
updateValues();
updateActionView(actionID);
// Check for mission frame
if (wp->getFrame() == MAV_FRAME_MISSION)
{
m_ui->comboBox_action->setCurrentIndex(m_ui->comboBox_action->count()-1);
}
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()));
connect(m_ui->autoContinue, SIGNAL(stateChanged(int)), this, SLOT(changedAutoContinue(int)));
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
committed
void WaypointEditableView::moveUp()
pixhawk
committed
void WaypointEditableView::moveDown()
pixhawk
committed
void WaypointEditableView::remove()
deleteLater();
pixhawk
committed
void WaypointEditableView::changedAutoContinue(int state)
pixhawk
committed
void WaypointEditableView::updateActionView(int action)
{
pixhawk
committed
//Hide all
if(MissionNavWaypointWidget) MissionNavWaypointWidget->hide();
if(MissionNavLoiterUnlimWidget) MissionNavLoiterUnlimWidget->hide();
if(MissionNavLoiterTurnsWidget) MissionNavLoiterTurnsWidget->hide();
if(MissionNavLoiterTimeWidget) MissionNavLoiterTimeWidget->hide();
if(MissionNavReturnToLaunchWidget) MissionNavReturnToLaunchWidget->hide();
if(MissionNavLandWidget) MissionNavLandWidget->hide();
if(MissionNavTakeoffWidget) MissionNavTakeoffWidget->hide();
if(MissionNavSweepWidget) MissionNavSweepWidget->hide();
pixhawk
committed
if(MissionConditionDelayWidget) MissionConditionDelayWidget->hide();
if(MissionDoJumpWidget) MissionDoJumpWidget->hide();
if(MissionDoStartSearchWidget) MissionDoStartSearchWidget->hide();
if(MissionDoFinishSearchWidget) MissionDoFinishSearchWidget->hide();
if(MissionOtherWidget) MissionOtherWidget->hide();
pixhawk
committed
//Show only the correct one
if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
{
switch(action) {
case MAV_CMD_NAV_WAYPOINT:
if(MissionNavWaypointWidget) MissionNavWaypointWidget->show();
break;
pixhawk
committed
case MAV_CMD_NAV_LOITER_UNLIM:
if(MissionNavLoiterUnlimWidget) MissionNavLoiterUnlimWidget->show();
break;
pixhawk
committed
case MAV_CMD_NAV_LOITER_TURNS:
if(MissionNavLoiterTurnsWidget) MissionNavLoiterTurnsWidget->show();
break;
pixhawk
committed
case MAV_CMD_NAV_LOITER_TIME:
if(MissionNavLoiterTimeWidget) MissionNavLoiterTimeWidget->show();
pixhawk
committed
break;
case MAV_CMD_NAV_RETURN_TO_LAUNCH:
if(MissionNavReturnToLaunchWidget) MissionNavReturnToLaunchWidget->show();
break;
case MAV_CMD_NAV_LAND:
if(MissionNavLandWidget) MissionNavLandWidget->show();
break;
case MAV_CMD_NAV_TAKEOFF:
if(MissionNavTakeoffWidget) MissionNavTakeoffWidget->show();
break;
case MAV_CMD_CONDITION_DELAY:
if(MissionConditionDelayWidget) MissionConditionDelayWidget->show();
pixhawk
committed
break;
case MAV_CMD_DO_JUMP:
if(MissionDoJumpWidget) MissionDoJumpWidget->show();
break;
pixhawk
committed
default:
if(MissionOtherWidget) MissionOtherWidget->show();
viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING;
pixhawk
committed
break;
}
}
else
{
if(MissionOtherWidget) MissionOtherWidget->show();
/**
* @param index The index of the combo box of the action entry, NOT the action ID
*/
pixhawk
committed
void WaypointEditableView::changedAction(int index)
int actionID = m_ui->comboBox_action->itemData(index).toUInt();
if (actionID == QVariant::Invalid || actionID == MAV_CMD_ENUM_END)
{
viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING;
}
else //(actionID < MAV_CMD_ENUM_END && actionID >= 0)
{
viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DEFAULT;
MAV_CMD action = (MAV_CMD) actionID;
wp->setAction(action);
}
// change the view
initializeActionView(actionID);
updateValues();
updateActionView(actionID);
}
void WaypointEditableView::initializeActionView(int actionID)
{
//initialize a new action-widget, if needed.
switch(actionID) {
pixhawk
committed
case MAV_CMD_NAV_WAYPOINT:
if (!MissionNavWaypointWidget)
{
MissionNavWaypointWidget = new QGCMissionNavWaypoint(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavWaypointWidget);
case MAV_CMD_NAV_LOITER_UNLIM:
if (!MissionNavLoiterUnlimWidget)
{
MissionNavLoiterUnlimWidget = new QGCMissionNavLoiterUnlim(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavLoiterUnlimWidget);
}
break;
case MAV_CMD_NAV_LOITER_TURNS:
if (!MissionNavLoiterTurnsWidget)
{
MissionNavLoiterTurnsWidget = new QGCMissionNavLoiterTurns(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavLoiterTurnsWidget);
}
break;
case MAV_CMD_NAV_LOITER_TIME:
if (!MissionNavLoiterTimeWidget)
{
MissionNavLoiterTimeWidget = new QGCMissionNavLoiterTime(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavLoiterTimeWidget);
}
break;
case MAV_CMD_NAV_RETURN_TO_LAUNCH:
if (!MissionNavReturnToLaunchWidget)
{
MissionNavReturnToLaunchWidget = new QGCMissionNavReturnToLaunch(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavReturnToLaunchWidget);
}
break;
case MAV_CMD_NAV_LAND:
if (!MissionNavLandWidget)
{
MissionNavLandWidget = new QGCMissionNavLand(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavLandWidget);
}
break;
case MAV_CMD_NAV_TAKEOFF:
if (!MissionNavTakeoffWidget)
{
MissionNavTakeoffWidget = new QGCMissionNavTakeoff(this);
m_ui->customActionWidget->layout()->addWidget(MissionNavTakeoffWidget);
}
break;
case MAV_CMD_CONDITION_DELAY:
if (!MissionConditionDelayWidget)
{
MissionConditionDelayWidget = new QGCMissionConditionDelay(this);
m_ui->customActionWidget->layout()->addWidget(MissionConditionDelayWidget);
}
break;
case MAV_CMD_DO_JUMP:
pixhawk
committed
if (!MissionDoJumpWidget)
MissionDoJumpWidget = new QGCMissionDoJump(this);
pixhawk
committed
m_ui->customActionWidget->layout()->addWidget(MissionDoJumpWidget);
pixhawk
committed
case MAV_CMD_ENUM_END:
default:
if (!MissionOtherWidget)
pixhawk
committed
MissionOtherWidget = new QGCMissionOther(this);
m_ui->customActionWidget->layout()->addWidget(MissionOtherWidget);
pixhawk
committed
void WaypointEditableView::deleted(QObject* waypoint)
// Do not dynamic cast or de-reference QObject, since object is either in destructor or may have already
// been destroyed.
Q_UNUSED(waypoint);
pixhawk
committed
void WaypointEditableView::changedFrame(int index)
{
// set waypoint action
MAV_FRAME frame = (MAV_FRAME)m_ui->comboBox_frame->itemData(index).toUInt();
wp->setFrame(frame);
}
pixhawk
committed
void WaypointEditableView::changedCurrent(int state)
{
if (state == 0)
{
if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current
{
m_ui->selectedBox->setChecked(true);
m_ui->selectedBox->setCheckState(Qt::Checked);
}
else
{
m_ui->selectedBox->setChecked(false);
m_ui->selectedBox->setCheckState(Qt::Unchecked);
}
}
else
{
// At this point we do not consider this signal
// to be valid / the edit check boxes should not change the view state
//emit changeCurrentWaypoint(wp->getId());
//the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
}
pixhawk
committed
void WaypointEditableView::updateValues()
// Check if we just lost the wp, delete the widget
// accordingly
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
//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);
}
}
}
}
}
// update frame
MAV_FRAME frame = wp->getFrame();
int frame_index = m_ui->comboBox_frame->findData(frame);
if (m_ui->comboBox_frame->currentIndex() != frame_index) {
m_ui->comboBox_frame->setCurrentIndex(frame_index);
int action_index = m_ui->comboBox_action->findData(action);
if (m_ui->comboBox_action->currentIndex() != action_index)
{
if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
// Set to "Other" action if it was -1
if (action_index == -1)
action_index = m_ui->comboBox_action->findData(MAV_CMD_ENUM_END);
viewMode = QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING;
m_ui->comboBox_action->setCurrentIndex(action_index);
pixhawk
committed
emit commandBroadcast(wp->getAction());
emit frameBroadcast(wp->getFrame());
emit param1Broadcast(wp->getParam1());
emit param2Broadcast(wp->getParam2());
emit param3Broadcast(wp->getParam3());
emit param4Broadcast(wp->getParam4());
emit param5Broadcast(wp->getParam5());
emit param6Broadcast(wp->getParam6());
emit param7Broadcast(wp->getParam7());
if (m_ui->selectedBox->isChecked() != wp->getCurrent())
{
// This is never a reason to emit a changed signal
m_ui->selectedBox->blockSignals(true);
m_ui->selectedBox->blockSignals(false);
if (m_ui->autoContinue->isChecked() != wp->getAutoContinue())
{
m_ui->autoContinue->setChecked(wp->getAutoContinue());
}
pixhawk
committed
m_ui->idLabel->setText(QString::number(wp->getId()));
pixhawk
committed
// Style alternating rows of Missions as lighter/darker.
static int lastId = -1;
int currId = wp->getId() % 2;
if (currId != lastId)
{
if (currId == 1)
{
this->setProperty("RowColoring", "odd");
this->setProperty("RowColoring", "even");
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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
// 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);
pixhawk
committed
void WaypointEditableView::setCurrent(bool state)
if (m_ui->selectedBox->isChecked() != state)
{
m_ui->selectedBox->blockSignals(true);
m_ui->selectedBox->setChecked(state);
m_ui->selectedBox->blockSignals(false);
}
pixhawk
committed
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
void WaypointEditableView::changedCommand(int mav_cmd_id)
{
if (mav_cmd_id<MAV_CMD_ENUM_END)
{
wp->setAction(mav_cmd_id);
}
}
void WaypointEditableView::changedParam1(double value)
{
wp->setParam1(value);
}
void WaypointEditableView::changedParam2(double value)
{
wp->setParam2(value);
}
void WaypointEditableView::changedParam3(double value)
{
wp->setParam3(value);
}
void WaypointEditableView::changedParam4(double value)
{
wp->setParam4(value);
}
void WaypointEditableView::changedParam5(double value)
{
wp->setParam5(value);
}
void WaypointEditableView::changedParam6(double value)
{
wp->setParam6(value);
}
void WaypointEditableView::changedParam7(double value)
{
wp->setParam7(value);
}
pixhawk
committed
WaypointEditableView::~WaypointEditableView()
pixhawk
committed
void WaypointEditableView::changeEvent(QEvent *e)
{
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
/**
* Implement paintEvent() so that stylesheets work for our custom widget.
*/