Commit c878bb8a authored by Valentin Platzgummer's avatar Valentin Platzgummer

WimaController renamed to WimaPlaner, WimaController is now responsible for...

WimaController renamed to WimaPlaner, WimaController is now responsible for coordination purposes in flyView
parent 81769297
...@@ -414,7 +414,9 @@ HEADERS += \ ...@@ -414,7 +414,9 @@ HEADERS += \
src/Wima/WimaTrackerPolyline.h \ src/Wima/WimaTrackerPolyline.h \
src/Wima/WimaController.h \ src/Wima/WimaController.h \
src/Wima/WimaVehicle.h \ src/Wima/WimaVehicle.h \
src/Wima/WimaDataContainer.h src/Wima/WimaDataContainer.h \
src/Wima/WimaPlaner.h \
src/Wima/WimaPlaner.h
SOURCES += \ SOURCES += \
src/api/QGCCorePlugin.cc \ src/api/QGCCorePlugin.cc \
src/api/QGCOptions.cc \ src/api/QGCOptions.cc \
...@@ -428,7 +430,8 @@ SOURCES += \ ...@@ -428,7 +430,8 @@ SOURCES += \
src/Wima/WimaTrackerPolyline.cc \ src/Wima/WimaTrackerPolyline.cc \
src/Wima/WimaController.cc \ src/Wima/WimaController.cc \
src/Wima/WimaVehicle.cc \ src/Wima/WimaVehicle.cc \
src/Wima/WimaDataContainer.cc src/Wima/WimaDataContainer.cc \
src/Wima/WimaPlaner.cc
# #
# Unit Test specific configuration goes here (requires full debug build with all plugins) # Unit Test specific configuration goes here (requires full debug build with all plugins)
......
...@@ -234,6 +234,8 @@ QList<QGeoCoordinate> QGCMapPolygon::coordinateList(void) const ...@@ -234,6 +234,8 @@ QList<QGeoCoordinate> QGCMapPolygon::coordinateList(void) const
void QGCMapPolygon::splitPolygonSegment(int vertexIndex) void QGCMapPolygon::splitPolygonSegment(int vertexIndex)
{ {
int nextIndex = vertexIndex + 1; int nextIndex = vertexIndex + 1;
if (nextIndex > _polygonPath.length() - 1) { if (nextIndex > _polygonPath.length() - 1) {
nextIndex = 0; nextIndex = 0;
} }
...@@ -367,6 +369,11 @@ void QGCMapPolygon::setInteractive(bool interactive) ...@@ -367,6 +369,11 @@ void QGCMapPolygon::setInteractive(bool interactive)
} }
} }
void QGCMapPolygon::update(const QGCMapPolygon &poly)
{
this->setPath(poly.path());
}
void print(const QGCMapPolygon &poly) void print(const QGCMapPolygon &poly)
{ {
QString message; QString message;
...@@ -391,19 +398,6 @@ void print(const QGCMapPolygon &poly, QString &outputString) ...@@ -391,19 +398,6 @@ void print(const QGCMapPolygon &poly, QString &outputString)
outputString.append(QString("Interactive: %s\n").arg(QVariant(poly._interactive).toString())); outputString.append(QString("Interactive: %s\n").arg(QVariant(poly._interactive).toString()));
} }
void swap(QGCMapPolygon &poly1, QGCMapPolygon &poly2)
{
using std::swap;
poly1._polygonPath.swap(poly2._polygonPath);
swap(poly1._polygonModel, poly2._polygonModel);
swap(poly1._dirty, poly2._dirty);
swap(poly1._center, poly2._center);
swap(poly1._centerDrag, poly2._centerDrag);
swap(poly1._ignoreCenterUpdates, poly2._ignoreCenterUpdates);
swap(poly1._interactive, poly2._interactive);
}
QGeoCoordinate QGCMapPolygon::vertexCoordinate(int vertex) const QGeoCoordinate QGCMapPolygon::vertexCoordinate(int vertex) const
{ {
if (vertex >= 0 && vertex < _polygonPath.count()) { if (vertex >= 0 && vertex < _polygonPath.count()) {
......
/**************************************************************************** /****************************************************************************
* *
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> * (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
* *
...@@ -99,14 +99,10 @@ public: ...@@ -99,14 +99,10 @@ public:
QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; } QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; }
QmlObjectListModel& pathModel (void) { return _polygonModel; } QmlObjectListModel& pathModel (void) { return _polygonModel; }
void setPath (const QList<QGeoCoordinate>& path); /// Updates this with data from poly
void setPath (const QVariantList& path); void update(const QGCMapPolygon &poly);
void setCenter (QGeoCoordinate newCenter);
void setCenterDrag (bool centerDrag);
void setInteractive (bool interactive);
// Friends // Friends
friend void swap(QGCMapPolygon& poly1, QGCMapPolygon& poly2);
friend void print(const QGCMapPolygon& poly, QString& outputString); friend void print(const QGCMapPolygon& poly, QString& outputString);
friend void print(const QGCMapPolygon& poly); friend void print(const QGCMapPolygon& poly);
...@@ -122,10 +118,17 @@ signals: ...@@ -122,10 +118,17 @@ signals:
void centerDragChanged (bool centerDrag); void centerDragChanged (bool centerDrag);
void interactiveChanged (bool interactive); void interactiveChanged (bool interactive);
public slots:
void setPath (const QList<QGeoCoordinate>& path);
void setPath (const QVariantList& path);
void setCenter (QGeoCoordinate newCenter);
void setCenterDrag (bool centerDrag);
void setInteractive (bool interactive);
private slots: private slots:
void _polygonModelCountChanged(int count); void _polygonModelCountChanged (int count);
void _polygonModelDirtyChanged(bool dirty); void _polygonModelDirtyChanged (bool dirty);
void _updateCenter(void); void _updateCenter (void);
private: private:
void _init(void); void _init(void);
......
...@@ -26,42 +26,14 @@ WimaArea::WimaArea(const WimaArea &other, QObject *parent) ...@@ -26,42 +26,14 @@ WimaArea::WimaArea(const WimaArea &other, QObject *parent)
_maxAltitude = other.maxAltitude(); _maxAltitude = other.maxAltitude();
} }
WimaArea &WimaArea::operator=(WimaArea other)
{
swap(*this, other); // copy-swap-idiom
return *this;
}
void WimaArea::setMaxAltitude(double alt) void WimaArea::setMaxAltitude(double alt)
{ {
if(alt > 0 && alt != _maxAltitude){ if ( alt > 0 && qFuzzyCompare(alt, _maxAltitude) ) {
_maxAltitude = alt; _maxAltitude = alt;
emit maxAltitudeChanged(); emit maxAltitudeChanged();
} }
} }
/*QList<WimaArea *>* WimaArea::splitArea<T>(WimaArea *polygonToSplitt, int numberOfFractions)
{
if(numberOfFractions > 0 && polygonToSplitt != nullptr){
WimaArea* poly;
if(p)
= new WimaArea(polygonToSplitt, this);
QList<WimaArea*>* list = new QList<WimaArea*>();
list->append(poly);
return list;
}
return nullptr;
}
QList<QGCMapPolygon*>* WimaArea::splitArea(int numberOfFractions)
{
return splitPolygonArea(this, numberOfFractions);
}*/
int WimaArea::getClosestVertexIndex(const QGeoCoordinate &coordinate) const int WimaArea::getClosestVertexIndex(const QGeoCoordinate &coordinate) const
{ {
if (this->count() == 0) { if (this->count() == 0) {
...@@ -327,32 +299,39 @@ bool WimaArea::intersects(const QGCMapPolyline &line1, const QGCMapPolyline &lin ...@@ -327,32 +299,39 @@ bool WimaArea::intersects(const QGCMapPolyline &line1, const QGCMapPolyline &lin
} }
} }
bool WimaArea::intersects(const QGCMapPolyline& line, const WimaArea& poly, QList<QGeoCoordinate>& intersectionList, QList<QPair<int, int> >& neighbourlist) bool WimaArea::intersects(const QGCMapPolyline &line,
const WimaArea &poly,
QList<QGeoCoordinate> &intersectionList,
QList<QPair<int, int> > &neighbourList)
{ {
neighbourlist.clear(); // ================ Brief Explanation ================
// This function checks whether line intersects with the border line of poly
// Returns true if at least one intersection occurs, false else.
// Stores the intersection points inside intersectionList.
// Stores the indices of the cloest two polygon vetices for each of coorespoinding intersection points in neighbourList
intersectionList.clear(); intersectionList.clear();
neighbourList.clear();
if (line.count() == 2 && poly.count() >= 3) { if (line.count() == 2 && poly.count() >= 3) { // are line a proper line and poly a proper poly?
// Asseble a line form each tow consecutive polygon vertices and check whether it intersects with line
for (int i = 0; i < poly.count(); i++) { for (int i = 0; i < poly.count(); i++) {
QGCMapPolyline polySegment;
QGCMapPolyline interatorLine;
QGeoCoordinate currentVertex = poly.vertexCoordinate(i); QGeoCoordinate currentVertex = poly.vertexCoordinate(i);
QGeoCoordinate nextVertex = poly.vertexCoordinate(poly.nextVertexIndex(i)); QGeoCoordinate nextVertex = poly.vertexCoordinate(poly.nextVertexIndex(i));
polySegment.appendVertex(currentVertex); interatorLine.appendVertex(currentVertex);
polySegment.appendVertex(nextVertex); interatorLine.appendVertex(nextVertex);
QGeoCoordinate intersectionPoint; QGeoCoordinate intersectionPoint;
//bool retVal2 = intersects(line, line, &intersectionPoint); if ( intersects(line, interatorLine, intersectionPoint) ){
bool retVal = intersects(line, polySegment, intersectionPoint);
if (retVal != false){
intersectionList.append(intersectionPoint); intersectionList.append(intersectionPoint);
QPair<int, int> neighbours; QPair<int, int> neighbours;
neighbours.first = i; neighbours.first = i;
neighbours.second = poly.nextVertexIndex(i); neighbours.second = poly.nextVertexIndex(i);
neighbourlist.append(neighbours); neighbourList.append(neighbours);
} }
} }
...@@ -390,42 +369,54 @@ double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate & ...@@ -390,42 +369,54 @@ double WimaArea::distInsidePoly(const QGeoCoordinate &c1, const QGeoCoordinate &
} }
} }
bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &end, const WimaArea &poly, QList<QGeoCoordinate> &dijkstraPath) bool WimaArea::dijkstraPath(const QGeoCoordinate &start,
const QGeoCoordinate &end,
const WimaArea &poly,
QList<QGeoCoordinate> &dijkstraPath)
{ {
// ================ Brief Explanation ================
// This function calculates the shortes Path between two GeoCoordinates (start, end) using the Dijkstra Algorithm.
// The path will be inside the polygon poly if possible.
// Stores the result inside dijkstraPath
// Returns true if a valid path was found.
if ( isSelfIntersecting(poly) ) { if ( isSelfIntersecting(poly) ) {
return false; return false;
} }
// Each QGeoCoordinate gets stuff into a Node
/// @param distance is the distance between the Node and it's predecessor
struct Node{ struct Node{
QGeoCoordinate coordinate; QGeoCoordinate coordinate;
double distance = std::numeric_limits<qreal>::infinity(); double distance = std::numeric_limits<qreal>::infinity();
Node* predecessorNode = nullptr; Node* predecessorNode = nullptr;
}; };
// The list with all Nodes (start, end + poly.path())
QList<Node> nodeList; QList<Node> nodeList;
// This list will be initalized with (pointer to) all elements of nodeList.
// Elements will be successively remove during the execution of the Dijkstra Algorithm.
QList<Node*> workingSet; QList<Node*> workingSet;
// initialize nodeList
// initialize // start cooridnate
// start
Node startNode; Node startNode;
startNode.coordinate = start; startNode.coordinate = start;
startNode.distance = 0; startNode.distance = 0;
nodeList.append(startNode); nodeList.append(startNode);
//poly //poly cooridnates
for (int i = 0; i < poly.count(); i++) { for (int i = 0; i < poly.count(); i++) {
Node node; Node node;
node.coordinate = poly.vertexCoordinate(i); node.coordinate = poly.vertexCoordinate(i);
nodeList.append(node); nodeList.append(node);
} }
//end //end coordinate
Node endNode; Node endNode;
endNode.coordinate = end; endNode.coordinate = end;
nodeList.append(endNode); nodeList.append(endNode);
// working set // initialize working set
for (int i = 0; i < nodeList.size(); i++) { for (int i = 0; i < nodeList.size(); i++) {
Node* nodePtr = &nodeList[i]; Node* nodePtr = &nodeList[i];
workingSet.append(nodePtr); workingSet.append(nodePtr);
...@@ -453,8 +444,9 @@ bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e ...@@ -453,8 +444,9 @@ bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e
for (int i = 0; i < workingSet.size(); i++) { for (int i = 0; i < workingSet.size(); i++) {
Node* v = workingSet[i]; Node* v = workingSet[i];
// is neighbour? // is neighbour? dist == infinity if no neihbour
double dist = distInsidePoly(u->coordinate, v->coordinate, poly); double dist = distInsidePoly(u->coordinate, v->coordinate, poly);
// is ther a alternative path which is shorter?
double alternative = u->distance + dist; double alternative = u->distance + dist;
if (alternative < v->distance) { if (alternative < v->distance) {
v->distance = alternative; v->distance = alternative;
...@@ -463,14 +455,17 @@ bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e ...@@ -463,14 +455,17 @@ bool WimaArea::dijkstraPath(const QGeoCoordinate &start, const QGeoCoordinate &e
} }
} }
// end Djikstra Algorithm
// create path // check it the Algorithm was sucessful
Node* Node = &nodeList.last(); Node* Node = &nodeList.last();
if (Node->predecessorNode == nullptr) { if (Node->predecessorNode == nullptr) {
qWarning("WimaArea::dijkstraPath(): Error, no path found!"); qWarning("WimaArea::dijkstraPath(): Error, no path found!");
return false; return false;
} }
// assemble path
while (1) { while (1) {
dijkstraPath.prepend(Node->coordinate); dijkstraPath.prepend(Node->coordinate);
...@@ -540,6 +535,12 @@ bool WimaArea::loadFromJson(const QJsonObject &json, QString& errorString) ...@@ -540,6 +535,12 @@ bool WimaArea::loadFromJson(const QJsonObject &json, QString& errorString)
} }
} }
void WimaArea::update(const WimaArea &area)
{
this->QGCMapPolygon::update(area);
this->setMaxAltitude(area.maxAltitude());
}
void WimaArea::init() void WimaArea::init()
{ {
this->setObjectName(wimaAreaName); this->setObjectName(wimaAreaName);
...@@ -554,16 +555,8 @@ void print(const WimaArea &area) ...@@ -554,16 +555,8 @@ void print(const WimaArea &area)
void print(const WimaArea &area, QString &outputString) void print(const WimaArea &area, QString &outputString)
{ {
outputString.append(QString("Type: %s").arg(area.objectName())); outputString.append(QString("Type: %1").arg(area.objectName()));
print(static_cast<const QGCMapPolygon&>(area), outputString); print(static_cast<const QGCMapPolygon&>(area), outputString);
outputString.append(QString("Maximum Altitude: %.3f").arg(area._maxAltitude)); outputString.append(QString("Maximum Altitude: %1").arg(area._maxAltitude));
}
void swap(WimaArea &area1, WimaArea &area2)
{
using std::swap;
swap(static_cast<QGCMapPolygon&>(area1), static_cast<QGCMapPolygon&>(area2));
swap(area1._maxAltitude, area2._maxAltitude);
} }
...@@ -17,7 +17,6 @@ class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas ...@@ -17,7 +17,6 @@ class WimaArea : public QGCMapPolygon //abstract base class for all WimaAreas
public: public:
WimaArea(QObject* parent = nullptr); WimaArea(QObject* parent = nullptr);
WimaArea(const WimaArea& other, QObject* parent = nullptr); WimaArea(const WimaArea& other, QObject* parent = nullptr);
WimaArea& operator=(WimaArea other);
Q_PROPERTY(double maxAltitude READ maxAltitude WRITE setMaxAltitude NOTIFY maxAltitudeChanged) Q_PROPERTY(double maxAltitude READ maxAltitude WRITE setMaxAltitude NOTIFY maxAltitudeChanged)
...@@ -27,25 +26,17 @@ public: ...@@ -27,25 +26,17 @@ public:
//Property accessors //Property accessors
double maxAltitude (void) const { return _maxAltitude;} double maxAltitude (void) const { return _maxAltitude;}
// overrides from WimaArea
virtual QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";} virtual QString mapVisualQML (void) const { return "WimaAreaMapVisual.qml";}
virtual QString editorQML (void) const { return "WimaAreaEditor.qml";} virtual QString editorQML (void) const { return "WimaAreaEditor.qml";}
//Property setters
void setMaxAltitude (double alt);
void setVehicle (WimaVehicle* vehicle);
// Member Methodes // Member Methodes
//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 (const QGeoCoordinate& coordinate) const; 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 (const QGeoCoordinate& coordinate) const; QGeoCoordinate getClosestVertex (const QGeoCoordinate& coordinate) const;
static QGCMapPolygon toQGCPolygon (const WimaArea& poly);
QGCMapPolygon toQGCPolygon () const; QGCMapPolygon toQGCPolygon () const;
static void join (QList<WimaArea*>* polyList, WimaArea* joinedPoly);// change to & notation 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)
/// see https://en.wikipedia.org/wiki/Simple_polygon
/// @return true if polygons have been joined, false else
static bool join (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly);
bool join (WimaArea &poly); bool join (WimaArea &poly);
bool isDisjunct (QList<WimaArea*>* polyList);// change to & notation, if necessary bool isDisjunct (QList<WimaArea*>* polyList);// change to & notation, if necessary
bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary bool isDisjunct (WimaArea* poly1, WimaArea* poly2);// change to & notation, if necessary
...@@ -55,34 +46,44 @@ public: ...@@ -55,34 +46,44 @@ public:
/// 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) const; int previousVertexIndex (int index) const;
void saveToJson (QJsonObject& jsonObject);
bool loadFromJson (const QJsonObject &jsonObject, QString& errorString);
// static Methodes
static QGCMapPolygon toQGCPolygon (const WimaArea& poly);
/// 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
/// @return true if polygons have been joined, false else
static bool join (WimaArea &poly1, WimaArea &poly2, WimaArea& joinedPoly);
/// 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(const QGCMapPolyline& line1, const 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(const QGCMapPolyline& line, const 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(const QGeoCoordinate& c1, const QGeoCoordinate& c2, WimaArea poly); static double distInsidePoly (const QGeoCoordinate& c1, const QGeoCoordinate& c2, 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
/// @return true if path was found, false else /// @return true if path was found, false else
static bool dijkstraPath(const QGeoCoordinate& c1, const QGeoCoordinate& c2, const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath); static bool dijkstraPath (const QGeoCoordinate& c1, const QGeoCoordinate& c2,
const WimaArea& poly, QList<QGeoCoordinate>& dijkstraPath);
/// @return true if the polygon is self intersecting /// @return true if the polygon is self intersecting
static bool isSelfIntersecting(const WimaArea& poly); static bool isSelfIntersecting (const WimaArea& poly);
bool isSelfIntersecting(); bool isSelfIntersecting ();
void saveToJson(QJsonObject& jsonObject);
bool loadFromJson(const QJsonObject &jsonObject, QString& errorString);
// Friends // Friends
friend void swap(WimaArea& area1, WimaArea& area2);
/// prints the member values of area to the outputString /// prints the member values of area to the outputString
friend void print(const WimaArea& area, QString& outputString); friend void print(const WimaArea& area, QString& outputString);
/// prints the member values of area to the console /// prints the member values of area to the console
...@@ -99,8 +100,12 @@ signals: ...@@ -99,8 +100,12 @@ signals:
void maxAltitudeChanged (void); void maxAltitudeChanged (void);
void vehicleChanged (void); void vehicleChanged (void);
public slots:
void setMaxAltitude (double alt);
/// Updates this with data from area
void update(const WimaArea& area);
protected: private:
double _maxAltitude; double _maxAltitude;
private: private:
......
...@@ -6,7 +6,6 @@ const char* WimaController::missionItemsName = "MissionItems"; ...@@ -6,7 +6,6 @@ const char* WimaController::missionItemsName = "MissionItems";
WimaController::WimaController(QObject *parent) WimaController::WimaController(QObject *parent)
: QObject (parent) : QObject (parent)
, _flyView (true)
, _readyForSaveSend (false) , _readyForSaveSend (false)
, _currentPolygonIndex (-1) , _currentPolygonIndex (-1)
, _container (nullptr) , _container (nullptr)
...@@ -18,7 +17,7 @@ WimaController::WimaController(QObject *parent) ...@@ -18,7 +17,7 @@ WimaController::WimaController(QObject *parent)
connect(this, &WimaController::currentPolygonIndexChanged, this, &WimaController::recalcPolygonInteractivity); connect(this, &WimaController::currentPolygonIndexChanged, this, &WimaController::recalcPolygonInteractivity);
} }
const QmlObjectListModel* WimaController::visualItems() const QmlObjectListModel* WimaController::visualItems()
{ {
return &_visualItems; return &_visualItems;
} }
...@@ -76,33 +75,18 @@ void WimaController::setDataContainer(WimaDataContainer *container) ...@@ -76,33 +75,18 @@ void WimaController::setDataContainer(WimaDataContainer *container)
if (_container == nullptr && container != nullptr) { if (_container == nullptr && container != nullptr) {
_container = container; _container = container;
if (_flyView) {
downloadFromContainer();
_visualItems.append(&_opArea);
_visualItems.append(&_serArea);
_visualItems.append(&_joinedArea);
connect(_container, &WimaDataContainer::opAreaChanged, this, &WimaController::setOpArea);
connect(_container, &WimaDataContainer::serAreaChanged, this, &WimaController::setSerArea);
connect(_container, &WimaDataContainer::corridorChanged, this, &WimaController::setCorridor);
connect(_container, &WimaDataContainer::joinedAreaChanged, this, &WimaController::setJoinedArea);
}
emit dataContainerChanged(); emit dataContainerChanged();
} }
} }
void WimaController::startWimaController(bool flyView) void WimaController::startWimaController(bool flyView)
{ {
_flyView = flyView;
} }
void WimaController::removeArea(int index) void WimaController::removeArea(int index)
{ {
if(index >= 0 && index < _visualItems.count()){ if(index >= 0 && index < _visualItems.count()){
if (_flyView) { //not editing allowed in flyView
return;
}
WimaArea* area = qobject_cast<WimaArea*>(_visualItems.removeAt(index)); WimaArea* area = qobject_cast<WimaArea*>(_visualItems.removeAt(index));
if ( area == nullptr) { if ( area == nullptr) {
...@@ -133,7 +117,7 @@ void WimaController::removeArea(int index) ...@@ -133,7 +117,7 @@ void WimaController::removeArea(int index)
bool WimaController::addGOperationArea() bool WimaController::addGOperationArea()
{ {
if (!_flyView && !_visualItems.contains(&_opArea)) { if (!_visualItems.contains(&_opArea)) {
_visualItems.append(&_opArea); _visualItems.append(&_opArea);
int newIndex = _visualItems.count()-1; int newIndex = _visualItems.count()-1;
...@@ -148,7 +132,7 @@ bool WimaController::addGOperationArea() ...@@ -148,7 +132,7 @@ bool WimaController::addGOperationArea()
bool WimaController::addServiceArea() bool WimaController::addServiceArea()
{ {
if (!_flyView && !_visualItems.contains(&_serArea)) { if (!_visualItems.contains(&_serArea)) {
_visualItems.append(&_serArea); _visualItems.append(&_serArea);
int newIndex = _visualItems.count()-1; int newIndex = _visualItems.count()-1;
...@@ -163,7 +147,7 @@ bool WimaController::addServiceArea() ...@@ -163,7 +147,7 @@ bool WimaController::addServiceArea()
bool WimaController::addVehicleCorridor() bool WimaController::addVehicleCorridor()
{ {
if (!_flyView && !_visualItems.contains(&_corridor)) { if (!_visualItems.contains(&_corridor)) {
_visualItems.append(&_corridor); _visualItems.append(&_corridor);
int newIndex = _visualItems.count()-1; int newIndex = _visualItems.count()-1;
...@@ -178,10 +162,6 @@ bool WimaController::addVehicleCorridor() ...@@ -178,10 +162,6 @@ bool WimaController::addVehicleCorridor()
void WimaController::removeAll() void WimaController::removeAll()
{ {
if (_flyView) {
return;
}
bool changesApplied = false; bool changesApplied = false;
while (_visualItems.count() > 0) { while (_visualItems.count() > 0) {
removeArea(0); removeArea(0);
...@@ -219,21 +199,19 @@ void WimaController::resumeMission() ...@@ -219,21 +199,19 @@ void WimaController::resumeMission()
bool WimaController::updateMission() bool WimaController::updateMission()
{ {
if (!_flyView) {
setReadyForSaveSend(false); setReadyForSaveSend(false);
#define debug 0 #define debug 0
if ( !updateJoinedArea()) { if ( !recalcJoinedArea()) {
qgcApp()->showMessage(tr("Not able to join areas. Areas must be overlapping")); qgcApp()->showMessage(tr("Not able to join areas. Areas must be overlapping"));
return false; return false;
} }
#if debug #if debug
_visualItems.append(&_joinedArea); _visualItems.append(&_joinedArea);
#endif #endif
// reset visual items // reset visual items
_missionController->removeAll(); _missionController->removeAll();
QmlObjectListModel* missionItems = _missionController->visualItems(); QmlObjectListModel* missionItems = _missionController->visualItems();
...@@ -320,10 +298,6 @@ bool WimaController::updateMission() ...@@ -320,10 +298,6 @@ bool WimaController::updateMission()
updateContainer(); updateContainer();
setReadyForSaveSend(true); setReadyForSaveSend(true);
return true; return true;
} else {
return true;
}
} }
void WimaController::saveToCurrent() void WimaController::saveToCurrent()
...@@ -405,23 +379,26 @@ bool WimaController::loadFromFile(const QString &filename) ...@@ -405,23 +379,26 @@ bool WimaController::loadFromFile(const QString &filename)
} }
QJsonObject json = jsonDoc.object(); QJsonObject json = jsonDoc.object();
// AreaItems // AreaItems
QJsonArray areaArray = json[areaItemsName].toArray(); QJsonArray areaArray = json[areaItemsName].toArray();
_visualItems.clear(); _visualItems.clear();
for( int i = 0; i < areaArray.size(); i++) { int validAreaCounter = 0;
for( int i = 0; i < areaArray.size() && validAreaCounter < 3; i++) {
QJsonObject jsonArea = areaArray[i].toObject(); QJsonObject jsonArea = areaArray[i].toObject();
if (jsonArea.contains(WimaArea::areaTypeName) && jsonArea[WimaArea::areaTypeName].isString()) { if (jsonArea.contains(WimaArea::areaTypeName) && jsonArea[WimaArea::areaTypeName].isString()) {
if ( jsonArea[WimaArea::areaTypeName] == WimaGOperationArea::wimaGOperationAreaName) { if ( jsonArea[WimaArea::areaTypeName] == WimaGOperationArea::wimaGOperationAreaName) {
print(_opArea);
bool success = _opArea.loadFromJson(jsonArea, errorString); bool success = _opArea.loadFromJson(jsonArea, errorString);
print(_opArea);
if ( !success ) { if ( !success ) {
qgcApp()->showMessage(errorMessage.arg(errorString)); qgcApp()->showMessage(errorMessage.arg(errorString));
return false; return false;
} }
validAreaCounter++;
_visualItems.append(&_opArea); _visualItems.append(&_opArea);
emit visualItemsChanged(); emit visualItemsChanged();
} else if ( jsonArea[WimaArea::areaTypeName] == WimaServiceArea::wimaServiceAreaName) { } else if ( jsonArea[WimaArea::areaTypeName] == WimaServiceArea::wimaServiceAreaName) {
...@@ -432,6 +409,7 @@ bool WimaController::loadFromFile(const QString &filename) ...@@ -432,6 +409,7 @@ bool WimaController::loadFromFile(const QString &filename)
return false; return false;
} }
validAreaCounter++;
_visualItems.append(&_serArea); _visualItems.append(&_serArea);
emit visualItemsChanged(); emit visualItemsChanged();
} else if ( jsonArea[WimaArea::areaTypeName] == WimaVCorridor::wimaVCorridorName) { } else if ( jsonArea[WimaArea::areaTypeName] == WimaVCorridor::wimaVCorridorName) {
...@@ -442,6 +420,7 @@ bool WimaController::loadFromFile(const QString &filename) ...@@ -442,6 +420,7 @@ bool WimaController::loadFromFile(const QString &filename)
return false; return false;
} }
validAreaCounter++;
_visualItems.append(&_corridor); _visualItems.append(&_corridor);
emit visualItemsChanged(); emit visualItemsChanged();
} else { } else {
...@@ -458,7 +437,7 @@ bool WimaController::loadFromFile(const QString &filename) ...@@ -458,7 +437,7 @@ bool WimaController::loadFromFile(const QString &filename)
_currentFile.sprintf("%s/%s.%s", fileInfo.path().toLocal8Bit().data(), fileInfo.completeBaseName().toLocal8Bit().data(), wimaFileExtension); _currentFile.sprintf("%s/%s.%s", fileInfo.path().toLocal8Bit().data(), fileInfo.completeBaseName().toLocal8Bit().data(), wimaFileExtension);
emit currentFileChanged(); emit currentFileChanged();
updateJoinedArea(); recalcJoinedArea();
// MissionItems // MissionItems
// extrac MissionItems part // extrac MissionItems part
...@@ -519,13 +498,14 @@ void WimaController::recalcPolygonInteractivity(int index) ...@@ -519,13 +498,14 @@ void WimaController::recalcPolygonInteractivity(int index)
} }
} }
bool WimaController::updateJoinedArea() bool WimaController::recalcJoinedArea()
{ {
// join service area, op area and corridor // join service area, op area and corridor
_joinedArea = _serArea; _joinedArea = _serArea;
_joinedArea.join(_corridor); _joinedArea.join(_corridor);
if ( !_joinedArea.join(_opArea) ) if ( !_joinedArea.join(_opArea) )
return false; return false; // this happens if all areas are pairwise disjoint
else { else {
emit joinedAreaChanged() ; emit joinedAreaChanged() ;
return true; return true;
...@@ -536,56 +516,21 @@ bool WimaController::updateJoinedArea() ...@@ -536,56 +516,21 @@ bool WimaController::updateJoinedArea()
void WimaController::updateContainer() void WimaController::updateContainer()
{ {
// Sets the pointers (inside _container) to the areas (of this).
// Should be called only (once) after a _container has been assigned.
if (_container != nullptr) { if (_container != nullptr) {
_container->setOpArea(_opArea); _container->setOpArea(&_opArea);
_container->setSerArea(_serArea); _container->setSerArea(&_serArea);
_container->setCorridor(_corridor); _container->setCorridor(&_corridor);
_container->setJoinedArea(_joinedArea); _container->setJoinedArea(&_joinedArea);
} else { } else {
qWarning("WimaController::uploadToContainer(): no container assigned."); qWarning("WimaController::uploadToContainer(): no container assigned.");
} }
} }
void WimaController::downloadFromContainer()
{
if (_flyView) {
_opArea = _container->opArea();
_serArea = _container->serArea();
_corridor = _container->corridor();
_joinedArea = _container->joinedArea();
}
}
void WimaController::setOpArea(const WimaGOperationArea &area)
{
if (_flyView) {
_opArea = area;
}
}
void WimaController::setSerArea(const WimaServiceArea &area)
{
if (_flyView) {
_serArea = area;
}
}
void WimaController::setCorridor(const WimaVCorridor &area)
{
if (_flyView) {
_corridor = area;
}
}
void WimaController::setJoinedArea(const WimaArea &area)
{
if (_flyView) {
_joinedArea = area;
}
}
void WimaController::resetAllInteractive() void WimaController::resetAllInteractive()
{ {
// Marks all areas as inactive (area.interactive == false)
int itemCount = _visualItems.count(); int itemCount = _visualItems.count();
if (itemCount > 0){ if (itemCount > 0){
for (int i = 0; i < itemCount; i++) { for (int i = 0; i < itemCount; i++) {
...@@ -602,6 +547,8 @@ void WimaController::setInteractive() ...@@ -602,6 +547,8 @@ void WimaController::setInteractive()
QJsonDocument WimaController::saveToJson(FileType fileType) QJsonDocument WimaController::saveToJson(FileType fileType)
{ {
/// This function save all areas (of WimaController) and all mission items (of MissionController) to a QJsonDocument
/// @param fileType is either WimaFile or PlanFile (enum), if fileType == PlanFile only mission items are stored
QJsonObject json; QJsonObject json;
if ( fileType == FileType::WimaFile ) { if ( fileType == FileType::WimaFile ) {
...@@ -617,6 +564,7 @@ QJsonDocument WimaController::saveToJson(FileType fileType) ...@@ -617,6 +564,7 @@ QJsonDocument WimaController::saveToJson(FileType fileType)
return QJsonDocument(); return QJsonDocument();
} }
// check the type of area, create and append the JsonObject to the JsonArray once determined
WimaGOperationArea* opArea = qobject_cast<WimaGOperationArea*>(area); WimaGOperationArea* opArea = qobject_cast<WimaGOperationArea*>(area);
if (opArea != nullptr) { if (opArea != nullptr) {
opArea->saveToJson(json); opArea->saveToJson(json);
......
...@@ -31,7 +31,7 @@ public: ...@@ -31,7 +31,7 @@ public:
Q_PROPERTY(PlanMasterController* masterController READ masterController WRITE setMasterController NOTIFY masterControllerChanged) Q_PROPERTY(PlanMasterController* masterController READ masterController WRITE setMasterController NOTIFY masterControllerChanged)
Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged) Q_PROPERTY(MissionController* missionController READ missionController WRITE setMissionController NOTIFY missionControllerChanged)
Q_PROPERTY(const 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(QString currentFile READ currentFile NOTIFY currentFileChanged) Q_PROPERTY(QString currentFile READ currentFile NOTIFY currentFileChanged)
Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT) Q_PROPERTY(QStringList loadNameFilters READ loadNameFilters CONSTANT)
...@@ -40,14 +40,14 @@ public: ...@@ -40,14 +40,14 @@ public:
Q_PROPERTY(QGeoCoordinate joinedAreaCenter READ joinedAreaCenter CONSTANT) Q_PROPERTY(QGeoCoordinate joinedAreaCenter READ joinedAreaCenter CONSTANT)
Q_PROPERTY(WimaArea joinedArea READ joinedArea NOTIFY joinedAreaChanged) Q_PROPERTY(WimaArea joinedArea READ joinedArea NOTIFY joinedAreaChanged)
Q_PROPERTY(bool flyView READ flyView CONSTANT) Q_PROPERTY(bool flyView READ flyView CONSTANT)
Q_PROPERTY(WimaDataContainer* dataContainer READ dataContainer WRITE setDataContainer NOTIFY dataContainerChanged) Q_PROPERTY(WimaDataContainer* dataContainer WRITE setDataContainer NOTIFY dataContainerChanged)
Q_PROPERTY(bool readyForSaveSend READ readyForSaveSend NOTIFY readyForSaveSendChanged) Q_PROPERTY(bool readyForSaveSend READ readyForSaveSend NOTIFY readyForSaveSendChanged)
// 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; }
const QmlObjectListModel* visualItems (void) const; QmlObjectListModel* visualItems (void) ;
int currentPolygonIndex (void) const { return _currentPolygonIndex; } int currentPolygonIndex (void) const { return _currentPolygonIndex; }
QString currentFile (void) const { return _currentFile; } QString currentFile (void) const { return _currentFile; }
QStringList loadNameFilters (void) const; QStringList loadNameFilters (void) const;
...@@ -55,8 +55,6 @@ public: ...@@ -55,8 +55,6 @@ public:
QString fileExtension (void) const { return wimaFileExtension; } QString fileExtension (void) const { return wimaFileExtension; }
QGeoCoordinate joinedAreaCenter (void) const; QGeoCoordinate joinedAreaCenter (void) const;
WimaArea joinedArea (void) const; WimaArea joinedArea (void) const;
WimaDataContainer* dataContainer (void) const { return _container; }
bool flyView (void) const { return _flyView; }
bool readyForSaveSend (void) const { return _readyForSaveSend; } bool readyForSaveSend (void) const { return _readyForSaveSend; }
...@@ -76,6 +74,7 @@ public: ...@@ -76,6 +74,7 @@ public:
Q_INVOKABLE void removeArea(int index); Q_INVOKABLE void removeArea(int index);
Q_INVOKABLE bool addServiceArea(); Q_INVOKABLE bool addServiceArea();
Q_INVOKABLE bool addVehicleCorridor(); Q_INVOKABLE bool addVehicleCorridor();
/// Remove all areas from WimaController and all mission items from MissionController
Q_INVOKABLE void removeAll(); Q_INVOKABLE void removeAll();
Q_INVOKABLE void startMission(); Q_INVOKABLE void startMission();
...@@ -115,23 +114,17 @@ signals: ...@@ -115,23 +114,17 @@ signals:
private slots: private slots:
void recalcPolygonInteractivity (int index); void recalcPolygonInteractivity (int index);
bool updateJoinedArea (); bool recalcJoinedArea ();
void updateContainer (); void updateContainer ();// only executed if flyView == false
void downloadFromContainer (); void downloadFromContainer ();// only executed if flyView == true
void setOpArea (const WimaGOperationArea& area);
void setSerArea (const WimaServiceArea& area);
void setCorridor (const WimaVCorridor& area);
void setJoinedArea (const WimaArea& area);
private: private:
bool _flyView;
bool _readyForSaveSend; bool _readyForSaveSend;
PlanMasterController* _masterController; PlanMasterController *_masterController;
MissionController* _missionController; MissionController *_missionController;
int _currentPolygonIndex; int _currentPolygonIndex;
QString _currentFile; QString _currentFile;
WimaDataContainer* _container; WimaDataContainer *_container;
QmlObjectListModel _visualItems; QmlObjectListModel _visualItems;
WimaArea _joinedArea; WimaArea _joinedArea;
WimaGOperationArea _opArea; WimaGOperationArea _opArea;
......
...@@ -2,44 +2,44 @@ ...@@ -2,44 +2,44 @@
WimaDataContainer::WimaDataContainer(QObject *parent) WimaDataContainer::WimaDataContainer(QObject *parent)
: QObject (parent) : QObject (parent)
, _joinedArea (this) , _joinedArea (nullptr)
, _opArea (this) , _opArea (nullptr)
, _serArea (this) , _serArea (nullptr)
, _corridor (this) , _corridor (nullptr)
{ {
} }
void WimaDataContainer::setJoinedArea(const WimaArea &joinedArea) void WimaDataContainer::setJoinedArea(const WimaArea *joinedArea)
{ {
if (_joinedArea.path() != joinedArea.path()) { if (_joinedArea != joinedArea) {
_joinedArea = joinedArea; _joinedArea = joinedArea;
emit joinedAreaChanged(_joinedArea); emit joinedAreaChanged(_joinedArea);
} }
} }
void WimaDataContainer::setOpArea(const WimaGOperationArea &opArea) void WimaDataContainer::setOpArea(const WimaGOperationArea *opArea)
{ {
if (_opArea.path() != opArea.path()) { if (_opArea != opArea) {
_opArea = opArea; _opArea = opArea;
emit opAreaChanged(_opArea); emit opAreaChanged(_opArea);
} }
} }
void WimaDataContainer::setSerArea(const WimaServiceArea &serArea) void WimaDataContainer::setSerArea(const WimaServiceArea *serArea)
{ {
if (_serArea.path() != serArea.path()) { if (_serArea != serArea) {
_serArea = serArea; _serArea = serArea;
emit serAreaChanged(_serArea); emit serAreaChanged(_serArea);
} }
} }
void WimaDataContainer::setCorridor(const WimaVCorridor &corridor) void WimaDataContainer::setCorridor(const WimaVCorridor *corridor)
{ {
if (_corridor.path() != corridor.path()) { if (_corridor != corridor) {
_corridor = corridor; _corridor = corridor;
emit corridorChanged(_corridor); emit corridorChanged(_corridor);
......
#ifndef WIMADATACONTAINER_H #pragma once
#define WIMADATACONTAINER_H
#include <QObject> #include <QObject>
...@@ -15,30 +14,30 @@ class WimaDataContainer : public QObject ...@@ -15,30 +14,30 @@ class WimaDataContainer : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit WimaDataContainer(QObject *parent = nullptr); explicit WimaDataContainer(QObject *parent = nullptr);
WimaDataContainer(WimaDataContainer &other, QObject *parent = nullptr) = delete;
WimaDataContainer(WimaDataContainer &other) = delete;
WimaArea joinedArea (void) { return _joinedArea; } const WimaArea * joinedArea (void) { return _joinedArea; }
WimaGOperationArea opArea (void) { return _opArea; } const WimaGOperationArea * opArea (void) { return _opArea; }
WimaServiceArea serArea (void) { return _serArea; } const WimaServiceArea * serArea (void) { return _serArea; }
WimaVCorridor corridor (void) { return _corridor; } const WimaVCorridor * corridor (void) { return _corridor; }
void setJoinedArea (const WimaArea& joinedArea);
void setOpArea (const WimaGOperationArea& opArea);
void setSerArea (const WimaServiceArea& serArea);
void setCorridor (const WimaVCorridor& corridor);
signals: signals:
void joinedAreaChanged (const WimaArea& area); void joinedAreaChanged (const WimaArea *area);
void opAreaChanged (const WimaGOperationArea& area); void opAreaChanged (const WimaGOperationArea *area);
void serAreaChanged (const WimaServiceArea& area); void serAreaChanged (const WimaServiceArea *area);
void corridorChanged (const WimaVCorridor& area); void corridorChanged (const WimaVCorridor *area);
public slots: public slots:
void setJoinedArea (const WimaArea *joinedArea);
void setOpArea (const WimaGOperationArea *opArea);
void setSerArea (const WimaServiceArea *serArea);
void setCorridor (const WimaVCorridor *corridor);
private: private:
WimaArea _joinedArea; const WimaArea *_joinedArea;
WimaGOperationArea _opArea; const WimaGOperationArea *_opArea;
WimaServiceArea _serArea; const WimaServiceArea *_serArea;
WimaVCorridor _corridor; const WimaVCorridor *_corridor;
}; };
#endif // WIMADATACONTAINER_H
...@@ -21,13 +21,6 @@ WimaGOperationArea::WimaGOperationArea(const WimaGOperationArea &other, QObject ...@@ -21,13 +21,6 @@ WimaGOperationArea::WimaGOperationArea(const WimaGOperationArea &other, QObject
init(); init();
} }
WimaGOperationArea &WimaGOperationArea::operator=(WimaGOperationArea other)
{
swap(*this, other);
return *this;
}
void WimaGOperationArea::saveToJson(QJsonObject &json) void WimaGOperationArea::saveToJson(QJsonObject &json)
{ {
this->WimaArea::saveToJson(json); this->WimaArea::saveToJson(json);
...@@ -77,6 +70,23 @@ bool WimaGOperationArea::loadFromJson(const QJsonObject &json, QString& errorStr ...@@ -77,6 +70,23 @@ bool WimaGOperationArea::loadFromJson(const QJsonObject &json, QString& errorStr
} }
} }
void WimaGOperationArea::update(const WimaGOperationArea &area)
{
this->WimaArea::update(area);
this->setBottomLayerAltitude(area.bottomLayerAltitude());
this->setNumberOfLayers(area.numberOfLayers());
this->setLayerDistance(area.layerDistance());
this->setBorderPolygonOffset(area.borderPolygonOffset());
recalcBorderPolygon();
}
void WimaGOperationArea::setBottomLayerAltitude(double altitude)
{
}
void print(const WimaGOperationArea &area) void print(const WimaGOperationArea &area)
{ {
QString message; QString message;
...@@ -87,30 +97,18 @@ void print(const WimaGOperationArea &area) ...@@ -87,30 +97,18 @@ void print(const WimaGOperationArea &area)
void print(const WimaGOperationArea &area, QString outputStr) void print(const WimaGOperationArea &area, QString outputStr)
{ {
print(static_cast<const WimaArea&>(area), outputStr); print(static_cast<const WimaArea&>(area), outputStr);
outputStr.append(QString("Bottom Layer Altitude: %.3f\n").arg(area._bottomLayerAltitude.rawValue().toDouble())); outputStr.append(QString("Bottom Layer Altitude: %1\n").arg(area._bottomLayerAltitude.rawValue().toDouble()));
outputStr.append(QString("Number of Layers: %i\n").arg(area._numberOfLayers.rawValue().toInt())); outputStr.append(QString("Number of Layers: %1\n").arg(area._numberOfLayers.rawValue().toInt()));
outputStr.append(QString("Layer Distance: %.3f\n").arg(area._layerDistance.rawValue().toDouble())); outputStr.append(QString("Layer Distance: %1\n").arg(area._layerDistance.rawValue().toDouble()));
outputStr.append(QString("Border Polygon Offset: %.3f\n").arg(area._borderPolygonOffset.rawValue().toDouble())); outputStr.append(QString("Border Polygon Offset: %1\n").arg(area._borderPolygonOffset.rawValue().toDouble()));
outputStr.append(QString("Border Polygon Coordinates\n").arg(area._borderPolygonOffset.rawValue().toDouble())); outputStr.append(QString("Border Polygon Coordinates\n").arg(area._borderPolygonOffset.rawValue().toDouble()));
for (int i = 0; i < area._borderPolygon.count(); i++) { for (int i = 0; i < area._borderPolygon.count(); i++) {
QGeoCoordinate coordinate = area._borderPolygon.vertexCoordinate(i); QGeoCoordinate coordinate = area._borderPolygon.vertexCoordinate(i);
outputStr.append(QString("%s\n").arg(coordinate.toString(QGeoCoordinate::Degrees))); outputStr.append(QString("%1\n").arg(coordinate.toString(QGeoCoordinate::Degrees)));
} }
} }
void swap(WimaGOperationArea &area1, WimaGOperationArea &area2)
{
using std::swap;
swap(area1._metaDataMap, area2._metaDataMap);
swap(area1._bottomLayerAltitude, area2._bottomLayerAltitude);
swap(area1._numberOfLayers, area2._numberOfLayers);
swap(area1._layerDistance, area2._layerDistance);
swap(area1._borderPolygonOffset, area2._borderPolygonOffset);
swap(area1._borderPolygon, area2._borderPolygon);
}
void WimaGOperationArea::recalcBorderPolygon() void WimaGOperationArea::recalcBorderPolygon()
{ {
//qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble()); //qWarning("WimaGOperationArea::recalcBorderPolygon() %f", _borderPolygonOffset.rawValue().toDouble());
......
...@@ -13,35 +13,34 @@ class WimaGOperationArea : public WimaArea ...@@ -13,35 +13,34 @@ class WimaGOperationArea : public WimaArea
Q_OBJECT Q_OBJECT
public: public:
WimaGOperationArea(QObject* parent = nullptr); WimaGOperationArea(QObject* parent = nullptr);
WimaGOperationArea(const WimaGOperationArea& other, QObject* parent = nullptr); WimaGOperationArea(const WimaGOperationArea &other, QObject *parent = nullptr);
WimaGOperationArea& operator=(WimaGOperationArea other);
Q_PROPERTY(Fact* bottomLayerAltitude READ bottomLayerAltitude CONSTANT) Q_PROPERTY(Fact* bottomLayerAltitude READ bottomLayerAltitudeFact CONSTANT)
Q_PROPERTY(Fact* numberOfLayers READ numberOfLayers CONSTANT) Q_PROPERTY(Fact* numberOfLayers READ numberOfLayersFact CONSTANT)
Q_PROPERTY(Fact* layerDistance READ layerDistance CONSTANT) Q_PROPERTY(Fact* layerDistance READ layerDistanceFact CONSTANT)
Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffset CONSTANT) Q_PROPERTY(Fact* borderPolygonOffset READ borderPolygonOffsetFact CONSTANT)
Q_PROPERTY(QGCMapPolygon* borderPolygon READ borderPolygon NOTIFY borderPolygonChanged) Q_PROPERTY(QGCMapPolygon borderPolygon READ borderPolygon NOTIFY borderPolygonChanged)
void setVehicleCorridor (WimaVCorridor* corridor);
// Overrides from WimaPolygon // Overrides from WimaPolygon
QString mapVisualQML (void) const { return "WimaGOperationAreaMapVisual.qml";} QString mapVisualQML (void) const { return "WimaGOperationAreaMapVisual.qml";}
QString editorQML (void) const { return "WimaGOperationAreaEditor.qml";} QString editorQML (void) const { return "WimaGOperationAreaEditor.qml";}
// Property accessors // Property accessors
Fact* bottomLayerAltitude (void) { return &_bottomLayerAltitude;} Fact* bottomLayerAltitudeFact (void) { return &_bottomLayerAltitude;}
Fact* numberOfLayers (void) { return &_numberOfLayers;} Fact* numberOfLayersFact (void) { return &_numberOfLayers;}
Fact* layerDistance (void) { return &_layerDistance;} Fact* layerDistanceFact (void) { return &_layerDistance;}
Fact* borderPolygonOffset (void) { return &_borderPolygonOffset;} Fact* borderPolygonOffsetFact (void) { return &_borderPolygonOffset;}
QGCMapPolygon* borderPolygon (void) { return &_borderPolygon;} double bottomLayerAltitude (void) const { return _bottomLayerAltitude.rawValue().toDouble();}
int numberOfLayers (void) const { return _numberOfLayers.rawValue().toInt();}
double layerDistance (void) const { return _layerDistance.rawValue().toDouble();}
double borderPolygonOffset (void) const { return _borderPolygonOffset.rawValue().toDouble();}
QGCMapPolygon borderPolygon (void) const { return _borderPolygon;}
// Member Methodes // Member Methodes
void saveToJson(QJsonObject& json); void saveToJson(QJsonObject& json);
bool loadFromJson(const QJsonObject& json, QString &errorString); bool loadFromJson(const QJsonObject& json, QString &errorString);
// Friends // Friends
friend void swap(WimaGOperationArea& area1, WimaGOperationArea& area2);
friend void print(const WimaGOperationArea& area, QString outputStr); friend void print(const WimaGOperationArea& area, QString outputStr);
friend void print(const WimaGOperationArea& area); friend void print(const WimaGOperationArea& area);
...@@ -53,21 +52,23 @@ public: ...@@ -53,21 +52,23 @@ public:
static const char* borderPolygonOffsetName; static const char* borderPolygonOffsetName;
static const char* wimaGOperationAreaName; static const char* wimaGOperationAreaName;
signals: signals:
void bottomLayerAltitudeChanged (void); void bottomLayerAltitudeChanged (void);
void numberOfLayersChanged (void); void numberOfLayersChanged (void);
void layerDistanceChanged (void); void layerDistanceChanged (void);
//void vehicleListChanged (void);
void polylineChanged (void); void polylineChanged (void);
//void vehiclePolygonsChanged (void);
void vehicleCorridorChanged (WimaVCorridor* corridor); void vehicleCorridorChanged (WimaVCorridor* corridor);
void borderPolygonChanged (void); void borderPolygonChanged (void);
public slots:
/// Updates this with data from area
void update(const WimaGOperationArea &area);
void setBottomLayerAltitude (double altitude);
void setNumberOfLayers (double numLayers);
void setLayerDistance (double layerDistance);
void setBorderPolygonOffset (double offset);
private slots: private slots:
void recalcBorderPolygon (void); void recalcBorderPolygon (void);
private: private:
// Member Methodes // Member Methodes
void init(); void init();
......
#include "WimaPlaner.h"
WimaPlaner::WimaPlaner()
{
}
#ifndef WIMAPLANER_H
#define WIMAPLANER_H
class WimaPlaner
{
public:
WimaPlaner();
};
#endif // WIMAPLANER_H
\ No newline at end of file
...@@ -16,13 +16,6 @@ WimaServiceArea::WimaServiceArea(const WimaServiceArea &other, QObject *parent) ...@@ -16,13 +16,6 @@ WimaServiceArea::WimaServiceArea(const WimaServiceArea &other, QObject *parent)
init(); init();
} }
WimaServiceArea &WimaServiceArea::operator=(WimaServiceArea other)
{
swap(*this, other);
return *this;
}
void WimaServiceArea::setTakeOffPosition(const QGeoCoordinate &coordinate) void WimaServiceArea::setTakeOffPosition(const QGeoCoordinate &coordinate)
{ {
if(_takeOffPosition != coordinate){ if(_takeOffPosition != coordinate){
...@@ -57,6 +50,13 @@ bool WimaServiceArea::loadFromJson(const QJsonObject &json, QString &errorString ...@@ -57,6 +50,13 @@ bool WimaServiceArea::loadFromJson(const QJsonObject &json, QString &errorString
} }
} }
void WimaServiceArea::update(const WimaServiceArea &area)
{
this->WimaArea::update(area);
this->setTakeOffPosition(area.takeOffPosition());
this->setLandPosition(area.landPosition());
}
void print(const WimaServiceArea &area) void print(const WimaServiceArea &area)
{ {
QString message; QString message;
...@@ -71,14 +71,6 @@ void print(const WimaServiceArea &area, QString &outputStr) ...@@ -71,14 +71,6 @@ void print(const WimaServiceArea &area, QString &outputStr)
outputStr.append(QString("Land Position: %s\n").arg(area._landPosition.toString(QGeoCoordinate::Degrees))); outputStr.append(QString("Land Position: %s\n").arg(area._landPosition.toString(QGeoCoordinate::Degrees)));
} }
void swap(WimaServiceArea &area1, WimaServiceArea &area2)
{
using std::swap;
swap(area1._takeOffPosition, area2._takeOffPosition);
swap(area1._landPosition, area2._landPosition);
}
void WimaServiceArea::init() void WimaServiceArea::init()
{ {
this->setObjectName(wimaServiceAreaName); this->setObjectName(wimaServiceAreaName);
......
...@@ -10,12 +10,10 @@ class WimaServiceArea : public WimaArea ...@@ -10,12 +10,10 @@ class WimaServiceArea : public WimaArea
public: public:
WimaServiceArea(QObject* parent = nullptr); WimaServiceArea(QObject* parent = nullptr);
WimaServiceArea(const WimaServiceArea& other, QObject* parent); WimaServiceArea(const WimaServiceArea& other, QObject* parent);
WimaServiceArea& operator=(WimaServiceArea other);
Q_PROPERTY(const QGeoCoordinate& takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged) Q_PROPERTY(const QGeoCoordinate& takeOffPosition READ takeOffPosition WRITE setTakeOffPosition NOTIFY takeOffPositionChanged)
Q_PROPERTY(const QGeoCoordinate& landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged) Q_PROPERTY(const QGeoCoordinate& landPosition READ landPosition WRITE setLandPosition NOTIFY landPositionChanged)
// Overrides from WimaPolygon // Overrides from WimaPolygon
QString mapVisualQML (void) const { return "WimaServiceAreaMapVisual.qml";} QString mapVisualQML (void) const { return "WimaServiceAreaMapVisual.qml";}
QString editorQML (void) const { return "WimaServiceAreaEditor.qml";} QString editorQML (void) const { return "WimaServiceAreaEditor.qml";}
...@@ -24,27 +22,29 @@ public: ...@@ -24,27 +22,29 @@ public:
const QGeoCoordinate& takeOffPosition (void) const { return _takeOffPosition;} const QGeoCoordinate& takeOffPosition (void) const { return _takeOffPosition;}
const QGeoCoordinate& landPosition (void) const { return _landPosition;} const QGeoCoordinate& landPosition (void) const { return _landPosition;}
// Property setters
void setTakeOffPosition (const QGeoCoordinate& coordinate);
void setLandPosition (const QGeoCoordinate& coordinate);
// Member Methodes // Member Methodes
void saveToJson(QJsonObject& json); void saveToJson(QJsonObject& json);
bool loadFromJson(const QJsonObject& json, QString& errorString); bool loadFromJson(const QJsonObject& json, QString& errorString);
// static Members
static const char* wimaServiceAreaName;
// Friends // Friends
friend void swap(WimaServiceArea& area1, WimaServiceArea& area2);
friend void print(const WimaServiceArea& area, QString& outputStr); friend void print(const WimaServiceArea& area, QString& outputStr);
friend void print(const WimaServiceArea& area); friend void print(const WimaServiceArea& area);
// 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);
public slots:
void setTakeOffPosition (const QGeoCoordinate& coordinate);
void setLandPosition (const QGeoCoordinate& coordinate);
/// Updates this with data from area
void update(const WimaServiceArea &area);
private: private:
// Member Methodes // Member Methodes
void init(); void init();
......
...@@ -16,13 +16,6 @@ WimaVCorridor::WimaVCorridor(const WimaVCorridor &other, QObject *parent) ...@@ -16,13 +16,6 @@ WimaVCorridor::WimaVCorridor(const WimaVCorridor &other, QObject *parent)
init(); init();
} }
WimaVCorridor &WimaVCorridor::operator=(WimaVCorridor other)
{
swap(*this, other);
return *this;
}
void WimaVCorridor::saveToJson(QJsonObject &json) void WimaVCorridor::saveToJson(QJsonObject &json)
{ {
this->WimaArea::saveToJson(json); this->WimaArea::saveToJson(json);
...@@ -41,6 +34,11 @@ bool WimaVCorridor::loadFromJson(const QJsonObject &json, QString &errorString) ...@@ -41,6 +34,11 @@ bool WimaVCorridor::loadFromJson(const QJsonObject &json, QString &errorString)
} }
} }
void WimaVCorridor::update(const WimaVCorridor &area)
{
this->WimaArea::update(area);
}
void WimaVCorridor::init() void WimaVCorridor::init()
{ {
this->setObjectName(wimaVCorridorName); this->setObjectName(wimaVCorridorName);
...@@ -57,10 +55,3 @@ void print(const WimaVCorridor &area, QString &outputString) ...@@ -57,10 +55,3 @@ void print(const WimaVCorridor &area, QString &outputString)
{ {
print(static_cast<const WimaArea&>(area), outputString); print(static_cast<const WimaArea&>(area), outputString);
} }
void swap(WimaVCorridor &area1, WimaVCorridor &area2)
{
using std::swap;
swap(static_cast<WimaArea&>(area1), static_cast<WimaArea&>(area2));
}
...@@ -11,7 +11,6 @@ class WimaVCorridor : public WimaArea ...@@ -11,7 +11,6 @@ class WimaVCorridor : public WimaArea
public: public:
WimaVCorridor(QObject* parent = nullptr); WimaVCorridor(QObject* parent = nullptr);
WimaVCorridor(const WimaVCorridor& other, QObject* parent = nullptr); WimaVCorridor(const WimaVCorridor& other, QObject* parent = nullptr);
WimaVCorridor& operator=(WimaVCorridor other);
// Overrides from WimaPolygon // Overrides from WimaPolygon
QString mapVisualQML (void) const { return "WimaVCorridorMapVisual.qml";} QString mapVisualQML (void) const { return "WimaVCorridorMapVisual.qml";}
...@@ -25,7 +24,6 @@ public: ...@@ -25,7 +24,6 @@ public:
static const char* wimaVCorridorName; static const char* wimaVCorridorName;
// Friends // Friends
friend void swap(WimaVCorridor& area1, WimaVCorridor& area2);
friend void print(const WimaVCorridor& area, QString& outputString); friend void print(const WimaVCorridor& area, QString& outputString);
friend void print(const WimaVCorridor& area); friend void print(const WimaVCorridor& area);
...@@ -33,6 +31,10 @@ signals: ...@@ -33,6 +31,10 @@ signals:
void serviceAreaChanged (WimaServiceArea* serviceArea); void serviceAreaChanged (WimaServiceArea* serviceArea);
void opAreaChanged (WimaGOperationArea* opArea); void opAreaChanged (WimaGOperationArea* opArea);
public slots:
/// Updates this with data from area
void update(const WimaVCorridor& area);
private: private:
void init(); void init();
......
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