@ -37,7 +37,6 @@ This file is part of the PIXHAWK project
@@ -37,7 +37,6 @@ This file is part of the PIXHAWK project
# include <UASManager.h>
# include <QDebug>
# include <QFileDialog>
# include "WaypointGlobalView.h"
# include <QMessageBox>
# include <QMouseEvent>
@ -89,8 +88,6 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) :
@@ -89,8 +88,6 @@ WaypointList::WaypointList(QWidget *parent, UASInterface* uas) :
updateStatusLabel ( " " ) ;
this - > setVisible ( false ) ;
isGlobalWP = false ;
isLocalWP = false ;
centerMapCoordinate . setX ( 0.0 ) ;
centerMapCoordinate . setY ( 0.0 ) ;
@ -101,7 +98,7 @@ WaypointList::~WaypointList()
@@ -101,7 +98,7 @@ WaypointList::~WaypointList()
delete m_ui ;
}
void WaypointList : : updateLocal Position ( UASInterface * uas , double x , double y , double z , quint64 usec )
void WaypointList : : updatePosition ( UASInterface * uas , double x , double y , double z , quint64 usec )
{
Q_UNUSED ( uas ) ;
Q_UNUSED ( usec ) ;
@ -139,7 +136,7 @@ void WaypointList::saveWaypoints()
@@ -139,7 +136,7 @@ void WaypointList::saveWaypoints()
if ( uas )
{
QString fileName = QFileDialog : : getSaveFileName ( this , tr ( " Save File " ) , " ./waypoints.txt " , tr ( " Waypoint File (*.txt) " ) ) ;
uas - > getWaypointManager ( ) . localS aveWaypoints( fileName ) ;
uas - > getWaypointManager ( ) . s aveWaypoints( fileName ) ;
}
}
@ -148,7 +145,7 @@ void WaypointList::loadWaypoints()
@@ -148,7 +145,7 @@ void WaypointList::loadWaypoints()
if ( uas )
{
QString fileName = QFileDialog : : getOpenFileName ( this , tr ( " Load File " ) , " . " , tr ( " Waypoint File (*.txt) " ) ) ;
uas - > getWaypointManager ( ) . localLo adWaypoints ( fileName ) ;
uas - > getWaypointManager ( ) . loadWaypoints ( fileName ) ;
}
}
@ -172,40 +169,41 @@ void WaypointList::add()
@@ -172,40 +169,41 @@ void WaypointList::add()
{
if ( uas )
{
if ( isGlobalWP )
{
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
if ( waypoints . size ( ) > 0 )
{
Waypoint * last = waypoints . at ( waypoints . size ( ) - 1 ) ;
Waypoint * wp = new Waypoint ( 0 , c enterMapCoordinate . x ( ) , centerMapCoordinate . y ( ) , last - > getZ ( ) , last - > getYaw ( ) , last - > getAutoContinue ( ) , false , last - > getOrbit ( ) , last - > getHoldTime ( ) ) ;
uas - > getWaypointManager ( ) . localA ddWaypoint( wp ) ;
}
else
{
Waypoint * wp = new Waypoint ( 0 , c enterMapCoordinate . x ( ) , c enterMapCoordinate . y ( ) , - 0.8 , 0.0 , true , true , 0.15 , 2000 ) ;
uas - > getWaypointManager ( ) . localA ddWaypoint( wp ) ;
}
emit createWaypointAtMap ( centerMapCoordinate ) ;
}
else
// if(isGlobalWP)
// {
// const QVector<Waypoint *> &waypoints = uas->getWaypointManager().getWaypointList();
// if (waypoints.size() > 0)
// {
// Waypoint *last = waypoints.at(waypoints.size()-1);
// Waypoint *wp = new Waypoint(0, c enterMapCoordinate.x(), centerMapCoordinate.y(), last->getZ(), last->getYaw(), last->getAutoContinue(), false, last->getOrbit(), last->getHoldTime());
// uas->getWaypointManager().a ddWaypoint(wp);
// }
// else
// {
// Waypoint *wp = new Waypoint(0, c enterMapCoordinate.x(), c enterMapCoordinate.y(), -0.8, 0.0, true, true, 0.15, 2000);
// uas->getWaypointManager().a ddWaypoint(wp);
// }
//
// emit createWaypointAtMap(centerMapCoordinate);
// }
// else
{
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
if ( waypoints . size ( ) > 0 )
{
Waypoint * last = waypoints . at ( waypoints . size ( ) - 1 ) ;
Waypoint * wp = new Waypoint ( 0 , last - > getX ( ) , last - > getY ( ) , last - > getZ ( ) , last - > getYaw ( ) , last - > getAutoContinue ( ) , false , last - > getOrbit ( ) , last - > getHoldTime ( ) ) ;
uas - > getWaypointManager ( ) . localAddWaypoint ( wp ) ;
Waypoint * wp = new Waypoint ( 0 , last - > getX ( ) , last - > getY ( ) , last - > getZ ( ) , last - > getYaw ( ) , last - > getAutoContinue ( ) , false , last - > getOrbit ( ) ,
last - > getHoldTime ( ) , last - > getFrame ( ) , last - > getAction ( ) ) ;
uas - > getWaypointManager ( ) . addWaypoint ( wp ) ;
}
else
{
isLocalWP = true ;
//isLocalWP = true;
Waypoint * wp = new Waypoint ( 0 , 1.1 , 1.1 , - 0.8 , 0.0 , true , true , 0.15 , 2000 ) ;
uas - > getWaypointManager ( ) . loc alA ddWaypoint( wp ) ;
uas - > getWaypointManager ( ) . addWaypoint ( wp ) ;
}
@ -215,31 +213,33 @@ void WaypointList::add()
@@ -215,31 +213,33 @@ void WaypointList::add()
void WaypointList : : addCurrentPositonWaypoint ( )
{
/* TODO: implement with new waypoint structure
if ( uas )
{
// For Global Waypoints
if ( isGlobalWP )
{
isLocalWP = false ;
}
else
//if(isGlobalWP)
//{
//isLocalWP = false;
//}
//else
{
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
if ( waypoints . size ( ) > 0 )
{
Waypoint * last = waypoints . at ( waypoints . size ( ) - 1 ) ;
Waypoint * wp = new Waypoint ( 0 , ( qRound ( mavX * 100 ) ) / 100. , ( qRound ( mavY * 100 ) ) / 100. , ( qRound ( mavZ * 100 ) ) / 100. , ( qRound ( mavYaw * 100 ) ) / 100. , last - > getAutoContinue ( ) , false , last - > getOrbit ( ) , last - > getHoldTime ( ) ) ;
uas - > getWaypointManager ( ) . loc alA ddWaypoint( wp ) ;
uas - > getWaypointManager ( ) . addWaypoint ( wp ) ;
}
else
{
Waypoint * wp = new Waypoint ( 0 , ( qRound ( mavX * 100 ) ) / 100. , ( qRound ( mavY * 100 ) ) / 100. , ( qRound ( mavZ * 100 ) ) / 100. , ( qRound ( mavYaw * 100 ) ) / 100. , true , true , 0.15 , 2000 ) ;
uas - > getWaypointManager ( ) . loc alA ddWaypoint( wp ) ;
uas - > getWaypointManager ( ) . addWaypoint ( wp ) ;
}
isLocalWP = true ;
//isLocalWP = true;
}
}
*/
}
void WaypointList : : updateStatusLabel ( const QString & string )
@ -287,59 +287,59 @@ void WaypointList::waypointListChanged()
@@ -287,59 +287,59 @@ void WaypointList::waypointListChanged()
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
// For Global Waypoints
if ( isGlobalWP )
{
isLocalWP = false ;
// first remove all views of non existing waypoints
if ( ! wpGlobalViews . empty ( ) )
{
QMapIterator < Waypoint * , WaypointGlobalView * > viewIt ( wpGlobalViews ) ;
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 ( ) )
{
WaypointGlobalView * widget = wpGlobalViews . find ( cur ) . value ( ) ;
widget - > hide ( ) ;
listLayout - > removeWidget ( widget ) ;
wpGlobalViews . 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 ( ! wpGlobalViews . contains ( wp ) )
{
WaypointGlobalView * wpview = new WaypointGlobalView ( wp , this ) ;
wpGlobalViews . insert ( wp , wpview ) ;
connect ( wpview , SIGNAL ( removeWaypoint ( Waypoint * ) ) , this , SLOT ( removeWaypoint ( Waypoint * ) ) ) ;
connect ( wpview , SIGNAL ( changePositionWP ( Waypoint * ) ) , this , SLOT ( changeWPPositionBySpinBox ( Waypoint * ) ) ) ;
// connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*)));
// connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*)));
// connect(wpview, SIGNAL(changePositionWP(Waypoint*)), this, SLOT(waypointGlobalPositionChanged(Waypoint*)));
// connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
// connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
}
WaypointGlobalView * wpgv = wpGlobalViews . value ( wp ) ;
wpgv - > updateValues ( ) ;
listLayout - > addWidget ( wpgv ) ;
}
}
else
//if(isGlobalWP)
//{
//isLocalWP = false;
//// first remove all views of non existing waypoints
//if (!wpGlobalViews.empty())
//{
//QMapIterator<Waypoint*,WaypointGlobalView*> viewIt(wpGlobalViews);
//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())
//{
//WaypointGlobalView* widget = wpGlobalViews.find(cur).value();
//widget->hide();
//listLayout->removeWidget(widget);
//wpGlobalViews.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 (!wpGlobalViews.contains(wp))
//{
//WaypointGlobalView* wpview = new WaypointGlobalView(wp, this);
//wpGlobalViews.insert(wp, wpview);
//connect(wpview, SIGNAL(removeWaypoint(Waypoint*)), this, SLOT(removeWaypoint(Waypoint*)));
//connect(wpview, SIGNAL(changePositionWP(Waypoint*)), this, SLOT(changeWPPositionBySpinBox(Waypoint*)));
//// connect(wpview, SIGNAL(moveDownWaypoint(Waypoint*)), this, SLOT(moveDown(Waypoint*)));
//// connect(wpview, SIGNAL(moveUpWaypoint(Waypoint*)), this, SLOT(moveUp(Waypoint*)));
//// connect(wpview, SIGNAL(changePositionWP(Waypoint*)), this, SLOT(waypointGlobalPositionChanged(Waypoint*)));
//// connect(wpview, SIGNAL(currentWaypointChanged(quint16)), this, SLOT(currentWaypointChanged(quint16)));
//// connect(wpview, SIGNAL(changeCurrentWaypoint(quint16)), this, SLOT(changeCurrentWaypoint(quint16)));
//}
//WaypointGlobalView *wpgv = wpGlobalViews.value(wp);
//wpgv->updateValues();
//listLayout->addWidget(wpgv);
//}
//}
//else
{
// for local Waypoints
// first remove all views of non existing waypoints
@ -414,7 +414,7 @@ void WaypointList::moveUp(Waypoint* wp)
@@ -414,7 +414,7 @@ void WaypointList::moveUp(Waypoint* wp)
// if wp was found and its not the first entry, move it
if ( i < waypoints . size ( ) & & i > 0 )
{
uas - > getWaypointManager ( ) . localM oveWaypoint( i , i - 1 ) ;
uas - > getWaypointManager ( ) . m oveWaypoint( i , i - 1 ) ;
}
}
}
@ -436,7 +436,7 @@ void WaypointList::moveDown(Waypoint* wp)
@@ -436,7 +436,7 @@ void WaypointList::moveDown(Waypoint* wp)
// if wp was found and its not the last entry, move it
if ( i < waypoints . size ( ) - 1 )
{
uas - > getWaypointManager ( ) . localM oveWaypoint( i , i + 1 ) ;
uas - > getWaypointManager ( ) . m oveWaypoint( i , i + 1 ) ;
}
}
}
@ -445,7 +445,7 @@ void WaypointList::removeWaypoint(Waypoint* wp)
@@ -445,7 +445,7 @@ void WaypointList::removeWaypoint(Waypoint* wp)
{
if ( uas )
{
uas - > getWaypointManager ( ) . localR emoveWaypoint( wp - > getId ( ) ) ;
uas - > getWaypointManager ( ) . r emoveWaypoint( wp - > getId ( ) ) ;
}
}
@ -467,43 +467,13 @@ void WaypointList::on_clearWPListButton_clicked()
@@ -467,43 +467,13 @@ void WaypointList::on_clearWPListButton_clicked()
if ( uas )
{
if ( isGlobalWP )
{
emit clearPathclicked ( ) ;
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
while ( ! waypoints . isEmpty ( ) ) //for(int i = 0; i <= waypoints.size(); i++)
{
WaypointGlobalView * widget = wpGlobalViews . find ( waypoints [ 0 ] ) . value ( ) ;
widget - > remove ( ) ;
}
isGlobalWP = false ;
}
else
emit clearPathclicked ( ) ;
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
while ( ! waypoints . isEmpty ( ) ) //for(int i = 0; i <= waypoints.size(); i++)
{
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
while ( ! waypoints . isEmpty ( ) ) //for(int i = 0; i <= waypoints.size(); i++)
{
WaypointView * widget = wpViews . find ( waypoints [ 0 ] ) . value ( ) ;
widget - > remove ( ) ;
}
WaypointView * widget = wpViews . find ( waypoints [ 0 ] ) . value ( ) ;
widget - > remove ( ) ;
}
}
}
@ -517,52 +487,16 @@ void WaypointList::addWaypointMouse(QPointF coordinate)
@@ -517,52 +487,16 @@ void WaypointList::addWaypointMouse(QPointF coordinate)
{
Waypoint * last = waypoints . at ( waypoints . size ( ) - 1 ) ;
Waypoint * wp = new Waypoint ( 0 , coordinate . x ( ) , coordinate . y ( ) , last - > getZ ( ) , last - > getYaw ( ) , last - > getAutoContinue ( ) , false , last - > getOrbit ( ) , last - > getHoldTime ( ) ) ;
uas - > getWaypointManager ( ) . loc alA ddWaypoint( wp ) ;
uas - > getWaypointManager ( ) . addWaypoint ( wp ) ;
}
else
{
Waypoint * wp = new Waypoint ( 0 , coordinate . x ( ) , coordinate . y ( ) , - 0.8 , 0.0 , true , true , 0.15 , 2000 ) ;
uas - > getWaypointManager ( ) . localAddWaypoint ( wp ) ;
}
}
}
/** @brief Notifies the user that a global waypoint will be created */
void WaypointList : : setIsWPGlobal ( bool value , QPointF centerCoordinate )
{
centerMapCoordinate = centerCoordinate ;
if ( isLocalWP )
{
if ( wpViews . size ( ) ! = 0 )
{
int ret = QMessageBox : : warning ( this , tr ( " QGroundControl " ) ,
tr ( " There are Local Waypoints created. \n "
" Do you want to clear them? " ) ,
QMessageBox : : Ok | QMessageBox : : Cancel ) ;
if ( ret )
{
clearLocalWPWidget ( ) ;
}
uas - > getWaypointManager ( ) . addWaypoint ( wp ) ;
}
isLocalWP = ! value ;
isGlobalWP = value ;
}
else
{
isGlobalWP = value ;
}
}
@ -580,8 +514,8 @@ void WaypointList::waypointGlobalChanged(QPointF coordinate, int indexWP)
@@ -580,8 +514,8 @@ void WaypointList::waypointGlobalChanged(QPointF coordinate, int indexWP)
temp - > setX ( coordinate . x ( ) ) ;
temp - > setY ( coordinate . y ( ) ) ;
WaypointGlobalView * widget = wpGlobalViews . find ( waypoints [ indexWP ] ) . value ( ) ;
widget - > updateValues ( ) ;
//WaypointGlobalView* widget = wpGlobalViews.find(waypoints[indexWP]).value();
//widget->updateValues();
}
}
@ -601,24 +535,16 @@ void WaypointList::waypointGlobalChanged(QPointF coordinate, int indexWP)
@@ -601,24 +535,16 @@ void WaypointList::waypointGlobalChanged(QPointF coordinate, int indexWP)
//}
void WaypointList : : clearLocal WPWidget ( )
void WaypointList : : clearWPWidget ( )
{
if ( uas )
{
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
while ( ! waypoints . isEmpty ( ) ) //for(int i = 0; i <= waypoints.size(); i++)
{
WaypointView * widget = wpViews . find ( waypoints [ 0 ] ) . value ( ) ;
widget - > remove ( ) ;
}
}
}
void WaypointList : : changeWPPositionBySpinBox ( Waypoint * wp )
{
emit changePositionWPGlobalBySpinBox ( wp - > getId ( ) , wp - > getY ( ) , wp - > getX ( ) ) ;
if ( uas )
{
const QVector < Waypoint * > & waypoints = uas - > getWaypointManager ( ) . getWaypointList ( ) ;
while ( ! waypoints . isEmpty ( ) ) //for(int i = 0; i <= waypoints.size(); i++)
{
WaypointView * widget = wpViews . find ( waypoints [ 0 ] ) . value ( ) ;
widget - > remove ( ) ;
}
}
//emit changePositionWPBySpinBox(wp->getId(), wp->getY(), wp->getX());
}