Commit ba55604f authored by Gus Grubba's avatar Gus Grubba

Compute mission bounding box

parent 2cc0a608
......@@ -35,6 +35,8 @@
#include "QGCQFileDialog.h"
#endif
#define UPDATE_TIMEOUT 5000 ///< How often we check for bounding box changes
QGC_LOGGING_CATEGORY(MissionControllerLog, "MissionControllerLog")
const char* MissionController::_settingsGroup = "MissionController";
......@@ -71,6 +73,8 @@ MissionController::MissionController(PlanMasterController* masterController, QOb
{
_resetMissionFlightStatus();
managerVehicleChanged(_managerVehicle);
_updateTimer.setSingleShot(true);
connect(&_updateTimer, &QTimer::timeout, this, &MissionController::_updateTimeout);
}
MissionController::~MissionController()
......@@ -409,9 +413,9 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate
}
if (surveyStyleItem) {
bool rollSupported = false;
bool rollSupported = false;
bool pitchSupported = false;
bool yawSupported = false;
bool yawSupported = false;
// If the vehicle is known to have a gimbal then we automatically point the gimbal straight down if not already set
......@@ -434,11 +438,13 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate
}
}
//-- Keep track of bounding box changes in complex items
if(!newItem->isSimpleItem()) {
connect(newItem, &ComplexMissionItem::boundingBoxChanged, this, &MissionController::_complexBoundingBoxChanged);
}
newItem->setSequenceNumber(sequenceNumber);
_initVisualItem(newItem);
_visualItems->insert(i, newItem);
_recalcAll();
return newItem->sequenceNumber();
......@@ -1491,6 +1497,7 @@ void MissionController::_recalcAll(void)
_recalcSequence();
_recalcChildItems();
_recalcWaypointLines();
_updateTimer.start(UPDATE_TIMEOUT);
}
/// Initializes a new set of mission items
......@@ -1987,3 +1994,57 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force)
emit currentPlanViewItemChanged();
}
}
void MissionController::_updateTimeout()
{
QRectF boundingBox;
double north = 0.0;
double south = 180.0;
double east = 0.0;
double west = 360.0;
for (int i = 1; i < _visualItems->count(); i++) {
VisualMissionItem* item = qobject_cast<VisualMissionItem*>(_visualItems->get(i));
if(item->isSimpleItem()) {
SimpleMissionItem* pSimpleItem = qobject_cast<SimpleMissionItem*>(item);
if(pSimpleItem) {
switch(pSimpleItem->command()) {
case MAV_CMD_NAV_WAYPOINT:
case MAV_CMD_NAV_LAND:
case MAV_CMD_NAV_TAKEOFF:
if(pSimpleItem->coordinate().isValid()) {
double lat = pSimpleItem->coordinate().latitude() + 90.0;
double lon = pSimpleItem->coordinate().longitude() + 180.0;
north = fmax(north, lat);
south = fmin(south, lat);
east = fmax(east, lon);
west = fmin(west, lon);
}
break;
default:
break;
}
}
} else {
ComplexMissionItem* pComplexItem = qobject_cast<ComplexMissionItem*>(item);
if(pComplexItem) {
QRectF bb = pComplexItem->boundingBox();
if(!bb.isNull()) {
north = fmax(north, bb.y() + 90.0);
south = fmin(south, bb.height() + 90.0);
east = fmax(east, bb.x() + 180.0);
west = fmin(west, bb.width() + 180.0);
}
}
}
}
boundingBox = QRectF(east - 180.0, north - 90.0, west - 180.0, south - 90.0);
if(_boundingBox != boundingBox) {
_boundingBox = boundingBox;
qCDebug(MissionControllerLog) << "Bounding box:" << _boundingBox.y() << _boundingBox.x() << _boundingBox.height() << _boundingBox.width();
}
}
void MissionController::_complexBoundingBoxChanged()
{
_updateTimer.start(UPDATE_TIMEOUT);
}
......@@ -205,6 +205,8 @@ private slots:
void _visualItemsDirtyChanged(bool dirty);
void _managerSendComplete(bool error);
void _managerRemoveAllComplete(bool error);
void _updateTimeout();
void _complexBoundingBoxChanged();
private:
void _init(void);
......@@ -258,6 +260,8 @@ private:
double _progressPct;
int _currentPlanViewIndex;
VisualMissionItem* _currentPlanViewItem;
QTimer _updateTimer;
QRectF _boundingBox;
static const char* _settingsGroup;
......
......@@ -743,8 +743,8 @@ void SurveyMissionItem::_generateGrid(void)
// Calc bounding box
double north = 0.0;
double south = 180.0;
double east = 360.0;
double west = 0.0;
double east = 0.0;
double west = 360.0;
for (int i = 0; i < _simpleGridPoints.count(); i++) {
QGeoCoordinate coord = _simpleGridPoints[i].value<QGeoCoordinate>();
double lat = coord.latitude() + 90.0;
......
......@@ -43,7 +43,7 @@ public:
Q_PROPERTY(bool homePosition READ homePosition CONSTANT) ///< true: This item is being used as a home position indicator
Q_PROPERTY(QGeoCoordinate coordinate READ coordinate WRITE setCoordinate NOTIFY coordinateChanged) ///< This is the entry point for a waypoint line into the item. For a simple item it is also the location of the item
Q_PROPERTY(double terrainAltitude READ terrainAltitude NOTIFY terrainAltitudeChanged) ///< The altitude of terrain at the coordinate position, NaN if not known
Q_PROPERTY(double terrainAltitude READ terrainAltitude NOTIFY terrainAltitudeChanged) ///< The altitude of terrain at the coordinate position, NaN if not known
Q_PROPERTY(bool coordinateHasRelativeAltitude READ coordinateHasRelativeAltitude NOTIFY coordinateHasRelativeAltitudeChanged) ///< true: coordinate.latitude is relative to home altitude
Q_PROPERTY(QGeoCoordinate exitCoordinate READ exitCoordinate NOTIFY exitCoordinateChanged) ///< This is the exit point for a waypoint line coming out of the item.
Q_PROPERTY(bool exitCoordinateHasRelativeAltitude READ exitCoordinateHasRelativeAltitude NOTIFY exitCoordinateHasRelativeAltitudeChanged) ///< true: coordinate.latitude is relative to home altitude
......
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