1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OpMap: now the HomeLocation is updated following the actual UAVObject value.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2170 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-11-27 20:13:32 +00:00 committed by edouard
parent 02366bf368
commit 45b216bf57
3 changed files with 36 additions and 4 deletions

View File

@ -7,5 +7,6 @@
<url>http://www.openpilot.org</url> <url>http://www.openpilot.org</url>
<dependencyList> <dependencyList>
<dependency name="Core" version="1.0.0"/> <dependency name="Core" version="1.0.0"/>
<dependency name="UAVObjects" version="1.0.0"/>
</dependencyList> </dependencyList>
</plugin> </plugin>

View File

@ -296,6 +296,17 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
m_statusUpdateTimer->start(); m_statusUpdateTimer->start();
// ************** // **************
// Last, connect to the UAVObject updates we require to become a bit aware of
// our environment:
// Register for Home Location state changes
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *obm = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject*>(obm->getObject(QString("HomeLocation")));
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this , SLOT(homePositionUpdated(UAVObject*)));
m_map->setFocus(); m_map->setFocus();
} }
@ -942,6 +953,20 @@ void OPMapGadgetWidget::on_toolButtonMoveToWP_clicked()
// ************************************************************************************* // *************************************************************************************
// public functions // public functions
/** Updates the Home position icon whenever the HomePosition object
is updated
*/
void OPMapGadgetWidget::homePositionUpdated(UAVObject* hp)
{
double lat = hp->getField("Latitude")->getDouble()*1e-7;
double lon = hp->getField("Longitude")->getDouble()*1e-7;
setHome(internals::PointLatLng(lat, lon));
}
/**
Sets the home position on the map widget
*/
void OPMapGadgetWidget::setHome(QPointF pos) void OPMapGadgetWidget::setHome(QPointF pos)
{ {
if (!m_widget || !m_map) if (!m_widget || !m_map)
@ -963,13 +988,14 @@ void OPMapGadgetWidget::setHome(QPointF pos)
setHome(internals::PointLatLng(latitude, longitude)); setHome(internals::PointLatLng(latitude, longitude));
} }
/**
Sets the home position on the map widget
*/
void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon) void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon)
{ {
if (!m_widget || !m_map) if (!m_widget || !m_map)
return; return;
// *********
if (pos_lat_lon.Lat() != pos_lat_lon.Lat() || pos_lat_lon.Lng() != pos_lat_lon.Lng()) if (pos_lat_lon.Lat() != pos_lat_lon.Lat() || pos_lat_lon.Lng() != pos_lat_lon.Lng())
return;; // nan prevention return;; // nan prevention
@ -990,7 +1016,7 @@ void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon)
// ********* // *********
#if defined(allow_manual_home_location_move) // #if defined(allow_manual_home_location_move)
home_position.coord = internals::PointLatLng(latitude, longitude); home_position.coord = internals::PointLatLng(latitude, longitude);
m_map->Home->SetCoord(home_position.coord); m_map->Home->SetCoord(home_position.coord);
@ -998,9 +1024,13 @@ void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon)
// move the magic waypoint to keep it within the safe area boundry // move the magic waypoint to keep it within the safe area boundry
keepMagicWaypointWithInSafeArea(); keepMagicWaypointWithInSafeArea();
#endif // #endif
} }
/**
Centers the map over the home position
*/
void OPMapGadgetWidget::goHome() void OPMapGadgetWidget::goHome()
{ {
if (!m_widget || !m_map) if (!m_widget || !m_map)

View File

@ -111,6 +111,7 @@ public:
void setMapMode(opMapModeType mode); void setMapMode(opMapModeType mode);
public slots: public slots:
void homePositionUpdated(UAVObject*);
protected: protected:
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);