1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

GCS/MapLib - Work continues on the future pathplaner

This commit is contained in:
PT_Dreamer 2012-05-30 16:19:36 +01:00
parent 9024a21af7
commit f7f6ffcab1
11 changed files with 216 additions and 56 deletions

View File

@ -46,6 +46,7 @@ namespace mapcontrol
connect(core,SIGNAL(OnMapZoomChanged()),this,SLOT(ChildPosRefresh()));
//resize();
}
void MapGraphicItem::start()
{
core->StartSystem();

View File

@ -40,8 +40,10 @@
#include <QObject>
#include "waypointitem.h"
//#include "uavitem.h"
namespace mapcontrol
{
class WayPointItem;
class OPMapWidget;
/**
* @brief The main graphicsItem used on the widget, contains the map and map logic
@ -213,6 +215,7 @@ namespace mapcontrol
*
* @param zoom
*/
void wpdoubleclicked(WayPointItem * wp);
void zoomChanged(double zoomtotal,double zoomreal,double zoomdigi);
};
}

View File

@ -53,6 +53,7 @@ namespace mapcontrol
connect(map->core,SIGNAL(OnTileLoadComplete()),this,SIGNAL(OnTileLoadComplete()));
connect(map->core,SIGNAL(OnTileLoadStart()),this,SIGNAL(OnTileLoadStart()));
connect(map->core,SIGNAL(OnTilesStillToLoad(int)),this,SIGNAL(OnTilesStillToLoad(int)));
connect(map,SIGNAL(wpdoubleclicked(WayPointItem*)),this,SIGNAL(OnWayPointDoubleClicked(WayPointItem*)));
SetShowDiagnostics(showDiag);
this->setMouseTracking(followmouse);
SetShowCompass(true);

View File

@ -478,6 +478,7 @@ namespace mapcontrol
* @param number the number of tiles still in the queue
*/
void OnTilesStillToLoad(int number);
void OnWayPointDoubleClicked(WayPointItem * waypoint);
public slots:
/**
* @brief Ripps the current selection to the DB

View File

@ -53,9 +53,10 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
}
if(myHome)
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing);
qDebug()<<"RELATIVE DISTANCE SET ON CTOR1"<<relativeCoord.distance;
connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
}
WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, const QString &description, MapGraphicItem *map,wptype type):coord(coord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map),myType(type)
{
@ -80,13 +81,16 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
}
if(myHome)
{
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing);
qDebug()<<"RELATIVE DISTANCE SET ON CTOR2"<<relativeCoord.distance;
connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
}
connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
}
WayPointItem::WayPointItem(const distBearing &relativeCoord, const int &altitude, const QString &description, MapGraphicItem *map):relativeCoord(relativeCoord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map)
WayPointItem::WayPointItem(const distBearing &relativeCoordenate, const int &altitude, const QString &description, MapGraphicItem *map):relativeCoord(relativeCoordenate),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map)
{
qDebug()<<"RELATIVE DISTANCE SET ON CTOR3"<<relativeCoord.distance;
myHome=NULL;
QList<QGraphicsItem *> list=map->childItems();
foreach(QGraphicsItem * obj,list)
@ -98,7 +102,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
if(myHome)
{
connect(myHome,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distante,relativeCoord.bearing);
coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing);
}
myType=relative;
text=0;
@ -112,9 +116,11 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
SetShowNumber(shownumber);
RefreshToolTip();
RefreshPos();
connect(this,SIGNAL(waypointdoubleclick(WayPointItem*)),map,SIGNAL(wpdoubleclicked(WayPointItem*)));
}
void WayPointItem::changeWPType(wptype type)
void WayPointItem::setWPType(wptype type)
{
myType=type;
emit WPValuesChanged(this);
@ -135,6 +141,14 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
if(this->isSelected())
painter->drawRect(QRectF(-picture.width()/2,-picture.height(),picture.width()-1,picture.height()-1));
}
void WayPointItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
emit waypointdoubleclick(this);
}
}
void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
@ -157,11 +171,17 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
{
if(event->button()==Qt::LeftButton)
{
delete text;
delete textBG;
coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y());
if(myHome)
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
if(text)
{
delete text;
text=NULL;
}
if(textBG)
{
delete textBG;
textBG=NULL;
}
isDragging=false;
RefreshToolTip();
@ -177,8 +197,11 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y());
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
if(myHome)
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
QString relativeCoord_str = QString::number(relativeCoord.distante) + "m " + QString::number(relativeCoord.bearing*180/M_PI)+"deg";
{
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing);
qDebug()<<"RELATIVE DISTANCE SET ON MOUSEMOVEEVENT"<<relativeCoord.distance;
}
QString relativeCoord_str = QString::number(relativeCoord.distance) + "m " + QString::number(relativeCoord.bearing*180/M_PI)+"deg";
text->setText(coord_str+"\n"+relativeCoord_str);
textBG->setRect(text->boundingRect());
@ -194,6 +217,18 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
emit WPValuesChanged(this);
this->update();
}
void WayPointItem::setRelativeCoord(distBearing value)
{
relativeCoord=value;
if(myHome)
{
coord=map->Projection()->translate(myHome->Coord(),relativeCoord.distance,relativeCoord.bearing);
}
RefreshPos();
RefreshToolTip();
this->update();
}
void WayPointItem::SetCoord(const internals::PointLatLng &value)
{
coord=value;
@ -275,7 +310,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
{
if(myType==relative)
{
coord=map->Projection()->translate(homepos,relativeCoord.distante,relativeCoord.bearing);
coord=map->Projection()->translate(homepos,relativeCoord.distance,relativeCoord.bearing);
emit WPValuesChanged(this);
RefreshPos();
RefreshToolTip();
@ -332,7 +367,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
else
type_str="Absolute";
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distante) + " Bearing:" + QString::number(relativeCoord.bearing*180/M_PI);
QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distance) + " Bearing:" + QString::number(relativeCoord.bearing*180/M_PI);
setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nAltitude:%6\nType:%7").arg(QString::number(WayPointItem::number)).arg(description).arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(type_str));
}

View File

@ -39,7 +39,7 @@ namespace mapcontrol
{
struct distBearing
{
double distante;
double distance;
double bearing;
};
class HomeItem;
@ -145,6 +145,8 @@ public:
* @param value
*/
void SetAltitude(int const& value);
void setRelativeCoord(distBearing value);
distBearing getRelativeCoord(){return relativeCoord;}
int type() const;
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -155,12 +157,13 @@ public:
~WayPointItem();
static int snumber;
void changeWPType(wptype type);
void setWPType(wptype type);
wptype WPType(){return myType;}
protected:
void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
private:
internals::PointLatLng coord;//coordinates of this WayPoint
distBearing relativeCoord;
@ -220,7 +223,7 @@ signals:
* @param waypoint a pointer to this WayPoint
*/
void WPValuesChanged(WayPointItem* waypoint);
void waypointdoubleclick(WayPointItem* waypoint);
};
}
#endif // WAYPOINTITEM_H

