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