...
 
Commits (2)
......@@ -41,6 +41,7 @@ const char *variantNamesKey = "VariantNames";
const char *generatorArrayKey = "GeneratorArray";
const char *variantArrayKey = "VariantArray";
const char *generatorIndexKey = "GeneratorIndex";
const char *connectionsStringKey = "ConnectionString";
} // namespace
MeasurementComplexItem::MeasurementComplexItem(
......@@ -55,7 +56,8 @@ MeasurementComplexItem::MeasurementComplexItem(
_variantIndex(settingsGroup, _metaDataMap[variantIndexKey]),
_pAreaData(new AreaData(this)), _pEditorData(new AreaData(this)),
_pCurrentData(_pAreaData), _holdProgress(false), _pGenerator(nullptr),
_pWorker(new RoutingThread(this)) {
_pWorker(new RoutingThread(this)),
_nemoCString(settingsGroup, _metaDataMap[connectionsStringKey]) {
// Setup altitude.
_altitude.setRawValue(qgcApp()
......@@ -91,17 +93,17 @@ MeasurementComplexItem::MeasurementComplexItem(
&MeasurementComplexItem::_storeRoutingData);
// Connect coordinate and exitCoordinate.
connect(this, &MeasurementComplexItem::routeChanged,
connect(this, &MeasurementComplexItem::routeChanged, this,
[this] { emit this->coordinateChanged(this->coordinate()); });
connect(this, &MeasurementComplexItem::routeChanged,
connect(this, &MeasurementComplexItem::routeChanged, this,
[this] { emit this->exitCoordinateChanged(this->exitCoordinate()); });
connect(this, &MeasurementComplexItem::routeChanged, [this] {
connect(this, &MeasurementComplexItem::routeChanged, this, [this] {
emit this->exitCoordinateSameAsEntryChanged(
this->exitCoordinateSameAsEntry());
});
// Connect isIncomplete.
connect(this, &MeasurementComplexItem::idleChanged, [this] {
connect(this, &MeasurementComplexItem::idleChanged, this, [this] {
if (this->idle()) {
if (this->route().size() > 0 && this->_isIncomplete == true) {
this->_isIncomplete = false;
......@@ -124,14 +126,14 @@ MeasurementComplexItem::MeasurementComplexItem(
&MeasurementComplexItem::_updateFlightpathSegments);
// Connect complexDistance.
connect(this, &MeasurementComplexItem::routeChanged,
connect(this, &MeasurementComplexItem::routeChanged, this,
[this] { emit this->complexDistanceChanged(); });
resetGenerators();
startEditing();
// connect to nemo interface
connect(pNemoInterface, &NemoInterface::progressChanged, this,
connect(pNemoInterface, &Nemointerface::progressChanged, this,
&MeasurementComplexItem::_onNewProgress);
}
......@@ -773,6 +775,17 @@ void MeasurementComplexItem::_onAltitudeChanged() {
}
}
QString MeasurementComplexItem::nemoError() const { return _nemoError; }
void MeasurementComplexItem::_setNemoError(const QString &nemoError) {
if (_nemoError != nemoError) {
_nemoError = nemoError;
emit nemoErrorChanged();
}
}
Fact *MeasurementComplexItem::nemoCString() { return &_nemoCString; }
bool MeasurementComplexItem::holdProgress() const { return _holdProgress; }
void MeasurementComplexItem::setHoldProgress(bool holdProgress) {
......@@ -781,10 +794,10 @@ void MeasurementComplexItem::setHoldProgress(bool holdProgress) {
emit holdProgressChanged();
if (_holdProgress) {
disconnect(pNemoInterface, &NemoInterface::progressChanged, this,
disconnect(pNemoInterface, &Nemointerface::progressChanged, this,
&MeasurementComplexItem::_onNewProgress);
} else {
connect(pNemoInterface, &NemoInterface::progressChanged, this,
connect(pNemoInterface, &Nemointerface::progressChanged, this,
&MeasurementComplexItem::_onNewProgress);
_onNewProgress(pNemoInterface->getProgress());
}
......
......@@ -14,6 +14,7 @@
class RoutingThread;
class RoutingResult;
class Nemointerface;
namespace routing {
class GeneratorBase;
......@@ -51,6 +52,8 @@ public:
Q_PROPERTY(int generatorIndex READ generatorIndex NOTIFY generatorChanged)
Q_PROPERTY(AreaData *areaData READ areaData NOTIFY areaDataChanged)
Q_PROPERTY(QVariantList route READ route NOTIFY routeChanged)
Q_PROPERTY(QString nemoError READ nemoError NOTIFY nemoErrorChanged)
Q_PROPERTY(Fact *nemoCString READ nemoCString CONSTANT)
Q_INVOKABLE void reverseRoute(void);
......@@ -224,6 +227,10 @@ public:
bool holdProgress() const;
void setHoldProgress(bool holdProgress);
QString nemoError() const;
Fact *nemoCString();
signals:
void variantNamesChanged();
......@@ -238,6 +245,8 @@ signals:
void routeChanged();
void holdProgressChanged();
void nemoErrorChanged();
private slots:
// Worker functions.
......@@ -257,6 +266,7 @@ private:
static bool _idle(STATE state);
void _updateFlightpathSegments();
void _onAltitudeChanged();
void _setNemoError(const QString &nemoError);
// Hirarcical stuff.
int _sequenceNumber;
......@@ -285,4 +295,9 @@ private:
QVector<Variant> _variantVector;
Variant _route;
PtrWorker _pWorker;
// NemoInterface
std::shared_ptr<Nemointerface> _pNemointerface;
QString _nemoError;
SettingsFact _nemoCString;
};
......@@ -13,20 +13,20 @@
#include "TilePtrArray.h"
#include "geometry/ProgressArray.h"
// Singelton class used to interface measurement devices implementing the nemo
// interface.
class NemoInterface : public QObject {
class NemointerfaceFactory;
class Nemointerface : public QObject {
Q_OBJECT
class Impl;
using PImpl = std::unique_ptr<Impl>;
NemoInterface();
NemoInterface(NemoInterface &other) = delete;
static NemoInterface *createInstance();
Nemointerface(const QString &connectionString);
Nemointerface(Nemointerface &other) = delete;
friend class NemointerfaceFactory;
public:
~NemoInterface() override;
static NemoInterface *instance();
~Nemointerface() override;
enum class STATUS {
NOT_CONNECTED,
......@@ -90,6 +90,7 @@ public:
QString infoString() const;
QString warningString() const;
bool running() const;
QString connectionString();
signals:
void statusChanged();
......@@ -103,4 +104,25 @@ private:
PImpl pImpl;
};
#define pNemoInterface NemoInterface::instance()
// Singelton class used for nemo interface creation.
class NemointerfaceFactory {
NemointerfaceFactory();
NemointerfaceFactory(const NemointerfaceFactory &other) = delete;
static NemointerfaceFactory *createInstance();
public:
~NemointerfaceFactory();
static NemointerfaceFactory *instance();
// Creates a interface with a connection string connectionString.
// Two different interfaces can't share the same connection string.
std::shared_ptr<Nemointerface> create(const QString &connectionString);
// Returns true if an interface with connection string connectionString can
// be created (i.e. doesn't exist yet), returns false either.
bool isCreatable(const QString &connectionString);
private:
std::map<QString, std::weak_ptr<Nemointerface>> _map;
};
#define pNemoInterfaceFactory NemointerfaceFactory::instance()
......@@ -19,7 +19,7 @@
#define MAX_TILES 1000
#endif
QString randomId();
QString randomId(std::size_t length = 10);
using namespace geometry;
namespace trans = bg::strategy::transform;
......@@ -726,13 +726,24 @@ bool getTiles(const FPolygon &area, Length tileHeight, Length tileWidth,
return true;
}
QString randomId() {
std::srand(std::time(nullptr));
std::int64_t r = 0;
for (int i = 0; i < 10; ++i) {
r ^= std::rand();
QString randomId(std::size_t length) {
static const QString values(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
static std::uint64_t counter = 0;
static auto firstCall = std::chrono::high_resolution_clock::now();
auto delta = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now() - firstCall)
.count();
std::srand((unsigned int)delta ^ counter);
QString str;
for (int i = 0; i < length; ++i) {
int index = std::rand() % values.length();
QChar c = values.at(index);
str.append(c);
}
return QString::number(r);
++counter;
return str;
}
......@@ -17,6 +17,13 @@
"min": 1,
"decimalPlaces": 1,
"default": 10.0
},
{
"name": "ConnectionString",
"shrotDesc": "Nemo Connection String.",
"longDesc": "Nemo Connection String (e.g. host_ip:port).",
"type": "string",
"default": "localhost:9090"
}
]
}
......@@ -672,7 +672,7 @@ void QGCApplication::_initCommon() {
qmlRegisterUncreatableType<routing::LinearGenerator>(
"MeasurementComplexItem", 1, 0, "LinearGenerator", kRefOnly);
qmlRegisterType<AreaData>("MeasurementComplexItem", 1, 0, "AreaData");
qmlRegisterSingletonType<NemoInterface>("MeasurementComplexItem", 1, 0,
qmlRegisterSingletonType<Nemointerface>("MeasurementComplexItem", 1, 0,
"NemoInterface", getNemoInterface);
qmlRegisterInterface<routing::GeneratorBase>("GeneratorBase");
qmlRegisterUncreatableType<routing::CircularGenerator>(
......