Commit c316e0fc authored by pixhawk's avatar pixhawk

View-Edit waypoint list separation implemented. Working, but still has come bugs.

parent ea098a0d
......@@ -267,16 +267,23 @@ void UASWaypointManager::notifyOfChangeEditable(Waypoint* wp)
}
}
//void notifyOfChangeViewOnly(Waypoint* wp)
//{
//}
void UASWaypointManager::notifyOfChangeViewOnly(Waypoint* wp)
{
if (wp != NULL) {
emit waypointViewOnlyChanged(uas.getUASID(), wp);
} else {
emit waypointViewOnlyListChanged();
emit waypointViewOnlyListChanged(uas.getUASID());
}
}
int UASWaypointManager::setCurrentWaypoint(quint16 seq)
{
if (seq < waypointsViewOnly.size()) {
if(current_state == WP_IDLE) {
/*
//update local main storage
for(int i = 0; i < waypointsViewOnly.size(); i++) {
if (waypointsViewOnly[i]->getId() == seq) {
......@@ -286,8 +293,8 @@ int UASWaypointManager::setCurrentWaypoint(quint16 seq)
waypointsViewOnly[i]->setCurrent(false);
}
}
*/
//TODO: signal changed waypoint list
//send change to UAS - important to note: if the transmission fails, we have inconsistencies
protocol_timer.start(PROTOCOL_TIMEOUT_MS);
......@@ -308,17 +315,30 @@ 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)
{
wp->setId(waypointsViewOnly.size());
if (waypointsEditable.size() == 0)
{
wp->setCurrent(true);
//currentWaypointEditable = wp;
}
{
waypointsViewOnly.insert(waypointsViewOnly.size(), wp);
connect(wp, SIGNAL(changed(Waypoint*)), this, SLOT(notifyOfChangeViewOnly(Waypoint*)));
......@@ -719,10 +739,19 @@ void UASWaypointManager::readWaypoints(bool readToEdit)
read_to_edit = readToEdit;
emit readGlobalWPFromUAS(true);
if(current_state == WP_IDLE) {
while(waypointsEditable.size()>0) {
delete waypointsEditable.back();
waypointsEditable.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);
......@@ -799,7 +828,7 @@ void UASWaypointManager::writeWaypoints()
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";
}
}
......
......@@ -82,7 +82,8 @@ public:
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 */
......@@ -136,7 +137,7 @@ public slots:
void saveWaypoints(const QString &saveFile); ///< saves the local waypoint list to saveFile
void loadWaypoints(const QString &loadFile); ///< loads a waypoint list from loadFile
void notifyOfChangeEditable(Waypoint* wp); ///< Notifies manager to changes to an editable waypoint
//void notifyOfChangeViewOnly(Waypoint* wp); ///< Notifies manager to changes to a viewonly 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);
......
......@@ -358,14 +358,27 @@ void WaypointEditableView::changedFrame(int index)
void WaypointEditableView::changedCurrent(int state)
{
if (state == 0) {
m_ui->selectedBox->setChecked(true);
m_ui->selectedBox->setCheckState(Qt::Checked);
//wp->setCurrent(false); //FIXME: Is this line needed?
} else {
m_ui->selectedBox->blockSignals(true);
if (state == 0)
{
if (wp->getCurrent() == true) //User clicked on the waypoint, that is already current
{
m_ui->selectedBox->setChecked(true);
m_ui->selectedBox->setCheckState(Qt::Checked);
}
else
{
m_ui->selectedBox->setChecked(false);
m_ui->selectedBox->setCheckState(Qt::Unchecked);
wp->setCurrent(false);
}
}
else
{
wp->setCurrent(true);
emit changeCurrentWaypoint(wp->getId()); //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
//emit changeCurrentWaypoint(wp->getId()); //the slot changeCurrentWaypoint() in WaypointList sets all other current flags to false
}
m_ui->selectedBox->blockSignals(false);
}
void WaypointEditableView::updateValues()
......
......@@ -62,7 +62,7 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) :
// 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()));
......@@ -143,7 +143,7 @@ void WaypointList::setUAS(UASInterface* uas)
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(currentWaypointChanged(quint16)));
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)));
}
......@@ -213,6 +213,7 @@ void WaypointList::addEditable()
}
}
/*
void WaypointList::addViewOnly()
{
if (uas)
......@@ -234,6 +235,7 @@ void WaypointList::addViewOnly()
}
}
}
*/
void WaypointList::addCurrentPositionWaypoint()
{
......@@ -298,7 +300,8 @@ void WaypointList::changeCurrentWaypoint(quint16 seq)
}
}
void WaypointList::currentWaypointChanged(quint16 seq)
void WaypointList::currentWaypointEditableChanged(quint16 seq)
{
if (uas)
{
......@@ -323,13 +326,45 @@ 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);
WaypointEditableView *wpv = wpEditableViews.value(wp);
wpv->updateValues();
}
void WaypointList::updateWaypointViewOnly(int uas, Waypoint* wp)
{
Q_UNUSED(uas);
WaypointViewOnlyView *wpv = wpViewOnlyViews.value(wp);
wpv->updateValues();
}
void WaypointList::waypointViewOnlyListChanged()
{
if (uas) {
......@@ -352,7 +387,7 @@ void WaypointList::waypointViewOnlyListChanged()
if (i == waypoints.size()) {
WaypointViewOnlyView* widget = wpViewOnlyViews.find(cur).value();
widget->hide();
editableListLayout->removeWidget(widget);
viewOnlyListLayout->removeWidget(widget);
wpViewOnlyViews.remove(cur);
}
}
......@@ -421,7 +456,7 @@ void WaypointList::waypointEditableListChanged()
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))); commented, because unused
//connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypointEditable(quint16)));
editableListLayout->insertWidget(i, wpview);
}
WaypointEditableView *wpv = wpEditableViews.value(wp);
......
......@@ -76,7 +76,7 @@ public slots:
/** @brief Add a waypoint to "edit"-tab */
void addEditable();
/** @brief Add a waypoint to "view"-tab */
void addViewOnly();
// void addViewOnly();
/** @brief Add a waypoint at the current MAV position */
void addCurrentPositionWaypoint();
/** @brief Add a waypoint by mouse click over the map */
......@@ -86,10 +86,14 @@ 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 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 */
......
......@@ -31,9 +31,14 @@ void WaypointViewOnlyView::changedAutoContinue(int state)
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);
......@@ -42,15 +47,27 @@ void WaypointViewOnlyView::changedCurrent(int state)
else
{
m_ui->current->setChecked(false);
m_ui->current->setCheckState(Qt::Unchecked);
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)
......
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