Commit 719189e9 authored by Gus Grubba's avatar Gus Grubba

Start work on create/update flight plan from mission

parent 066699f3
......@@ -153,3 +153,10 @@ AirMapManager::_instantiateAirspaceRestrictionProvider()
connect(airspaces, &AirMapRestrictionManager::error, this, &AirMapManager::_error);
return airspaces;
}
//-----------------------------------------------------------------------------
void
AirMapManager::createFlight(MissionController* missionController)
{
Q_UNUSED(missionController);
}
......@@ -45,6 +45,7 @@ public:
QString providerName () const override { return QString("AirMap"); }
AirspaceVehicleManager* instantiateVehicle (const Vehicle& vehicle) override;
void createFlight (MissionController* missionController) override;
protected:
AirspaceRulesetsProvider* _instantiateRulesetsProvider () override;
......
......@@ -40,6 +40,7 @@ class AirspaceRulesetsProvider;
class AirspaceVehicleManager;
class AirspaceAdvisoryProvider;
class AirspaceRestrictionProvider;
class MissionController;
Q_DECLARE_LOGGING_CATEGORY(AirspaceManagementLog)
......@@ -61,7 +62,7 @@ public:
Q_PROPERTY(AirspaceRestrictionProvider* airspaces READ airspaces CONSTANT)
Q_PROPERTY(bool airspaceVisible READ airspaceVisible WRITE setAirspaceVisible NOTIFY airspaceVisibleChanged)
Q_INVOKABLE void setROI (QGeoCoordinate center, double radius);
Q_INVOKABLE void setROI (QGeoCoordinate center, double radius);
AirspaceWeatherInfoProvider* weatherInfo () { return _weatherProvider; }
AirspaceAdvisoryProvider* advisories () { return _advisories; }
......@@ -80,6 +81,11 @@ public:
*/
virtual AirspaceVehicleManager* instantiateVehicle (const Vehicle& vehicle) = 0;
/**
* Create/upload a flight from a mission.
*/
virtual void createFlight (MissionController* missionController) = 0;
signals:
void airspaceVisibleChanged ();
......
......@@ -199,6 +199,13 @@ void MissionController::_newMissionItemsAvailableFromVehicle(bool removeAllReque
_initAllVisualItems();
_updateContainsItems();
emit newItemsFromVehicle();
//-- If airspace management enabled, create new flight
#if defined(QGC_AIRMAP_ENABLED)
if(qgcApp()->toolbox()->settingsManager()->airMapSettings()->enableAirMap()->rawValue().toBool()) {
qgcApp()->toolbox()->airspaceManager()->createFlight(this);
}
#endif
}
_itemsRequested = false;
}
......@@ -361,6 +368,13 @@ int MissionController::insertSimpleMissionItem(QGeoCoordinate coordinate, int i)
_recalcAll();
//-- If airspace management enabled and this is the first item, create new flight
#if defined(QGC_AIRMAP_ENABLED)
if(_visualItems->count() == 2 && qgcApp()->toolbox()->settingsManager()->airMapSettings()->enableAirMap()->rawValue().toBool()) {
qgcApp()->toolbox()->airspaceManager()->createFlight(this);
}
#endif
return newItem->sequenceNumber();
}
......@@ -447,6 +461,13 @@ int MissionController::insertComplexMissionItem(QString itemName, QGeoCoordinate
_visualItems->insert(i, newItem);
_recalcAll();
//-- If airspace management enabled and this is the first item, create new flight
#if defined(QGC_AIRMAP_ENABLED)
if(_visualItems->count() == 2 && qgcApp()->toolbox()->settingsManager()->airMapSettings()->enableAirMap()->rawValue().toBool()) {
qgcApp()->toolbox()->airspaceManager()->createFlight(this);
}
#endif
return newItem->sequenceNumber();
}
......@@ -1997,6 +2018,7 @@ void MissionController::setCurrentPlanViewIndex(int sequenceNumber, bool force)
void MissionController::_updateTimeout()
{
QGeoCoordinate takeoffCoordinate;
QGCGeoBoundingCube boundingCube;
double north = 0.0;
double south = 180.0;
......@@ -2010,9 +2032,11 @@ void MissionController::_updateTimeout()
SimpleMissionItem* pSimpleItem = qobject_cast<SimpleMissionItem*>(item);
if(pSimpleItem) {
switch(pSimpleItem->command()) {
case MAV_CMD_NAV_TAKEOFF:
takeoffCoordinate = pSimpleItem->coordinate();
// Fall through
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;
......@@ -2047,8 +2071,10 @@ void MissionController::_updateTimeout()
boundingCube = QGCGeoBoundingCube(
QGeoCoordinate(north - 90.0, west - 180.0, minAlt),
QGeoCoordinate(south - 90.0, east - 180.0, maxAlt));
if(_travelBoundingCube != boundingCube) {
if(_travelBoundingCube != boundingCube || _takeoffCoordinate != takeoffCoordinate) {
_takeoffCoordinate = takeoffCoordinate;
_travelBoundingCube = boundingCube;
emit missionBoundingCubeChanged();
qCDebug(MissionControllerLog) << "Bounding cube:" << _travelBoundingCube.pointNW << _travelBoundingCube.pointSE;
}
}
......
......@@ -125,6 +125,9 @@ public:
bool loadJsonFile(QFile& file, QString& errorString);
bool loadTextFile(QFile& file, QString& errorString);
QGCGeoBoundingCube travelBoundingCube () { return _travelBoundingCube; }
QGeoCoordinate takeoffCoordinate () { return _takeoffCoordinate; }
// Overrides from PlanElementController
bool supported (void) const final { return true; }
void start (bool editMode) final;
......@@ -192,6 +195,7 @@ signals:
void currentMissionIndexChanged (int currentMissionIndex);
void currentPlanViewIndexChanged (void);
void currentPlanViewItemChanged (void);
void missionBoundingCubeChanged (void);
private slots:
void _newMissionItemsAvailableFromVehicle(bool removeAllRequested);
......@@ -263,6 +267,7 @@ private:
VisualMissionItem* _currentPlanViewItem;
QTimer _updateTimer;
QGCGeoBoundingCube _travelBoundingCube;
QGeoCoordinate _takeoffCoordinate;
static const char* _settingsGroup;
......
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