Commit c82f5a2a authored by Valentin Platzgummer's avatar Valentin Platzgummer

adding json saving thing

parent 730535d4
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
typedef struct _MissionFlightStatus_t { typedef struct _MissionFlightStatus_t {
double maxTelemetryDistance; double maxTelemetryDistance;
void dirtyChanged(); void dirtyChanged();
double totalDistance; double totalDistance;
double totalTime; double totalTime;
double hoverDistance; double hoverDistance;
......
This diff is collapsed.
...@@ -42,44 +42,51 @@ public: ...@@ -42,44 +42,51 @@ public:
template <class T> template <class T>
QList<T*>* splitArea (int numberOfFractions); // use QScopedPointer to store return value*/ QList<T*>* splitArea (int numberOfFractions); // use QScopedPointer to store return value*/
//iterates over all vertices in _polygon and returns the index of that one closest to coordinate //iterates over all vertices in _polygon and returns the index of that one closest to coordinate
int getClosestVertexIndex (QGeoCoordinate coordinate); int getClosestVertexIndex (const QGeoCoordinate& coordinate) const;
//iterates over all vertices in _polygon and returns that one closest to coordinate //iterates over all vertices in _polygon and returns that one closest to coordinate
QGeoCoordinate getClosestVertex (QGeoCoordinate coordinate); QGeoCoordinate getClosestVertex (const QGeoCoordinate& coordinate) const;
QGCMapPolygon* toQGCPolygon (WimaArea* poly); QGCMapPolygon& toQGCPolygon (const WimaArea& poly) const;
static void join (QList<WimaArea*>* polyList, WimaArea* joinedPoly); static void join (QList<WimaArea*>* polyList, WimaArea* joinedPoly);// change to & notation
/// joins the poly1 and poly2 if possible, joins the polygons to form a simple polygon (no holes) /// joins the poly1 and poly2 if possible, joins the polygons to form a simple polygon (no holes)
/// see https://en.wikipedia.org/wiki/Simple_polygon /// see https://en.wikipedia.org/wiki/Simple_polygon
/// @return the joined polygon of poly1 and poly2 if possible, poly1 else /// @return the joined polygon of poly1 and poly2 if possible, poly1 else
static void join (WimaArea* poly1, WimaArea* poly2, WimaArea* joinedPoly); static void join (const WimaArea& poly1, const WimaArea& poly2, WimaArea& joinedPoly);
void join (WimaArea* poly); void join (const WimaArea& poly);
bool isDisjunct (QList<WimaArea*>* polyList); bool isDisjunct (QList<WimaArea*>* polyList);// change to & notation, if necessary
bool isDisjunct (WimaArea* poly1, WimaArea* poly2); bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary
/// calculates the next polygon vertex index /// calculates the next polygon vertex index
/// @return index + 1 if index < poly->count()-1 && index >= 0, or 0 if index == poly->count()-1, -1 else /// @return index + 1 if index < poly->count()-1 && index >= 0, or 0 if index == poly->count()-1, -1 else
int nextVertexIndex (int index); int nextVertexIndex (int index) const;
/// calculates the previous polygon vertex index /// calculates the previous polygon vertex index
/// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else /// @return index - 1 if index < poly->count() && index > 0, or poly->count()-1 if index == 0, -1 else
int previousVertexIndex (int index); int previousVertexIndex (int index) const;
/// checks if line1 and line2 intersect with each other, takes latitude and longitute into account only (height neglected) /// checks if line1 and line2 intersect with each other, takes latitude and longitute into account only (height neglected)
/// @param line1 line containing two coordinates, height not taken into account /// @param line1 line containing two coordinates, height not taken into account
/// @param line2 line containing two coordinates, height not taken into account /// @param line2 line containing two coordinates, height not taken into account
/// @param intersectionPt Coordinate item to store intersection pt. in. /// @param intersectionPt Coordinate item to store intersection pt. in.
/// @return false on error or no intersection, true else /// @return false on error or no intersection, true else
static bool intersects(QGCMapPolyline* line1, QGCMapPolyline* line2, QGeoCoordinate* intersectionPt); static bool intersects(const QGCMapPolyline& line1, const QGCMapPolyline& line2, QGeoCoordinate& intersectionPt);
/// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected) /// checks if line1 and poly intersect with each other, takes latitude and longitute into account only (height neglected)
/// @param line line containing two coordinates, height not taken into account /// @param line line containing two coordinates, height not taken into account
/// @param intersectionList Empty list to store intersection points in. /// @param intersectionList Empty list to store intersection points in.
/// @param neighbourList Empty list to store the indices of the neighbours (the two Vertices of poly with the smallest distance to the intersection pt.) /// @param neighbourList Empty list to store the indices of the neighbours (the two Vertices of poly with the smallest distance to the intersection pt.)
/// @return false on error or no intersection, true else /// @return false on error or no intersection, true else
static bool intersects(QGCMapPolyline* line, WimaArea* poly, QList<QGeoCoordinate>* intersectionList, QList<QPair<int, int>>* neighbourlist); static bool intersects(const QGCMapPolyline& line, const WimaArea& poly, QList<QGeoCoordinate>& intersectionList, QList<QPair<int, int>>& neighbourlist);
/// calculates the distance between to geo coordinates, returns the distance if the path lies within the polygon and inf. else. /// calculates the distance between to geo coordinates, returns the distance if the path lies within the polygon and inf. else.
/// @return the distance if the path lies within the polygon and inf. else. /// @return the distance if the path lies within the polygon and inf. else.
static double distInsidePoly(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly); static double distInsidePoly(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly);
/// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm /// calculates the shortes path between two geo coordinates inside a polygon using the Dijkstra Algorithm
static void dijkstraPath(QGeoCoordinate *c1, QGeoCoordinate *c2, WimaArea *poly, QList<QGeoCoordinate> *dijkstraPath); static void dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath);
void saveToJson(QJsonObject& jsonObject);
bool loadFromJson(const QJsonObject &jsonObject, QString& errorString);
// static Members
// Accurracy used to compute isDisjunct // Accurracy used to compute isDisjunct
static const double numericalAccuracy; static const double numericalAccuracy;
static const char* maxAltitudeName;
static const char* wimaAreaName;
static const char* areaTypeName;
signals: signals:
void maxAltitudeChanged (void); void maxAltitudeChanged (void);
......
#include "WimaController.h" #include "WimaController.h"
const char* WimaController::wimaFileExtension = "wima";
WimaController::WimaController(QObject *parent) : WimaController::WimaController(QObject *parent) :
QObject (parent) QObject (parent)
,_planView (true) ,_planView (true)
...@@ -135,16 +137,16 @@ bool WimaController::updateMission() ...@@ -135,16 +137,16 @@ bool WimaController::updateMission()
} }
// join service area and op area // join service area and op area
WimaArea* joinedArea = new WimaArea(this); WimaArea joinedArea(this);
if (corridor != nullptr) { if (corridor != nullptr) {
WimaArea::join(corridor, serArea, joinedArea); WimaArea::join(*corridor, *serArea, joinedArea);
joinedArea->join(opArea); joinedArea.join(*opArea);
} else { } else {
WimaArea::join(serArea, opArea, joinedArea); WimaArea::join(serArea, opArea, joinedArea);
} }
_visualItems->append(joinedArea); _visualItems->append(&joinedArea);
// reset visual items // reset visual items
...@@ -177,7 +179,7 @@ bool WimaController::updateMission() ...@@ -177,7 +179,7 @@ bool WimaController::updateMission()
QGeoCoordinate start = serArea->center(); QGeoCoordinate start = serArea->center();
QGeoCoordinate end = survey->visualTransectPoints().first().value<QGeoCoordinate>(); QGeoCoordinate end = survey->visualTransectPoints().first().value<QGeoCoordinate>();
QList<QGeoCoordinate> path; QList<QGeoCoordinate> path;
WimaArea::dijkstraPath(&start, &end, joinedArea, &path); WimaArea::dijkstraPath(start, end, joinedArea, path);
for (int i = 1; i < path.count()-1; i++) { for (int i = 1; i < path.count()-1; i++) {
_missionController->insertSimpleMissionItem(path.value(i), i+1); _missionController->insertSimpleMissionItem(path.value(i), i+1);
index++; index++;
...@@ -187,7 +189,7 @@ bool WimaController::updateMission() ...@@ -187,7 +189,7 @@ bool WimaController::updateMission()
start = survey->visualTransectPoints().last().value<QGeoCoordinate>(); start = survey->visualTransectPoints().last().value<QGeoCoordinate>();
end = serArea->center(); end = serArea->center();
path.clear(); path.clear();
WimaArea::dijkstraPath(&start, &end, joinedArea, &path); WimaArea::dijkstraPath(start, end, joinedArea, path);
for (int i = 1; i < path.count()-1; i++) { for (int i = 1; i < path.count()-1; i++) {
_missionController->insertSimpleMissionItem(path.value(i), index++); _missionController->insertSimpleMissionItem(path.value(i), index++);
} }
...@@ -209,12 +211,39 @@ bool WimaController::updateMission() ...@@ -209,12 +211,39 @@ bool WimaController::updateMission()
return true; return true;
} }
void WimaController::saveMission() void WimaController::saveToCurrent()
{ {
} }
void WimaController::loadMission() void WimaController::saveToFile(const QString& filename)
{
if (filename.isEmpty()) {
return;
}
QString planFilename = filename;
if (!QFileInfo(filename).fileName().contains(".")) {
planFilename += QString(".%1").arg(wimaFileExtension);
}
QFile file(planFilename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qgcApp()->showMessage(tr("Plan save error %1 : %2").arg(filename).arg(file.errorString()));
_currentFile.clear();
emit currentFileChanged();
} else {
QJsonDocument saveDoc = saveToJson();
file.write(saveDoc.toJson());
if(_currentFile != planFilename) {
_currentFile = planFilename;
emit currentFileChanged();
}
}
}
void WimaController::loadFromFile()
{ {
} }
...@@ -259,5 +288,49 @@ void WimaController::setInteractive() ...@@ -259,5 +288,49 @@ void WimaController::setInteractive()
recalcPolygonInteractivity(_currentPolygonIndex); recalcPolygonInteractivity(_currentPolygonIndex);
} }
QJsonDocument WimaController::saveToJson()
{
QJsonArray jsonArray;
for (int i = 0; i < _visualItems->count(); i++) {
QJsonObject json;
WimaArea* area = qobject_cast<WimaArea*>(_visualItems->get(i));
if (area == nullptr) {
qWarning("WimaController::saveToJson(): Internal error, area == nullptr!");
return QJsonDocument();
}
WimaGOperationArea* opArea = qobject_cast<WimaGOperationArea*>(area);
if (opArea != nullptr) {
opArea->saveToJson(json);
jsonArray.append(json);
break;
}
WimaServiceArea* serArea = qobject_cast<WimaServiceArea*>(area);
if (serArea != nullptr) {
serArea->saveToJson(json);
jsonArray.append(json);
break;
}
WimaVCorridor* corridor = qobject_cast<WimaVCorridor*>(area);
if (corridor != nullptr) {
corridor->saveToJson(json);
jsonArray.append(json);
break;
}
// if non of the obove branches was trigger, type must be WimaArea
area->saveToJson(json);
jsonArray.append(json);
}
return QJsonDocument(jsonArray);
}
#pragma once #pragma once
#include <QObject> #include <QObject>
#include "QGCMapPolygon.h" #include "QGCMapPolygon.h"
...@@ -27,13 +27,15 @@ public: ...@@ -27,13 +27,15 @@ public:
Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged) Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged)
Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged) Q_PROPERTY(QmlObjectListModel* visualItems READ visualItems NOTIFY visualItemsChanged)
Q_PROPERTY(int currentPolygonIndex READ currentPolygonIndex WRITE setCurrentPolygonIndex NOTIFY currentPolygonIndexChanged) Q_PROPERTY(int currentPolygonIndex READ currentPolygonIndex WRITE setCurrentPolygonIndex NOTIFY currentPolygonIndexChanged)
Q_PROPERTY(const QString currentFile READ currentFile NOTIFY currentFileChanged)
// Property accessors // Property accessors
PlanMasterController* masterController (void) const { return _masterController;} PlanMasterController* masterController (void) const { return _masterController; }
MissionController* missionController (void) const { return _missionController;} MissionController* missionController (void) const { return _missionController; }
QmlObjectListModel* visualItems (void) { return _visualItems; } QmlObjectListModel* visualItems (void) const { return _visualItems; }
int currentPolygonIndex (void) const { return _currentPolygonIndex; } int currentPolygonIndex (void) const { return _currentPolygonIndex; }
const QString& currentFile (void) const { return _currentFile; }
...@@ -59,19 +61,28 @@ public: ...@@ -59,19 +61,28 @@ public:
/// Recalculates vehicle corridor, flight path, etc. /// Recalculates vehicle corridor, flight path, etc.
Q_INVOKABLE bool updateMission(); Q_INVOKABLE bool updateMission();
Q_INVOKABLE void saveMission(); Q_INVOKABLE void saveToCurrent();
Q_INVOKABLE void loadMission(); Q_INVOKABLE void saveToFile(const QString& filename);
Q_INVOKABLE void loadFromFile();
Q_INVOKABLE void resetAllInteractive(void); Q_INVOKABLE void resetAllInteractive(void);
Q_INVOKABLE void setInteractive(void); Q_INVOKABLE void setInteractive(void);
// static Members
static const char* wimaFileExtension;
// Member Methodes
QJsonDocument saveToJson();
signals: signals:
void masterControllerChanged (void); void masterControllerChanged (void);
void missionControllerChanged (void); void missionControllerChanged (void);
void visualItemsChanged (void); void visualItemsChanged (void);
void currentPolygonIndexChanged (int index); void currentPolygonIndexChanged (int index);
void currentFileChanged ();
private slots: private slots:
void recalcVehicleCorridor(); void recalcVehicleCorridor();
...@@ -86,5 +97,6 @@ private: ...@@ -86,5 +97,6 @@ private:
PlanMasterController* _masterController; PlanMasterController* _masterController;
MissionController* _missionController; MissionController* _missionController;
int _currentPolygonIndex; int _currentPolygonIndex;
QString _currentFile;
}; };
...@@ -6,6 +6,7 @@ const char* WimaGOperationArea::bottomLayerAltitudeName = "BottomLayerAl ...@@ -6,6 +6,7 @@ const char* WimaGOperationArea::bottomLayerAltitudeName = "BottomLayerAl
const char* WimaGOperationArea::numberOfLayersName = "NumberOfLayers"; const char* WimaGOperationArea::numberOfLayersName = "NumberOfLayers";
const char* WimaGOperationArea::layerDistanceName = "LayerDistance"; const char* WimaGOperationArea::layerDistanceName = "LayerDistance";
const char* WimaGOperationArea::borderPolygonOffsetName = "BorderPolygonOffset"; const char* WimaGOperationArea::borderPolygonOffsetName = "BorderPolygonOffset";
const char* WimaGOperationArea::wimaGOperationAreaName = "Operation Area";
WimaGOperationArea::WimaGOperationArea(QObject *parent) WimaGOperationArea::WimaGOperationArea(QObject *parent)
: WimaGOperationArea (nullptr, parent) : WimaGOperationArea (nullptr, parent)
...@@ -20,11 +21,9 @@ WimaGOperationArea::WimaGOperationArea(WimaArea *other, QObject *parent) ...@@ -20,11 +21,9 @@ WimaGOperationArea::WimaGOperationArea(WimaArea *other, QObject *parent)
, _numberOfLayers (settingsGroup, _metaDataMap[numberOfLayersName]) , _numberOfLayers (settingsGroup, _metaDataMap[numberOfLayersName])
, _layerDistance (settingsGroup, _metaDataMap[layerDistanceName]) , _layerDistance (settingsGroup, _metaDataMap[layerDistanceName])
, _borderPolygonOffset (settingsGroup, _metaDataMap[borderPolygonOffsetName]) , _borderPolygonOffset (settingsGroup, _metaDataMap[borderPolygonOffsetName])
, _polyline (new WimaTrackerPolyline(this))
, _borderPolygon (new QGCMapPolygon(this)) , _borderPolygon (new QGCMapPolygon(this))
{ {
this->setObjectName("Operation Area"); this->setObjectName(wimaGOperationAreaName);
_polyline.bindPolygon(this);
connect(this, &WimaGOperationArea::pathChanged, this, &WimaGOperationArea::recalcBorderPolygon); connect(this, &WimaGOperationArea::pathChanged, this, &WimaGOperationArea::recalcBorderPolygon);
connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaGOperationArea::recalcBorderPolygon); connect(&_borderPolygonOffset, &SettingsFact::rawValueChanged, this, &WimaGOperationArea::recalcBorderPolygon);
//qWarning("Here I am!"); //qWarning("Here I am!");
...@@ -62,13 +61,62 @@ void WimaGOperationArea::setVehicleCorridor(WimaVCorridor *corridor) ...@@ -62,13 +61,62 @@ void WimaGOperationArea::setVehicleCorridor(WimaVCorridor *corridor)
} }
} }
void WimaGOperationArea::saveToJson(QJsonObject &json)
{
this->WimaArea::saveToJson(json);
json[bottomLayerAltitudeName] = _bottomLayerAltitude.rawValue().toDouble();
json[numberOfLayersName] = _numberOfLayers.rawValue().toInt();
json[layerDistanceName] = _layerDistance.rawValue().toDouble();
json[borderPolygonOffsetName] = _borderPolygonOffset.rawValue().toDouble();
json[areaTypeName] = wimaGOperationAreaName;
}
bool WimaGOperationArea::loadFromJson(const QJsonObject &json, QString& errorString)
{
if (this->WimaArea::loadFromJson(json, errorString)) {
bool retVal = true;
if ( json.contains(bottomLayerAltitudeName) && json[bottomLayerAltitudeName].isDouble() ) {
_bottomLayerAltitude.setRawValue(json[bottomLayerAltitudeName].toDouble());
} else {
errorString.append("Could not load Bottom Layer Altitude!\n");
retVal = false;
}
if ( json.contains(numberOfLayersName) && json[numberOfLayersName].isDouble() ) {
_numberOfLayers.setRawValue(json[numberOfLayersName].toInt());
} else {
errorString.append("Could not load Number of Layers!\n");
retVal = false;
}
if ( json.contains(layerDistanceName) && json[layerDistanceName].isDouble() ) {
_layerDistance.setRawValue(json[layerDistanceName].toDouble());
} else {
errorString.append("Could not load Layer Distance!\n");
retVal = false;
}
if ( json.contains(borderPolygonOffsetName) && json[borderPolygonOffsetName].isDouble() ) {
_borderPolygonOffset.setRawValue(json[borderPolygonOffsetName].toDouble());
} else {
errorString.append("Could not load Border Polygon Offset!\n");
retVal = false;
}
return retVal;
} else {
return false;
}
}
void WimaGOperationArea::recalcBorderPolygon() void WimaGOperationArea::recalcBorderPolygon()
{ {
//qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble()); //qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble());
QGCMapPolygon* polyCopy = this->toQGCPolygon(this); QGCMapPolygon polyCopy = this->toQGCPolygon(this);
polyCopy->offset(_borderPolygonOffset.rawValue().toDouble()); polyCopy.offset(_borderPolygonOffset.rawValue().toDouble());
_borderPolygon.setPath(polyCopy->path()); _borderPolygon.setPath(polyCopy.path());
polyCopy->deleteLater(); polyCopy.deleteLater();
emit borderPolygonChanged(); emit borderPolygonChanged();
} }
......
...@@ -21,8 +21,7 @@ public: ...@@ -21,8 +21,7 @@ public:
Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffset CONSTANT) Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffset CONSTANT)
/*Q_PROPERTY(QmlObjectListModel* vehicleList READ vehicleList NOTIFY vehicleListChanged) /*Q_PROPERTY(QmlObjectListModel* vehicleList READ vehicleList NOTIFY vehicleListChanged)
Q_PROPERTY(QmlObjectListModel* vehiclePolygons READ vehiclePolygons NOTIFY vehiclePolygonsChanged)*/ Q_PROPERTY(QmlObjectListModel* vehiclePolygons READ vehiclePolygons NOTIFY vehiclePolygonsChanged)*/
Q_PROPERTY(WimaTrackerPolyline* polyline READ polyline CONSTANT) Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged)
Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged)
Q_INVOKABLE void addVehicle (WimaVehicle *vehicle); Q_INVOKABLE void addVehicle (WimaVehicle *vehicle);
...@@ -46,16 +45,20 @@ public: ...@@ -46,16 +45,20 @@ public:
Fact* borderPolygonOffset (void) { return &_borderPolygonOffset;} Fact* borderPolygonOffset (void) { return &_borderPolygonOffset;}
/*QmlObjectListModel* vehicleList (void) const { return _vehicleList;} /*QmlObjectListModel* vehicleList (void) const { return _vehicleList;}
QmlObjectListModel* vehiclePolygons (void) const { return _vehiclePolygons;}*/ QmlObjectListModel* vehiclePolygons (void) const { return _vehiclePolygons;}*/
WimaTrackerPolyline* polyline (void) { return &_polyline;}
WimaVCorridor* vehicleCorridor (void) { return _vehicleCorridor;} WimaVCorridor* vehicleCorridor (void) { return _vehicleCorridor;}
QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;} QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;}
// Member Methodes
void saveToJson(QJsonObject& json);
bool loadFromJson(const QJsonObject& json, QString &errorString);
static const char* settingsGroup; static const char* settingsGroup;
static const char* bottomLayerAltitudeName; static const char* bottomLayerAltitudeName;
static const char* numberOfLayersName; static const char* numberOfLayersName;
static const char* layerDistanceName; static const char* layerDistanceName;
static const char* borderPolygonOffsetName; static const char* borderPolygonOffsetName;
static const char* wimaGOperationAreaName;
signals: signals:
...@@ -83,7 +86,6 @@ private: ...@@ -83,7 +86,6 @@ private:
/*QmlObjectListModel* _vehicleList; /*QmlObjectListModel* _vehicleList;
QmlObjectListModel* _vehiclePolygons;*/ QmlObjectListModel* _vehiclePolygons;*/
WimaTrackerPolyline _polyline;
WimaVCorridor* _vehicleCorridor; WimaVCorridor* _vehicleCorridor;
QGCMapPolygon _borderPolygon; QGCMapPolygon _borderPolygon;
......
#include "WimaServiceArea.h" #include "WimaServiceArea.h"
const char* WimaServiceArea::wimaServiceAreaName = "Service Area";
WimaServiceArea::WimaServiceArea(QObject *parent): WimaServiceArea::WimaServiceArea(QObject *parent):
WimaServiceArea (nullptr, parent) WimaServiceArea (nullptr, parent)
{ {
...@@ -9,38 +11,52 @@ WimaServiceArea::WimaServiceArea(QObject *parent): ...@@ -9,38 +11,52 @@ WimaServiceArea::WimaServiceArea(QObject *parent):
WimaServiceArea::WimaServiceArea(WimaArea *other, QObject *parent): WimaServiceArea::WimaServiceArea(WimaArea *other, QObject *parent):
WimaArea (other, parent) WimaArea (other, parent)
{ {
_polyline.bindPolygon(this); this->setObjectName(wimaServiceAreaName);
this->setObjectName("Service Area");
} }
void WimaServiceArea::setTakeOffPosition(QGeoCoordinate* coordinate) void WimaServiceArea::setTakeOffPosition(const QGeoCoordinate &coordinate)
{ {
if(_takeOffPosition != *coordinate){ if(_takeOffPosition != coordinate){
_takeOffPosition = *coordinate; _takeOffPosition = coordinate;
emit takeOffPositionChanged(); emit takeOffPositionChanged();
} }
} }
void WimaServiceArea::setLandPosition(QGeoCoordinate* coordinate) void WimaServiceArea::setLandPosition(const QGeoCoordinate &coordinate)
{ {
if(_landPosition != *coordinate){ if(_landPosition != coordinate){
_landPosition = *coordinate; _landPosition = coordinate;
emit landPositionChanged(); emit landPositionChanged();
} }
} }
void WimaServiceArea::setVehicleCorridor(WimaVCorridor *corridor) void WimaServiceArea::setVehicleCorridor(WimaVCorridor &corridor)
{
if (&corridor != _vehicleCorridor){
_vehicleCorridor = &corridor;
emit vehicleCorridorChanged(*_vehicleCorridor);
}
else {
qWarning("WimaServiceArea::setVehicleCorridor(): new corridor equals old _vehicleCorridor!");
}
}
void WimaServiceArea::saveToJson(QJsonObject &json)
{
this->WimaArea::saveToJson(json);
json[areaTypeName] = wimaServiceAreaName;
}
bool WimaServiceArea::loadFromJson(const QJsonObject &json, QString &errorString)
{ {
if(corridor != nullptr){ if ( this->WimaArea::loadFromJson(json, errorString)) {
if (corridor != _vehicleCorridor){ bool retVal = true;
_vehicleCorridor = corridor; // code for loading here
emit vehicleCorridorChanged(_vehicleCorridor); return retVal;
} } else {
else { qWarning() << errorString;
qWarning("WimaServiceArea::setVehicleCorridor(): new corridor equals old _vehicleCorridor!"); return false;
}
}else{
qWarning("WimaServiceArea::setVehicleCorridor(): corridor == nullptr!");
} }
} }
...@@ -11,9 +11,8 @@ public: ...@@ -11,9 +11,8 @@ public:
WimaServiceArea(QObject* parent = nullptr); WimaServiceArea(QObject* parent = nullptr);
WimaServiceArea(WimaArea* other = nullptr, QObject* parent = nullptr); WimaServiceArea(WimaArea* other = nullptr, QObject* parent = nullptr);
Q_PROPERTY(QGeoCoordinate* takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged) Q_PROPERTY(const QGeoCoordinate& takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged)
Q_PROPERTY(QGeoCoordinate* landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged) Q_PROPERTY(const QGeoCoordinate& landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged)
Q_PROPERTY(WimaTrackerPolyline* polyline READ polyline CONSTANT)
// Overrides from WimaPolygon // Overrides from WimaPolygon
...@@ -21,23 +20,28 @@ public: ...@@ -21,23 +20,28 @@ public:
QString editorQML (void) const { return "WimaServiceAreaEditor.qml";} QString editorQML (void) const { return "WimaServiceAreaEditor.qml";}
// Property acessors // Property acessors
QGeoCoordinate* takeOffPosition (void) { return &_takeOffPosition;} const QGeoCoordinate& takeOffPosition (void) const { return _takeOffPosition;}
QGeoCoordinate* landPosition (void) { return &_landPosition;} const QGeoCoordinate& landPosition (void) const { return _landPosition;}
WimaTrackerPolyline* polyline (void) { return &_polyline;} WimaVCorridor& vehicleCorridor (void) const { return *_vehicleCorridor;}
WimaVCorridor* vehicleCorridor (void) { return _vehicleCorridor;}
// Property setters // Property setters
void setTakeOffPosition (QGeoCoordinate* coordinate); void setTakeOffPosition (const QGeoCoordinate& coordinate);
void setLandPosition (QGeoCoordinate* coordinate); void setLandPosition (const QGeoCoordinate& coordinate);
void setVehicleCorridor (WimaVCorridor* corridor); void setVehicleCorridor (WimaVCorridor& corridor);
// Member Methodes
void saveToJson(QJsonObject& json);
bool loadFromJson(const QJsonObject& json, QString& errorString);
// static Members
static const char* wimaServiceAreaName;
signals: signals:
void takeOffPositionChanged (void); void takeOffPositionChanged (void);
void landPositionChanged (void); void landPositionChanged (void);
void vehicleCorridorChanged (WimaVCorridor* corridor); void vehicleCorridorChanged (WimaVCorridor& corridor);
private: private:
WimaTrackerPolyline _polyline;
QGeoCoordinate _takeOffPosition; QGeoCoordinate _takeOffPosition;
QGeoCoordinate _landPosition; QGeoCoordinate _landPosition;
WimaVCorridor* _vehicleCorridor; WimaVCorridor* _vehicleCorridor;
......
#include "WimaVCorridor.h" #include "WimaVCorridor.h"
const char* WimaVCorridor::wimaVCorridorName = "Corridor";
WimaVCorridor::WimaVCorridor(QObject *parent): WimaVCorridor::WimaVCorridor(QObject *parent):
WimaVCorridor(nullptr, parent) WimaVCorridor(nullptr, parent)
{ {
...@@ -11,35 +13,43 @@ WimaVCorridor::WimaVCorridor(WimaArea *other, QObject *parent): ...@@ -11,35 +13,43 @@ WimaVCorridor::WimaVCorridor(WimaArea *other, QObject *parent):
,_serviceArea (nullptr) ,_serviceArea (nullptr)
,_opArea (nullptr) ,_opArea (nullptr)
{ {
this->setObjectName("Corridor"); this->setObjectName(wimaVCorridorName);
} }
void WimaVCorridor::setServiceArea(WimaServiceArea *serviceArea) void WimaVCorridor::setServiceArea(WimaServiceArea &serviceArea)
{ {
if (serviceArea != nullptr){ if(&serviceArea != _serviceArea){
if(serviceArea != _serviceArea){ _serviceArea = &serviceArea;
_serviceArea = serviceArea; emit serviceAreaChanged(_serviceArea);
emit serviceAreaChanged(_serviceArea); }else {
}else { qWarning("WimaVCorridor::setServiceArea(): new serviceArea does not differ from old _serviceArea!");
qWarning("WimaVCorridor::setServiceArea(): new serviceArea does not differ from old _serviceArea!"); }
} }
void WimaVCorridor::setOpArea(WimaGOperationArea &opArea)
{
if(&opArea != _opArea){
_opArea = &opArea;
emit opAreaChanged(_opArea);
}else { }else {
qWarning("WimaVCorridor::setServiceArea(): serviceArea == nullptr!"); qWarning("WimaVCorridor::setOpArea(): new opArea does not differ from old _opArea!");
} }
} }
void WimaVCorridor::setOpArea(WimaGOperationArea *opArea) void WimaVCorridor::saveToJson(QJsonObject &json)
{ {
if (opArea != nullptr){ this->WimaArea::saveToJson(json);
if(&opArea != &_opArea){ json[areaTypeName] = wimaVCorridorName;
_opArea = opArea; }
emit opAreaChanged(_opArea);
}else {
qWarning("WimaVCorridor::setOpArea(): new opArea does not differ from old _opArea!");
}
}else { bool WimaVCorridor::loadFromJson(const QJsonObject &json, QString &errorString)
qWarning("WimaVCorridor::setOpArea(): opArea == nullptr!"); {
if ( this->WimaArea::loadFromJson(json, errorString)) {
bool retVal = true;
// code for loading here
return retVal;
} else {
qWarning() << errorString;
return false;
} }
} }
...@@ -17,10 +17,15 @@ public: ...@@ -17,10 +17,15 @@ public:
QString editorQML (void) const { return "WimaVCorridorEditor.qml";} QString editorQML (void) const { return "WimaVCorridorEditor.qml";}
// Methodes // Methodes
void setServiceArea (WimaServiceArea* serviceArea); void setServiceArea (WimaServiceArea& serviceArea);
void setOpArea (WimaGOperationArea* opArea); void setOpArea (WimaGOperationArea& opArea);
WimaServiceArea* serviceArea (void) const {return _serviceArea;} WimaServiceArea& serviceArea (void) const {return *_serviceArea;}
WimaGOperationArea* opArea (void) const {return _opArea;} WimaGOperationArea& opArea (void) const {return *_opArea;}
void saveToJson (QJsonObject& json);
bool loadFromJson (const QJsonObject& json, QString& errorString);
// static Members
static const char* wimaVCorridorName;
signals: signals:
void serviceAreaChanged (WimaServiceArea* serviceArea); void serviceAreaChanged (WimaServiceArea* serviceArea);
......
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