View File

@ -36,8 +36,8 @@ opmap_edit_waypoint_dialog::opmap_edit_waypoint_dialog(QWidget *parent) :
ui(new Ui::opmap_edit_waypoint_dialog)
{
ui->setupUi(this);
waypoint_item = NULL;
connect(ui->rbRelative,SIGNAL(toggled(bool)),this,SLOT(setupWidgets(bool)));
}
// destrutor
@ -87,6 +87,22 @@ void opmap_edit_waypoint_dialog::on_pushButtonRevert_clicked()
saveSettings();
}
void opmap_edit_waypoint_dialog::setupWidgets(bool isRelative)
{
ui->lbLong->setVisible(!isRelative);
ui->lbDegLong->setVisible(!isRelative);
ui->doubleSpinBoxLongitude->setVisible(!isRelative);
ui->lbLat->setVisible(!isRelative);
ui->lbDegLat->setVisible(!isRelative);
ui->doubleSpinBoxLatitude->setVisible(!isRelative);
ui->lbDistance->setVisible(isRelative);
ui->lbDistanceMeters->setVisible(isRelative);
ui->lbBearing->setVisible(isRelative);
ui->lbBearingDeg->setVisible(isRelative);
ui->spinBoxDistance->setVisible(isRelative);
ui->doubleSpinBoxBearing->setVisible(isRelative);
}
void opmap_edit_waypoint_dialog::on_pushButtonCancel_clicked()
{
waypoint_item = NULL;
@ -123,7 +139,14 @@ int opmap_edit_waypoint_dialog::saveSettings()
waypoint_item->SetAltitude(altitude);
waypoint_item->SetDescription(description);
waypoint_item->setFlag(QGraphicsItem::ItemIsMovable, !locked);
if(ui->rbAbsolute->isChecked())
waypoint_item->setWPType(mapcontrol::WayPointItem::absolute);
else
waypoint_item->setWPType(mapcontrol::WayPointItem::relative);
mapcontrol::distBearing pt;
pt.distance=ui->spinBoxDistance->value();
pt.bearing=ui->doubleSpinBoxBearing->value()/180*M_PI;
this->waypoint_item->setRelativeCoord(pt);
// ********************
return 0; // all ok
@ -143,14 +166,22 @@ void opmap_edit_waypoint_dialog::editWaypoint(mapcontrol::WayPointItem *waypoint
original_coord = this->waypoint_item->Coord();
original_altitude = this->waypoint_item->Altitude();
original_description = this->waypoint_item->Description().simplified();
original_type=this->waypoint_item->WPType();
original_distance=this->waypoint_item->getRelativeCoord().distance;
original_bearing=this->waypoint_item->getRelativeCoord().bearing*180/M_PI;
ui->checkBoxLocked->setChecked(original_locked);
ui->spinBoxNumber->setValue(original_number);
ui->doubleSpinBoxLatitude->setValue(original_coord.Lat());
ui->doubleSpinBoxLongitude->setValue(original_coord.Lng());
ui->doubleSpinBoxAltitude->setValue(original_altitude);
ui->lineEditDescription->setText(original_description);
if(original_type==mapcontrol::WayPointItem::absolute)
ui->rbAbsolute->setChecked(true);
else
ui->rbRelative->setChecked(true);
ui->doubleSpinBoxBearing->setValue(original_bearing);
ui->spinBoxDistance->setValue(original_distance);
setupWidgets(ui->rbRelative->isChecked());
show();
}

View File

@ -61,6 +61,9 @@ private:
internals::PointLatLng original_coord;
double original_altitude;
QString original_description;
double original_distance;
double original_bearing;
mapcontrol::WayPointItem::wptype original_type;
mapcontrol::WayPointItem *waypoint_item;
@ -69,6 +72,7 @@ private:
private slots:
private slots:
void setupWidgets(bool isRelative);
void on_pushButtonCancel_clicked();
void on_pushButtonRevert_clicked();
void on_pushButtonApply_clicked();

View File

@ -9,28 +9,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>187</height>
<width>546</width>
<height>261</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>187</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>187</height>
</size>
</property>
<property name="windowTitle">
<string>OpenPilot GCS Edit Waypoint</string>
</property>
@ -60,8 +48,8 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<item row="2" column="0">
<widget class="QLabel" name="lbLat">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -76,8 +64,11 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<item row="3" column="0">
<widget class="QLabel" name="lbLong">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -92,7 +83,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
@ -108,14 +99,14 @@
</property>
</widget>
</item>
<item row="3" column="3">
<item row="6" column="3">
<widget class="QLabel" name="label_6">
<property name="text">
<string>meters</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
@ -131,7 +122,7 @@
</property>
</widget>
</item>
<item row="4" column="2" colspan="4">
<item row="7" column="2" colspan="4">
<widget class="QLineEdit" name="lineEditDescription"/>
</item>
<item row="0" column="5">
@ -151,7 +142,7 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLatitude">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -170,7 +161,7 @@
</property>
</widget>
</item>
<item row="2" column="2">
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBoxLongitude">
<property name="decimals">
<number>7</number>
@ -183,7 +174,7 @@
</property>
</widget>
</item>
<item row="3" column="2">
<item row="6" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBoxAltitude">
<property name="minimum">
<double>-5000.000000000000000</double>
@ -193,20 +184,104 @@
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_4">
<item row="3" column="3">
<widget class="QLabel" name="lbDegLong">
<property name="text">
<string>degrees</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="lbDegLat">
<property name="text">
<string>degrees</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="Type">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Type </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QRadioButton" name="rbRelative">
<property name="text">
<string>Relative</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QRadioButton" name="rbAbsolute">
<property name="text">
<string>Absolute</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QSpinBox" name="spinBoxDistance">
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QLabel" name="lbDistanceMeters">
<property name="text">
<string>meters</string>
</property>
</widget>
</item>
<item row="5" column="3">
<widget class="QLabel" name="lbBearingDeg">
<property name="text">
<string>degrees</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbBearing">
<property name="text">
<string>Bearing </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QDoubleSpinBox" name="doubleSpinBoxBearing">
<property name="maximum">
<double>360.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbDistance">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Distance </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -264,14 +264,14 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
connect(m_map, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(WPValuesChanged(WayPointItem*)));
connect(m_map, SIGNAL(WPInserted(int const&, WayPointItem*)), this, SLOT(WPInserted(int const&, WayPointItem*)));
connect(m_map, SIGNAL(WPDeleted(int const&)), this, SLOT(WPDeleted(int const&)));
connect(m_map,SIGNAL(OnWayPointDoubleClicked(WayPointItem*)),this,SLOT(wpDoubleClickEvent(WayPointItem*)));
m_map->SetCurrentPosition(m_home_position.coord); // set the map position
m_map->Home->SetCoord(m_home_position.coord); // set the HOME position
m_map->UAV->SetUAVPos(m_home_position.coord, 0.0); // set the UAV position
if(m_map->GPS)
m_map->GPS->SetUAVPos(m_home_position.coord, 0.0); // set the UAV position
distBearing db;
db.distante=100;
db.distance=100;
db.bearing=0;
m_map->WPCreate(db,10,"aaa");
// **************
@ -387,6 +387,11 @@ void OPMapGadgetWidget::mouseMoveEvent(QMouseEvent *event)
QWidget::mouseMoveEvent(event);
}
void OPMapGadgetWidget::wpDoubleClickEvent(WayPointItem *wp)
{
m_mouse_waypoint = wp;
onEditWayPointAct_triggered();
}
void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event)
{ // the user has right clicked on the map - create the pop-up context menu and display it

View File

@ -119,7 +119,8 @@ public:
void setCacheLocation(QString cacheLocation);
void setMapMode(opMapModeType mode);
void SetUavPic(QString UAVPic);
void setMaxUpdateRate(int update_rate);
void setMaxUpdateRate(int update_rate);
public slots:
void homePositionUpdated(UAVObject *);
@ -131,8 +132,8 @@ protected:
void mouseMoveEvent(QMouseEvent *event);
void contextMenuEvent(QContextMenuEvent *event);
void keyPressEvent(QKeyEvent* event);
private slots:
void wpDoubleClickEvent(WayPointItem *wp);
void updatePosition();
void updateMousePos();