From 5ec2133782b79029a90f40d82ac87b4f338393be Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 21 Mar 2022 10:14:35 +0000 Subject: [PATCH] Update station icon on map when My Position preference changes --- plugins/channelrx/demodadsb/adsbdemodgui.cpp | 55 +++++++++++++++++ plugins/channelrx/demodadsb/adsbdemodgui.h | 1 + plugins/channelrx/demodadsb/readme.md | 2 +- plugins/feature/map/mapgui.cpp | 64 +++++++++++++++----- plugins/feature/map/mapgui.h | 2 + plugins/feature/map/mapmodel.cpp | 7 ++- plugins/feature/map/mapsettings.cpp | 4 +- plugins/feature/map/readme.md | 2 +- 8 files changed, 116 insertions(+), 21 deletions(-) diff --git a/plugins/channelrx/demodadsb/adsbdemodgui.cpp b/plugins/channelrx/demodadsb/adsbdemodgui.cpp index 525c671e5..91ba74d06 100644 --- a/plugins/channelrx/demodadsb/adsbdemodgui.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodgui.cpp @@ -3802,6 +3802,9 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb ui->warning->setText("Please set your antenna location under Preferences > My Position"); } + // Get updated when position changes + connect(&MainCore::instance()->getSettings(), &MainSettings::preferenceChanged, this, &ADSBDemodGUI::preferenceChanged); + // Add airports within range of My Position if (m_airportInfo != nullptr) { updateAirports(); @@ -4587,3 +4590,55 @@ void ADSBDemodGUI::handleImportReply(QNetworkReply* reply) reply->deleteLater(); } } + +void ADSBDemodGUI::preferenceChanged(int elementType) +{ + Preferences::ElementType pref = (Preferences::ElementType)elementType; + if ((pref == Preferences::Latitude) || (pref == Preferences::Longitude) || (pref == Preferences::Altitude)) + { + Real stationLatitude = MainCore::instance()->getSettings().getLatitude(); + Real stationLongitude = MainCore::instance()->getSettings().getLongitude(); + Real stationAltitude = MainCore::instance()->getSettings().getAltitude(); + + if ( (stationLatitude != m_azEl.getLocationSpherical().m_latitude) + || (stationLongitude != m_azEl.getLocationSpherical().m_longitude) + || (stationAltitude != m_azEl.getLocationSpherical().m_altitude)) + { + m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude); + + // Update distances and what is visible + updateAirports(); + updateAirspaces(); + updateNavAids(); + + // Update icon position on Map + QQuickItem *item = ui->map->rootObject(); + QObject *map = item->findChild("map"); + if (map != nullptr) + { + QObject *stationObject = map->findChild("station"); + if(stationObject != NULL) + { + QGeoCoordinate coords = stationObject->property("coordinate").value(); + coords.setLatitude(stationLatitude); + coords.setLongitude(stationLongitude); + coords.setAltitude(stationAltitude); + stationObject->setProperty("coordinate", QVariant::fromValue(coords)); + } + } + } + } + if (pref == Preferences::StationName) + { + // Update icon label on Map + QQuickItem *item = ui->map->rootObject(); + QObject *map = item->findChild("map"); + if (map != nullptr) + { + QObject *stationObject = map->findChild("station"); + if(stationObject != NULL) { + stationObject->setProperty("stationName", QVariant::fromValue(MainCore::instance()->getSettings().getStationName())); + } + } + } +} diff --git a/plugins/channelrx/demodadsb/adsbdemodgui.h b/plugins/channelrx/demodadsb/adsbdemodgui.h index 8ca93d000..fd898afb2 100644 --- a/plugins/channelrx/demodadsb/adsbdemodgui.h +++ b/plugins/channelrx/demodadsb/adsbdemodgui.h @@ -942,6 +942,7 @@ private slots: virtual bool eventFilter(QObject *obj, QEvent *event); void import(); void handleImportReply(QNetworkReply* reply); + void preferenceChanged(int elementType); signals: void homePositionChanged(); diff --git a/plugins/channelrx/demodadsb/readme.md b/plugins/channelrx/demodadsb/readme.md index 54e2de187..48cc25afb 100644 --- a/plugins/channelrx/demodadsb/readme.md +++ b/plugins/channelrx/demodadsb/readme.md @@ -275,7 +275,7 @@ The map displays aircraft locations and data geographically. Four types of map c ![ADS-B Demodulator Map](../../../doc/img/ADSBDemod_plugin_map2.png) -The initial antenna location is placed according to My Position set under the Preferences > My Position menu. The position is only updated when the ADS-B demodulator plugin is first opened. +The antenna location is placed according to My Position set under the Preferences > My Position menu. If My Position is not set correctly, the position of aircraft may not be computed correctly. Aircraft are only placed upon the map when a position can be calculated, which can require several frames to be received. diff --git a/plugins/feature/map/mapgui.cpp b/plugins/feature/map/mapgui.cpp index cbf49acb9..0509eeee1 100644 --- a/plugins/feature/map/mapgui.cpp +++ b/plugins/feature/map/mapgui.cpp @@ -232,21 +232,24 @@ MapGUI::MapGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *featur } // Create antenna at My Position - SWGSDRangel::SWGMapItem antennaMapItem; - antennaMapItem.setName(new QString(MainCore::instance()->getSettings().getStationName())); - antennaMapItem.setLatitude(stationLatitude); - antennaMapItem.setLongitude(stationLongitude); - antennaMapItem.setAltitude(stationAltitude); - antennaMapItem.setImage(new QString("antenna.png")); - antennaMapItem.setImageRotation(0); - antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName())); - antennaMapItem.setModel(new QString("antenna.glb")); - antennaMapItem.setFixedPosition(true); - antennaMapItem.setOrientation(0); - antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName())); - antennaMapItem.setLabelAltitudeOffset(4.5); - antennaMapItem.setAltitudeReference(1); - update(m_map, &antennaMapItem, "Station"); + //m_antennaMapItem.setName(new QString(MainCore::instance()->getSettings().getStationName())); + m_antennaMapItem.setName(new QString("Station")); + m_antennaMapItem.setLatitude(stationLatitude); + m_antennaMapItem.setLongitude(stationLongitude); + m_antennaMapItem.setAltitude(stationAltitude); + m_antennaMapItem.setImage(new QString("antenna.png")); + m_antennaMapItem.setImageRotation(0); + m_antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName())); + m_antennaMapItem.setModel(new QString("antenna.glb")); + m_antennaMapItem.setFixedPosition(true); + m_antennaMapItem.setOrientation(0); + m_antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName())); + m_antennaMapItem.setLabelAltitudeOffset(4.5); + m_antennaMapItem.setAltitudeReference(1); + update(m_map, &m_antennaMapItem, "Station"); + + // Get updated when position changes + connect(&MainCore::instance()->getSettings(), &MainSettings::preferenceChanged, this, &MapGUI::preferenceChanged); // Read beacons, if they exist QList *beacons = Beacon::readIARUCSV(MapGUI::getBeaconFilename()); @@ -1177,3 +1180,34 @@ void MapGUI::fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest) ui->splitter->addWidget(ui->web); } } + +void MapGUI::preferenceChanged(int elementType) +{ + Preferences::ElementType pref = (Preferences::ElementType)elementType; + if ((pref == Preferences::Latitude) || (pref == Preferences::Longitude) || (pref == Preferences::Altitude)) + { + float stationLatitude = MainCore::instance()->getSettings().getLatitude(); + float stationLongitude = MainCore::instance()->getSettings().getLongitude(); + float stationAltitude = MainCore::instance()->getSettings().getAltitude(); + + if ( (stationLatitude != m_azEl.getLocationSpherical().m_latitude) + || (stationLongitude != m_azEl.getLocationSpherical().m_longitude) + || (stationAltitude != m_azEl.getLocationSpherical().m_altitude)) + { + // Update position of station + m_azEl.setLocation(stationLatitude, stationLongitude, stationAltitude); + + m_antennaMapItem.setLatitude(stationLatitude); + m_antennaMapItem.setLongitude(stationLongitude); + m_antennaMapItem.setAltitude(stationAltitude); + update(m_map, &m_antennaMapItem, "Station"); + } + } + if (pref == Preferences::StationName) + { + // Update station name + m_antennaMapItem.setLabel(new QString(MainCore::instance()->getSettings().getStationName())); + m_antennaMapItem.setText(new QString(MainCore::instance()->getSettings().getStationName())); + update(m_map, &m_antennaMapItem, "Station"); + } +} diff --git a/plugins/feature/map/mapgui.h b/plugins/feature/map/mapgui.h index 1fc55ce14..51d2f00c9 100644 --- a/plugins/feature/map/mapgui.h +++ b/plugins/feature/map/mapgui.h @@ -103,6 +103,7 @@ private: MessageQueue m_inputMessageQueue; MapModel m_mapModel; AzEl m_azEl; // Position of station + SWGSDRangel::SWGMapItem m_antennaMapItem; QList *m_beacons; MapBeaconDialog m_beaconDialog; MapIBPBeaconDialog m_ibpBeaconDialog; @@ -158,6 +159,7 @@ private slots: virtual void showEvent(QShowEvent *event); virtual bool eventFilter(QObject *obj, QEvent *event); void fullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest); + void preferenceChanged(int elementType); }; diff --git a/plugins/feature/map/mapmodel.cpp b/plugins/feature/map/mapmodel.cpp index 03d611369..6b25e63e1 100644 --- a/plugins/feature/map/mapmodel.cpp +++ b/plugins/feature/map/mapmodel.cpp @@ -231,7 +231,7 @@ void MapModel::update(const PipeEndPoint *sourcePipe, SWGSDRangel::SWGMapItem *s remove(item); // Need to call update, for it to be removed in 3D map // Item is set to not be available from this point in time - // It will still be avialable if time is set in the past + // It will still be available if time is set in the past item->update(swgMapItem); } else @@ -508,11 +508,12 @@ QVariant MapModel::data(const QModelIndex &index, int role) const else if (role == MapModel::mapTextRole) { // Create the text to go in the bubble next to the image + QString name = m_items[row]->m_label.isEmpty() ? m_items[row]->m_name : m_items[row]->m_label; if (row == m_target) { AzEl *azEl = m_gui->getAzEl(); QString text = QString("%1
Az: %2%5 El: %3%5 Dist: %4 km") - .arg(m_selected[row] ? m_items[row]->m_text : m_items[row]->m_name) + .arg(m_selected[row] ? m_items[row]->m_text : name) .arg(std::round(azEl->getAzimuth())) .arg(std::round(azEl->getElevation())) .arg(std::round(azEl->getDistance() / 1000.0)) @@ -525,7 +526,7 @@ QVariant MapModel::data(const QModelIndex &index, int role) const } else { - return QVariant::fromValue(m_items[row]->m_name); + return QVariant::fromValue(name); } } else if (role == MapModel::mapTextVisibleRole) diff --git a/plugins/feature/map/mapsettings.cpp b/plugins/feature/map/mapsettings.cpp index 7ba01fd0c..732e58502 100644 --- a/plugins/feature/map/mapsettings.cpp +++ b/plugins/feature/map/mapsettings.cpp @@ -69,7 +69,9 @@ MapSettings::MapSettings() : m_itemSettings.insert("RadioSonde", new MapItemSettings("RadioSonde", QColor(102, 0, 102), false, 11, modelMinPixelSize)); m_itemSettings.insert("Radio Time Transmitters", new MapItemSettings("Radio Time Transmitters", QColor(255, 0, 0), true, 8)); m_itemSettings.insert("Radar", new MapItemSettings("Radar", QColor(255, 0, 0), true, 8)); - m_itemSettings.insert("Station", new MapItemSettings("Station", QColor(255, 0, 0), true, 11)); + MapItemSettings *stationItemSettings = new MapItemSettings("Station", QColor(255, 0, 0), true, 11); + stationItemSettings->m_display2DTrack = false; + m_itemSettings.insert("Station", stationItemSettings); resetToDefaults(); } diff --git a/plugins/feature/map/readme.md b/plugins/feature/map/readme.md index b05db2691..35e9208f7 100644 --- a/plugins/feature/map/readme.md +++ b/plugins/feature/map/readme.md @@ -141,7 +141,7 @@ These are not included with the SDRangel distribution, so must be downloaded. The map feature displays a 2D and a 3D map overlaid with objects reported by other SDRangel channels and features, as well as beacon locations. -* The "Home Station" antenna location is placed according to My Position set under the Preferences > My Position menu. The position is only updated when the Map plugin is first opened. +* The "Home Station" antenna location is placed according to My Position set under the Preferences > My Position menu. * To pan around the map, click the left mouse button and drag. To zoom in or out, use the mouse scroll wheel. * Single clicking on an object in the map will display a text bubble with additional information about the object. * Right clicking on a object on the 2D map will open a context menu, which allows: