Commit a8417079 authored by LM's avatar LM

Merge branch 'v10release' of github.com:pixhawk/qgroundcontrol into v10release

parents e0bd2a74 c0691261
......@@ -173,7 +173,6 @@ FORMS += src/ui/MainWindow.ui \
src/ui/UASView.ui \
src/ui/ParameterInterface.ui \
src/ui/WaypointList.ui \
src/ui/WaypointView.ui \
src/ui/ObjectDetectionView.ui \
src/ui/JoystickWidget.ui \
src/ui/DebugConsole.ui \
......@@ -209,7 +208,9 @@ FORMS += src/ui/MainWindow.ui \
src/ui/mission/QGCMissionConditionWidget.ui \
src/ui/map/QGCMapTool.ui \
src/ui/map/QGCMapToolBar.ui \
src/ui/QGCMAVLinkInspector.ui
src/ui/QGCMAVLinkInspector.ui \
src/ui/WaypointViewOnlyView.ui \
src/ui/WaypointEditableView.ui
INCLUDEPATH += src \
src/ui \
src/ui/linechart \
......@@ -256,7 +257,6 @@ HEADERS += src/MG.h \
src/ui/ParameterInterface.h \
src/ui/WaypointList.h \
src/Waypoint.h \
src/ui/WaypointView.h \
src/ui/ObjectDetectionView.h \
src/input/JoystickInput.h \
src/ui/JoystickWidget.h \
......@@ -322,7 +322,10 @@ HEADERS += src/MG.h \
src/QGCGeo.h \
src/ui/QGCToolBar.h \
src/ui/QGCMAVLinkInspector.h \
src/ui/MAVLinkDecoder.h
src/ui/MAVLinkDecoder.h \
src/ui/WaypointViewOnlyView.h \
src/ui/WaypointViewOnlyView.h \
src/ui/WaypointEditableView.h
# Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler
macx|win32-msvc2008|win32-msvc2010::HEADERS += src/ui/map3D/QGCGoogleEarthView.h
......@@ -384,7 +387,6 @@ SOURCES += src/main.cc \
src/ui/ParameterInterface.cc \
src/ui/WaypointList.cc \
src/Waypoint.cc \
src/ui/WaypointView.cc \
src/ui/ObjectDetectionView.cc \
src/input/JoystickInput.cc \
src/ui/JoystickWidget.cc \
......@@ -447,7 +449,9 @@ SOURCES += src/main.cc \
src/ui/map/QGCMapToolBar.cc \
src/ui/QGCToolBar.cc \
src/ui/QGCMAVLinkInspector.cc \
src/ui/MAVLinkDecoder.cc
src/ui/MAVLinkDecoder.cc \
src/ui/WaypointViewOnlyView.cc \
src/ui/WaypointEditableView.cc
# Enable Google Earth only on Mac OS and Windows with Visual Studio compiler
macx|win32-msvc2008|win32-msvc2010::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
......
......@@ -206,7 +206,7 @@ void Waypoint::setFrame(MAV_FRAME frame)
void Waypoint::setAutocontinue(bool autoContinue)
{
if (this->autocontinue != autocontinue) {
if (this->autocontinue != autoContinue) {
this->autocontinue = autoContinue;
emit changed(this);
}
......
......@@ -28,59 +28,59 @@
#include "SerialLink.h"
UAS::UAS(MAVLinkProtocol* protocol, int id) : UASInterface(),
uasId(id),
startTime(QGC::groundTimeMilliseconds()),
commStatus(COMM_DISCONNECTED),
name(""),
autopilot(-1),
links(new QList<LinkInterface*>()),
unknownPackets(),
mavlink(protocol),
waypointManager(*this),
thrustSum(0),
thrustMax(10),
startVoltage(0),
warnVoltage(9.5f),
warnLevelPercent(20.0f),
currentVoltage(12.0f),
lpVoltage(12.0f),
batteryRemainingEstimateEnabled(true),
mode(-1),
status(-1),
navMode(-1),
onboardTimeOffset(0),
controlRollManual(true),
controlPitchManual(true),
controlYawManual(true),
controlThrustManual(true),
manualRollAngle(0),
manualPitchAngle(0),
manualYawAngle(0),
manualThrust(0),
receiveDropRate(0),
sendDropRate(0),
lowBattAlarm(false),
positionLock(false),
localX(0.0),
localY(0.0),
localZ(0.0),
latitude(0.0),
longitude(0.0),
altitude(0.0),
roll(0.0),
pitch(0.0),
yaw(0.0),
statusTimeout(new QTimer(this)),
paramsOnceRequested(false),
airframe(QGC_AIRFRAME_EASYSTAR),
attitudeKnown(false),
paramManager(NULL),
attitudeStamped(false),
lastAttitude(0),
simulation(new QGCFlightGearLink(this)),
isLocalPositionKnown(false),
isGlobalPositionKnown(false),
systemIsArmed(false)
uasId(id),
startTime(QGC::groundTimeMilliseconds()),
commStatus(COMM_DISCONNECTED),
name(""),
autopilot(-1),
links(new QList<LinkInterface*>()),
unknownPackets(),
mavlink(protocol),
waypointManager(this),
thrustSum(0),
thrustMax(10),
startVoltage(0),
warnVoltage(9.5f),
warnLevelPercent(20.0f),
currentVoltage(12.0f),
lpVoltage(12.0f),
batteryRemainingEstimateEnabled(true),
mode(-1),
status(-1),
navMode(-1),
onboardTimeOffset(0),
controlRollManual(true),
controlPitchManual(true),
controlYawManual(true),
controlThrustManual(true),
manualRollAngle(0),
manualPitchAngle(0),
manualYawAngle(0),
manualThrust(0),
receiveDropRate(0),
sendDropRate(0),
lowBattAlarm(false),
positionLock(false),
localX(0.0),
localY(0.0),
localZ(0.0),
latitude(0.0),
longitude(0.0),
altitude(0.0),
roll(0.0),
pitch(0.0),
yaw(0.0),
statusTimeout(new QTimer(this)),
paramsOnceRequested(false),
airframe(QGC_AIRFRAME_EASYSTAR),
attitudeKnown(false),
paramManager(NULL),
attitudeStamped(false),
lastAttitude(0),
simulation(new QGCFlightGearLink(this)),
isLocalPositionKnown(false),
isGlobalPositionKnown(false),
systemIsArmed(false)
{
color = UASInterface::getNextColor();
setBatterySpecs(QString("9V,9.5V,12.6V"));
......
......@@ -30,14 +30,14 @@ This file is part of the QGROUNDCONTROL project
*/
#include "UASWaypointManager.h"
#include "UAS.h"
#include "uas.h"
#include "mavlink_types.h"
#define PROTOCOL_TIMEOUT_MS 2000 ///< maximum time to wait for pending messages until timeout
#define PROTOCOL_DELAY_MS 40 ///< minimum delay between sent messages
#define PROTOCOL_MAX_RETRIES 3 ///< maximum number of send retries (after timeout)
#define PROTOCOL_DELAY_MS 20 ///< minimum delay between sent messages
#define PROTOCOL_MAX_RETRIES 5 ///< maximum number of send retries (after timeout)
UASWaypointManager::UASWaypointManager(UAS &_uas)
UASWaypointManager::UASWaypointManager(UAS* _uas)
: uas(_uas),
current_retries(0),
current_wp_id(0),
......@@ -46,11 +46,19 @@ UASWaypointManager::UASWaypointManager(UAS &_uas)
current_partner_systemid(0),
current_partner_compid(0),
protocol_timer(this),
currentWaypoint(NULL)
currentWaypointEditable(NULL)
{
if (uas)
{
uasid = uas->getUASID();
connect(&protocol_timer, SIGNAL(timeout()), this, SLOT(timeout()));
connect(&uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(handleLocalPositionChanged(UASInterface*,double,double,double,quint64)));
connect(&uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(handleGlobalPositionChanged(UASInterface*,double,double,double,quint64)));
connect(uas, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(handleLocalPositionChanged(UASInterface*,double,double,double,quint64)));
connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(handleGlobalPositionChanged(UASInterface*,double,double,double,quint64)));
}
else
{
uasid = 0;
}
}
void UASWaypointManager::timeout()
......@@ -92,11 +100,11 @@ void UASWaypointManager::handleLocalPositionChanged(UASInterface* mav, double x,
{
Q_UNUSED(mav);
Q_UNUSED(time);
if (waypoints.count() > 0 && currentWaypoint && (currentWaypoint->getFrame() == MAV_FRAME_LOCAL_NED || currentWaypoint->getFrame() == MAV_FRAME_LOCAL_ENU))
if (waypointsEditable.count() > 0 && currentWaypointEditable && (currentWaypointEditable->getFrame() == MAV_FRAME_LOCAL_NED || currentWaypointEditable->getFrame() == MAV_FRAME_LOCAL_ENU))
{
double xdiff = x-currentWaypoint->getX();
double ydiff = y-currentWaypoint->getY();
double zdiff = z-currentWaypoint->getZ();
double xdiff = x-currentWaypointEditable->getX();
double ydiff = y-currentWaypointEditable->getY();
double zdiff = z-currentWaypointEditable->getZ();
double dist = sqrt(xdiff*xdiff + ydiff*ydiff + zdiff*zdiff);
emit waypointDistanceChanged(dist);
}
......@@ -144,9 +152,17 @@ void UASWaypointManager::handleWaypoint(quint8 systemId, quint8 compId, mavlink_
if(wp->seq == current_wp_id) {
//// // qDebug() << "Got WP: " << wp->seq << wp->x << wp->y << wp->z << wp->param4 << "auto:" << wp->autocontinue << "curr:" << wp->current << wp->param1 << wp->param2 << "Frame:"<< (MAV_FRAME) wp->frame << "Command:" << (MAV_CMD) wp->command;
Waypoint *lwp = new Waypoint(wp->seq, wp->x, wp->y, wp->z, wp->param1, wp->param2, wp->param3, wp->param4, wp->autocontinue, wp->current, (MAV_FRAME) wp->frame, (MAV_CMD) wp->command);
addWaypoint(lwp, false);
if (wp->current == 1) currentWaypoint = lwp;
Waypoint *lwp_vo = new Waypoint(wp->seq, wp->x, wp->y, wp->z, wp->param1, wp->param2, wp->param3, wp->param4, wp->autocontinue, wp->current, (MAV_FRAME) wp->frame, (MAV_CMD) wp->command);
addWaypointViewOnly(lwp_vo);
if (read_to_edit == true) {
Waypoint *lwp_ed = new Waypoint(wp->seq, wp->x, wp->y, wp->z, wp->param1, wp->param2, wp->param3, wp->param4, wp->autocontinue, wp->current, (MAV_FRAME) wp->frame, (MAV_CMD) wp->command);
addWaypointEditable(lwp_ed, false);
if (wp->current == 1) currentWaypointEditable = lwp_ed;
}
//get next waypoint
current_wp_id++;
......@@ -165,7 +181,7 @@ void UASWaypointManager::handleWaypoint(quint8 systemId, quint8 compId, mavlink_
protocol_timer.stop();
emit readGlobalWPFromUAS(false);
if (currentWaypoint) emit currentWaypointChanged(currentWaypoint->getId());
//if (currentWaypointEditable) emit currentWaypointChanged(currentWaypointEditable->getId());
emit updateStatusString("done.");
// // qDebug() << "got all waypoints from ID " << systemId;
......@@ -216,28 +232,29 @@ void UASWaypointManager::handleWaypointRequest(quint8 systemId, quint8 compId, m
void UASWaypointManager::handleWaypointReached(quint8 systemId, quint8 compId, mavlink_mission_item_reached_t *wpr)
{
if (systemId == uas.getUASID()) {
if (!uas) return;
if (systemId == uasid) {
emit updateStatusString(QString("Reached waypoint %1").arg(wpr->seq));
}
}
void UASWaypointManager::handleWaypointCurrent(quint8 systemId, quint8 compId, mavlink_mission_current_t *wpc)
{
if (systemId == uas.getUASID()) {
if (!uas) return;
if (systemId == uasid) {
// FIXME Petri
if (current_state == WP_SETCURRENT) {
protocol_timer.stop();
current_state = WP_IDLE;
// update the local main storage
if (wpc->seq < waypoints.size()) {
for(int i = 0; i < waypoints.size(); i++) {
if (waypoints[i]->getId() == wpc->seq) {
waypoints[i]->setCurrent(true);
currentWaypoint = waypoints[i];
if (wpc->seq < waypointsViewOnly.size()) {
for(int i = 0; i < waypointsViewOnly.size(); i++) {
if (waypointsViewOnly[i]->getId() == wpc->seq) {
waypointsViewOnly[i]->setCurrent(true);
//currentWaypointEditable = waypoints[i];
} else {
waypoints[i]->setCurrent(false);
waypointsViewOnly[i]->setCurrent(false);
}
}
}
......@@ -248,33 +265,33 @@ void UASWaypointManager::handleWaypointCurrent(quint8 systemId, quint8 compId, m
}
}
void UASWaypointManager::notifyOfChange(Waypoint* wp)
void UASWaypointManager::notifyOfChangeEditable(Waypoint* wp)
{
// // qDebug() << "WAYPOINT CHANGED: ID:" << wp->getId();
// If only one waypoint was changed, emit only WP signal
if (wp != NULL) {
emit waypointChanged(uas.getUASID(), wp);
emit waypointEditableChanged(uasid, wp);
} else {
emit waypointListChanged();
emit waypointListChanged(uas.getUASID());
emit waypointEditableListChanged();
emit waypointEditableListChanged(uasid);
}
}
int UASWaypointManager::setCurrentWaypoint(quint16 seq)
void UASWaypointManager::notifyOfChangeViewOnly(Waypoint* wp)
{
if (seq < waypoints.size()) {
if(current_state == WP_IDLE) {
//update local main storage
for(int i = 0; i < waypoints.size(); i++) {
if (waypoints[i]->getId() == seq) {
waypoints[i]->setCurrent(true);
currentWaypoint = waypoints[i];
if (wp != NULL) {
emit waypointViewOnlyChanged(uasid, wp);
} else {
waypoints[i]->setCurrent(false);
}
emit waypointViewOnlyListChanged();
emit waypointViewOnlyListChanged(uasid);
}
}
//TODO: signal changed waypoint list
int UASWaypointManager::setCurrentWaypoint(quint16 seq)
{
if (seq < waypointsViewOnly.size()) {
if(current_state == WP_IDLE) {
//send change to UAS - important to note: if the transmission fails, we have inconsistencies
protocol_timer.start(PROTOCOL_TIMEOUT_MS);
......@@ -282,7 +299,7 @@ int UASWaypointManager::setCurrentWaypoint(quint16 seq)
current_state = WP_SETCURRENT;
current_wp_id = seq;
current_partner_systemid = uas.getUASID();
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
sendWaypointSetCurrent(current_wp_id);
......@@ -295,26 +312,59 @@ int UASWaypointManager::setCurrentWaypoint(quint16 seq)
return -1;
}
int UASWaypointManager::setCurrentEditable(quint16 seq)
{
if (seq < waypointsEditable.size()) {
if(current_state == WP_IDLE) {
//update local main storage
for(int i = 0; i < waypointsEditable.size(); i++) {
if (waypointsEditable[i]->getId() == seq) {
waypointsEditable[i]->setCurrent(true);
//currentWaypointEditable = waypoints[i];
} else {
waypointsEditable[i]->setCurrent(false);
}
}
return 0;
}
}
return -1;
}
void UASWaypointManager::addWaypointViewOnly(Waypoint *wp)
{
if (wp)
{
waypointsViewOnly.insert(waypointsViewOnly.size(), wp);
connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChangeViewOnly(Waypoint*)));
emit waypointViewOnlyListChanged();
emit waypointViewOnlyListChanged(uasid);
}
}
/**
* @warning Make sure the waypoint stays valid for the whole application lifecycle!
* @param enforceFirstActive Enforces that the first waypoint is set as active
* @see createWaypoint() is more suitable for most use cases
*/
void UASWaypointManager::addWaypoint(Waypoint *wp, bool enforceFirstActive)
void UASWaypointManager::addWaypointEditable(Waypoint *wp, bool enforceFirstActive)
{
if (wp)
{
wp->setId(waypoints.size());
if (enforceFirstActive && waypoints.size() == 0)
wp->setId(waypointsEditable.size());
if (enforceFirstActive && waypointsEditable.size() == 0)
{
wp->setCurrent(true);
currentWaypoint = wp;
currentWaypointEditable = wp;
}
waypoints.insert(waypoints.size(), wp);
connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChange(Waypoint*)));
waypointsEditable.insert(waypointsEditable.size(), wp);
connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChangeEditable(Waypoint*)));
emit waypointListChanged();
emit waypointListChanged(uas.getUASID());
emit waypointEditableListChanged();
emit waypointEditableListChanged(uasid);
}
}
......@@ -324,36 +374,36 @@ void UASWaypointManager::addWaypoint(Waypoint *wp, bool enforceFirstActive)
Waypoint* UASWaypointManager::createWaypoint(bool enforceFirstActive)
{
Waypoint* wp = new Waypoint();
wp->setId(waypoints.size());
if (enforceFirstActive && waypoints.size() == 0)
wp->setId(waypointsEditable.size());
if (enforceFirstActive && waypointsEditable.size() == 0)
{
wp->setCurrent(true);
currentWaypoint = wp;
currentWaypointEditable = wp;
}
waypoints.insert(waypoints.size(), wp);
connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChange(Waypoint*)));
waypointsEditable.insert(waypointsEditable.size(), wp);
connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChangeEditable(Waypoint*)));
emit waypointListChanged();
emit waypointListChanged(uas.getUASID());
emit waypointEditableListChanged();
emit waypointEditableListChanged(uasid);
return wp;
}
int UASWaypointManager::removeWaypoint(quint16 seq)
{
if (seq < waypoints.size())
if (seq < waypointsEditable.size())
{
Waypoint *t = waypoints[seq];
waypoints.remove(seq);
Waypoint *t = waypointsEditable[seq];
waypointsEditable.remove(seq);
delete t;
t = NULL;
for(int i = seq; i < waypoints.size(); i++)
for(int i = seq; i < waypointsEditable.size(); i++)
{
waypoints[i]->setId(i);
waypointsEditable[i]->setId(i);
}
emit waypointListChanged();
emit waypointListChanged(uas.getUASID());
emit waypointEditableListChanged();
emit waypointEditableListChanged(uasid);
return 0;
}
return -1;
......@@ -361,26 +411,26 @@ int UASWaypointManager::removeWaypoint(quint16 seq)
void UASWaypointManager::moveWaypoint(quint16 cur_seq, quint16 new_seq)
{
if (cur_seq != new_seq && cur_seq < waypoints.size() && new_seq < waypoints.size())
if (cur_seq != new_seq && cur_seq < waypointsEditable.size() && new_seq < waypointsEditable.size())
{
Waypoint *t = waypoints[cur_seq];
Waypoint *t = waypointsEditable[cur_seq];
if (cur_seq < new_seq) {
for (int i = cur_seq; i < new_seq; i++)
{
waypoints[i] = waypoints[i+1];
waypointsEditable[i] = waypointsEditable[i+1];
}
}
else
{
for (int i = cur_seq; i > new_seq; i--)
{
waypoints[i] = waypoints[i-1];
waypointsEditable[i] = waypointsEditable[i-1];
}
}
waypoints[new_seq] = t;
waypointsEditable[new_seq] = t;
emit waypointListChanged();
emit waypointListChanged(uas.getUASID());
emit waypointEditableListChanged();
emit waypointEditableListChanged(uasid);
}
}
......@@ -395,10 +445,10 @@ void UASWaypointManager::saveWaypoints(const QString &saveFile)
//write the waypoint list version to the first line for compatibility check
out << "QGC WPL 110\r\n";
for (int i = 0; i < waypoints.size(); i++)
for (int i = 0; i < waypointsEditable.size(); i++)
{
waypoints[i]->setId(i);
waypoints[i]->save(out);
waypointsEditable[i]->setId(i);
waypointsEditable[i]->save(out);
}
file.close();
}
......@@ -409,9 +459,9 @@ void UASWaypointManager::loadWaypoints(const QString &loadFile)
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
while(waypoints.size()>0) {
Waypoint *t = waypoints[0];
waypoints.remove(0);
while(waypointsEditable.size()>0) {
Waypoint *t = waypointsEditable[0];
waypointsEditable.remove(0);
delete t;
}
......@@ -430,8 +480,8 @@ void UASWaypointManager::loadWaypoints(const QString &loadFile)
Waypoint *t = new Waypoint();
if(t->load(in))
{
t->setId(waypoints.size());
waypoints.insert(waypoints.size(), t);
t->setId(waypointsEditable.size());
waypointsEditable.insert(waypointsEditable.size(), t);
}
else
{
......@@ -445,8 +495,8 @@ void UASWaypointManager::loadWaypoints(const QString &loadFile)
file.close();
emit loadWPFile();
emit waypointListChanged();
emit waypointListChanged(uas.getUASID());
emit waypointEditableListChanged();
emit waypointEditableListChanged(uasid);
}
void UASWaypointManager::clearWaypointList()
......@@ -458,7 +508,7 @@ void UASWaypointManager::clearWaypointList()
current_state = WP_CLEARLIST;
current_wp_id = 0;
current_partner_systemid = uas.getUASID();
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
sendWaypointClearAll();
......@@ -471,7 +521,7 @@ const QVector<Waypoint *> UASWaypointManager::getGlobalFrameWaypointList()
// with complete waypoint list
// instead of filtering on each request
QVector<Waypoint*> wps;
foreach (Waypoint* wp, waypoints)
foreach (Waypoint* wp, waypointsEditable)
{
if (wp->getFrame() == MAV_FRAME_GLOBAL || wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT)
{
......@@ -487,7 +537,7 @@ const QVector<Waypoint *> UASWaypointManager::getGlobalFrameAndNavTypeWaypointLi
// with complete waypoint list
// instead of filtering on each request
QVector<Waypoint*> wps;
foreach (Waypoint* wp, waypoints)
foreach (Waypoint* wp, waypointsEditable)
{
if ((wp->getFrame() == MAV_FRAME_GLOBAL || wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT) && wp->isNavigationType())
{
......@@ -503,7 +553,7 @@ const QVector<Waypoint *> UASWaypointManager::getNavTypeWaypointList()
// with complete waypoint list
// instead of filtering on each request
QVector<Waypoint*> wps;
foreach (Waypoint* wp, waypoints)
foreach (Waypoint* wp, waypointsEditable)
{
if (wp->isNavigationType())
{
......@@ -515,15 +565,15 @@ const QVector<Waypoint *> UASWaypointManager::getNavTypeWaypointList()
int UASWaypointManager::getIndexOf(Waypoint* wp)
{
return waypoints.indexOf(wp);
return waypointsEditable.indexOf(wp);
}
int UASWaypointManager::getGlobalFrameIndexOf(Waypoint* wp)
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints) {
foreach (Waypoint* p, waypointsEditable) {
if (p->getFrame() == MAV_FRAME_GLOBAL || wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT)
{
if (p == wp)
......@@ -539,10 +589,10 @@ int UASWaypointManager::getGlobalFrameIndexOf(Waypoint* wp)
int UASWaypointManager::getGlobalFrameAndNavTypeIndexOf(Waypoint* wp)
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints) {
foreach (Waypoint* p, waypointsEditable) {
if ((p->getFrame() == MAV_FRAME_GLOBAL || wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT) && p->isNavigationType())
{
if (p == wp)
......@@ -558,10 +608,10 @@ int UASWaypointManager::getGlobalFrameAndNavTypeIndexOf(Waypoint* wp)
int UASWaypointManager::getNavTypeIndexOf(Waypoint* wp)
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints)
foreach (Waypoint* p, waypointsEditable)
{
if (p->isNavigationType())
{
......@@ -578,10 +628,10 @@ int UASWaypointManager::getNavTypeIndexOf(Waypoint* wp)
int UASWaypointManager::getGlobalFrameCount()
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints)
foreach (Waypoint* p, waypointsEditable)
{
if (p->getFrame() == MAV_FRAME_GLOBAL || p->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT)
{
......@@ -594,10 +644,10 @@ int UASWaypointManager::getGlobalFrameCount()
int UASWaypointManager::getGlobalFrameAndNavTypeCount()
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints) {
foreach (Waypoint* p, waypointsEditable) {
if ((p->getFrame() == MAV_FRAME_GLOBAL || p->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT) && p->isNavigationType())
{
i++;
......@@ -609,10 +659,10 @@ int UASWaypointManager::getGlobalFrameAndNavTypeCount()
int UASWaypointManager::getNavTypeCount()
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints) {
foreach (Waypoint* p, waypointsEditable) {
if (p->isNavigationType()) {
i++;
}
......@@ -623,10 +673,10 @@ int UASWaypointManager::getNavTypeCount()
int UASWaypointManager::getLocalFrameCount()
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in global frame
int i = 0;
foreach (Waypoint* p, waypoints)
foreach (Waypoint* p, waypointsEditable)
{
if (p->getFrame() == MAV_FRAME_LOCAL_NED || p->getFrame() == MAV_FRAME_LOCAL_ENU)
{
......@@ -639,10 +689,10 @@ int UASWaypointManager::getLocalFrameCount()
int UASWaypointManager::getLocalFrameIndexOf(Waypoint* wp)
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in local frame
int i = 0;
foreach (Waypoint* p, waypoints)
foreach (Waypoint* p, waypointsEditable)
{
if (p->getFrame() == MAV_FRAME_LOCAL_NED || p->getFrame() == MAV_FRAME_LOCAL_ENU)
{
......@@ -659,10 +709,10 @@ int UASWaypointManager::getLocalFrameIndexOf(Waypoint* wp)
int UASWaypointManager::getMissionFrameIndexOf(Waypoint* wp)
{
// Search through all waypoints,
// Search through all waypointsEditable,
// counting only those in mission frame
int i = 0;
foreach (Waypoint* p, waypoints)
foreach (Waypoint* p, waypointsEditable)
{
if (p->getFrame() == MAV_FRAME_MISSION)
{
......@@ -677,14 +727,28 @@ int UASWaypointManager::getMissionFrameIndexOf(Waypoint* wp)
return -1;
}
void UASWaypointManager::readWaypoints()
/**
* @param readToEdit If true, incoming waypoints will be copied both to "edit"-tab and "view"-tab. Otherwise, only to "view"-tab.
*/
void UASWaypointManager::readWaypoints(bool readToEdit)
{
read_to_edit = readToEdit;
emit readGlobalWPFromUAS(true);
if(current_state == WP_IDLE) {
while(waypoints.size()>0) {
delete waypoints.back();
waypoints.pop_back();
//Clear the old view-list before receiving the new one
while(waypointsViewOnly.size()>0) {
delete waypointsViewOnly.back();
waypointsViewOnly.pop_back();
}
//Clear the old edit-list before receiving the new one
if (read_to_edit == true){
while(waypointsEditable.size()>0) {
delete waypointsEditable.back();
waypointsEditable.pop_back();
}
}
protocol_timer.start(PROTOCOL_TIMEOUT_MS);
......@@ -692,7 +756,7 @@ void UASWaypointManager::readWaypoints()
current_state = WP_GETLIST;
current_wp_id = 0;
current_partner_systemid = uas.getUASID();
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
sendWaypointRequestList();
......@@ -704,14 +768,14 @@ void UASWaypointManager::writeWaypoints()
{
if (current_state == WP_IDLE) {
// Send clear all if count == 0
if (waypoints.count() > 0) {
if (waypointsEditable.count() > 0) {
protocol_timer.start(PROTOCOL_TIMEOUT_MS);
current_retries = PROTOCOL_MAX_RETRIES;
current_count = waypoints.count();
current_count = waypointsEditable.count();
current_state = WP_SENDLIST;
current_wp_id = 0;
current_partner_systemid = uas.getUASID();
current_partner_systemid = uasid;
current_partner_compid = MAV_COMP_ID_MISSIONPLANNER;
//clear local buffer
......@@ -730,7 +794,7 @@ void UASWaypointManager::writeWaypoints()
waypoint_buffer.push_back(new mavlink_mission_item_t);
mavlink_mission_item_t *cur_d = waypoint_buffer.back();
memset(cur_d, 0, sizeof(mavlink_mission_item_t)); //initialize with zeros
const Waypoint *cur_s = waypoints.at(i);
const Waypoint *cur_s = waypointsEditable.at(i);
cur_d->autocontinue = cur_s->getAutoContinue();
cur_d->current = cur_s->getCurrent() & noCurrent; //make sure only one current waypoint is selected, the first selected will be chosen
......@@ -757,81 +821,85 @@ void UASWaypointManager::writeWaypoints()
//send the waypoint count to UAS (this starts the send transaction)
sendWaypointCount();
}
} else if (waypoints.count() == 0) {
} else if (waypointsEditable.count() == 0) {
sendWaypointClearAll();
} else {
//we're in another transaction, ignore command
// // qDebug() << "UASWaypointManager::sendWaypoints() doing something else ignoring command";
qDebug() << "UASWaypointManager::sendWaypoints() doing something else ignoring command";
}
}
void UASWaypointManager::sendWaypointClearAll()
{
if (!uas) return;
mavlink_message_t message;
mavlink_mission_clear_all_t wpca;
wpca.target_system = uas.getUASID();
wpca.target_system = uasid;
wpca.target_component = MAV_COMP_ID_MISSIONPLANNER;
emit updateStatusString(QString("Clearing waypoint list..."));
mavlink_msg_mission_clear_all_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpca);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_clear_all_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, &wpca);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
// // qDebug() << "sent waypoint clear all to ID " << wpca.target_system;
}
void UASWaypointManager::sendWaypointSetCurrent(quint16 seq)
{
if (!uas) return;
mavlink_message_t message;
mavlink_mission_set_current_t wpsc;
wpsc.target_system = uas.getUASID();
wpsc.target_system = uasid;
wpsc.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpsc.seq = seq;
emit updateStatusString(QString("Updating target waypoint..."));
mavlink_msg_mission_set_current_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpsc);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_set_current_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, &wpsc);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
// // qDebug() << "sent waypoint set current (" << wpsc.seq << ") to ID " << wpsc.target_system;
}
void UASWaypointManager::sendWaypointCount()
{
if (!uas) return;
mavlink_message_t message;
mavlink_mission_count_t wpc;
wpc.target_system = uas.getUASID();
wpc.target_system = uasid;
wpc.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpc.count = current_count;
// // qDebug() << "sent waypoint count (" << wpc.count << ") to ID " << wpc.target_system;
emit updateStatusString(QString("Starting to transmit waypoints..."));
mavlink_msg_mission_count_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpc);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_count_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, &wpc);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
// // qDebug() << "sent waypoint count (" << wpc.count << ") to ID " << wpc.target_system;
}
void UASWaypointManager::sendWaypointRequestList()
{
if (!uas) return;
mavlink_message_t message;
mavlink_mission_request_list_t wprl;
wprl.target_system = uas.getUASID();
wprl.target_system = uasid;
wprl.target_component = MAV_COMP_ID_MISSIONPLANNER;
emit updateStatusString(QString("Requesting waypoint list..."));
mavlink_msg_mission_request_list_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wprl);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_request_list_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, &wprl);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
// // qDebug() << "sent waypoint list request to ID " << wprl.target_system;
......@@ -840,24 +908,26 @@ void UASWaypointManager::sendWaypointRequestList()
void UASWaypointManager::sendWaypointRequest(quint16 seq)
{
if (!uas) return;
mavlink_message_t message;
mavlink_mission_request_t wpr;
wpr.target_system = uas.getUASID();
wpr.target_system = uasid;
wpr.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpr.seq = seq;
emit updateStatusString(QString("Retrieving waypoint ID %1 of %2 total").arg(wpr.seq).arg(current_count));
mavlink_msg_mission_request_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpr);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_request_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, &wpr);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
// // qDebug() << "sent waypoint request (" << wpr.seq << ") to ID " << wpr.target_system;
}
void UASWaypointManager::sendWaypoint(quint16 seq)
{
if (!uas) return;
mavlink_message_t message;
// // qDebug() <<" WP Buffer count: "<<waypoint_buffer.count();
......@@ -867,32 +937,32 @@ void UASWaypointManager::sendWaypoint(quint16 seq)
wp = waypoint_buffer.at(seq);
wp->target_system = uas.getUASID();
wp->target_system = uasid;
wp->target_component = MAV_COMP_ID_MISSIONPLANNER;
emit updateStatusString(QString("Sending waypoint ID %1 of %2 total").arg(wp->seq).arg(current_count));
// // qDebug() << "sent waypoint (" << wp->seq << ") to ID " << wp->target_system<<" WP Buffer count: "<<waypoint_buffer.count();
mavlink_msg_mission_item_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, wp);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_item_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, wp);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
}
}
void UASWaypointManager::sendWaypointAck(quint8 type)
{
if (!uas) return;
mavlink_message_t message;
mavlink_mission_ack_t wpa;
wpa.target_system = uas.getUASID();
wpa.target_system = uasid;
wpa.target_component = MAV_COMP_ID_MISSIONPLANNER;
wpa.type = type;
mavlink_msg_mission_ack_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpa);
uas.sendMessage(message);
MG::SLEEP::usleep(PROTOCOL_DELAY_MS * 1000);
mavlink_msg_mission_ack_encode(uas->mavlink->getSystemId(), uas->mavlink->getComponentId(), &message, &wpa);
if (uas) uas->sendMessage(message);
QGC::SLEEP::msleep(PROTOCOL_DELAY_MS);
// // qDebug() << "sent waypoint ack (" << wpa.type << ") to ID " << wpa.target_system;
}
......@@ -64,7 +64,7 @@ private:
}; ///< The possible states for the waypoint protocol
public:
UASWaypointManager(UAS&); ///< Standard constructor.
UASWaypointManager(UAS* uas=NULL); ///< Standard constructor
/** @name Received message handlers */
/*@{*/
......@@ -79,15 +79,20 @@ public:
/** @name Remote operations */
/*@{*/
void clearWaypointList(); ///< Sends the waypoint clear all message to the MAV
void readWaypoints(); ///< Requests the MAV's current waypoint list
void readWaypoints(bool read_to_edit=false); ///< Requests the MAV's current waypoint list.
void writeWaypoints(); ///< Sends the waypoint list to the MAV
int setCurrentWaypoint(quint16 seq); ///< Changes the current waypoint and sends the sequence number of the waypoint that should get the new target waypoint to the UAS
int setCurrentWaypoint(quint16 seq); ///< Sends the sequence number of the waypoint that should get the new target waypoint to the UAS
int setCurrentEditable(quint16 seq); ///< Changes the current waypoint in edit tab
/*@}*/
/** @name Waypoint list operations */
/*@{*/
const QVector<Waypoint *> &getWaypointList(void) {
return waypoints; ///< Returns a const reference to the waypoint list.
const QVector<Waypoint *> &getWaypointEditableList(void) {
return waypointsEditable; ///< Returns a const reference to the waypoint list.
}
const QVector<Waypoint *> &getWaypointViewOnlyList(void) {
return waypointsViewOnly; ///< Returns a const reference to the waypoint list.
}
const QVector<Waypoint *> getGlobalFrameWaypointList(); ///< Returns a global waypoint list
const QVector<Waypoint *> getGlobalFrameAndNavTypeWaypointList(); ///< Returns a global waypoint list containing only waypoints suitable for navigation. Actions and other mission items are filtered out.
......@@ -104,7 +109,7 @@ public:
int getLocalFrameCount(); ///< Get the count of local waypoints in the list
/*@}*/
UAS& getUAS() {
UAS* getUAS() {
return this->uas; ///< Returns the owning UAS
}
......@@ -124,21 +129,26 @@ public slots:
void timeout(); ///< Called by the timer if a response times out. Handles send retries.
/** @name Waypoint list operations */
/*@{*/
void addWaypoint(Waypoint *wp, bool enforceFirstActive=true); ///< adds a new waypoint to the end of the list and changes its sequence number accordingly
void addWaypointEditable(Waypoint *wp, bool enforceFirstActive=true); ///< adds a new waypoint to the end of the editable list and changes its sequence number accordingly
void addWaypointViewOnly(Waypoint *wp); ///< adds a new waypoint to the end of the view-only list and changes its sequence number accordingly
Waypoint* createWaypoint(bool enforceFirstActive=true); ///< Creates a waypoint
int removeWaypoint(quint16 seq); ///< locally remove the specified waypoint from the storage
void moveWaypoint(quint16 cur_seq, quint16 new_seq); ///< locally move a waypoint from its current position cur_seq to a new position new_seq
void saveWaypoints(const QString &saveFile); ///< saves the local waypoint list to saveFile
void loadWaypoints(const QString &loadFile); ///< loads a waypoint list from loadFile
void notifyOfChange(Waypoint* wp); ///< Notifies manager to changes to a waypoint
void notifyOfChangeEditable(Waypoint* wp); ///< Notifies manager to changes to an editable waypoint
void notifyOfChangeViewOnly(Waypoint* wp); ///< Notifies manager to changes to a viewonly waypoint, e.g. some widget wants to change "current"
/*@}*/
void handleLocalPositionChanged(UASInterface* mav, double x, double y, double z, quint64 time);
void handleGlobalPositionChanged(UASInterface* mav, double lat, double lon, double alt, quint64 time);
signals:
void waypointListChanged(void); ///< emits signal that the waypoint list has been changed
void waypointListChanged(int uasid); ///< Emits signal that list has been changed
void waypointChanged(int uasid, Waypoint* wp); ///< emits signal that waypoint has been changed
void waypointEditableListChanged(void); ///< emits signal that the list of editable waypoints has been changed
void waypointEditableListChanged(int uasid); ///< emits signal that the list of editable waypoints has been changed
void waypointEditableChanged(int uasid, Waypoint* wp); ///< emits signal that a single editable waypoint has been changed
void waypointViewOnlyListChanged(void); ///< emits signal that the list of editable waypoints has been changed
void waypointViewOnlyListChanged(int uasid); ///< emits signal that the list of editable waypoints has been changed
void waypointViewOnlyChanged(int uasid, Waypoint* wp); ///< emits signal that a single editable waypoint has been changed
void currentWaypointChanged(quint16); ///< emits the new current waypoint sequence number
void updateStatusString(const QString &); ///< emits the current status string
void waypointDistanceChanged(double distance); ///< Distance to next waypoint changed (in meters)
......@@ -147,18 +157,22 @@ signals:
void readGlobalWPFromUAS(bool value); ///< emits signal when finish to read Global WP from UAS
private:
UAS &uas; ///< Reference to the corresponding UAS
UAS* uas; ///< Reference to the corresponding UAS
quint32 current_retries; ///< The current number of retries left
quint16 current_wp_id; ///< The last used waypoint ID in the current protocol transaction
quint16 current_count; ///< The number of waypoints in the current protocol transaction
WaypointState current_state; ///< The current protocol state
quint8 current_partner_systemid; ///< The current protocol communication target system
quint8 current_partner_compid; ///< The current protocol communication target component
bool read_to_edit; ///< If true, after readWaypoints() incoming waypoints will be copied both to "edit"-tab and "view"-tab. Otherwise, only to "view"-tab.
QVector<Waypoint *> waypoints; ///< local waypoint list (main storage)
Waypoint* currentWaypoint; ///< The currently used waypoint
QVector<Waypoint *> waypointsViewOnly; ///< local copy of current waypoint list on MAV
QVector<Waypoint *> waypointsEditable; ///< local editable waypoint list
Waypoint* currentWaypointEditable; ///< The currently used waypoint
QVector<mavlink_mission_item_t *> waypoint_buffer; ///< buffer for waypoints during communication
QTimer protocol_timer; ///< Timer to catch timeouts
bool standalone; ///< If standalone is set, do not write to UAS
int uasid;
};
#endif // UASWAYPOINTMANAGER_H
......@@ -954,7 +954,7 @@ void HSIDisplay::drawWaypoints(QPainter& painter)
{
if (uas)
{
const QVector<Waypoint*>& list = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint*>& list = uas->getWaypointManager()->getWaypointEditableList();
QColor color;
painter.setBrush(Qt::NoBrush);
......
......@@ -15,10 +15,12 @@ QGCWaypointListMulti::QGCWaypointListMulti(QWidget *parent) :
void QGCWaypointListMulti::systemDeleted(QObject* uas)
{
UASInterface* mav = dynamic_cast<UASInterface*>(uas);
if (mav) {
if (mav)
{
int id = mav->getUASID();
WaypointList* list = lists.value(id, NULL);
if (list) {
if (list)
{
delete list;
lists.remove(id);
}
......
......@@ -41,14 +41,13 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
{
SerialLinkInterface* serialLink = dynamic_cast<SerialLinkInterface*>(link);
if(serialLink != 0) {
if(serialLink != 0)
{
serialLink->loadSettings();
this->link = serialLink;
// Setup the user interface according to link type
ui.setupUi(this);
//this->setVisible(false);
//this->hide();
// Create action to open this menu
// Create configuration action for this link
......@@ -154,10 +153,10 @@ SerialConfigurationWindow::SerialConfigurationWindow(LinkInterface* link, QWidge
// Display the widget
this->window()->setWindowTitle(tr("Serial Communication Settings"));
//this->show();
} else {
}
else
{
qDebug() << "Link is NOT a serial link, can't open configuration window";
}
}
......@@ -220,9 +219,12 @@ void SerialConfigurationWindow::setupPortList()
void SerialConfigurationWindow::enableFlowControl(bool flow)
{
if(flow) {
if(flow)
{
link->setFlowType(1);
} else {
}
else
{
link->setFlowType(0);
}
}
......
......@@ -17,15 +17,15 @@
#include <cmath>
#include <qmath.h>
#include "WaypointView.h"
#include "ui_WaypointView.h"
#include "WaypointEditableView.h"
#include "ui_WaypointEditableView.h"
#include "ui_QGCCustomWaypointAction.h"
WaypointView::WaypointView(Waypoint* wp, QWidget* parent) :
WaypointEditableView::WaypointEditableView(Waypoint* wp, QWidget* parent) :
QWidget(parent),
customCommand(new Ui_QGCCustomWaypointAction),
viewMode(QGC_WAYPOINTVIEW_MODE_NAV),
m_ui(new Ui::WaypointView)
viewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_NAV),
m_ui(new Ui::WaypointEditableView)
{
m_ui->setupUi(this);
......@@ -63,7 +63,8 @@ WaypointView::WaypointView(Waypoint* wp, QWidget* parent) :
updateValues();
// Check for mission frame
if (wp->getFrame() == MAV_FRAME_MISSION) {
if (wp->getFrame() == MAV_FRAME_MISSION)
{
m_ui->comboBox_action->setCurrentIndex(m_ui->comboBox_action->count()-1);
}
......@@ -102,24 +103,24 @@ WaypointView::WaypointView(Waypoint* wp, QWidget* parent) :
connect(customCommand->param7SpinBox, SIGNAL(valueChanged(double)), wp, SLOT(setParam7(double)));
}
void WaypointView::moveUp()
void WaypointEditableView::moveUp()
{
emit moveUpWaypoint(wp);
}
void WaypointView::moveDown()
void WaypointEditableView::moveDown()
{
emit moveDownWaypoint(wp);
}
void WaypointView::remove()
void WaypointEditableView::remove()
{
emit removeWaypoint(wp);
deleteLater();
}
void WaypointView::changedAutoContinue(int state)
void WaypointEditableView::changedAutoContinue(int state)
{
if (state == 0)
wp->setAutocontinue(false);
......@@ -127,7 +128,7 @@ void WaypointView::changedAutoContinue(int state)
wp->setAutocontinue(true);
}
void WaypointView::updateActionView(int action)
void WaypointEditableView::updateActionView(int action)
{
// Remove stretch item at index 17 (m_ui->removeSpacer)
m_ui->horizontalLayout->takeAt(17);
......@@ -231,7 +232,7 @@ void WaypointView::updateActionView(int action)
/**
* @param index The index of the combo box of the action entry, NOT the action ID
*/
void WaypointView::changedAction(int index)
void WaypointEditableView::changedAction(int index)
{
// set waypoint action
int actionIndex = m_ui->comboBox_action->itemData(index).toUInt();
......@@ -252,7 +253,7 @@ void WaypointView::changedAction(int index)
case MAV_CMD_NAV_LOITER_UNLIM:
case MAV_CMD_NAV_LOITER_TURNS:
case MAV_CMD_NAV_LOITER_TIME:
changeViewMode(QGC_WAYPOINTVIEW_MODE_NAV);
changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_NAV);
// Update frame view
updateFrameView(m_ui->comboBox_frame->currentIndex());
// Update view
......@@ -261,23 +262,23 @@ void WaypointView::changedAction(int index)
case MAV_CMD_ENUM_END:
default:
// Switch to mission frame
changeViewMode(QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING);
changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING);
break;
}
}
void WaypointView::changeViewMode(QGC_WAYPOINTVIEW_MODE mode)
void WaypointEditableView::changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE mode)
{
viewMode = mode;
switch (mode) {
case QGC_WAYPOINTVIEW_MODE_NAV:
case QGC_WAYPOINTVIEW_MODE_CONDITION:
case QGC_WAYPOINTEDITABLEVIEW_MODE_NAV:
case QGC_WAYPOINTEDITABLEVIEW_MODE_CONDITION:
// Hide everything, show condition widget
// TODO
case QGC_WAYPOINTVIEW_MODE_DO:
case QGC_WAYPOINTEDITABLEVIEW_MODE_DO:
break;
case QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING:
case QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING:
// Hide almost everything
m_ui->orbitSpinBox->hide();
m_ui->takeOffAngleSpinBox->hide();
......@@ -307,7 +308,7 @@ void WaypointView::changeViewMode(QGC_WAYPOINTVIEW_MODE mode)
}
void WaypointView::updateFrameView(int frame)
void WaypointEditableView::updateFrameView(int frame)
{
switch(frame) {
case MAV_FRAME_GLOBAL:
......@@ -338,7 +339,7 @@ void WaypointView::updateFrameView(int frame)
}
}
void WaypointView::deleted(QObject* waypoint)
void WaypointEditableView::deleted(QObject* waypoint)
{
Q_UNUSED(waypoint);
// if (waypoint == this->wp)
......@@ -347,7 +348,7 @@ void WaypointView::deleted(QObject* waypoint)
// }
}
void WaypointView::changedFrame(int index)
void WaypointEditableView::changedFrame(int index)
{
// set waypoint action
MAV_FRAME frame = (MAV_FRAME)m_ui->comboBox_frame->itemData(index).toUInt();
......@@ -356,19 +357,35 @@ void WaypointView::changedFrame(int index)
updateFrameView(frame);
}
void WaypointView::changedCurrent(int state)
void WaypointEditableView::changedCurrent(int state)
{
if (state == 0) {
//m_ui->selectedBox->blockSignals(true);
if (state == 0)
{
if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current
{
qDebug() << "Editable " << wp->getId() << " changedCurrent: State 0, current true" ;
m_ui->selectedBox->setChecked(true);
m_ui->selectedBox->setCheckState(Qt::Checked);
wp->setCurrent(false);
} else {
}
else
{
qDebug() << "Editable " << wp->getId() << " changedCurrent: State 0, current false";
m_ui->selectedBox->setChecked(false);
m_ui->selectedBox->setCheckState(Qt::Unchecked);
//wp->setCurrent(false);
}
}
else
{
qDebug() << "Editable " << wp->getId() << " changedCurrent: State 2";
wp->setCurrent(true);
emit changeCurrentWaypoint(wp->getId()); //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
}
//m_ui->selectedBox->blockSignals(false);
}
void WaypointView::updateValues()
void WaypointEditableView::updateValues()
{
// Check if we just lost the wp, delete the widget
// accordingly
......@@ -501,11 +518,11 @@ void WaypointView::updateValues()
// If action is unknown, set direct editing mode
if (wp->getAction() < 0 || wp->getAction() > MAV_CMD_NAV_TAKEOFF)
{
changeViewMode(QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING);
changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING);
}
else
{
if (viewMode != QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING)
if (viewMode != QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING)
{
// Action ID known, update
m_ui->comboBox_action->setCurrentIndex(action_index);
......@@ -696,19 +713,19 @@ void WaypointView::updateValues()
// wp->blockSignals(false);
}
void WaypointView::setCurrent(bool state)
void WaypointEditableView::setCurrent(bool state)
{
m_ui->selectedBox->blockSignals(true);
m_ui->selectedBox->setChecked(state);
m_ui->selectedBox->blockSignals(false);
}
WaypointView::~WaypointView()
WaypointEditableView::~WaypointEditableView()
{
delete m_ui;
}
void WaypointView::changeEvent(QEvent *e)
void WaypointEditableView::changeEvent(QEvent *e)
{
switch (e->type()) {
case QEvent::LanguageChange:
......
......@@ -30,33 +30,33 @@ This file is part of the QGROUNDCONTROL project
*
*/
#ifndef WAYPOINTVIEW_H
#define WAYPOINTVIEW_H
#ifndef WAYPOINTEDITABLEVIEW_H
#define WAYPOINTEDITABLEVIEW_H
#include <QtGui/QWidget>
#include "Waypoint.h"
#include <iostream>
enum QGC_WAYPOINTVIEW_MODE {
QGC_WAYPOINTVIEW_MODE_NAV,
QGC_WAYPOINTVIEW_MODE_CONDITION,
QGC_WAYPOINTVIEW_MODE_DO,
QGC_WAYPOINTVIEW_MODE_DIRECT_EDITING
enum QGC_WAYPOINTEDITABLEVIEW_MODE {
QGC_WAYPOINTEDITABLEVIEW_MODE_NAV,
QGC_WAYPOINTEDITABLEVIEW_MODE_CONDITION,
QGC_WAYPOINTEDITABLEVIEW_MODE_DO,
QGC_WAYPOINTEDITABLEVIEW_MODE_DIRECT_EDITING
};
namespace Ui
{
class WaypointView;
class WaypointEditableView;
}
class Ui_QGCCustomWaypointAction;
class WaypointView : public QWidget
class WaypointEditableView : public QWidget
{
Q_OBJECT
Q_DISABLE_COPY(WaypointView)
Q_DISABLE_COPY(WaypointEditableView)
public:
explicit WaypointView(Waypoint* wp, QWidget* parent);
virtual ~WaypointView();
explicit WaypointEditableView(Waypoint* wp, QWidget* parent);
virtual ~WaypointEditableView();
public:
void setCurrent(bool state);
......@@ -76,7 +76,7 @@ public slots:
void updateValues(void);
protected slots:
void changeViewMode(QGC_WAYPOINTVIEW_MODE mode);
void changeViewMode(QGC_WAYPOINTEDITABLEVIEW_MODE mode);
protected:
virtual void changeEvent(QEvent *e);
......@@ -84,18 +84,18 @@ protected:
// Special widgets extendending the
// waypoint view to mission capabilities
Ui_QGCCustomWaypointAction* customCommand;
QGC_WAYPOINTVIEW_MODE viewMode;
QGC_WAYPOINTEDITABLEVIEW_MODE viewMode;
private:
Ui::WaypointView *m_ui;
Ui::WaypointEditableView *m_ui;
signals:
void moveUpWaypoint(Waypoint*);
void moveDownWaypoint(Waypoint*);
void removeWaypoint(Waypoint*);
void currentWaypointChanged(quint16);
//void currentWaypointChanged(quint16); //unused
void changeCurrentWaypoint(quint16);
void setYaw(double);
};
#endif // WAYPOINTVIEW_H
#endif // WAYPOINTEDITABLEVIEW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WaypointView</class>
<widget class="QWidget" name="WaypointView">
<class>WaypointEditableView</class>
<widget class="QWidget" name="WaypointEditableView">
<property name="geometry">
<rect>
<x>0</x>
......@@ -604,7 +604,7 @@ Time to stay at this position before advancing</string>
<string/>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/go-up.svg</normaloff>:/images/actions/go-up.svg</iconset>
</property>
</widget>
......@@ -630,7 +630,7 @@ Time to stay at this position before advancing</string>
<string/>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/go-down.svg</normaloff>:/images/actions/go-down.svg</iconset>
</property>
</widget>
......@@ -653,7 +653,7 @@ Time to stay at this position before advancing</string>
<string/>
</property>
<property name="icon">
<iconset resource="../../mavground.qrc">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/list-remove.svg</normaloff>:/images/actions/list-remove.svg</iconset>
</property>
</widget>
......@@ -664,7 +664,7 @@ Time to stay at this position before advancing</string>
</layout>
</widget>
<resources>
<include location="../../mavground.qrc"/>
<include location="../../qgroundcontrol.qrc"/>
</resources>
<connections/>
</ui>
......@@ -51,16 +51,18 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) :
{
m_ui->setupUi(this);
listLayout = new QVBoxLayout(m_ui->listWidget);
listLayout->setSpacing(0);
listLayout->setMargin(0);
listLayout->setAlignment(Qt::AlignTop);
m_ui->listWidget->setLayout(listLayout);
//EDIT TAB
editableListLayout = new QVBoxLayout(m_ui->editableListWidget);
editableListLayout->setSpacing(0);
editableListLayout->setMargin(0);
editableListLayout->setAlignment(Qt::AlignTop);
m_ui->editableListWidget->setLayout(editableListLayout);
// ADD WAYPOINT
// Connect add action, set right button icon and connect action to this class
connect(m_ui->addButton, SIGNAL(clicked()), m_ui->actionAddWaypoint, SIGNAL(triggered()));
connect(m_ui->actionAddWaypoint, SIGNAL(triggered()), this, SLOT(add()));
connect(m_ui->actionAddWaypoint, SIGNAL(triggered()), this, SLOT(addEditable()));
// ADD WAYPOINT AT CURRENT POSITION
connect(m_ui->positionAddButton, SIGNAL(clicked()), this, SLOT(addCurrentPositionWaypoint()));
......@@ -77,6 +79,17 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) :
//connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setUAS(UASInterface*)));
//VIEW TAB
viewOnlyListLayout = new QVBoxLayout(m_ui->viewOnlyListWidget);
viewOnlyListLayout->setSpacing(0);
viewOnlyListLayout->setMargin(0);
viewOnlyListLayout->setAlignment(Qt::AlignTop);
m_ui->viewOnlyListWidget->setLayout(viewOnlyListLayout);
// REFRESH VIEW TAB
connect(m_ui->refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
// SET UAS AFTER ALL SIGNALS/SLOTS ARE CONNECTED
......@@ -126,9 +139,11 @@ void WaypointList::setUAS(UASInterface* uas)
connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64)));
connect(uas->getWaypointManager(), SIGNAL(updateStatusString(const QString &)), this, SLOT(updateStatusLabel(const QString &)));
connect(uas->getWaypointManager(), SIGNAL(waypointListChanged(void)), this, SLOT(waypointListChanged(void)));
connect(uas->getWaypointManager(), SIGNAL(waypointChanged(int,Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
connect(uas->getWaypointManager(), SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
connect(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged(void)), this, SLOT(waypointEditableListChanged(void)));
connect(uas->getWaypointManager(), SIGNAL(waypointEditableChanged(int,Waypoint*)), this, SLOT(updateWaypointEditable(int,Waypoint*)));
connect(uas->getWaypointManager(), SIGNAL(waypointViewOnlyListChanged(void)), this, SLOT(waypointViewOnlyListChanged(void)));
connect(uas->getWaypointManager(), SIGNAL(waypointViewOnlyChanged(int,Waypoint*)), this, SLOT(updateWaypointViewOnly(int,Waypoint*)));
connect(uas->getWaypointManager(), SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointViewOnlyChanged(quint16)));
//connect(uas->getWaypointManager(),SIGNAL(loadWPFile()),this,SLOT(setIsLoadFileWP()));
//connect(uas->getWaypointManager(),SIGNAL(readGlobalWPFromUAS(bool)),this,SLOT(setIsReadGlobalWP(bool)));
}
......@@ -164,15 +179,46 @@ void WaypointList::read()
{
if (uas)
{
uas->getWaypointManager()->readWaypoints();
uas->getWaypointManager()->readWaypoints(true);
}
}
void WaypointList::refresh()
{
if (uas)
{
uas->getWaypointManager()->readWaypoints(false);
}
}
void WaypointList::addEditable()
{
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
Waypoint *wp;
if (waypoints.size() > 0)
{
// Create waypoint with last frame
Waypoint *last = waypoints.at(waypoints.size()-1);
wp = new Waypoint(0, last->getX(), last->getY(), last->getZ(), last->getParam1(), last->getParam2(), last->getParam3(), last->getParam4(),
last->getAutoContinue(), false, last->getFrame(), last->getAction());
uas->getWaypointManager()->addWaypointEditable(wp);
}
else
{
// Create first waypoint at current MAV position
addCurrentPositionWaypoint();
}
}
}
void WaypointList::add()
/*
void WaypointList::addViewOnly()
{
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointViewOnlyList();
Waypoint *wp;
if (waypoints.size() > 0)
{
......@@ -180,7 +226,7 @@ void WaypointList::add()
Waypoint *last = waypoints.at(waypoints.size()-1);
wp = new Waypoint(0, last->getX(), last->getY(), last->getZ(), last->getParam1(), last->getParam2(), last->getParam3(), last->getParam4(),
last->getAutoContinue(), false, last->getFrame(), last->getAction());
uas->getWaypointManager()->addWaypoint(wp);
uas->getWaypointManager()->addWaypointEditable(wp);
}
else
{
......@@ -189,12 +235,13 @@ void WaypointList::add()
}
}
}
*/
void WaypointList::addCurrentPositionWaypoint()
{
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
Waypoint *wp;
Waypoint *last = 0;
if (waypoints.size() > 0)
......@@ -215,7 +262,7 @@ void WaypointList::addCurrentPositionWaypoint()
}
// Create global frame waypoint per default
wp = new Waypoint(0, uas->getLatitude(), uas->getLongitude(), uas->getAltitude(), 0, acceptanceRadiusGlobal, holdTime, yawGlobal, true, true, MAV_FRAME_GLOBAL_RELATIVE_ALT, MAV_CMD_NAV_WAYPOINT);
uas->getWaypointManager()->addWaypoint(wp);
uas->getWaypointManager()->addWaypointEditable(wp);
updateStatusLabel(tr("Added GLOBAL, ALTITUDE OVER GROUND waypoint"));
}
else if (uas->localPositionKnown())
......@@ -229,7 +276,7 @@ void WaypointList::addCurrentPositionWaypoint()
}
// Create local frame waypoint as second option
wp = new Waypoint(0, uas->getLocalX(), uas->getLocalY(), uas->getLocalZ(), uas->getYaw(), acceptanceRadiusLocal, holdTime, 0.0, true, true, MAV_FRAME_LOCAL_NED, MAV_CMD_NAV_WAYPOINT);
uas->getWaypointManager()->addWaypoint(wp);
uas->getWaypointManager()->addWaypointEditable(wp);
updateStatusLabel(tr("Added LOCAL (NED) waypoint"));
}
else
......@@ -242,7 +289,10 @@ void WaypointList::addCurrentPositionWaypoint()
void WaypointList::updateStatusLabel(const QString &string)
{
// Status label in write widget
m_ui->statusLabel->setText(string);
// Status label in read only widget
m_ui->viewStatusLabel->setText(string);
}
void WaypointList::changeCurrentWaypoint(quint16 seq)
......@@ -253,17 +303,22 @@ void WaypointList::changeCurrentWaypoint(quint16 seq)
}
}
void WaypointList::currentWaypointChanged(quint16 seq)
void WaypointList::currentWaypointEditableChanged(quint16 seq)
{
qDebug() << "WaypointList::currentWaypointEditableChanged";
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
uas->getWaypointManager()->setCurrentEditable(seq);
/*
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
if (seq < waypoints.size())
{
for(int i = 0; i < waypoints.size(); i++)
{
WaypointView* widget = wpViews.find(waypoints[i]).value();
WaypointEditableView* widget = wpEditableViews.find(waypoints[i]).value();
if (waypoints[i]->getId() == seq)
{
......@@ -275,25 +330,59 @@ void WaypointList::currentWaypointChanged(quint16 seq)
}
}
}
*/
}
}
void WaypointList::updateWaypoint(int uas, Waypoint* wp)
void WaypointList::currentWaypointViewOnlyChanged(quint16 seq)
{
if (uas)
{
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointViewOnlyList();
if (seq < waypoints.size())
{
for(int i = 0; i < waypoints.size(); i++)
{
WaypointViewOnlyView* widget = wpViewOnlyViews.find(waypoints[i]).value();
if (waypoints[i]->getId() == seq)
{
widget->setCurrent(true);
}
else
{
widget->setCurrent(false);
}
}
}
}
}
void WaypointList::updateWaypointEditable(int uas, Waypoint* wp)
{
Q_UNUSED(uas);
WaypointView *wpv = wpViews.value(wp);
WaypointEditableView *wpv = wpEditableViews.value(wp);
wpv->updateValues();
}
void WaypointList::waypointListChanged()
void WaypointList::updateWaypointViewOnly(int uas, Waypoint* wp)
{
Q_UNUSED(uas);
WaypointViewOnlyView *wpv = wpViewOnlyViews.value(wp);
wpv->updateValues();
}
void WaypointList::waypointViewOnlyListChanged()
{
if (uas) {
// Prevent updates to prevent visual flicker
this->setUpdatesEnabled(false);
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointViewOnlyList();
if (!wpViews.empty()) {
QMapIterator<Waypoint*,WaypointView*> viewIt(wpViews);
if (!wpViewOnlyViews.empty()) {
QMapIterator<Waypoint*,WaypointViewOnlyView*> viewIt(wpViewOnlyViews);
viewIt.toFront();
while(viewIt.hasNext()) {
viewIt.next();
......@@ -305,10 +394,10 @@ void WaypointList::waypointListChanged()
}
}
if (i == waypoints.size()) {
WaypointView* widget = wpViews.find(cur).value();
WaypointViewOnlyView* widget = wpViewOnlyViews.find(cur).value();
widget->hide();
listLayout->removeWidget(widget);
wpViews.remove(cur);
viewOnlyListLayout->removeWidget(widget);
wpViewOnlyViews.remove(cur);
}
}
}
......@@ -316,22 +405,75 @@ void WaypointList::waypointListChanged()
// then add/update the views for each waypoint in the list
for(int i = 0; i < waypoints.size(); i++) {
Waypoint *wp = waypoints[i];
if (!wpViews.contains(wp)) {
WaypointView* wpview = new WaypointView(wp, this);
wpViews.insert(wp, wpview);
if (!wpViewOnlyViews.contains(wp)) {
WaypointViewOnlyView* wpview = new WaypointViewOnlyView(wp, this);
wpViewOnlyViews.insert(wp, wpview);
connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
viewOnlyListLayout->insertWidget(i, wpview);
}
WaypointViewOnlyView *wpv = wpViewOnlyViews.value(wp);
//check if ordering has changed
if(viewOnlyListLayout->itemAt(i)->widget() != wpv) {
viewOnlyListLayout->removeWidget(wpv);
viewOnlyListLayout->insertWidget(i, wpv);
}
wpv->updateValues(); // update the values of the ui elements in the view
}
this->setUpdatesEnabled(true);
loadFileGlobalWP = false;
}
}
void WaypointList::waypointEditableListChanged()
{
if (uas) {
// Prevent updates to prevent visual flicker
this->setUpdatesEnabled(false);
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
if (!wpEditableViews.empty()) {
QMapIterator<Waypoint*,WaypointEditableView*> viewIt(wpEditableViews);
viewIt.toFront();
while(viewIt.hasNext()) {
viewIt.next();
Waypoint *cur = viewIt.key();
int i;
for (i = 0; i < waypoints.size(); i++) {
if (waypoints[i] == cur) {
break;
}
}
if (i == waypoints.size()) {
WaypointEditableView* widget = wpEditableViews.find(cur).value();
widget->hide();
editableListLayout->removeWidget(widget);
wpEditableViews.remove(cur);
}
}
}
// then add/update the views for each waypoint in the list
for(int i = 0; i < waypoints.size(); i++) {
Waypoint *wp = waypoints[i];
if (!wpEditableViews.contains(wp)) {
WaypointEditableView* wpview = new WaypointEditableView(wp, this);
wpEditableViews.insert(wp, wpview);
connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*)));
connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*)));
connect(wpview, SIGNAL(removeWaypoint(Waypoint*)), this, SLOT(removeWaypoint(Waypoint*)));
connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
listLayout->insertWidget(i, wpview);
//connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(currentWaypointEditableChanged(quint16)));
editableListLayout->insertWidget(i, wpview);
}
WaypointView *wpv = wpViews.value(wp);
WaypointEditableView *wpv = wpEditableViews.value(wp);
//check if ordering has changed
if(listLayout->itemAt(i)->widget() != wpv) {
listLayout->removeWidget(wpv);
listLayout->insertWidget(i, wpv);
if(editableListLayout->itemAt(i)->widget() != wpv) {
editableListLayout->removeWidget(wpv);
editableListLayout->insertWidget(i, wpv);
}
wpv->updateValues(); // update the values of the ui elements in the view
......@@ -341,38 +483,38 @@ void WaypointList::waypointListChanged()
}
}
//void WaypointList::waypointListChanged()
//void WaypointList::waypointEditableListChanged()
//{
// if (uas)
// {
// // Prevent updates to prevent visual flicker
// this->setUpdatesEnabled(false);
// // Get all waypoints
// const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
// const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
//// // Store the current state, then check which widgets to update
//// // and which ones to delete
//// QList<Waypoint*> oldWaypoints = wpViews.keys();
//// QList<Waypoint*> oldWaypoints = wpEditableViews.keys();
//// foreach (Waypoint* wp, waypoints)
//// {
//// WaypointView* wpview;
//// WaypointEditableView* wpview;
//// // Create any new waypoint
//// if (!wpViews.contains(wp))
//// if (!wpEditableViews.contains(wp))
//// {
//// wpview = new WaypointView(wp, this);
//// wpViews.insert(wp, wpview);
//// wpview = new WaypointEditableView(wp, this);
//// wpEditableViews.insert(wp, wpview);
//// connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*)));
//// connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*)));
//// connect(wpview, SIGNAL(removeWaypoint(Waypoint*)), this, SLOT(removeWaypoint(Waypoint*)));
//// connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
//// connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
//// listLayout->addWidget(wpview);
//// editableListLayout->addWidget(wpview);
//// }
//// else
//// {
//// // Update existing waypoints
//// wpview = wpViews.value(wp);
//// wpview = wpEditableViews.value(wp);
//// }
//// // Mark as updated by removing from old list
......@@ -386,18 +528,18 @@ void WaypointList::waypointListChanged()
//// foreach (Waypoint* wp, oldWaypoints)
//// {
//// // Delete waypoint view and entry in list
//// WaypointView* wpv = wpViews.value(wp);
//// WaypointEditableView* wpv = wpEditableViews.value(wp);
//// if (wpv)
//// {
//// listLayout->removeWidget(wpv);
//// editableListLayout->removeWidget(wpv);
//// delete wpv;
//// }
//// wpViews.remove(wp);
//// wpEditableViews.remove(wp);
//// }
// if (!wpViews.empty())
// if (!wpEditableViews.empty())
// {
// QMapIterator<Waypoint*,WaypointView*> viewIt(wpViews);
// QMapIterator<Waypoint*,WaypointEditableView*> viewIt(wpEditableViews);
// viewIt.toFront();
// while(viewIt.hasNext())
// {
......@@ -413,13 +555,13 @@ void WaypointList::waypointListChanged()
// }
// if (i == waypoints.size())
// {
// WaypointView* widget = wpViews.find(cur).value();
// WaypointEditableView* widget = wpEditableViews.find(cur).value();
// if (widget)
// {
// widget->hide();
// listLayout->removeWidget(widget);
// editableListLayout->removeWidget(widget);
// }
// wpViews.remove(cur);
// wpEditableViews.remove(cur);
// }
// }
// }
......@@ -428,19 +570,19 @@ void WaypointList::waypointListChanged()
// for(int i = 0; i < waypoints.size(); i++)
// {
// Waypoint *wp = waypoints[i];
// if (!wpViews.contains(wp))
// if (!wpEditableViews.contains(wp))
// {
// WaypointView* wpview = new WaypointView(wp, this);
// wpViews.insert(wp, wpview);
// WaypointEditableView* wpview = new WaypointEditableView(wp, this);
// wpEditableViews.insert(wp, wpview);
// connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*)));
// connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*)));
// connect(wpview, SIGNAL(removeWaypoint(Waypoint*)), this, SLOT(removeWaypoint(Waypoint*)));
// connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
// connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
// }
// WaypointView *wpv = wpViews.value(wp);
// WaypointEditableView *wpv = wpEditableViews.value(wp);
// wpv->updateValues(); // update the values of the ui elements in the view
// listLayout->addWidget(wpv);
// editableListLayout->addWidget(wpv);
// }
// this->setUpdatesEnabled(true);
......@@ -451,7 +593,7 @@ void WaypointList::waypointListChanged()
void WaypointList::moveUp(Waypoint* wp)
{
if (uas) {
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
//get the current position of wp in the local storage
int i;
......@@ -470,7 +612,7 @@ void WaypointList::moveUp(Waypoint* wp)
void WaypointList::moveDown(Waypoint* wp)
{
if (uas) {
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
//get the current position of wp in the local storage
int i;
......@@ -512,9 +654,9 @@ void WaypointList::on_clearWPListButton_clicked()
if (uas) {
emit clearPathclicked();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
while(!waypoints.isEmpty()) { //for(int i = 0; i <= waypoints.size(); i++)
WaypointView* widget = wpViews.find(waypoints[0]).value();
WaypointEditableView* widget = wpEditableViews.find(waypoints[0]).value();
widget->remove();
}
} else {
......@@ -531,7 +673,7 @@ void WaypointList::on_clearWPListButton_clicked()
//{
// if (uas)
// {
// const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
// const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
// if (waypoints.size() > 0)
// {
// Waypoint *temp = waypoints.at(indexWP);
......@@ -563,9 +705,9 @@ void WaypointList::on_clearWPListButton_clicked()
void WaypointList::clearWPWidget()
{
if (uas) {
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *> &waypoints = uas->getWaypointManager()->getWaypointEditableList();
while(!waypoints.isEmpty()) { //for(int i = 0; i <= waypoints.size(); i++)
WaypointView* widget = wpViews.find(waypoints[0]).value();
WaypointEditableView* widget = wpEditableViews.find(waypoints[0]).value();
widget->remove();
}
}
......
......@@ -40,8 +40,8 @@ This file is part of the QGROUNDCONTROL project
#include <QTimer>
#include "Waypoint.h"
#include "UASInterface.h"
#include "WaypointView.h"
#include "WaypointEditableView.h"
#include "WaypointViewOnlyView.h"
namespace Ui
{
......@@ -69,10 +69,14 @@ public slots:
void loadWaypoints();
/** @brief Transmit the local waypoint list to the UAS */
void transmit();
/** @brief Read the remote waypoint list */
/** @brief Read the remote waypoint list to both tabs */
void read();
/** @brief Add a waypoint */
void add();
/** @brief Read the remote waypoint list to "view"-tab only*/
void refresh();
/** @brief Add a waypoint to "edit"-tab */
void addEditable();
/** @brief Add a waypoint to "view"-tab */
// void addViewOnly();
/** @brief Add a waypoint at the current MAV position */
void addCurrentPositionWaypoint();
/** @brief Add a waypoint by mouse click over the map */
......@@ -82,12 +86,18 @@ public slots:
void updateStatusLabel(const QString &string);
/** @brief The user wants to change the current waypoint */
void changeCurrentWaypoint(quint16 seq);
/** @brief The waypoint planner changed the current waypoint */
void currentWaypointChanged(quint16 seq);
/** @brief The waypoint manager informs that one waypoint was changed */
void updateWaypoint(int uas, Waypoint* wp);
/** @brief The waypoint manager informs that the waypoint list was changed */
void waypointListChanged(void);
/** @brief Current waypoint in edit-tab was changed, so the list must be updated (to contain only one waypoint checked as "current") */
void currentWaypointEditableChanged(quint16 seq);
/** @brief Current waypoint on UAV was changed, update view-tab */
void currentWaypointViewOnlyChanged(quint16 seq);
/** @brief The waypoint manager informs that one editable waypoint was changed */
void updateWaypointEditable(int uas, Waypoint* wp);
/** @brief The waypoint manager informs that one viewonly waypoint was changed */
void updateWaypointViewOnly(int uas, Waypoint* wp);
/** @brief The waypoint manager informs that the editable waypoint list was changed */
void waypointEditableListChanged(void);
/** @brief The waypoint manager informs that the waypoint list on the MAV was changed */
void waypointViewOnlyListChanged(void);
// /** @brief The MapWidget informs that a waypoint global was changed on the map */
// void waypointGlobalChanged(const QPointF coordinate, const int indexWP);
......@@ -115,8 +125,10 @@ protected:
virtual void changeEvent(QEvent *e);
protected:
QMap<Waypoint*, WaypointView*> wpViews;
QVBoxLayout* listLayout;
QMap<Waypoint*, WaypointEditableView*> wpEditableViews;
QMap<Waypoint*, WaypointViewOnlyView*> wpViewOnlyViews;
QVBoxLayout* viewOnlyListLayout;
QVBoxLayout* editableListLayout;
UASInterface* uas;
double mavX;
double mavY;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>798</width>
<height>218</height>
<width>854</width>
<height>398</height>
</rect>
</property>
<property name="minimumSize">
......@@ -19,14 +19,48 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="100,0,0,0" columnstretch="1,1,5,5,100,10,5,5,5,5,5">
<property name="margin">
<number>4</number>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>4</number>
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="editTab">
<attribute name="title">
<string>Edit Waypoints</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>6</number>
</property>
<item row="0" column="0" colspan="11">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0" colspan="9">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
......@@ -36,19 +70,28 @@
<rect>
<x>0</x>
<y>0</y>
<width>786</width>
<height>174</height>
<width>834</width>
<height>325</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QWidget" name="listWidget" native="true">
<widget class="QWidget" name="editableListWidget" native="true">
<property name="toolTip">
<string>Waypoint list. The list is empty until you issue a read command or add waypoints.</string>
</property>
......@@ -64,47 +107,72 @@
</widget>
</widget>
</item>
<item row="2" column="9">
<widget class="QPushButton" name="readButton">
<item row="1" column="0">
<widget class="QPushButton" name="saveButton">
<property name="toolTip">
<string>Read all waypoints from the MAV. Clears the list on this computer.</string>
<string>Save waypoints to a file on the local harddisk. Does not save them on the MAV.</string>
</property>
<property name="statusTip">
<string>Read all waypoints from the MAV. Clears the list on this computer.</string>
<string>Save waypoints to a file on the local harddisk. Does not save them on the MAV.</string>
</property>
<property name="whatsThis">
<string>Read all waypoints from the MAV. Clears the list on this computer.</string>
<string>Save waypoints to a file on the local harddisk. Does not save them on the MAV.</string>
</property>
<property name="text">
<string>Read</string>
<string>Save WPs</string>
</property>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/status/software-update-available.svg</normaloff>:/images/status/software-update-available.svg</iconset>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="loadButton">
<property name="toolTip">
<string>Load waypoints from a file on the local harddisk. Does not load the waypoints on the MAV.</string>
</property>
<property name="statusTip">
<string>Load waypoints from a file on the local harddisk. Does not load the waypoints on the MAV.</string>
</property>
<property name="whatsThis">
<string>Load waypoints from a file on the local harddisk. Does not load the waypoints on the MAV.</string>
</property>
<property name="text">
<string>Load WPs</string>
</property>
</widget>
</item>
<item row="2" column="10">
<widget class="QPushButton" name="transmitButton">
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>127</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="4">
<widget class="QToolButton" name="positionAddButton">
<property name="toolTip">
<string>Transmit all waypoints on this list to the MAV.</string>
<string>Set the current vehicle position as new waypoint</string>
</property>
<property name="statusTip">
<string>Transmit all waypoints on this list to the MAV.</string>
<string>Set the current vehicle position as new waypoint</string>
</property>
<property name="whatsThis">
<string>Transmit all waypoints on this list to the MAV.</string>
<string>Set the current vehicle position as new waypoint</string>
</property>
<property name="text">
<string>Write</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/devices/network-wireless.svg</normaloff>:/images/devices/network-wireless.svg</iconset>
<normaloff>:/images/actions/go-bottom.svg</normaloff>:/images/actions/go-bottom.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="7">
<item row="1" column="5">
<widget class="QToolButton" name="addButton">
<property name="toolTip">
<string>Add a new waypoint to this list. Transmit via write to the MAV.</string>
......@@ -124,108 +192,190 @@
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="loadButton">
<item row="1" column="6">
<widget class="QToolButton" name="clearWPListButton">
<property name="toolTip">
<string>Load waypoints from a file on the local harddisk. Does not load the waypoints on the MAV.</string>
<string>Delete all waypoints from this list. You have to click write to clear the list on the MAV as well.</string>
</property>
<property name="statusTip">
<string>Load waypoints from a file on the local harddisk. Does not load the waypoints on the MAV.</string>
<string>Delete all waypoints from this list. You have to click write to clear the list on the MAV as well.</string>
</property>
<property name="whatsThis">
<string>Load waypoints from a file on the local harddisk. Does not load the waypoints on the MAV.</string>
<string>Delete all waypoints from this list. You have to click write to clear the list on the MAV as well.</string>
</property>
<property name="text">
<string>Load WPs</string>
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/process-stop.svg</normaloff>:/images/actions/process-stop.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="saveButton">
<item row="1" column="7">
<widget class="QPushButton" name="readButton">
<property name="toolTip">
<string>Save waypoints to a file on the local harddisk. Does not save them on the MAV.</string>
<string>Read all waypoints from the MAV. Clears the list on this computer.</string>
</property>
<property name="statusTip">
<string>Save waypoints to a file on the local harddisk. Does not save them on the MAV.</string>
<string>Read all waypoints from the MAV. Clears the list on this computer.</string>
</property>
<property name="whatsThis">
<string>Save waypoints to a file on the local harddisk. Does not save them on the MAV.</string>
<string>Read all waypoints from the MAV. Clears the list on this computer.</string>
</property>
<property name="text">
<string>Save WPs</string>
</property>
</widget>
</item>
<item row="2" column="5">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<string>Read</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>127</width>
<height>20</height>
</size>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/status/software-update-available.svg</normaloff>:/images/status/software-update-available.svg</iconset>
</property>
</spacer>
</widget>
</item>
<item row="2" column="6">
<widget class="QToolButton" name="positionAddButton">
<item row="1" column="8">
<widget class="QPushButton" name="transmitButton">
<property name="toolTip">
<string>Set the current vehicle position as new waypoint</string>
<string>Transmit all waypoints on this list to the MAV.</string>
</property>
<property name="statusTip">
<string>Set the current vehicle position as new waypoint</string>
<string>Transmit all waypoints on this list to the MAV.</string>
</property>
<property name="whatsThis">
<string>Set the current vehicle position as new waypoint</string>
<string>Transmit all waypoints on this list to the MAV.</string>
</property>
<property name="text">
<string>...</string>
<string>Write</string>
</property>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/go-bottom.svg</normaloff>:/images/actions/go-bottom.svg</iconset>
<normaloff>:/images/devices/network-wireless.svg</normaloff>:/images/devices/network-wireless.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="8">
<widget class="QToolButton" name="clearWPListButton">
<item row="1" column="2">
<widget class="QLabel" name="statusLabel">
<property name="toolTip">
<string>Delete all waypoints from this list. You have to click write to clear the list on the MAV as well.</string>
<string>The current waypoint transmission status</string>
</property>
<property name="statusTip">
<string>Delete all waypoints from this list. You have to click write to clear the list on the MAV as well.</string>
<string>The current waypoint transmission status</string>
</property>
<property name="whatsThis">
<string>Delete all waypoints from this list. You have to click write to clear the list on the MAV as well.</string>
<string>The current waypoint transmission status</string>
</property>
<property name="text">
<string>...</string>
<string>Please add first waypoint.</string>
</property>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/process-stop.svg</normaloff>:/images/actions/process-stop.svg</iconset>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="viewTab">
<attribute name="title">
<string>Onboard Waypoints</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0" colspan="3">
<widget class="QScrollArea" name="readOnlyScrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>834</width>
<height>331</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QWidget" name="viewOnlyListWidget" native="true">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QLabel" name="statusLabel">
</layout>
</widget>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>714</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="refreshButton">
<property name="toolTip">
<string>The current waypoint transmission status</string>
<string>Read all waypoints from the MAV and display in View tab..</string>
</property>
<property name="statusTip">
<string>The current waypoint transmission status</string>
<string>Read all waypoints from the MAV and display in View tab..</string>
</property>
<property name="whatsThis">
<string>The current waypoint transmission status</string>
<string>Read all waypoints from the MAV and display in View tab.</string>
</property>
<property name="text">
<string>Please add first waypoint.</string>
<string>Refresh</string>
</property>
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
<normaloff>:/images/actions/go-jump.svg</normaloff>:/images/actions/go-jump.svg</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="viewStatusLabel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
<action name="actionAddWaypoint">
<property name="icon">
<iconset resource="../../qgroundcontrol.qrc">
......
#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)
{
bool new_value = false;
if (state != 0)
{
new_value = true;
}
m_ui->autoContinue->blockSignals(true);
m_ui->autoContinue->setChecked(state);
m_ui->autoContinue->blockSignals(false);
wp->setAutocontinue(new_value);
emit changeAutoContinue(wp->getId(),new_value);
}
void WaypointViewOnlyView::changedCurrent(int state)
{
qDebug() << "Trof: WaypointViewOnlyView::changedCurrent(" << state << ") ID:" << wp->getId();
m_ui->current->blockSignals(true);
if (state == 0)
{
/*
m_ui->current->setStyleSheet("");
*/
if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current
{
m_ui->current->setChecked(true);
m_ui->current->setCheckState(Qt::Checked);
}
else
{
m_ui->current->setChecked(false);
m_ui->current->setCheckState(Qt::Unchecked);
wp->setCurrent(false);
}
}
else
{
/*
FIXME: The checkbox should turn gray to indicate, that set_current request has been sent to UAV. It should become blue (checked) after receiving set_current_ack from waypointplanner.
m_ui->current->setStyleSheet("*::indicator { \
border: 1px solid #777777; \
border-radius: 2px; \
color: #999999; \
width: 10px; \
height: 10px; \
}");
*/
wp->setCurrent(true);
emit changeCurrentWaypoint(wp->getId()); //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
}
m_ui->current->blockSignals(false);
}
void WaypointViewOnlyView::setCurrent(bool state)
{
m_ui->current->blockSignals(true);
m_ui->current->setChecked(state);
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;
}
// 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;
}
// update frame
m_ui->idLabel->setText(QString("%1").arg(wp->getId()));
if (m_ui->current->isChecked() != wp->getCurrent())
{
m_ui->current->blockSignals(true);
m_ui->current->setChecked(wp->getCurrent());
m_ui->current->blockSignals(false);
}
if (m_ui->autoContinue->isChecked() != wp->getAutoContinue())
{
m_ui->autoContinue->blockSignals(true);
m_ui->autoContinue->setChecked(wp->getAutoContinue());
m_ui->autoContinue->blockSignals(false);
}
switch (wp->getAction())
{
case MAV_CMD_NAV_WAYPOINT:
{
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()).arg(wp->getY()).arg(wp->getZ()).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()).arg(wp->getY()).arg(wp->getZ()).arg(wp->getParam4()).arg(wp->getParam2()));
}
break;
}
case MAV_CMD_NAV_LAND:
{
m_ui->displayBar->setText(QString("LAND. Go to (%1, %2, %3) and descent; yaw: %4").arg(wp->getX()).arg(wp->getY()).arg(wp->getZ()).arg(wp->getParam4()));
break;
}
case MAV_CMD_NAV_TAKEOFF:
{
m_ui->displayBar->setText(QString("TAKEOFF. Go to (%1, %2, %3); yaw: %4").arg(wp->getX()).arg(wp->getY()).arg(wp->getZ()).arg(wp->getParam4()));
break;
}
case MAV_CMD_DO_JUMP:
{
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;
}
case MAV_CMD_CONDITION_DELAY:
{
m_ui->displayBar->setText(QString("Delay: %1 sec").arg(wp->getParam1()));
break;
}
case 237: //MAV_CMD_DO_START_SEARCH
{
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;
}
case 238: //MAV_CMD_DO_FINISH_SEARCH
{
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;
}
case 240: //MAV_CMD_DO_SWEEP
{
m_ui->displayBar->setText(QString("Sweep. Corners: (%1,%2) and (%3,%4); z: %5; scan radius: %6").arg(wp->getParam3()).arg(wp->getParam4()).arg(wp->getParam5()).arg(wp->getParam6()).arg(wp->getParam7()).arg(wp->getParam1()));
break;
}
default:
{
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;
}
}
}
WaypointViewOnlyView::~WaypointViewOnlyView()
{
delete m_ui;
}
#ifndef WAYPOINTVIEWONLYVIEW_H
#define WAYPOINTVIEWONLYVIEW_H
#include <QtGui/QWidget>
#include "Waypoint.h"
#include <iostream>
namespace Ui {
class WaypointViewOnlyView;
}
class WaypointViewOnlyView : public QWidget
{
Q_OBJECT
public:
explicit WaypointViewOnlyView(Waypoint* wp, QWidget *parent = 0);
~WaypointViewOnlyView();
public slots:
void changedCurrent(int state);
void changedAutoContinue(int state);
void updateValues(void);
void setCurrent(bool state);
signals:
void changeCurrentWaypoint(quint16);
void changeAutoContinue(quint16, bool);
protected:
Waypoint* wp;
private:
Ui::WaypointViewOnlyView *m_ui;
};
#endif // WAYPOINTVIEWONLYVIEW_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WaypointViewOnlyView</class>
<widget class="QWidget" name="WaypointViewOnlyView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>381</width>
<height>40</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,100,1">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="current">
<property name="toolTip">
<string>Currently executed waypoint</string>
</property>
<property name="statusTip">
<string>Currently executed waypoint</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="idLabel">
<property name="text">
<string>ID</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="displayBar">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoContinue">
<property name="toolTip">
<string>Automatically continue after this waypoint</string>
</property>
<property name="statusTip">
<string>Automatically continue after this waypoint</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -164,7 +164,7 @@ void QGCMapWidget::mouseDoubleClickEvent(QMouseEvent* event)
wp->setLongitude(pos.Lng());
wp->setAltitude(0);
// wp->blockSignals(false);
// currWPManager->notifyOfChange(wp);
// currWPManager->notifyOfChangeEditable(wp);
}
}
OPMapWidget::mouseDoubleClickEvent(event);
......@@ -190,10 +190,10 @@ void QGCMapWidget::activeUASSet(UASInterface* uas)
if (currWPManager)
{
// Disconnect the waypoint manager / data storage from the UI
disconnect(currWPManager, SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
disconnect(currWPManager, SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
disconnect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypoint(Waypoint*)));
disconnect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChange(Waypoint*)));
disconnect(currWPManager, SIGNAL(waypointEditableListChanged(int)), this, SLOT(updateWaypointList(int)));
disconnect(currWPManager, SIGNAL(waypointEditableChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
disconnect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypointEditable(Waypoint*)));
disconnect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChangeEditable(Waypoint*)));
}
if (uas)
......@@ -201,10 +201,10 @@ void QGCMapWidget::activeUASSet(UASInterface* uas)
currWPManager = uas->getWaypointManager();
// Connect the waypoint manager / data storage to the UI
connect(currWPManager, SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(currWPManager, SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
connect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypoint(Waypoint*)));
connect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChange(Waypoint*)));
connect(currWPManager, SIGNAL(waypointEditableListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(currWPManager, SIGNAL(waypointEditableChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
connect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypointEditable(Waypoint*)));
connect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChangeEditable(Waypoint*)));
updateSelectedSystem(uas->getUASID());
followUAVID = uas->getUASID();
......
......@@ -278,7 +278,7 @@ Pixhawk3DWidget::insertWaypoint(void)
if (wp) {
wp->setFrame(frame);
uas->getWaypointManager()->addWaypoint(wp);
uas->getWaypointManager()->addWaypointEditable(wp);
}
}
}
......@@ -294,7 +294,7 @@ Pixhawk3DWidget::setWaypoint(void)
{
if (uas) {
const QVector<Waypoint *> waypoints =
uas->getWaypointManager()->getWaypointList();
uas->getWaypointManager()->getWaypointEditableList();
Waypoint* waypoint = waypoints.at(selectedWpIndex);
if (frame == MAV_FRAME_GLOBAL) {
......@@ -341,7 +341,7 @@ Pixhawk3DWidget::setWaypointAltitude(void)
if (uas) {
bool ok;
const QVector<Waypoint *> waypoints =
uas->getWaypointManager()->getWaypointList();
uas->getWaypointManager()->getWaypointEditableList();
Waypoint* waypoint = waypoints.at(selectedWpIndex);
double altitude = waypoint->getZ();
......@@ -367,7 +367,7 @@ Pixhawk3DWidget::clearAllWaypoints(void)
{
if (uas) {
const QVector<Waypoint *> waypoints =
uas->getWaypointManager()->getWaypointList();
uas->getWaypointManager()->getWaypointEditableList();
for (int i = waypoints.size() - 1; i >= 0; --i) {
uas->getWaypointManager()->removeWaypoint(i);
}
......
......@@ -209,9 +209,9 @@ void QGCGoogleEarthView::addUAS(UASInterface* uas)
connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64)));
// Receive waypoint updates
// Connect the waypoint manager / data storage to the UI
connect(uas->getWaypointManager(), SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(uas->getWaypointManager(), SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
//connect(this, SIGNAL(waypointCreated(Waypoint*)), uas->getWaypointManager(), SLOT(addWaypoint(Waypoint*)));
connect(uas->getWaypointManager(), SIGNAL(waypointEditableListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(uas->getWaypointManager(), SIGNAL(waypointEditableChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
//connect(this, SIGNAL(waypointCreated(Waypoint*)), uas->getWaypointManager(), SLOT(addWaypointEditable(Waypoint*)));
// TODO Update waypoint list on UI changes here
}
......@@ -722,7 +722,7 @@ void QGCGoogleEarthView::updateState()
wp->setLatitude(latitude);
wp->setLongitude(longitude);
wp->setAltitude(altitude);
mav->getWaypointManager()->notifyOfChange(wp);
mav->getWaypointManager()->notifyOfChangeEditable(wp);
}
}
}
......
......@@ -73,7 +73,7 @@ WaypointGroupNode::update(MAV_FRAME frame, UASInterface *uas)
removeChild(0, getNumChildren());
}
const QVector<Waypoint *>& list = uas->getWaypointManager()->getWaypointList();
const QVector<Waypoint *>& list = uas->getWaypointManager()->getWaypointEditableList();
for (int i = 0; i < list.size(); i++) {
Waypoint* wp = list.at(i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment