mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-08-26 13:26:24 -04:00
Map feature and dependent plugins: implement new message pipes. Part of #1154
This commit is contained in:
+189
-19
@@ -20,6 +20,7 @@
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QBuffer>
|
||||
#include <QTimer>
|
||||
|
||||
#include "SWGFeatureSettings.h"
|
||||
#include "SWGFeatureReport.h"
|
||||
@@ -38,6 +39,7 @@
|
||||
MESSAGE_CLASS_DEFINITION(Map::MsgConfigureMap, Message)
|
||||
MESSAGE_CLASS_DEFINITION(Map::MsgFind, Message)
|
||||
MESSAGE_CLASS_DEFINITION(Map::MsgSetDateTime, Message)
|
||||
MESSAGE_CLASS_DEFINITION(Map::MsgReportAvailableChannelOrFeatures, Message)
|
||||
|
||||
const char* const Map::m_featureIdURI = "sdrangel.feature.map";
|
||||
const char* const Map::m_featureId = "Map";
|
||||
@@ -51,8 +53,6 @@ Map::Map(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
||||
setObjectName(m_featureId);
|
||||
m_state = StIdle;
|
||||
m_errorMessage = "Map error";
|
||||
connect(&m_updatePipesTimer, SIGNAL(timeout()), this, SLOT(updatePipes()));
|
||||
m_updatePipesTimer.start(1000);
|
||||
m_networkManager = new QNetworkAccessManager();
|
||||
QObject::connect(
|
||||
m_networkManager,
|
||||
@@ -60,10 +60,35 @@ Map::Map(WebAPIAdapterInterface *webAPIAdapterInterface) :
|
||||
this,
|
||||
&Map::networkManagerFinished
|
||||
);
|
||||
QObject::connect(
|
||||
MainCore::instance(),
|
||||
&MainCore::featureAdded,
|
||||
this,
|
||||
&Map::handleFeatureAdded
|
||||
);
|
||||
QObject::connect(
|
||||
MainCore::instance(),
|
||||
&MainCore::channelAdded,
|
||||
this,
|
||||
&Map::handleChannelAdded
|
||||
);
|
||||
QTimer::singleShot(2000, this, SLOT(scanAvailableChannelsAndFeatures()));
|
||||
}
|
||||
|
||||
Map::~Map()
|
||||
{
|
||||
QObject::disconnect(
|
||||
MainCore::instance(),
|
||||
&MainCore::featureAdded,
|
||||
this,
|
||||
&Map::handleFeatureAdded
|
||||
);
|
||||
QObject::disconnect(
|
||||
MainCore::instance(),
|
||||
&MainCore::channelAdded,
|
||||
this,
|
||||
&Map::handleChannelAdded
|
||||
);
|
||||
QObject::disconnect(
|
||||
m_networkManager,
|
||||
&QNetworkAccessManager::finished,
|
||||
@@ -85,6 +110,7 @@ bool Map::handleMessage(const Message& cmd)
|
||||
}
|
||||
else if (MainCore::MsgMapItem::match(cmd))
|
||||
{
|
||||
qDebug() << "Map::handleMessage: MsgMapItem";
|
||||
MainCore::MsgMapItem& msgMapItem = (MainCore::MsgMapItem&) cmd;
|
||||
MainCore::MsgMapItem *copy = new MainCore::MsgMapItem(msgMapItem);
|
||||
getMessageQueueToGUI()->push(copy);
|
||||
@@ -96,23 +122,6 @@ bool Map::handleMessage(const Message& cmd)
|
||||
}
|
||||
}
|
||||
|
||||
void Map::updatePipes()
|
||||
{
|
||||
QList<AvailablePipeSource> availablePipes = updateAvailablePipeSources("mapitems", MapSettings::m_pipeTypes, MapSettings::m_pipeURIs, this);
|
||||
|
||||
if (availablePipes != m_availablePipes)
|
||||
{
|
||||
m_availablePipes = availablePipes;
|
||||
if (getMessageQueueToGUI())
|
||||
{
|
||||
MsgReportPipes *msgToGUI = MsgReportPipes::create();
|
||||
QList<AvailablePipeSource>& msgAvailablePipes = msgToGUI->getAvailablePipes();
|
||||
msgAvailablePipes.append(availablePipes);
|
||||
getMessageQueueToGUI()->push(msgToGUI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray Map::serialize() const
|
||||
{
|
||||
return m_settings.serialize();
|
||||
@@ -435,3 +444,164 @@ QDateTime Map::getMapDateTime()
|
||||
return m_mapDateTime.addMSecs(diffMsecs * m_multiplier);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::scanAvailableChannelsAndFeatures()
|
||||
{
|
||||
qDebug("Map::scanAvailableChannelsAndFeatures");
|
||||
std::vector<FeatureSet*>& featureSets = MainCore::instance()->getFeatureeSets();
|
||||
m_availableChannelOrFeatures.clear();
|
||||
|
||||
for (const auto& featureSet : featureSets)
|
||||
{
|
||||
for (int fei = 0; fei < featureSet->getNumberOfFeatures(); fei++)
|
||||
{
|
||||
Feature *feature = featureSet->getFeatureAt(fei);
|
||||
|
||||
if (MapSettings::m_pipeURIs.contains(feature->getURI()) && !m_availableChannelOrFeatures.contains(feature))
|
||||
{
|
||||
qDebug("Map::scanAvailableChannelsAndFeatures: store feature %d:%d %s (%p)",
|
||||
featureSet->getIndex(), fei, qPrintable(feature->getURI()), feature);
|
||||
registerPipe(feature);
|
||||
MapSettings::AvailableChannelOrFeature availableItem =
|
||||
MapSettings::AvailableChannelOrFeature{
|
||||
"F",
|
||||
featureSet->getIndex(),
|
||||
fei,
|
||||
feature->getIdentifier(),
|
||||
feature
|
||||
};
|
||||
m_availableChannelOrFeatures[feature] = availableItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DeviceSet*>& deviceSets = MainCore::instance()->getDeviceSets();
|
||||
|
||||
for (const auto& deviceSet : deviceSets)
|
||||
{
|
||||
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
|
||||
|
||||
if (deviceSourceEngine)
|
||||
{
|
||||
for (int chi = 0; chi < deviceSet->getNumberOfChannels(); chi++)
|
||||
{
|
||||
ChannelAPI *channel = deviceSet->getChannelAt(chi);
|
||||
|
||||
if (MapSettings::m_pipeURIs.contains(channel->getURI()) && !m_availableChannelOrFeatures.contains(channel))
|
||||
{
|
||||
qDebug("Map::scanAvailableChannelsAndFeatures: store channel %d:%d %s (%p)",
|
||||
deviceSet->getIndex(), chi, qPrintable(channel->getURI()), channel);
|
||||
registerPipe(channel);
|
||||
MapSettings::AvailableChannelOrFeature availableItem =
|
||||
MapSettings::AvailableChannelOrFeature{
|
||||
"R",
|
||||
deviceSet->getIndex(),
|
||||
chi,
|
||||
channel->getIdentifier(),
|
||||
channel};
|
||||
m_availableChannelOrFeatures[channel] = availableItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notifyUpdate();
|
||||
}
|
||||
|
||||
void Map::handleFeatureAdded(int featureSetIndex, Feature *feature)
|
||||
{
|
||||
FeatureSet *featureSet = MainCore::instance()->getFeatureeSets()[featureSetIndex];
|
||||
|
||||
if (MapSettings::m_pipeURIs.contains(feature->getURI()))
|
||||
{
|
||||
qDebug("Map::handleFeatureAdded: featureSetIndex: %d:%d feature: %s (%p)",
|
||||
featureSetIndex, feature->getIndexInFeatureSet(), qPrintable(feature->getURI()), feature);
|
||||
registerPipe(feature);
|
||||
MapSettings::AvailableChannelOrFeature availableItem =
|
||||
MapSettings::AvailableChannelOrFeature{
|
||||
"F",
|
||||
featureSet->getIndex(),
|
||||
feature->getIndexInFeatureSet(),
|
||||
feature->getIdentifier(),
|
||||
feature
|
||||
};
|
||||
m_availableChannelOrFeatures[feature] = availableItem;
|
||||
notifyUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void Map::handleChannelAdded(int deviceSetIndex, ChannelAPI *channel)
|
||||
{
|
||||
DeviceSet *deviceSet = MainCore::instance()->getDeviceSets()[deviceSetIndex];
|
||||
DSPDeviceSourceEngine *deviceSourceEngine = deviceSet->m_deviceSourceEngine;
|
||||
|
||||
if (deviceSourceEngine && MapSettings::m_pipeURIs.contains(channel->getURI()))
|
||||
{
|
||||
qDebug("Map::handleChannelAdded: deviceSetIndex: %d:%d channel: %s (%p)",
|
||||
deviceSetIndex, channel->getIndexInDeviceSet(), qPrintable(channel->getURI()), channel);
|
||||
registerPipe(channel);
|
||||
MapSettings::AvailableChannelOrFeature availableItem =
|
||||
MapSettings::AvailableChannelOrFeature{
|
||||
"R",
|
||||
deviceSet->getIndex(),
|
||||
channel->getIndexInDeviceSet(),
|
||||
channel->getIdentifier(),
|
||||
channel
|
||||
};
|
||||
m_availableChannelOrFeatures[channel] = availableItem;
|
||||
notifyUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void Map::registerPipe(QObject *object)
|
||||
{
|
||||
qDebug("Map::registerPipe: register %s (%p)", qPrintable(object->objectName()), object);
|
||||
MessagePipes& messagePipes = MainCore::instance()->getMessagePipes();
|
||||
ObjectPipe *pipe = messagePipes.registerProducerToConsumer(object, this, "mapitems");
|
||||
MessageQueue *messageQueue = qobject_cast<MessageQueue*>(pipe->m_element);
|
||||
QObject::connect(
|
||||
messageQueue,
|
||||
&MessageQueue::messageEnqueued,
|
||||
this,
|
||||
[=](){ this->handlePipeMessageQueue(messageQueue); },
|
||||
Qt::QueuedConnection
|
||||
);
|
||||
QObject::connect(
|
||||
pipe,
|
||||
&ObjectPipe::toBeDeleted,
|
||||
this,
|
||||
&Map::handleMessagePipeToBeDeleted
|
||||
);
|
||||
}
|
||||
|
||||
void Map::notifyUpdate()
|
||||
{
|
||||
if (getMessageQueueToGUI())
|
||||
{
|
||||
MsgReportAvailableChannelOrFeatures *msg = MsgReportAvailableChannelOrFeatures::create();
|
||||
msg->getItems() = m_availableChannelOrFeatures.values();
|
||||
getMessageQueueToGUI()->push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void Map::handleMessagePipeToBeDeleted(int reason, QObject* object)
|
||||
{
|
||||
if ((reason == 0) && m_availableChannelOrFeatures.contains(object)) // producer
|
||||
{
|
||||
qDebug("Map::handleMessagePipeToBeDeleted: removing channel or feature at (%p)", object);
|
||||
m_availableChannelOrFeatures.remove(object);
|
||||
notifyUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void Map::handlePipeMessageQueue(MessageQueue* messageQueue)
|
||||
{
|
||||
Message* message;
|
||||
|
||||
while ((message = messageQueue->pop()) != nullptr)
|
||||
{
|
||||
if (handleMessage(*message)) {
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <QThread>
|
||||
#include <QHash>
|
||||
#include <QNetworkRequest>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QMutex>
|
||||
|
||||
@@ -103,6 +102,24 @@ public:
|
||||
{}
|
||||
};
|
||||
|
||||
class MsgReportAvailableChannelOrFeatures : public Message {
|
||||
MESSAGE_CLASS_DECLARATION
|
||||
|
||||
public:
|
||||
QList<MapSettings::AvailableChannelOrFeature>& getItems() { return m_availableChannelOrFeatures; }
|
||||
|
||||
static MsgReportAvailableChannelOrFeatures* create() {
|
||||
return new MsgReportAvailableChannelOrFeatures();
|
||||
}
|
||||
|
||||
private:
|
||||
QList<MapSettings::AvailableChannelOrFeature> m_availableChannelOrFeatures;
|
||||
|
||||
MsgReportAvailableChannelOrFeatures() :
|
||||
Message()
|
||||
{}
|
||||
};
|
||||
|
||||
Map(WebAPIAdapterInterface *webAPIAdapterInterface);
|
||||
virtual ~Map();
|
||||
virtual void destroy() { delete this; }
|
||||
@@ -156,8 +173,7 @@ public:
|
||||
private:
|
||||
QThread m_thread;
|
||||
MapSettings m_settings;
|
||||
QList<AvailablePipeSource> m_availablePipes;
|
||||
QTimer m_updatePipesTimer;
|
||||
QHash<QObject*, MapSettings::AvailableChannelOrFeature> m_availableChannelOrFeatures;
|
||||
|
||||
QNetworkAccessManager *m_networkManager;
|
||||
QNetworkRequest m_networkRequest;
|
||||
@@ -165,6 +181,8 @@ private:
|
||||
void applySettings(const MapSettings& settings, bool force = false);
|
||||
void webapiFormatFeatureReport(SWGSDRangel::SWGFeatureReport& response);
|
||||
void webapiReverseSendSettings(QList<QString>& featureSettingsKeys, const MapSettings& settings, bool force);
|
||||
void registerPipe(QObject *object);
|
||||
void notifyUpdate();
|
||||
|
||||
QDateTime m_mapDateTime;
|
||||
QDateTime m_systemDateTime;
|
||||
@@ -172,8 +190,12 @@ private:
|
||||
QMutex m_dateTimeMutex;
|
||||
|
||||
private slots:
|
||||
void updatePipes();
|
||||
void networkManagerFinished(QNetworkReply *reply);
|
||||
void scanAvailableChannelsAndFeatures();
|
||||
void handleFeatureAdded(int featureSetIndex, Feature *feature);
|
||||
void handleChannelAdded(int deviceSetIndex, ChannelAPI *channel);
|
||||
void handleMessagePipeToBeDeleted(int reason, QObject* object);
|
||||
void handlePipeMessageQueue(MessageQueue* messageQueue);
|
||||
};
|
||||
|
||||
#endif // INCLUDE_FEATURE_MAP_H_
|
||||
|
||||
@@ -96,10 +96,10 @@ bool MapGUI::handleMessage(const Message& message)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (PipeEndPoint::MsgReportPipes::match(message))
|
||||
else if (Map::MsgReportAvailableChannelOrFeatures::match(message))
|
||||
{
|
||||
PipeEndPoint::MsgReportPipes& report = (PipeEndPoint::MsgReportPipes&) message;
|
||||
m_availablePipes = report.getAvailablePipes();
|
||||
Map::MsgReportAvailableChannelOrFeatures& report = (Map::MsgReportAvailableChannelOrFeatures&) message;
|
||||
m_availableChannelOrFeatures = report.getItems();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -124,18 +124,20 @@ bool MapGUI::handleMessage(const Message& message)
|
||||
|
||||
// TODO: Could have this in SWGMapItem so plugins can create additional groups
|
||||
QString group;
|
||||
for (int i = 0; i < m_availablePipes.size(); i++)
|
||||
|
||||
for (int i = 0; i < m_availableChannelOrFeatures.size(); i++)
|
||||
{
|
||||
if (m_availablePipes[i].m_source == msgMapItem.getPipeSource())
|
||||
if (m_availableChannelOrFeatures[i].m_source == msgMapItem.getPipeSource())
|
||||
{
|
||||
for (int j = 0; j < MapSettings::m_pipeTypes.size(); j++)
|
||||
{
|
||||
if (m_availablePipes[i].m_id == MapSettings::m_pipeTypes[j]) {
|
||||
group = m_availablePipes[i].m_id;
|
||||
if (m_availableChannelOrFeatures[i].m_type == MapSettings::m_pipeTypes[j]) {
|
||||
group = m_availableChannelOrFeatures[i].m_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update(msgMapItem.getPipeSource(), swgMapItem, group);
|
||||
return true;
|
||||
}
|
||||
@@ -288,7 +290,7 @@ MapGUI::~MapGUI()
|
||||
}
|
||||
|
||||
// Update a map item or image
|
||||
void MapGUI::update(const PipeEndPoint *source, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group)
|
||||
void MapGUI::update(const QObject *source, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group)
|
||||
{
|
||||
if (swgMapItem->getType() == 0)
|
||||
{
|
||||
|
||||
@@ -97,7 +97,7 @@ private:
|
||||
MapSettings m_settings;
|
||||
RollupState m_rollupState;
|
||||
bool m_doApplySettings;
|
||||
QList<PipeEndPoint::AvailablePipeSource> m_availablePipes;
|
||||
QList<MapSettings::AvailableChannelOrFeature> m_availableChannelOrFeatures;
|
||||
|
||||
Map* m_map;
|
||||
MessageQueue m_inputMessageQueue;
|
||||
@@ -119,7 +119,7 @@ private:
|
||||
explicit MapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent = nullptr);
|
||||
virtual ~MapGUI();
|
||||
|
||||
void update(const PipeEndPoint *source, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group);
|
||||
void update(const QObject *source, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group);
|
||||
void blockApplySettings(bool block);
|
||||
void applySettings(bool force = false);
|
||||
void applyMap2DSettings(bool reloadMap);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include "SWGTargetAzimuthElevation.h"
|
||||
|
||||
MapItem::MapItem(const PipeEndPoint *sourcePipe, const QString &group, MapSettings::MapItemSettings *itemSettings, SWGSDRangel::SWGMapItem *mapItem) :
|
||||
MapItem::MapItem(const QObject *sourcePipe, const QString &group, MapSettings::MapItemSettings *itemSettings, SWGSDRangel::SWGMapItem *mapItem) :
|
||||
m_altitude(0.0)
|
||||
{
|
||||
m_sourcePipe = sourcePipe;
|
||||
@@ -216,7 +216,7 @@ Q_INVOKABLE void MapModel::add(MapItem *item)
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void MapModel::update(const PipeEndPoint *sourcePipe, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group)
|
||||
void MapModel::update(const QObject *sourcePipe, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group)
|
||||
{
|
||||
QString name = *swgMapItem->getName();
|
||||
// Add, update or delete and item
|
||||
@@ -440,7 +440,7 @@ Q_INVOKABLE void MapModel::moveToBack(int oldRow)
|
||||
}
|
||||
}
|
||||
|
||||
MapItem *MapModel::findMapItem(const PipeEndPoint *source, const QString& name)
|
||||
MapItem *MapModel::findMapItem(const QObject *source, const QString& name)
|
||||
{
|
||||
// FIXME: Should consider adding a QHash for this
|
||||
QListIterator<MapItem *> i(m_items);
|
||||
|
||||
@@ -31,13 +31,12 @@
|
||||
class MapModel;
|
||||
class MapGUI;
|
||||
class CZML;
|
||||
class PipeEndPoint;
|
||||
|
||||
// Information required about each item displayed on the map
|
||||
class MapItem {
|
||||
|
||||
public:
|
||||
MapItem(const PipeEndPoint *sourcePipe, const QString &group, MapSettings::MapItemSettings *itemSettings, SWGSDRangel::SWGMapItem *mapItem);
|
||||
MapItem(const QObject *sourcePipe, const QString &group, MapSettings::MapItemSettings *itemSettings, SWGSDRangel::SWGMapItem *mapItem);
|
||||
void update(SWGSDRangel::SWGMapItem *mapItem);
|
||||
QGeoCoordinate getCoordinates();
|
||||
|
||||
@@ -50,7 +49,7 @@ private:
|
||||
friend CZML;
|
||||
QString m_group;
|
||||
MapSettings::MapItemSettings *m_itemSettings;
|
||||
const PipeEndPoint *m_sourcePipe; // Channel/feature that created the item
|
||||
const QObject *m_sourcePipe; // Channel/feature that created the item
|
||||
QString m_name;
|
||||
QString m_label;
|
||||
float m_latitude;
|
||||
@@ -127,7 +126,7 @@ public:
|
||||
void playAnimations(MapItem *item);
|
||||
|
||||
Q_INVOKABLE void add(MapItem *item);
|
||||
void update(const PipeEndPoint *source, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group="");
|
||||
void update(const QObject *source, SWGSDRangel::SWGMapItem *swgMapItem, const QString &group="");
|
||||
void update(MapItem *item);
|
||||
void remove(MapItem *item);
|
||||
void allUpdated();
|
||||
@@ -141,7 +140,7 @@ public:
|
||||
Q_INVOKABLE void moveToFront(int oldRow);
|
||||
Q_INVOKABLE void moveToBack(int oldRow);
|
||||
|
||||
MapItem *findMapItem(const PipeEndPoint *source, const QString& name);
|
||||
MapItem *findMapItem(const QObject *source, const QString& name);
|
||||
MapItem *findMapItem(const QString& name);
|
||||
QModelIndex findMapItemIndex(const QString& name);
|
||||
|
||||
|
||||
@@ -51,6 +51,26 @@ struct MapSettings
|
||||
bool deserialize(const QByteArray& data);
|
||||
};
|
||||
|
||||
struct AvailableChannelOrFeature
|
||||
{
|
||||
QString m_kind; //!< "R" for channel, "F" for feature
|
||||
int m_superIndex;
|
||||
int m_index;
|
||||
QString m_type;
|
||||
QObject *m_source;
|
||||
|
||||
AvailableChannelOrFeature() = default;
|
||||
AvailableChannelOrFeature(const AvailableChannelOrFeature&) = default;
|
||||
AvailableChannelOrFeature& operator=(const AvailableChannelOrFeature&) = default;
|
||||
bool operator==(const AvailableChannelOrFeature& a) const {
|
||||
return (m_kind == a.m_kind)
|
||||
&& (m_superIndex == a.m_superIndex)
|
||||
&& (m_index == a.m_index)
|
||||
&& (m_type == a.m_type)
|
||||
&& (m_source == a.m_source);
|
||||
}
|
||||
};
|
||||
|
||||
bool m_displayNames;
|
||||
QString m_mapProvider;
|
||||
QString m_thunderforestAPIKey;
|
||||
|
||||
Reference in New Issue
Block a user