Commit 0a9d836e authored by Valentin Platzgummer's avatar Valentin Platzgummer

befor integrating Waypoint managers into WimaController

parent 72acd11d
......@@ -440,11 +440,11 @@ HEADERS += \
src/Wima/Snake/SnakeWorker.h \
src/Wima/WaypointManager/AreaInterface.h \
src/Wima/WaypointManager/DefaultManager.h \
src/Wima/WaypointManager/GenericSlicer.h \
src/Wima/WaypointManager/GenericWaypointManager.h \
src/Wima/Geometry/WimaPolygonArray.h \
src/Wima/Snake/snaketile.h \
src/Wima/WaypointManager/Settings.h \
src/Wima/WaypointManager/Slicer.h \
src/Wima/WaypointManager/Utils.h \
src/api/QGCCorePlugin.h \
src/api/QGCOptions.h \
......@@ -501,9 +501,9 @@ SOURCES += \
src/Wima/Snake/SnakeWorker.cc \
src/Wima/WaypointManager/AreaInterface.cpp \
src/Wima/WaypointManager/DefaultManager.cpp \
src/Wima/WaypointManager/GenericSlicer.cpp \
src/Wima/WaypointManager/GenericWaypointManager.cpp \
src/Wima/WaypointManager/Settings.cpp \
src/Wima/WaypointManager/Slicer.cpp \
src/Wima/WaypointManager/Utils.cpp \
src/comm/ros_bridge/include/ComPrivateInclude.cpp \
src/comm/ros_bridge/include/MessageTag.cpp \
......
......@@ -47,7 +47,7 @@ public:
QObject* operator[] (int i);
const QObject* operator[] (int i) const;
template<class T> T value (int index) { return qobject_cast<T>(_objectList[index]); }
template<class T> T value (int index) const { return qobject_cast<T>(_objectList[index]); }
QList<QObject*>* objectList () { return &_objectList; }
/// Calls deleteLater on all items and this itself.
......
......@@ -23,10 +23,6 @@ public:
static const char* typeString;
signals:
public slots:
protected:
void assign(const WimaJoinedAreaData &other);
void assign(const WimaJoinedArea &other);
......
......@@ -41,6 +41,16 @@ void WaypointManager::AreaInterface::setJoinedArea(WimaJoinedAreaData *area)
_jArea = area;
}
const WimaMeasurementAreaData *WaypointManager::AreaInterface::measurementArea() const
{
return _mArea;
}
const WimaServiceAreaData *WaypointManager::AreaInterface::serviceArea() const
{
return _sArea;
}
const WimaCorridorData *WaypointManager::AreaInterface::corridor() const
{
return _cArea;
......
......@@ -8,7 +8,7 @@ bool WaypointManager::DefaultManager::update()
{
// extract waypoints
_slice.clear();
_slicer->update(_waypoints, _slice);
Slicer::update(_waypoints, _slice);
return _worker();
}
......@@ -16,7 +16,7 @@ bool WaypointManager::DefaultManager::next()
{
// extract waypoints
_slice.clear();
_slicer->next(_waypoints, _slice);
Slicer::next(_waypoints, _slice);
return _worker();
}
......@@ -24,7 +24,7 @@ bool WaypointManager::DefaultManager::previous()
{
// extract waypoints
_slice.clear();
_slicer->previous(_waypoints, _slice);
Slicer::previous(_waypoints, _slice);
return _worker();
}
......@@ -32,7 +32,7 @@ bool WaypointManager::DefaultManager::reset()
{
// extract waypoints
_slice.clear();
_slicer->reset(_waypoints, _slice);
Slicer::reset(_waypoints, _slice);
return _worker();
}
......
......@@ -20,8 +20,7 @@ class DefaultManager : public ManagerBase
{
public:
DefaultManager() = delete;
DefaultManager(Slicer *slicer,
Settings *settings,
DefaultManager(Settings *settings,
AreaInterface *interface);
......
#pragma once
#include <assert.h>
#include <iostream>
#include "Utils.h"
//! @brief Base class for all waypoint managers.
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
class GenericSlicer
{
public:
typedef Container<ElementType> ContainerType;
GenericSlicer();
// Slicing.
void update (const ContainerType &source, ContainerType &update);
void next (const ContainerType &source, ContainerType &update);
void previous (const ContainerType &source, ContainerType &update);
void reset (const ContainerType &source, ContainerType &update);
// Slicing parameters.
//! @brief Sets the overlap.
//!
//! @param overlap The number of overlapping vertices
//! between on and the next slice.
void setOverlap (uint32_t overlap);
//! @brief Sets the number of vertices per slice.
//!
//! @param N The number of vertices per slice.
void setN (std::uint32_t N);
//! @brief Sets the start index.
//!
//! @param idxStart The start index.
void setStartIndex (int idxStart);
//! @return Returns the overlap.
uint32_t overlap ();
//! @return Returns the number of vertices per slice N.
uint32_t N ();
//! @return Returns the start index.
int startIndex ();
private:
void _updateIdx(std::size_t size);
long _idxStart;
long _idxEnd;
long _idxNext;
long _idxPrevious;
uint32_t _overlap;
uint32_t _N;
bool _idxValid;
bool _atEnd;
};
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
GenericSlicer<ElementType, Container>::GenericSlicer():
_idxValid(false)
, _atEnd(false)
{}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::setOverlap(std::uint32_t overlap)
{
_idxValid = false;
_overlap = overlap;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::setN(uint32_t N)
{
_idxValid = false;
_N = N > 0 ? N : 1;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::setStartIndex(int idxStart)
{
_idxValid = false;
_idxStart = idxStart;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
uint32_t GenericSlicer<ElementType, Container>::overlap()
{
return _overlap;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
uint32_t GenericSlicer<ElementType, Container>::N()
{
return _N;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
int GenericSlicer<ElementType, Container>::startIndex()
{
return _idxStart;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::_updateIdx(std::size_t size)
{
_idxValid = true;
_atEnd = false;
if ( _idxStart >= size-1 ) {
_idxStart = size-1;
_idxEnd = _idxStart;
_idxNext = _idxStart;
_atEnd = true;
return;
}
_idxStart < 0 ? 0 : _idxStart;
_idxEnd = _idxStart + _N - 1;
_idxEnd = _idxEnd < size ? _idxEnd : size-1;
_idxNext = _idxEnd + 1 - _overlap;
_idxNext = _idxNext < 0 ? 0 : _idxNext;
_idxNext = _idxNext < size ? _idxNext : size-1;
_idxPrevious = _idxStart - 1 + _overlap;
_idxPrevious = _idxPrevious < 0 ? 0 : _idxPrevious;
_idxPrevious = _idxPrevious < size ? _idxPrevious : size-1;
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::update(const ContainerType &source,
Container<ElementType> &slice){
if ( !_idxValid)
_updateIdx(source.size());
WaypointManager::Utils::extract(source, slice, _idxStart, _idxEnd);
// extract waypoints
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::next(const ContainerType &source, Container<ElementType> &slice){
setStartIndex(_idxNext);
slice(source, slice);
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::previous(const ContainerType &source, Container<ElementType> &slice){
setStartIndex(_idxPrevious);
slice(source, slice);
}
template <class ElementType, template <class, class...> class Container /*e.g. QVector*/>
void GenericSlicer<ElementType, Container>::reset(const ContainerType &source, Container<ElementType> &slice){
setStartIndex(0);
slice(source, slice);
}
......@@ -2,7 +2,7 @@
#include <iostream>
#include "GenericSlicer.h"
#include "Slicer.h"
namespace WaypointManager {
......@@ -10,14 +10,13 @@ template<class WaypointType,
template<class, class...> class ContainerType,
class MissionItemList,
class SettingsType>
class GenericWaypointManager
class GenericWaypointManager : public Slicer
{
public:
typedef GenericSlicer<WaypointType, ContainerType> Slicer;
typedef ContainerType<WaypointType> WaypointList;
GenericWaypointManager() = delete;
GenericWaypointManager(Slicer *slicer, SettingsType *settings);
GenericWaypointManager(SettingsType *settings);
// Waypoint editing.
void setWaypoints(const WaypointList &waypoints);
......@@ -42,7 +41,6 @@ protected:
WaypointList _waypoints;
WaypointList _slice;
MissionItemList _missionItems;
Slicer *_slicer;
SettingsType *_settings;
};
......@@ -54,12 +52,9 @@ template<class WaypointType,
GenericWaypointManager<WaypointType,
ContainerType,
MissionItemList,
SettingsType>::GenericWaypointManager(
Slicer *slicer,
SettingsType *Settings
SettingsType>::GenericWaypointManager(SettingsType *Settings
)
: _slicer(slicer)
, _settings(_settings)
: _settings(_settings)
{}
template<class WaypointType,
......
#include "Slicer.h"
Slicer::Slicer():
_idxValid(false)
, _atEnd(false)
{}
void Slicer::setOverlap(uint32_t overlap)
{
_idxValid = false;
_overlap = overlap;
}
void Slicer::setN(uint32_t N)
{
_idxValid = false;
_N = N > 0 ? N : 1;
}
void Slicer::setStartIndex(int idxStart)
{
_idxValid = false;
_idxStart = idxStart;
}
uint32_t Slicer::overlap()
{
return _overlap;
}
uint32_t Slicer::N()
{
return _N;
}
int Slicer::startIndex()
{
return _idxStart;
}
Slicer &Slicer::operator=(const Slicer &other)
{
}
void Slicer::_updateIdx(std::size_t size)
{
_idxValid = true;
_atEnd = false;
if ( _idxStart >= long(size)-1 ) {
_idxStart = long(size)-1;
_idxEnd = _idxStart;
_idxNext = _idxStart;
_atEnd = true;
return;
}
_idxStart = _idxStart < 0 ? 0 : _idxStart;
_idxEnd = _idxStart + _N - 1;
_idxEnd = _idxEnd < long(size) ? _idxEnd : size-1;
_idxNext = _idxEnd + 1 - _overlap;
_idxNext = _idxNext < 0 ? 0 : _idxNext;
_idxNext = _idxNext < long(size) ? _idxNext : size-1;
_idxPrevious = _idxStart - 1 + _overlap;
_idxPrevious = _idxPrevious < 0 ? 0 : _idxPrevious;
_idxPrevious = _idxPrevious < long(size) ? _idxPrevious : size-1;
}
#pragma once
#include <assert.h>
#include <iostream>
#include "Utils.h"
//! @brief Base class for all waypoint managers.
class Slicer
{
public:
Slicer();
protected:
// Slicing.
template <class Container1, class Container2>
void update (const Container1 &source, Container2 &slice);
template <class Container1, class Container2>
void next (const Container1 &source, Container2 &slice);
template <class Container1, class Container2>
void previous (const Container1 &source, Container2 &slice);
template <class Container1, class Container2>
void reset (const Container1 &source, Container2 &slice);
public:
// Slicing parameters.
//! @brief Sets the overlap.
//!
//! @param overlap The number of overlapping vertices
//! between on and the next slice.
void setOverlap (uint32_t overlap);
//! @brief Sets the number of vertices per slice.
//!
//! @param N The number of vertices per slice.
void setN (std::uint32_t N);
//! @brief Sets the start index.
//!
//! @param idxStart The start index.
void setStartIndex (int idxStart);
//! @return Returns the overlap.
uint32_t overlap ();
//! @return Returns the number of vertices per slice N.
uint32_t N ();
//! @return Returns the start index.
int startIndex ();
Slicer &operator=(const Slicer &other);
private:
void _updateIdx(std::size_t size);
long _idxStart;
long _idxEnd;
long _idxNext;
long _idxPrevious;
uint32_t _overlap;
uint32_t _N;
bool _idxValid;
bool _atEnd;
};
template <class Container1, class Container2>
void Slicer::update(const Container1 &source, Container2 &slice){
if ( !_idxValid)
_updateIdx(source.size());
WaypointManager::Utils::extract(source, slice, _idxStart, _idxEnd);
}
template <class Container1, class Container2>
void Slicer::next(const Container1 &source, Container2 &slice){
setStartIndex(_idxNext);
update(source, slice);
}
template <class Container1, class Container2>
void Slicer::previous(const Container1 &source, Container2 &slice){
setStartIndex(_idxPrevious);
update(source, slice);
}
template <class Container1, class Container2>
void Slicer::reset(const Container1 &source, Container2 &slice){
setStartIndex(0);
update(source, slice);
}
......@@ -20,7 +20,7 @@ QVariant getCoordinate(const SimpleMissionItem* item);
/// extracts the coordinates stored in missionItems (list of MissionItems) and stores them in coordinateList.
template <class CoordinateType, template <class, class...> class ContainerType>
bool extract(QmlObjectListModel &missionItems,
bool extract(const QmlObjectListModel &missionItems,
ContainerType<CoordinateType> &coordinateList,
std::size_t startIndex,
std::size_t endIndex)
......@@ -59,7 +59,7 @@ bool extract(QmlObjectListModel &missionItems,
/// extracts the coordinates stored in missionItems (list of MissionItems) and stores them in coordinateList.
template <class CoordinateType, template <class, class...> class ContainerType>
bool extract(QmlObjectListModel &missionItems,
bool extract(const QmlObjectListModel &missionItems,
ContainerType<CoordinateType> &coordinateList)
{
......@@ -73,7 +73,7 @@ bool extract(QmlObjectListModel &missionItems,
/// extracts the coordinates stored in missionItems (list of MissionItems) and stores them in coordinateList.
template <class CoordinateType, template <class, class...> class ContainerType>
bool extract(ContainerType<CoordinateType> &source,
bool extract(const ContainerType<CoordinateType> &source,
ContainerType<CoordinateType> &destination,
std::size_t startIndex,
std::size_t endIndex)
......
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