Commit 46adaf36 authored by Valentin Platzgummer's avatar Valentin Platzgummer

wima planer, wima controller edited

parent 912e993b
......@@ -174,23 +174,30 @@ Rectangle {
BusyIndicator{
id: indicator
anchors.horizontalCenter: parent.horizontalCenter
running: missionItem.calculating
property bool calculating: missionItem.calculating
running: calculating
onRunningChanged: {
if(running){
onCalculatingChanged: {
if(calculating){
visible = true
} else {
timer.restart()
}
}
Component.onCompleted: {
if (calculating){
visible = true
}
}
Timer{
id: timer
interval: 2000
interval: 1000
repeat: false
onTriggered: {
if (indicator.running == false){
if (indicator.calculating == false){
indicator.visible = false
}
}
......
......@@ -64,6 +64,9 @@ void CSWorker::update(const QGeoCoordinate &depot,
Lock lk(this->_mutex);
this->_depot = depot;
this->_safeArea = safeArea;
for (auto &v : this->_safeArea) {
v.setAltitude(0);
}
this->_polygon = polygon;
for (auto &v : this->_polygon) {
v.setAltitude(0);
......@@ -96,6 +99,7 @@ void CSWorker::run() {
depot = this->_depot;
safeArea = this->_safeArea;
} else {
depot = this->_origin;
safeArea = this->_polygon;
}
const auto polygon = this->_polygon;
......@@ -379,11 +383,11 @@ void CSWorker::run() {
} else {
// Find index of first waypoint.
std::size_t idxFirst = 0;
const auto &info1 =
this->_useDepotSafeArea ? transectsInfo[1] : transectsInfo[0];
const auto &firstTransect = transectsENU[info1.index];
const auto &firstWaypoint =
info1.reversed ? firstTransect.back() : firstTransect.front();
const auto &infoFirst = transectsInfo.front();
const auto &firstTransect = transectsENU[infoFirst.index];
const auto &firstWaypoint = infoFirst.reversed
? firstTransect.back()
: firstTransect.front();
double th = 0.001;
for (std::size_t i = 0; i < route.size(); ++i) {
auto dist = bg::distance(route[i], firstWaypoint);
......@@ -393,11 +397,11 @@ void CSWorker::run() {
}
}
// Find index of last waypoint.
std::size_t idxLast = 0;
const auto &info = transectsInfo.back();
const auto &lastTransect = transectsENU[info.index];
std::size_t idxLast = route.size() - 1;
const auto &infoLast = transectsInfo.back();
const auto &lastTransect = transectsENU[infoLast.index];
const auto &lastWaypoint =
info.reversed ? lastTransect.front() : lastTransect.back();
infoLast.reversed ? lastTransect.front() : lastTransect.back();
for (long i = route.size() - 1; i >= 0; --i) {
auto dist = bg::distance(route[i], lastWaypoint);
if (dist < th) {
......
......@@ -29,7 +29,7 @@ public:
Q_PROPERTY(Fact *deltaAlpha READ deltaAlpha CONSTANT)
Q_PROPERTY(Fact *transectMinLength READ transectMinLength CONSTANT)
Q_PROPERTY(bool calculating READ calculating NOTIFY calculatingChanged)
Q_PROPERTY(bool hidePolygon READ hidePolygon NOTIFY hidePolygon)
Q_PROPERTY(bool hidePolygon READ hidePolygon NOTIFY hidePolygonChanged)
Q_INVOKABLE void resetReference(void);
Q_INVOKABLE void reverse(void);
......
......@@ -20,11 +20,15 @@ WimaServiceArea &WimaServiceArea::operator=(const WimaServiceArea &other) {
return *this;
}
void WimaServiceArea::setDepot(const QGeoCoordinate &coordinate) {
bool WimaServiceArea::setDepot(const QGeoCoordinate &coordinate) {
if (_depot != coordinate) {
_depot = coordinate;
emit depotChanged();
if (this->containsCoordinate(coordinate)) {
_depot = coordinate;
emit depotChanged();
return true;
}
}
return false;
}
void WimaServiceArea::saveToJson(QJsonObject &json) {
......@@ -58,8 +62,8 @@ void print(const WimaServiceArea &area, QString &outputStr) {
void WimaServiceArea::init() {
this->setObjectName(wimaServiceAreaName);
connect(this, &WimaServiceArea::centerChanged, [this] {
if (!this->_depot.isValid()) {
connect(this, &WimaArea::pathChanged, [this] {
if (!this->_depot.isValid() || !this->containsCoordinate(this->_depot)) {
this->setDepot(this->center());
}
});
......
......@@ -34,7 +34,7 @@ signals:
void depotChanged(void);
public slots:
void setDepot(const QGeoCoordinate &coordinate);
bool setDepot(const QGeoCoordinate &coordinate);
private:
// Member Methodes
......
......@@ -2,37 +2,33 @@
const char *WimaServiceAreaData::typeString = "WimaServiceAreaData";
WimaServiceAreaData::WimaServiceAreaData(QObject *parent)
: WimaAreaData(parent)
{
: WimaAreaData(parent) {}
WimaServiceAreaData::WimaServiceAreaData(const WimaServiceAreaData &other,
QObject *parent)
: WimaAreaData(parent) {
*this = other;
}
WimaServiceAreaData::WimaServiceAreaData(const WimaServiceAreaData &other, QObject *parent)
: WimaAreaData (parent)
{
*this = other;
WimaServiceAreaData::WimaServiceAreaData(const WimaServiceArea &other,
QObject *parent)
: WimaAreaData(parent) {
*this = other;
}
WimaServiceAreaData::WimaServiceAreaData(const WimaServiceArea &other, QObject *parent)
: WimaAreaData (parent)
{
*this = other;
WimaServiceAreaData &WimaServiceAreaData::
operator=(const WimaServiceAreaData &otherData) {
this->assign(otherData);
this->setDepot(otherData.depot());
return *this;
}
WimaServiceAreaData &WimaServiceAreaData::operator=(const WimaServiceAreaData &otherData)
{
this->assign(otherData);
return *this;
}
WimaServiceAreaData &WimaServiceAreaData::operator=(const WimaServiceArea &otherArea)
{
this->assign(otherArea);
return *this;
WimaServiceAreaData &WimaServiceAreaData::
operator=(const WimaServiceArea &otherArea) {
this->assign(otherArea);
this->setDepot(otherArea.depot());
return *this;
}
/*!
......@@ -40,77 +36,41 @@ WimaServiceAreaData &WimaServiceAreaData::operator=(const WimaServiceArea &other
* Returns a constant reference to the takeOffPosition.
*
*/
const QGeoCoordinate &WimaServiceAreaData::takeOffPosition() const
{
return _takeOffPosition;
}
/*!
* \fn const QGeoCoordinate &WimaServiceAreaData::landOffPosition() const
* Returns a constant reference to the landOffPosition.
*
*/
const QGeoCoordinate &WimaServiceAreaData::landPosition() const
{
return _landPosition;
}
QString WimaServiceAreaData::type() const
{
return this->typeString;
}
/*!
* \fn void WimaServiceAreaData::setTakeOffPosition(const QGeoCoordinate &newCoordinate)
* Sets the takeoff position to the \a newCoordinate and emits the takeOffPositionChanged() signal,
* if newCoordinate differs from the member value.
*
*/
void WimaServiceAreaData::setTakeOffPosition(const QGeoCoordinate &newCoordinate)
{
if (_takeOffPosition != newCoordinate) {
_takeOffPosition = newCoordinate;
emit takeOffPositionChanged(_takeOffPosition);
}
}
const QGeoCoordinate &WimaServiceAreaData::depot() const { return _depot; }
QString WimaServiceAreaData::type() const { return this->typeString; }
/*!
* \fn void WimaServiceAreaData::setLandOffPosition(const QGeoCoordinate &newCoordinate)
* Sets the land position to the \a newCoordinate and emits the landOffPositionChanged() signal,
* if newCoordinate differs from the member value.
* \fn void WimaServiceAreaData::setTakeOffPosition(const QGeoCoordinate
* &newCoordinate) Sets the takeoff position to the \a newCoordinate and emits
* the takeOffPositionChanged() signal, if newCoordinate differs from the member
* value.
*
*/
void WimaServiceAreaData::setLandPosition(const QGeoCoordinate &newCoordinate)
{
if (_landPosition != newCoordinate) {
_landPosition = newCoordinate;
emit landPositionChanged(_landPosition);
}
void WimaServiceAreaData::setDepot(const QGeoCoordinate &newCoordinate) {
if (_depot != newCoordinate) {
_depot = newCoordinate;
emit depotChanged(_depot);
}
}
void WimaServiceAreaData::assign(const WimaServiceAreaData &other)
{
WimaAreaData::assign(other);
setLandPosition(other.landPosition());
setTakeOffPosition(other.takeOffPosition());
void WimaServiceAreaData::assign(const WimaServiceAreaData &other) {
WimaAreaData::assign(other);
setDepot(other.depot());
}
void WimaServiceAreaData::assign(const WimaServiceArea &other)
{
WimaAreaData::assign(other);
setLandPosition(other.landPosition());
setTakeOffPosition(other.depot());
void WimaServiceAreaData::assign(const WimaServiceArea &other) {
WimaAreaData::assign(other);
setDepot(other.depot());
}
/*!
* \class WimaAreaData::WimaServiceAreaData
* \brief Class to store and exchange data of a \c WimaServiceArea Object.
* Class to store and exchange data of a \c WimaServiceArea Object. In contrast to \c WimaServiceArea this class
* does not provied any interface to a grafical user interface, neiter it uses the QGC Fact System.
* It is designed to exchange data between the \c WimaPlaner and the \c WimaController class. And it
* is the derived from WimaAreaData.
* Class to store and exchange data of a \c WimaServiceArea Object. In contrast
* to \c WimaServiceArea this class does not provied any interface to a grafical
* user interface, neiter it uses the QGC Fact System. It is designed to
* exchange data between the \c WimaPlaner and the \c WimaController class. And
* it is the derived from WimaAreaData.
*
* \sa WimaServiceArea, WimaAreaData
*/
#pragma once
#include <QObject>
#include "QGeoCoordinate"
#include <QObject>
#include "WimaAreaData.h"
#include "WimaServiceArea.h"
class WimaServiceAreaData : public WimaAreaData
{
Q_OBJECT
class WimaServiceAreaData : public WimaAreaData {
Q_OBJECT
public:
WimaServiceAreaData(QObject *parent = nullptr);
WimaServiceAreaData(const WimaServiceAreaData &other, QObject *parent = nullptr);
WimaServiceAreaData(const WimaServiceArea &other, QObject *parent = nullptr);
WimaServiceAreaData& operator=(const WimaServiceAreaData &otherData);
WimaServiceAreaData& operator=(const WimaServiceArea &otherArea);
WimaServiceAreaData(QObject *parent = nullptr);
WimaServiceAreaData(const WimaServiceAreaData &other,
QObject *parent = nullptr);
WimaServiceAreaData(const WimaServiceArea &other, QObject *parent = nullptr);
WimaServiceAreaData &operator=(const WimaServiceAreaData &otherData);
WimaServiceAreaData &operator=(const WimaServiceArea &otherArea);
const QGeoCoordinate &takeOffPosition() const;
const QGeoCoordinate &landPosition() const;
const QGeoCoordinate &depot() const;
QString type() const;
WimaServiceAreaData *Clone() const {return new WimaServiceAreaData();}
static const char* typeString;
QString type() const;
WimaServiceAreaData *Clone() const { return new WimaServiceAreaData(); }
static const char *typeString;
signals:
void takeOffPositionChanged(const QGeoCoordinate& other);
void landPositionChanged(const QGeoCoordinate& other);
void depotChanged(const QGeoCoordinate &other);
public slots:
void setTakeOffPosition(const QGeoCoordinate& newCoordinate);
void setLandPosition(const QGeoCoordinate& newCoordinate);
void setDepot(const QGeoCoordinate &newCoordinate);
protected:
void assign(const WimaServiceAreaData &other);
void assign(const WimaServiceArea &other);
void assign(const WimaServiceAreaData &other);
void assign(const WimaServiceArea &other);
private:
// see WimaServieArea.h for explanation
QGeoCoordinate _takeOffPosition;
QGeoCoordinate _landPosition;
// see WimaServieArea.h for explanation
QGeoCoordinate _depot;
};
#include "WimaBridge.h"
#include "WimaController.h"
WimaBridge::WimaBridge(QObject *parent)
: QObject (parent)
{
WimaBridge::WimaBridge(QObject *parent) : QObject(parent) {}
}
WimaController *WimaBridge::wimaController() { return _wimaController; }
WimaController *WimaBridge::wimaController()
{
return _wimaController;
}
WimaPlaner *WimaBridge::wimaPlaner() { return _wimaPlaner; }
WimaPlaner *WimaBridge::wimaPlaner()
{
return _wimaPlaner;
}
WimaBridge *WimaBridge::thisPointer()
{
return this;
}
WimaBridge *WimaBridge::thisPointer() { return this; }
void WimaBridge::setWimaController(WimaController *controller)
{
if (_wimaController != controller){
_wimaController = controller;
void WimaBridge::setWimaController(WimaController *controller) {
if (_wimaController != controller) {
_wimaController = controller;
emit wimaControllerChanged(_wimaController);
}
emit wimaControllerChanged(_wimaController);
}
}
void WimaBridge::setWimaPlaner(WimaPlaner *planer)
{
if (_wimaPlaner != planer){
_wimaPlaner = planer;
emit wimaPlanerChanged(_wimaPlaner);
}
void WimaBridge::setWimaPlaner(WimaPlaner *planer) {
if (_wimaPlaner != planer) {
_wimaPlaner = planer;
emit wimaPlanerChanged(_wimaPlaner);
}
}
bool WimaBridge::setWimaPlanData(const WimaPlanData &planData)
{
if ( _wimaController != nullptr) {
return _wimaController->setWimaPlanData(planData);
}
return false;
bool WimaBridge::setWimaPlanData(QSharedPointer<WimaPlanData> planData) {
if (_wimaController != nullptr) {
return _wimaController->setWimaPlanData(planData);
}
return false;
}
#pragma once
#include <QObject>
#include <QSharedPointer>
#include "WimaPlanData.h"
......@@ -11,38 +12,33 @@ class WimaPlaner;
//! \brief The WimaBridge class
//!
//! A bridge establishing a link between WimaController and WimaPlaner
class WimaBridge : public QObject
{
Q_OBJECT
class WimaBridge : public QObject {
Q_OBJECT
public:
WimaBridge(QObject *parent = nullptr);
WimaBridge(WimaBridge &other) = delete;
WimaBridge(QObject *parent = nullptr);
WimaBridge(WimaBridge &other) = delete;
Q_PROPERTY(WimaPlaner *wimaPlaner
READ wimaPlaner
WRITE setWimaPlaner
NOTIFY wimaPlanerChanged)
Q_PROPERTY(WimaController *wimaController
READ wimaController
WRITE setWimaController
NOTIFY wimaControllerChanged)
Q_PROPERTY(WimaPlaner *wimaPlaner READ wimaPlaner WRITE setWimaPlaner NOTIFY
wimaPlanerChanged)
Q_PROPERTY(WimaController *wimaController READ wimaController WRITE
setWimaController NOTIFY wimaControllerChanged)
WimaController *wimaController();
WimaPlaner *wimaPlaner();
WimaController *wimaController();
WimaPlaner *wimaPlaner();
Q_INVOKABLE WimaBridge *thisPointer();
Q_INVOKABLE WimaBridge *thisPointer();
void setWimaController (WimaController *controller);
void setWimaPlaner (WimaPlaner *planer);
void setWimaController(WimaController *controller);
void setWimaPlaner(WimaPlaner *planer);
signals:
void wimaControllerChanged (WimaController *controller);
void wimaPlanerChanged (WimaPlaner *planer);
void wimaControllerChanged(WimaController *controller);
void wimaPlanerChanged(WimaPlaner *planer);
public slots:
bool setWimaPlanData(const WimaPlanData &planData);
bool setWimaPlanData(QSharedPointer<WimaPlanData> planData);
private:
WimaController *_wimaController;
WimaPlaner *_wimaPlaner;
WimaController *_wimaController;
WimaPlaner *_wimaPlaner;
};
......@@ -353,7 +353,7 @@ bool WimaController::_calcShortestPath(const QGeoCoordinate &start,
return retVal;
}
bool WimaController::setWimaPlanData(const WimaPlanData &planData) {
bool WimaController::setWimaPlanData(QSharedPointer<WimaPlanData> planData) {
// reset visual items
_areas.clear();
_defaultWM.clear();
......@@ -368,7 +368,7 @@ bool WimaController::setWimaPlanData(const WimaPlanData &planData) {
_localPlanDataValid = false;
// extract list with WimaAreas
QList<const WimaAreaData *> areaList = planData.areaList();
QList<const WimaAreaData *> areaList = planData->areaList();
int areaCounter = 0;
const int numAreas = 4; // extract only numAreas Areas, if there are more they
......@@ -424,7 +424,7 @@ bool WimaController::setWimaPlanData(const WimaPlanData &planData) {
emit visualItemsChanged();
// extract mission items
QList<MissionItem> tempMissionItems = planData.missionItems();
QList<MissionItem> tempMissionItems = planData->missionItems();
if (tempMissionItems.size() < 1) {
qWarning("WimaController: Mission items from WimaPlaner empty!");
return false;
......@@ -435,7 +435,7 @@ bool WimaController::setWimaPlanData(const WimaPlanData &planData) {
}
_WMSettings.setHomePosition(QGeoCoordinate(
_serviceArea.center().latitude(), _serviceArea.center().longitude(), 0));
_serviceArea.depot().latitude(), _serviceArea.depot().longitude(), 0));
if (!_defaultWM.reset()) {
Q_ASSERT(false);
......
......@@ -148,7 +148,7 @@ public:
// Property setters
void setMasterController(PlanMasterController *masterController);
void setMissionController(MissionController *missionController);
bool setWimaPlanData(const WimaPlanData &planData);
bool setWimaPlanData(QSharedPointer<WimaPlanData> planData);
// Member Methodes
Q_INVOKABLE WimaController *thisPointer();
......
#include "WimaPlanData.h"
WimaPlanData::WimaPlanData(QObject *parent)
: QObject (parent)
{
}
WimaPlanData::WimaPlanData(QObject *parent) : QObject(parent) {}
WimaPlanData::WimaPlanData(const WimaPlanData &other, QObject *parent)
: QObject (parent)
{
*this = other;
: QObject(parent) {
*this = other;
}
/*!
......@@ -18,44 +13,41 @@ WimaPlanData::WimaPlanData(const WimaPlanData &other, QObject *parent)
* Copies the data area list of \a other to the calling \c WimaPlanData object.
* Returns a reference to the calling \c WimaPlanData object.
*/
WimaPlanData &WimaPlanData::operator=(const WimaPlanData &other)
{
// copy wima areas
QList<const WimaAreaData*> areaList = other.areaList();
_areaList.clear();
for (int i = 0; i < areaList.size(); i++) {
const WimaAreaData *areaData = areaList[i];
// determine area type and append
if (areaData->type() == WimaJoinedAreaData::typeString) {
this->append(*qobject_cast<const WimaJoinedAreaData*>(areaData));
}else if (areaData->type() == WimaServiceAreaData::typeString) {
this->append(*qobject_cast<const WimaServiceAreaData*>(areaData));
}else if (areaData->type() == WimaMeasurementAreaData::typeString) {
this->append(*qobject_cast<const WimaMeasurementAreaData*>(areaData));
}else if (areaData->type() == WimaCorridorData::typeString) {
this->append(*qobject_cast<const WimaCorridorData*>(areaData));
}
WimaPlanData &WimaPlanData::operator=(const WimaPlanData &other) {
// copy wima areas
QList<const WimaAreaData *> areaList = other.areaList();
_areaList.clear();
for (int i = 0; i < areaList.size(); i++) {
const WimaAreaData *areaData = areaList[i];
// determine area type and append
if (areaData->type() == WimaJoinedAreaData::typeString) {
this->append(*qobject_cast<const WimaJoinedAreaData *>(areaData));
} else if (areaData->type() == WimaServiceAreaData::typeString) {
this->append(*qobject_cast<const WimaServiceAreaData *>(areaData));
} else if (areaData->type() == WimaMeasurementAreaData::typeString) {
this->append(*qobject_cast<const WimaMeasurementAreaData *>(areaData));
} else if (areaData->type() == WimaCorridorData::typeString) {
this->append(*qobject_cast<const WimaCorridorData *>(areaData));
}
}
// copy mission items
_missionItems = other.missionItems();
// copy mission items
_missionItems = other.missionItems();
return *this;
return *this;
}
/*!
* \fn void WimaPlanData::append(const WimaAreaData &areaData)
*
* Adds a WimaAreaData item.
*/
void WimaPlanData::append(const WimaJoinedAreaData &areaData)
{
_joinedArea = areaData;
void WimaPlanData::append(const WimaJoinedAreaData &areaData) {
_joinedArea = areaData;
if( !_areaList.contains(&_joinedArea) ) {
_areaList.append(&_joinedArea);
}
if (!_areaList.contains(&_joinedArea)) {
_areaList.append(&_joinedArea);
}
}
/*!
......@@ -63,13 +55,12 @@ void WimaPlanData::append(const WimaJoinedAreaData &areaData)
*
* Adds a WimaServiceAreaData item.
*/
void WimaPlanData::append(const WimaServiceAreaData &areaData)
{
_serviceArea = areaData;
void WimaPlanData::append(const WimaServiceAreaData &areaData) {
_serviceArea = areaData;
if( !_areaList.contains(&_serviceArea) ) {
_areaList.append(&_serviceArea);
}
if (!_areaList.contains(&_serviceArea)) {
_areaList.append(&_serviceArea);
}
}
/*!
......@@ -77,13 +68,12 @@ void WimaPlanData::append(const WimaServiceAreaData &areaData)
*
* Adds a WimaCorridorData item.
*/
void WimaPlanData::append(const WimaCorridorData &areaData)
{
_corridor = areaData;
void WimaPlanData::append(const WimaCorridorData &areaData) {
_corridor = areaData;
if( !_areaList.contains(&_corridor) ) {
_areaList.append(&_corridor);
}
if (!_areaList.contains(&_corridor)) {
_areaList.append(&_corridor);
}
}
/*!
......@@ -91,21 +81,19 @@ void WimaPlanData::append(const WimaCorridorData &areaData)
*
* Adds a WimaMeasurementAreaData item.
*/
void WimaPlanData::append(const WimaMeasurementAreaData &areaData)
{
_measurementArea = areaData;
void WimaPlanData::append(const WimaMeasurementAreaData &areaData) {
_measurementArea = areaData;
if( !_areaList.contains(&_measurementArea) ) {
_areaList.append(&_measurementArea);
}
if (!_areaList.contains(&_measurementArea)) {
_areaList.append(&_measurementArea);
}
}
void WimaPlanData::append(const QList<MissionItem *> &missionItems)
{
for (MissionItem *item : missionItems) {
MissionItem copy = MissionItem(*item, this);
_missionItems.append(copy);
}
void WimaPlanData::append(const QList<MissionItem *> &missionItems) {
for (auto *item : missionItems) {
item->setParent(this);
_missionItems.append(item);
}
}
/*!
......@@ -113,20 +101,17 @@ void WimaPlanData::append(const QList<MissionItem *> &missionItems)
*
* Clears all stored objects
*/
void WimaPlanData::clear()
{
_areaList.clear();
_missionItems.clear();
void WimaPlanData::clear() {
_areaList.clear();
_missionItems.clear();
}
QList<const WimaAreaData *> WimaPlanData::areaList() const
{
return _areaList;
const QList<const WimaAreaData *> &WimaPlanData::areaList() const {
return _areaList;
}
QList<MissionItem> WimaPlanData::missionItems() const
{
return _missionItems;
const QList<MissionItem> &WimaPlanData::missionItems() const {
return _missionItems;
}
/*!
......@@ -135,8 +120,8 @@ QList<MissionItem> WimaPlanData::missionItems() const
*
* This class is designed to store data generated by the \c WimaPlaner class and
* meant for data exchange between the \c WimaController and the \c WimaPlanner.
* It stores a QList of \c WimaAreaData objects, called area data list, containing the data of serveral \c WimaAreas
* generated by the \c WimaPlaner.
* It stores a QList of \c WimaAreaData objects, called area data list,
* containing the data of serveral \c WimaAreas generated by the \c WimaPlaner.
*
* \sa QList
*/
......@@ -3,45 +3,46 @@
#include <QObject>
#include "Geometry/WimaAreaData.h"
#include "Geometry/WimaServiceAreaData.h"
#include "Geometry/WimaCorridorData.h"
#include "Geometry/WimaMeasurementAreaData.h"
#include "Geometry/WimaJoinedAreaData.h"
#include "Geometry/WimaMeasurementAreaData.h"
#include "Geometry/WimaServiceAreaData.h"
#include "MissionItem.h"
class WimaPlanData : QObject
{
Q_OBJECT
class WimaPlanData : public QObject {
Q_OBJECT
public:
WimaPlanData(QObject *parent = nullptr);
WimaPlanData(const WimaPlanData &other, QObject *parent = nullptr);
WimaPlanData& operator=(const WimaPlanData &other);
// Member Methodes
void append(const WimaJoinedAreaData &areaData);
void append(const WimaServiceAreaData &areaData);
void append(const WimaCorridorData &areaData);
void append(const WimaMeasurementAreaData &areaData);
void append(const QList<MissionItem *> &missionItems);
void clear();
QList<const WimaAreaData *> areaList() const;
QList<MissionItem> missionItems() const;
WimaPlanData(QObject *parent = nullptr);
WimaPlanData(const WimaPlanData &other, QObject *parent = nullptr);
WimaPlanData &operator=(const WimaPlanData &other);
// Member Methodes
void append(const WimaJoinedAreaData &areaData);
void append(const WimaServiceAreaData &areaData);
void append(const WimaCorridorData &areaData);
void append(const WimaMeasurementAreaData &areaData);
//!
//! \brief append
//! \param missionItems
//! \note Takes owenership of MissionItems*
void append(const QList<MissionItem *> &missionItems);
void clear();
const QList<const WimaAreaData *> &areaList() const;
const QList<MissionItem> &missionItems() const;
signals:
void areaListChanged();
void areaListChanged();
private:
void _clearAndDeleteMissionItems();
void _clearAndDeleteMissionItems();
private:
WimaJoinedAreaData _joinedArea;
WimaServiceAreaData _serviceArea;
WimaCorridorData _corridor;
WimaMeasurementAreaData _measurementArea;
QList<const WimaAreaData*> _areaList;
WimaJoinedAreaData _joinedArea;
WimaServiceAreaData _serviceArea;
WimaCorridorData _corridor;
WimaMeasurementAreaData _measurementArea;
QList<const WimaAreaData *> _areaList;
QList<MissionItem> _missionItems;
QList<MissionItem> _missionItems;
};
......@@ -25,7 +25,7 @@ WimaPlaner::WimaPlaner(QObject *parent)
_currentAreaIndex(-1), _wimaBridge(nullptr), _mAreaChanged(true),
_sAreaChanged(true), _corridorChanged(true), _joinedArea(this),
_arrivalPathLength(0), _returnPathLength(0), _TSComplexItem(nullptr),
_surveyChanged(true), _synchronized(false) {
_surveyChanged(true), _synchronized(false), _needsUpdate(true) {
connect(this, &WimaPlaner::currentPolygonIndexChanged, this,
&WimaPlaner::updatePolygonInteractivity);
......@@ -37,6 +37,10 @@ WimaPlaner::WimaPlaner(QObject *parent)
this->_sAreaChanged = true;
this->setNeedsUpdate(true);
});
connect(&this->_serviceArea, &WimaServiceArea::depotChanged, [this] {
this->_sAreaChanged = true;
this->setNeedsUpdate(true);
});
connect(&this->_corridor, &WimaArea::pathChanged, [this] {
this->_corridorChanged = true;
this->setNeedsUpdate(true);
......@@ -255,6 +259,11 @@ bool WimaPlaner::update() {
return false;
}
if (!_serviceArea.containsCoordinate(_serviceArea.depot())) {
qgcApp()->showMessage(tr("Depot not inside service area."));
return false;
}
// Join areas.
bool jAreaChanged =
this->_mAreaChanged || this->_sAreaChanged || this->_corridorChanged;
......@@ -426,9 +435,9 @@ bool WimaPlaner::update() {
return false;
}
this->_surveyChanged = false;
setNeedsUpdate(false);
}
setNeedsUpdate(false);
return true;
}
void WimaPlaner::saveToCurrent() { saveToFile(_currentFile); }
......@@ -655,11 +664,11 @@ void WimaPlaner::updatePolygonInteractivity(int index) {
}
}
void WimaPlaner::pushToWimaController() {
void WimaPlaner::synchronize() {
if (_wimaBridge != nullptr) {
if (!_needsUpdate)
if (_needsUpdate)
return;
WimaPlanData planData = toPlanData();
auto planData = toPlanData();
(void)_wimaBridge->setWimaPlanData(planData);
this->_synchronized = true;
emit synchronizedChanged();
......@@ -718,30 +727,20 @@ void WimaPlaner::setInteractive() {
*
* \sa WimaController, WimaPlanData
*/
WimaPlanData WimaPlaner::toPlanData() {
WimaPlanData planData;
QSharedPointer<WimaPlanData> WimaPlaner::toPlanData() {
QSharedPointer<WimaPlanData> planData(new WimaPlanData());
// store areas
planData.append(WimaMeasurementAreaData(_measurementArea));
planData.append(WimaServiceAreaData(_serviceArea));
planData.append(WimaCorridorData(_corridor));
planData.append(WimaJoinedAreaData(_joinedArea));
planData->append(WimaMeasurementAreaData(_measurementArea));
planData->append(WimaServiceAreaData(_serviceArea));
planData->append(WimaCorridorData(_corridor));
planData->append(WimaJoinedAreaData(_joinedArea));
// convert mission items to mavlink commands
QObject deleteObject; // used to automatically delete content of
// rgMissionItems after this function call
QList<MissionItem *> rgMissionItems;
QmlObjectListModel *visualItems = _missionController->visualItems();
QmlObjectListModel visualItemsToCopy;
for (unsigned long i = _arrivalPathLength + 1;
i < visualItems->count() - _returnPathLength; i++)
visualItemsToCopy.append(visualItems->get(i));
MissionController::convertToMissionItems(&visualItemsToCopy, rgMissionItems,
&deleteObject);
QList<MissionItem *> missionItems;
_TSComplexItem->appendMissionItems(missionItems, nullptr);
// store mavlink commands
planData.append(rgMissionItems);
planData->append(missionItems);
return planData;
}
......@@ -749,7 +748,7 @@ WimaPlanData WimaPlaner::toPlanData() {
void WimaPlaner::autoLoadMission() {
loadFromFile("/home/valentin/Desktop/drones/qgroundcontrol/Paths/"
"KlingenbachTest.wima");
pushToWimaController();
synchronize();
}
#endif
......
......@@ -2,6 +2,7 @@
#include "QmlObjectListModel.h"
#include <QObject>
#include <QSharedPointer>
#include "Geometry/WimaCorridor.h"
#include "Geometry/WimaCorridorData.h"
......@@ -82,7 +83,7 @@ public:
/// Recalculates vehicle corridor, flight path, etc.
Q_INVOKABLE bool update();
/// Pushes the generated mission data to the wimaController.
Q_INVOKABLE void pushToWimaController();
Q_INVOKABLE void synchronize();
Q_INVOKABLE void saveToCurrent();
Q_INVOKABLE void saveToFile(const QString &filename);
Q_INVOKABLE bool loadFromCurrent();
......@@ -118,7 +119,7 @@ signals:
private:
// Member Functions
WimaPlanData toPlanData();
QSharedPointer<WimaPlanData> toPlanData();
bool shortestPath(const QGeoCoordinate &start,
const QGeoCoordinate &destination,
QVector<QGeoCoordinate> &path);
......
......@@ -27,16 +27,17 @@ Item {
property var coordinate
property int sequenceNumber
property bool checked
property string label: "Reference"
property var _itemVisual
property bool _itemVisualShowing: false
property var _dragArea
property bool _dragAreaShowing: false
signal clicked(int sequenceNumber)
signal released(int sequenceNumber)
signal entered(int sequenceNumber)
signal exited(int sequenceNumber)
signal clicked()
signal released()
signal entered()
signal exited()
signal dragStart()
signal dragStop()
......@@ -114,16 +115,16 @@ Item {
id: indicatorComponent
CoordinateIndicator {
label: "Reference"
label: _root.label
checked: _root.checked
z: QGroundControl.zOrderMapItems
sequenceNumber: _root.sequenceNumber
coordinate: _root.coordinate
onClicked: _root.clicked(_missionItem.sequenceNumber)
onReleased: _root.released(_missionItem.sequenceNumber)
onEntered: _root.entered(_missionItem.sequenceNumber)
onExited: _root.exited(_missionItem.sequenceNumber)
onClicked: _root.clicked()
onReleased: _root.released()
onEntered: _root.entered()
onExited: _root.exited()
}
}
}
......@@ -42,6 +42,8 @@ Item {
property bool _circle: false
property real _circleRadius
property bool _editCircleRadius: false
property bool _handelsVisible: false // state tracker
property bool _polygonVisible: false // state tracker
property real _zorderDragHandle: QGroundControl.zOrderMapItems + 3 // Highest to prevent splitting when items overlap
property real _zorderSplitHandle: QGroundControl.zOrderMapItems + 2
......@@ -49,19 +51,28 @@ Item {
signal dragStop // triggered if node or center handle was stopped dragging
function addVisuals() {
_polygonComponent = polygonComponent.createObject(mapControl)
mapControl.addMapItem(_polygonComponent)
function addPolygon() {
if (!_polygonComponent){
_polygonComponent = polygonComponent.createObject(mapControl)
mapControl.addMapItem(_polygonComponent)
}
}
function removeVisuals() {
_polygonComponent.destroy()
function removePolygon() {
if (_polygonComponent){
_polygonComponent.destroy()
_polygonComponent = undefined
}
}
function addHandles() {
if (!_dragHandlesComponent) {
_dragHandlesComponent = dragHandlesComponent.createObject(mapControl)
}
if (!_splitHandlesComponent) {
_splitHandlesComponent = splitHandlesComponent.createObject(mapControl)
}
if (!_centerDragHandleComponent) {
_centerDragHandleComponent = centerDragHandleComponent.createObject(mapControl)
}
}
......@@ -153,27 +164,38 @@ Item {
setCircleRadius(center, radius)
}
function updateVisibility(){
if (visible){
addPolygon()
if(interactive){
addHandles()
}else{
removeHandles()
}
} else {
removeHandles()
removePolygon()
}
}
onInteractiveChanged: {
if (interactive) {
addHandles()
} else {
removeHandles()
}
updateVisibility()
}
onVisibleChanged: {
updateVisibility()
}
Component.onCompleted: {
if(initPolygon){
addInitialPolygon()
}
addVisuals()
if (interactive) {
addHandles()
}
updateVisibility()
}
Component.onDestruction: {
removeVisuals()
removePolygon()
removeHandles()
}
......
......@@ -18,7 +18,6 @@ import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.FlightMap 1.0
/// Wima Global Measurement Area visuals
Item {
id: _root
......@@ -27,9 +26,37 @@ Item {
property var areaItem: object
property var _polygon: areaItem
property var _depot
property bool showDepot: areaItem.interactive || areaItem.borderPolygon.interactive
property bool _depotVisible: false
onShowDepotChanged: {
if (showDepot){
if (!_depotVisible){
_addDepot()
}
} else {
if (_depotVisible){
_destroyDepot()
}
}
}
signal clicked(int sequenceNumber)
function _addDepot() {
_depot = depotPointComponent.createObject(map)
map.addMapItem(_depot)
_depotVisible = true
}
function _destroyDepot() {
if (_depot){
_depot.destroy()
}
_depotVisible = false
}
/// Add an initial 4 sided polygon if there is none
function _addInitialPolygon() {
......@@ -73,18 +100,17 @@ Item {
_polygon.appendVertex(bottomLeftCoord)
}
}
}
Component.onCompleted: {
_addInitialPolygon()
//_addInitialPolyline()
if (interactive){
_addDepot()
}
}
Component.onDestruction: {
_destroyDepot()
}
WimaMapPolygonVisuals {
......@@ -107,28 +133,24 @@ Item {
interiorOpacity: 1
}
// Depot Point.
Component {
id: depotPointComponent
DragCoordinate {
property var depot: areaItem.depot
map: _root.map
qgcView: _root.qgcView
z: QGroundControl.zOrderMapItems
checked: areaItem.interactive
coordinate: areaItem.depot
property var point: areaItem.depot
onRefPointChanged: {
if (point !== coordinate) {
coordinate = point
}
}
checked: showDepot
coordinate: depot
label: "Depot"
onDragReleased: {
areaItem.depot = coordinate
if (areaItem.containsCoordinate(coordinate)){
areaItem.depot = coordinate
}
coordinate = Qt.binding(function() { return areaItem.depot; })
}
}
}
......
......@@ -290,7 +290,7 @@ Rectangle {
onClicked: {
if (wimaPlaner){
if (!wimaPlaner.needsUpdate) {
wimaPlaner.pushToWimaController()
wimaPlaner.synchronize()
} else {
wimaPlaner.update()
}
......@@ -302,7 +302,9 @@ Rectangle {
from: 0.5
to: 1
loops: Animation.Infinite
running: wimaPlaner ? wimaPlaner.needsUpdate : false
running: wimaPlaner ? wimaPlaner.needsUpdate ||
(!wimaPlaner.needsUpdate && !wimaPlaner.synchronized)
: false
alwaysRunToEnd: true
duration: 2000
}
......
......@@ -592,7 +592,7 @@ QGCView {
// Add lines between waypoints
MissionLineView {
model: _editingLayer == _layerMission ? _missionController.waypointLines : undefined
model: _editingLayer == _layerMission ? _missionController.waypointLines : []
}
//Add Wima Visuals
......
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