From 32c7f879c51e4465720477e70da67721d4e11778 Mon Sep 17 00:00:00 2001 From: Valentin Platzgummer Date: Mon, 8 Jul 2019 12:43:44 +0200 Subject: [PATCH] befor editing WimaAreaData --- qgroundcontrol.pro | 8 +++- src/Wima/WimaArea.h | 4 +- src/Wima/WimaAreaData.cc | 21 ++++----- src/Wima/WimaAreaData.h | 16 ++++--- src/Wima/WimaController.cc | 24 +++++----- src/Wima/WimaCorridorData.cpp | 6 +++ src/Wima/WimaCorridorData.h | 2 + src/Wima/WimaJoinedArea.cc | 69 +++++++++++++++++++++++++++++ src/Wima/WimaJoinedArea.h | 40 +++++++++++++++++ src/Wima/WimaJoinedAreaData.cc | 61 +++++++++++++++++++++++++ src/Wima/WimaJoinedAreaData.h | 31 +++++++++++++ src/Wima/WimaMeasurementArea.h | 1 - src/Wima/WimaMeasurementAreaData.cc | 6 +++ src/Wima/WimaMeasurementAreaData.h | 4 +- src/Wima/WimaPlanData.cc | 9 ++-- src/Wima/WimaPlaner.cc | 11 ++--- src/Wima/WimaPlaner.h | 14 +++--- src/Wima/WimaServiceAreaData.cc | 5 +++ src/Wima/WimaServiceAreaData.h | 2 + 19 files changed, 281 insertions(+), 53 deletions(-) create mode 100644 src/Wima/WimaJoinedArea.cc create mode 100644 src/Wima/WimaJoinedArea.h create mode 100644 src/Wima/WimaJoinedAreaData.cc create mode 100644 src/Wima/WimaJoinedAreaData.h diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 6ba3ab3d1..f495fb24d 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -421,7 +421,9 @@ HEADERS += \ src/Wima/WimaServiceAreaData.h \ src/Wima/WimaCorridorData.h \ src/Wima/WimaMeasurementAreaData.h \ - src/Wima/WimaPlanData.h + src/Wima/WimaPlanData.h \ + src/Wima/WimaJoinedArea.h \ + src/Wima/WimaJoinedAreaData.h SOURCES += \ src/api/QGCCorePlugin.cc \ src/api/QGCOptions.cc \ @@ -441,7 +443,9 @@ SOURCES += \ src/Wima/WimaServiceAreaData.cc \ src/Wima/WimaCorridorData.cpp \ src/Wima/WimaPlanData.cc \ - src/Wima/WimaMeasurementAreaData.cc + src/Wima/WimaMeasurementAreaData.cc \ + src/Wima/WimaJoinedArea.cc \ + src/Wima/WimaJoinedAreaData.cc # # Unit Test specific configuration goes here (requires full debug build with all plugins) diff --git a/src/Wima/WimaArea.h b/src/Wima/WimaArea.h index 1914f4ccc..60e099663 100644 --- a/src/Wima/WimaArea.h +++ b/src/Wima/WimaArea.h @@ -28,8 +28,8 @@ public: double maxAltitude (void) const { return _maxAltitude;} // overrides from WimaArea - virtual QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";} - virtual QString editorQML (void) const { return "WimaAreaEditor.qml";} + virtual QString mapVisualQML (void) const; + virtual QString editorQML (void) const; // Member Methodes int getClosestVertexIndex (const QGeoCoordinate& coordinate) const; diff --git a/src/Wima/WimaAreaData.cc b/src/Wima/WimaAreaData.cc index 248699a8e..371cc627f 100644 --- a/src/Wima/WimaAreaData.cc +++ b/src/Wima/WimaAreaData.cc @@ -1,8 +1,7 @@ #include "WimaAreaData.h" -const char *WimaAreaData::typeString = "WimaAreaData"; - -WimaAreaData::WimaAreaData(QObject *parent) : QObject(parent) +WimaAreaData::WimaAreaData(QObject *parent) + : QObject(parent) { _maxAltitude = 0; } @@ -47,6 +46,7 @@ WimaAreaData &WimaAreaData::operator=(const WimaArea &otherArea) return *this; } + /*! * \fn double WimaAreaData::maxAltitude() * @@ -67,16 +67,6 @@ QVariantList WimaAreaData::path() const return _path; } -/*! - * \fn QString WimaAreaData::type() - * - * Returns the type name of the object. Used to destinguish between derived objects. - */ -QString WimaAreaData::type() const -{ - return typeString; -} - /*! * \fn void WimaAreaData::setMaxAltitude(double maxAltitude) * @@ -98,6 +88,11 @@ void WimaAreaData::setPath(const QVariantList &coordinateList) _path.append(coordinateList); } +void WimaAreaData::assign(const WimaAreaData &other) +{ + +} + /*! * \fn void WimaAreaData::setPath(const QList &coordinateList) diff --git a/src/Wima/WimaAreaData.h b/src/Wima/WimaAreaData.h index ba2f6c8e1..62699edc8 100644 --- a/src/Wima/WimaAreaData.h +++ b/src/Wima/WimaAreaData.h @@ -6,7 +6,7 @@ #include "WimaArea.h" -class WimaAreaData : public QObject +class WimaAreaData : public QObject // Abstract class for all WimaAreaData derived objects { Q_OBJECT @@ -14,16 +14,15 @@ public: Q_PROPERTY(const QVariantList path READ path NOTIFY pathChanged) WimaAreaData(QObject *parent = nullptr); - WimaAreaData(const WimaAreaData &other, QObject *parent = nullptr); - WimaAreaData(const WimaArea &other, QObject *parent = nullptr); - WimaAreaData& operator=(const WimaAreaData& otherData); - WimaAreaData& operator=(const WimaArea& otherArea); + //WimaAreaData(const WimaAreaData &other, QObject *parent = nullptr); + //WimaAreaData(const WimaArea &other, QObject *parent = nullptr); + WimaAreaData& operator=(const WimaAreaData& otherData) = delete; // avoid slicing double maxAltitude() const; QVariantList path() const; - QString type() const; - static const char *typeString; + + virtual QString type() const = 0; signals: void maxAltitudeChanged (double maxAltitude); @@ -34,6 +33,9 @@ public slots: void setPath(const QList &coordinateList); void setPath(const QVariantList &coordinateList); +protected: + void assign(const WimaAreaData &other); + private: // Member Functions diff --git a/src/Wima/WimaController.cc b/src/Wima/WimaController.cc index 810d698f4..31c989061 100644 --- a/src/Wima/WimaController.cc +++ b/src/Wima/WimaController.cc @@ -106,7 +106,7 @@ void WimaController::saveToCurrent() void WimaController::saveToFile(const QString& filename) { - + QString file = filename; } bool WimaController::loadFromCurrent() @@ -116,6 +116,7 @@ bool WimaController::loadFromCurrent() bool WimaController::loadFromFile(const QString &filename) { + QString file = filename; return true; } @@ -123,6 +124,10 @@ bool WimaController::loadFromFile(const QString &filename) QJsonDocument WimaController::saveToJson(FileType fileType) { + if(fileType) + { + + } return QJsonDocument(); } @@ -148,19 +153,20 @@ void WimaController::containerDataValidChanged(bool valid) int areaCounter = 0; int numAreas = 4; // extract only numAreas Areas, if there are more they are invalid and ignored bool joinedAreaAssigned = false; + qWarning() << QString("List Size: %1").arg(areaList.size()); for (int i = 0; i < areaList.size(); i++) { const WimaAreaData *areaData = areaList[i]; - + qWarning() << areaData->type(); if (areaData->type() == WimaServiceAreaData::typeString) { // is it a service area? - _serviceArea = *qobject_cast(areaData); + //_serviceArea = *qobject_cast(areaData); qWarning("Service area, wuhuuu!"); areaCounter++; continue; } - WimaMeasurementAreaData *measurementAreaData = qobject_cast(areaData); + /*WimaMeasurementAreaData *measurementAreaData = qobject_cast(areaData); if (measurementAreaData != nullptr) { // is it a measurement area? _measurementArea = *measurementAreaData; qWarning("Measurement area, wuhuuu!"); @@ -185,7 +191,7 @@ void WimaController::containerDataValidChanged(bool valid) joinedAreaAssigned = true; continue; - } + }*/ if (areaCounter >= numAreas) break; @@ -197,15 +203,13 @@ void WimaController::containerDataValidChanged(bool valid) //_visualItems.append(&_serviceArea); _visualItems.append(&_joinedArea); - emit visualItemsChanged(); - _localPlanDataValid = true; } else { _localPlanDataValid = false; - _visualItems.clear(); - - emit visualItemsChanged(); + _visualItems.clear(); } + + emit visualItemsChanged(); } diff --git a/src/Wima/WimaCorridorData.cpp b/src/Wima/WimaCorridorData.cpp index 2ebee0ddd..915c39bad 100644 --- a/src/Wima/WimaCorridorData.cpp +++ b/src/Wima/WimaCorridorData.cpp @@ -44,6 +44,12 @@ WimaCorridorData &WimaCorridorData::operator=(const WimaCorridor &other) return *this; } +QString WimaCorridorData::type() const +{ + return this->typeString; +} + + /*! * \class WimaAreaData::WimaCorridorData * \brief Class to store and exchange data of a \c WimaCorridorData Object. diff --git a/src/Wima/WimaCorridorData.h b/src/Wima/WimaCorridorData.h index b8efc26d4..634b73562 100644 --- a/src/Wima/WimaCorridorData.h +++ b/src/Wima/WimaCorridorData.h @@ -18,6 +18,8 @@ public: WimaCorridorData &operator=(const WimaCorridorData &other); WimaCorridorData &operator=(const WimaCorridor &other); + QString type() const; + static const char* typeString; diff --git a/src/Wima/WimaJoinedArea.cc b/src/Wima/WimaJoinedArea.cc new file mode 100644 index 000000000..f59658e88 --- /dev/null +++ b/src/Wima/WimaJoinedArea.cc @@ -0,0 +1,69 @@ +#include "WimaJoinedArea.h" + +const char* WimaJoinedArea::WimaJoinedAreaName = "WimaJoinedArea"; + +WimaJoinedArea::WimaJoinedArea(QObject *parent) + : WimaArea (parent) +{ + +} + +WimaJoinedArea::WimaJoinedArea(const WimaJoinedArea &other, QObject *parent) + : WimaArea (parent) +{ + *this = other; +} + +/*! + * \overload operator=() + * + * Calls the inherited operator WimaArea::operator=(). + */ +WimaJoinedArea &WimaJoinedArea::operator=(const WimaJoinedArea &other) +{ + WimaArea::operator=(other); + + return *this; +} + + +void WimaJoinedArea::saveToJson(QJsonObject &json) +{ + this->WimaArea::saveToJson(json); + json[areaTypeName] = WimaJoinedAreaName; +} + +bool WimaJoinedArea::loadFromJson(const QJsonObject &json, QString &errorString) +{ + if ( this->WimaArea::loadFromJson(json, errorString)) { + bool retVal = true; + // code for loading here + return retVal; + } else { + qWarning() << errorString; + return false; + } +} + +void WimaJoinedArea::init() +{ + this->setObjectName(WimaJoinedAreaName); +} + +void print(const WimaJoinedArea &area) +{ + QString message; + print(area, message); + qWarning() << message; +} + +void print(const WimaJoinedArea &area, QString &outputString) +{ + print(static_cast(area), outputString); +} + + +/*! + \class WimaJoinedArea + \brief Joined area (derived from \c WimaArea) composed by the \c WimaMeasurementArea, the \c WimaCorridor, and the \c WimaServiceArea. +*/ diff --git a/src/Wima/WimaJoinedArea.h b/src/Wima/WimaJoinedArea.h new file mode 100644 index 000000000..33897bae2 --- /dev/null +++ b/src/Wima/WimaJoinedArea.h @@ -0,0 +1,40 @@ +#ifndef WIMAJOINEDAREA_H +#define WIMAJOINEDAREA_H + +#include + +#include "WimaArea.h" + +class WimaJoinedArea : public WimaArea +{ + Q_OBJECT +public: + WimaJoinedArea(QObject* parent = nullptr); + WimaJoinedArea(const WimaJoinedArea& other, QObject* parent = nullptr); + + WimaJoinedArea &operator=(const WimaJoinedArea &other); + + // Overrides from WimaPolygon + QString mapVisualQML (void) const { return "WimaJoinedAreaMapVisual.qml";} + QString editorQML (void) const { return "";} + + // Methodes + void saveToJson (QJsonObject& json); + bool loadFromJson (const QJsonObject& json, QString& errorString); + + // static Members + static const char* WimaJoinedAreaName; + + // Friends + friend void print(const WimaJoinedArea& area, QString& outputString); + friend void print(const WimaJoinedArea& area); + +signals: + +public slots: + +private: + void init(); +}; + +#endif // WIMAJOINEDAREA_H diff --git a/src/Wima/WimaJoinedAreaData.cc b/src/Wima/WimaJoinedAreaData.cc new file mode 100644 index 000000000..309e4c010 --- /dev/null +++ b/src/Wima/WimaJoinedAreaData.cc @@ -0,0 +1,61 @@ +#include "WimaJoinedAreaData.h" + +const char *WimaJoinedAreaData::typeString = "WimaJoinedAreaData"; + +WimaJoinedAreaData::WimaJoinedAreaData(QObject *parent) + :WimaAreaData (parent) +{ + +} + +WimaJoinedAreaData::WimaJoinedAreaData(const WimaJoinedAreaData &other, QObject *parent) + : WimaAreaData (parent) +{ + *this = other; +} + +WimaJoinedAreaData::WimaJoinedAreaData(const WimaJoinedArea &other, QObject *parent) + : WimaAreaData (parent) +{ + *this = other; +} + +/*! + * \overload operator=() + * + * Assigns \a other to the invoking object. + */ +WimaJoinedAreaData &WimaJoinedAreaData::operator=(const WimaJoinedAreaData &other) +{ + WimaAreaData::operator=(other); + + return *this; +} + +/*! + * \overload operator=() + * + * Assigns \a other to the invoking object. + */ +WimaJoinedAreaData &WimaJoinedAreaData::operator=(const WimaJoinedArea &other) +{ + WimaAreaData::operator=(other); + return *this; +} + +QString WimaJoinedAreaData::type() const +{ + return this->typeString; +} + + +/*! + * \class WimaAreaData::WimaJoinedAreaData + * \brief Class to store and exchange data of a \c WimaJoinedAreaData Object. + * Class to store and exchange data of a \c WimaJoinedArea Object. In contrast to \c WimaJoinedArea 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 WimaJoinedArea, WimaAreaData + */ diff --git a/src/Wima/WimaJoinedAreaData.h b/src/Wima/WimaJoinedAreaData.h new file mode 100644 index 000000000..1ef83dcfb --- /dev/null +++ b/src/Wima/WimaJoinedAreaData.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "WimaAreaData.h" +#include "WimaJoinedArea.h" + +#include "QGeoCoordinate" + +class WimaJoinedAreaData : public WimaAreaData +{ + Q_OBJECT + +public: + WimaJoinedAreaData(QObject *parent = nullptr); + WimaJoinedAreaData(const WimaJoinedAreaData &other, QObject *parent = nullptr); + WimaJoinedAreaData(const WimaJoinedArea &other, QObject *parent = nullptr); + WimaJoinedAreaData &operator=(const WimaJoinedAreaData &other); + WimaJoinedAreaData &operator=(const WimaJoinedArea &other); + + QString type() const; + + static const char* typeString; + +signals: + +public slots: + +private: +}; + diff --git a/src/Wima/WimaMeasurementArea.h b/src/Wima/WimaMeasurementArea.h index 02ad10af6..3d73aa558 100644 --- a/src/Wima/WimaMeasurementArea.h +++ b/src/Wima/WimaMeasurementArea.h @@ -4,7 +4,6 @@ #include #include "WimaArea.h" -#include "WimaMeasurementAreaData.h" #include "SettingsFact.h" diff --git a/src/Wima/WimaMeasurementAreaData.cc b/src/Wima/WimaMeasurementAreaData.cc index f40c2f2ea..9d5b9e007 100644 --- a/src/Wima/WimaMeasurementAreaData.cc +++ b/src/Wima/WimaMeasurementAreaData.cc @@ -44,3 +44,9 @@ WimaMeasurementAreaData &WimaMeasurementAreaData::operator=(const WimaMeasuremen return *this; } +QString WimaMeasurementAreaData::type() const +{ + return this->typeString; +} + + diff --git a/src/Wima/WimaMeasurementAreaData.h b/src/Wima/WimaMeasurementAreaData.h index 9b7a1e517..fb6c81814 100644 --- a/src/Wima/WimaMeasurementAreaData.h +++ b/src/Wima/WimaMeasurementAreaData.h @@ -1,7 +1,7 @@ #pragma once #include -#include "QGeoCoordinate" +#include #include "WimaAreaData.h" @@ -20,6 +20,8 @@ public: WimaMeasurementAreaData& operator=(const WimaMeasurementAreaData &other); WimaMeasurementAreaData& operator=(const WimaMeasurementArea &other); + QString type() const; + static const char* typeString; signals: diff --git a/src/Wima/WimaPlanData.cc b/src/Wima/WimaPlanData.cc index 3aba84c11..acb52193d 100644 --- a/src/Wima/WimaPlanData.cc +++ b/src/Wima/WimaPlanData.cc @@ -22,15 +22,16 @@ WimaPlanData &WimaPlanData::operator=(const WimaPlanData &other) { QList areaList = other.areaList(); _areaList.clear(); - for (const WimaAreaData* areaData: areaList) { + for (int i = 0; i < areaList.size(); i++) { + const WimaAreaData *areaData = areaList[i]; if (areaData->type() == WimaAreaData::typeString) { this->append(*areaData); }else if (areaData->type() == WimaServiceAreaData::typeString) { - this->append(*qobject_cast(areaData)); + this->append(*qobject_cast(areaData)); }else if (areaData->type() == WimaMeasurementAreaData::typeString) { - this->append(*qobject_cast(areaData)); + this->append(*qobject_cast(areaData)); }else if (areaData->type() == WimaCorridorData::typeString) { - this->append(*qobject_cast(areaData)); + this->append(*qobject_cast(areaData)); } } diff --git a/src/Wima/WimaPlaner.cc b/src/Wima/WimaPlaner.cc index e78c5a3bc..e10749c7f 100644 --- a/src/Wima/WimaPlaner.cc +++ b/src/Wima/WimaPlaner.cc @@ -516,7 +516,7 @@ bool WimaPlaner::recalcJoinedArea(QString &errorString) } // join service area, op area and corridor - _joinedArea = _serviceArea; + _joinedArea.WimaArea::operator=(_serviceArea); _joinedArea.join(_corridor); if ( !_joinedArea.join(_measurementArea) ) { errorString.append(tr("Not able to join areas. Service area and measurement are" @@ -576,16 +576,13 @@ void WimaPlaner::setInteractive() WimaPlanData WimaPlaner::toPlanData() { WimaPlanData planData; - /* Note: constructor call: WimaMeasuretr(mentAreaData::WimaMeasurementAreaData(const WimaMeasurementArea &other, QObject *parent) - * converts WimaMeasurementArea to WimaMeasurementAreaData, this makes: planData.appendWimaAreaData(_measurementArea); possible. - * Same for the following statements - */ planData.append(WimaMeasurementAreaData(_measurementArea)); planData.append(WimaServiceAreaData(_serviceArea)); planData.append(WimaCorridorData(_corridor)); - planData.append(WimaAreaData(_joinedArea)); + planData.append(WimaJoinedAreaData(_joinedArea)); - return WimaPlanData(planData); + + return planData; } void WimaPlaner::setMissionReady(bool ready) diff --git a/src/Wima/WimaPlaner.h b/src/Wima/WimaPlaner.h index 4b3fdbe6d..c1207ba5f 100644 --- a/src/Wima/WimaPlaner.h +++ b/src/Wima/WimaPlaner.h @@ -5,15 +5,17 @@ #include "QmlObjectListModel.h" #include "WimaArea.h" -#include "WimaMeasurementArea.h" -#include "WimaServiceArea.h" -#include "WimaCorridor.h" -#include "WimaDataContainer.h" -#include "WimaPlanData.h" #include "WimaAreaData.h" +#include "WimaServiceArea.h" #include "WimaServiceAreaData.h" +#include "WimaMeasurementArea.h" #include "WimaMeasurementAreaData.h" +#include "WimaCorridor.h" #include "WimaCorridorData.h" +#include "WimaJoinedArea.h" +#include "WimaJoinedAreaData.h" +#include "WimaPlanData.h" +#include "WimaDataContainer.h" #include "PlanMasterController.h" #include "MissionController.h" @@ -129,7 +131,7 @@ private: QString _currentFile; // file for saveing WimaDataContainer *_container; // container for data exchange with WimaController QmlObjectListModel _visualItems; // contains all visible areas - WimaArea _joinedArea; // joined area fromed by _measurementArea, _serviceArea, _corridor + WimaJoinedArea _joinedArea; // joined area fromed by _measurementArea, _serviceArea, _corridor WimaMeasurementArea _measurementArea; // measurement area WimaServiceArea _serviceArea; // area for supplying WimaCorridor _corridor; // corridor connecting _measurementArea and _serviceArea diff --git a/src/Wima/WimaServiceAreaData.cc b/src/Wima/WimaServiceAreaData.cc index a07056be3..1e6f66f97 100644 --- a/src/Wima/WimaServiceAreaData.cc +++ b/src/Wima/WimaServiceAreaData.cc @@ -59,6 +59,10 @@ 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, @@ -89,6 +93,7 @@ void WimaServiceAreaData::setLandPosition(const QGeoCoordinate &newCoordinate) } } + /*! * \class WimaAreaData::WimaServiceAreaData * \brief Class to store and exchange data of a \c WimaServiceArea Object. diff --git a/src/Wima/WimaServiceAreaData.h b/src/Wima/WimaServiceAreaData.h index ece5574cc..c6e91a7b2 100644 --- a/src/Wima/WimaServiceAreaData.h +++ b/src/Wima/WimaServiceAreaData.h @@ -22,6 +22,8 @@ public: const QGeoCoordinate &takeOffPosition() const; const QGeoCoordinate &landPosition() const; + QString type() const; + static const char* typeString; signals: -- 2.22.0