Commit a90ceccb authored by lm's avatar lm

Made map settings persistent with respect to UAV trail setup

parent 1df0c0d5
......@@ -51,6 +51,10 @@ void QGCMapToolBar::setMap(QGCMapWidget* map)
updateTimesMenu.setTitle(tr("&Limit map view update rate to.."));
// FIXME MARK CURRENT VALUES IN MENU
QAction* action = trailPlotMenu.addAction(tr("No trail"), this, SLOT(setUAVTrailTime()));
action->setData(-1);
action->setCheckable(true);
trailSettingsGroup->addAction(action);
for (int i = 0; i < uavTrailTimeCount; ++i)
{
......@@ -58,6 +62,11 @@ void QGCMapToolBar::setMap(QGCMapWidget* map)
action->setData(uavTrailTimeList[i]);
action->setCheckable(true);
trailSettingsGroup->addAction(action);
if (static_cast<mapcontrol::UAVTrailType::Types>(map->getTrailType()) == mapcontrol::UAVTrailType::ByTimeElapsed && map->getTrailInterval() == uavTrailTimeList[i])
{
// This is the current active time, set the action checked
action->setChecked(true);
}
}
for (int i = 0; i < uavTrailDistanceCount; ++i)
{
......@@ -65,7 +74,19 @@ void QGCMapToolBar::setMap(QGCMapWidget* map)
action->setData(uavTrailDistanceList[i]);
action->setCheckable(true);
trailSettingsGroup->addAction(action);
if (static_cast<mapcontrol::UAVTrailType::Types>(map->getTrailType()) == mapcontrol::UAVTrailType::ByDistance && map->getTrailInterval() == uavTrailDistanceList[i])
{
// This is the current active time, set the action checked
action->setChecked(true);
}
}
// Set no trail checked if no action is checked yet
if (!trailSettingsGroup->checkedAction())
{
action->setChecked(true);
}
optionsMenu.addMenu(&trailPlotMenu);
// Add update times menu
......
......@@ -7,11 +7,14 @@
#include "UASWaypointManager.h"
QGCMapWidget::QGCMapWidget(QWidget *parent) :
mapcontrol::OPMapWidget(parent),
currWPManager(NULL),
firingWaypointChange(NULL),
maxUpdateInterval(2.1), // 2 seconds
followUAVEnabled(false)
mapcontrol::OPMapWidget(parent),
currWPManager(NULL),
firingWaypointChange(NULL),
maxUpdateInterval(2.1), // 2 seconds
followUAVEnabled(false),
trailType(mapcontrol::UAVTrailType::ByTimeElapsed),
trailInterval(2.0f),
followUAVID(0)
{
// Widget is inactive until shown
......@@ -26,7 +29,7 @@ QGCMapWidget::~QGCMapWidget()
void QGCMapWidget::showEvent(QShowEvent* event)
{
// FIXME XXX this is a hack to trick OPs current 1-system design
// Disable OP's standard UAV, we have more than one
SetShowUAV(false);
// Pass on to parent widget
......@@ -42,50 +45,13 @@ void QGCMapWidget::showEvent(QShowEvent* event)
internals::PointLatLng pos_lat_lon = internals::PointLatLng(0, 0);
// // **************
// // default home position
// home_position.coord = pos_lat_lon;
// home_position.altitude = altitude;
// home_position.locked = false;
// // **************
// // default magic waypoint params
// magic_waypoint.map_wp_item = NULL;
// magic_waypoint.coord = home_position.coord;
// magic_waypoint.altitude = altitude;
// magic_waypoint.description = "Magic waypoint";
// magic_waypoint.locked = false;
// magic_waypoint.time_seconds = 0;
// magic_waypoint.hold_time_seconds = 0;
SetMouseWheelZoomType(internals::MouseWheelZoomType::MousePositionWithoutCenter); // set how the mouse wheel zoom functions
SetFollowMouse(true); // we want a contiuous mouse position reading
SetShowHome(true); // display the HOME position on the map
// SetShowUAV(true); // display the UAV position on the map
//SetShowDiagnostics(true); // Not needed in flight / production mode
Home->SetSafeArea(30); // set radius (meters)
Home->SetShowSafeArea(true); // show the safe area
//// UAV->SetTrailTime(uav_trail_time_list[0]); // seconds
//// UAV->SetTrailDistance(uav_trail_distance_list[1]); // meters
//// UAV->SetTrailType(mapcontrol::UAVTrailType::ByTimeElapsed);
//// UAV->SetTrailType(mapcontrol::UAVTrailType::ByDistance);
// GPS->SetTrailTime(uav_trail_time_list[0]); // seconds
// GPS->SetTrailDistance(uav_trail_distance_list[1]); // meters
// GPS->SetTrailType(UAVTrailType::ByTimeElapsed);
SetCurrentPosition(pos_lat_lon); // set the map position
Home->SetCoord(pos_lat_lon); // set the HOME position
// UAV->SetUAVPos(pos_lat_lon, 0.0); // set the UAV position
// GPS->SetUAVPos(pos_lat_lon, 0.0); // set the UAV position
setFrameStyle(QFrame::NoFrame); // no border frame
setBackgroundBrush(QBrush(Qt::black)); // tile background
......@@ -96,19 +62,16 @@ void QGCMapWidget::showEvent(QShowEvent* event)
// Set currently selected system
activeUASSet(UASManager::instance()->getActiveUAS());
// FIXME XXX this is a hack to trick OPs current 1-system design
SetShowUAV(false);
// Connect map updates to the adapter slots
connect(this, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(handleMapWaypointEdit(WayPointItem*)));
SetCurrentPosition(pos_lat_lon); // set the map position
setFocus();
// Start timer
connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateGlobalPosition()));
updateTimer.start(maxUpdateInterval*1000);
// Update all UAV positions
updateGlobalPosition();
//QTimer::singleShot(800, this, SLOT(loadSettings()));
}
......@@ -119,7 +82,10 @@ void QGCMapWidget::hideEvent(QHideEvent* event)
OPMapWidget::hideEvent(event);
}
void QGCMapWidget::loadSettings()
/**
* @param changePosition Load also the last position from settings and update the map position.
*/
void QGCMapWidget::loadSettings(bool changePosition)
{
// Atlantic Ocean near Africa, coordinate origin
double lastZoom = 1;
......@@ -128,11 +94,32 @@ void QGCMapWidget::loadSettings()
QSettings settings;
settings.beginGroup("QGC_MAPWIDGET");
lastLat = settings.value("LAST_LATITUDE", lastLat).toDouble();
lastLon = settings.value("LAST_LONGITUDE", lastLon).toDouble();
lastZoom = settings.value("LAST_ZOOM", lastZoom).toDouble();
if (changePosition)
{
lastLat = settings.value("LAST_LATITUDE", lastLat).toDouble();
lastLon = settings.value("LAST_LONGITUDE", lastLon).toDouble();
lastZoom = settings.value("LAST_ZOOM", lastZoom).toDouble();
}
trailType = static_cast<mapcontrol::UAVTrailType::Types>(settings.value("TRAIL_TYPE", trailType).toInt());
trailInterval = settings.value("TRAIL_INTERVAL", trailInterval).toFloat();
settings.endGroup();
// SET TRAIL TYPE
foreach (mapcontrol::UAVItem* uav, GetUAVS())
{
// Set the correct trail type
uav->SetTrailType(trailType);
// Set the correct trail interval
if (trailType == mapcontrol::UAVTrailType::ByDistance)
{
uav->SetTrailDistance(trailInterval);
}
else if (trailType == mapcontrol::UAVTrailType::ByTimeElapsed)
{
uav->SetTrailTime(trailInterval);
}
}
// SET INITIAL POSITION AND ZOOM
internals::PointLatLng pos_lat_lon = internals::PointLatLng(lastLat, lastLon);
SetCurrentPosition(pos_lat_lon); // set the map position
......@@ -147,6 +134,8 @@ void QGCMapWidget::storeSettings()
settings.setValue("LAST_LATITUDE", pos.Lat());
settings.setValue("LAST_LONGITUDE", pos.Lng());
settings.setValue("LAST_ZOOM", ZoomReal());
settings.setValue("TRAIL_TYPE", static_cast<int>(trailType));
settings.setValue("TRAIL_INTERVAL", trailInterval);
settings.endGroup();
settings.sync();
}
......@@ -163,13 +152,13 @@ void QGCMapWidget::mouseDoubleClickEvent(QMouseEvent* event)
// Create new waypoint
internals::PointLatLng pos = map->FromLocalToLatLng(event->pos().x(), event->pos().y());
Waypoint* wp = currWPManager->createWaypoint();
// wp->blockSignals(true);
// wp->setFrame(MAV_FRAME_GLOBAL_RELATIVE_ALT);
// wp->blockSignals(true);
// wp->setFrame(MAV_FRAME_GLOBAL_RELATIVE_ALT);
wp->setLatitude(pos.Lat());
wp->setLongitude(pos.Lng());
wp->setAltitude(0);
// wp->blockSignals(false);
// currWPManager->notifyOfChange(wp);
// wp->blockSignals(false);
// currWPManager->notifyOfChange(wp);
}
}
OPMapWidget::mouseDoubleClickEvent(event);
......
......@@ -27,7 +27,11 @@ public:
/** @brief Map centered on current active system */
bool getFollowUAVEnabled() { return followUAVEnabled; }
/** @brief The maximum map update rate */
float getUpdateRateLimit() { return maxUpdateInterval; };
float getUpdateRateLimit() { return maxUpdateInterval; }
/** @brief Get the trail type */
int getTrailType() { return static_cast<int>(trailType); }
/** @brief Get the trail interval */
float getTrailInterval() { return trailInterval; }
signals:
void homePositionChanged(double latitude, double longitude, double altitude);
......@@ -62,26 +66,42 @@ public slots:
void cacheVisibleRegion();
/** @brief Set follow mode */
void setFollowUAVEnabled(bool enabled) { followUAVEnabled = enabled; }
/** @brief Set trail to time mode and set time */
/** @brief Set trail to time mode and set time @param seconds The minimum time between trail dots in seconds. If set to a value < 0, trails will be disabled*/
void setTrailModeTimed(int seconds)
{
foreach(mapcontrol::UAVItem* uav, GetUAVS())
{
uav->SetTrailTime(seconds);
uav->SetTrailType(mapcontrol::UAVTrailType::ByTimeElapsed);
if (seconds >= 0)
{
uav->SetTrailTime(seconds);
uav->SetTrailType(mapcontrol::UAVTrailType::ByTimeElapsed);
}
else
{
uav->SetTrailType(mapcontrol::UAVTrailType::NoTrail);
}
}
}
/** @brief Set trail to distance mode and set time */
/** @brief Set trail to distance mode and set time @param meters The minimum distance between trail dots in meters. The actual distance depends on the MAV's update rate as well. If set to a value < 0, trails will be disabled*/
void setTrailModeDistance(int meters)
{
foreach(mapcontrol::UAVItem* uav, GetUAVS())
{
uav->SetTrailDistance(meters);
uav->SetTrailType(mapcontrol::UAVTrailType::ByDistance);
if (meters >= 0)
{
uav->SetTrailDistance(meters);
uav->SetTrailType(mapcontrol::UAVTrailType::ByDistance);
}
else
{
uav->SetTrailType(mapcontrol::UAVTrailType::NoTrail);
}
}
}
void loadSettings();
/** @brief Load the settings for this widget from disk */
void loadSettings(bool changePosition=false);
/** @brief Store the settings for this widget to disk */
void storeSettings();
protected slots:
......@@ -113,6 +133,8 @@ protected:
};
editMode currEditMode; ///< The current edit mode on the map
bool followUAVEnabled; ///< Does the map follow the UAV?
mapcontrol::UAVTrailType::Types trailType; ///< Time or distance based trail dots
float trailInterval; ///< Time or distance between trail items
int followUAVID; ///< Which UAV should be tracked?
......
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