From d72d26dfd982b00b02c0d60c3de0d73de9681d6a Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sat, 3 Feb 2024 13:38:09 -0800 Subject: [PATCH 1/3] Add support for displaying cardinal directions instead of headings. --- src/config/ReportingConfiguration.cpp | 5 +++ src/config/ReportingConfiguration.h | 1 + src/gui/dialogs/dlg_options.cpp | 8 +++++ src/gui/dialogs/dlg_options.h | 1 + src/gui/dialogs/freedv_reporter.cpp | 49 ++++++++++++++++++++++++--- src/gui/dialogs/freedv_reporter.h | 1 + 6 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/config/ReportingConfiguration.cpp b/src/config/ReportingConfiguration.cpp index 6df90788e..e5b320618 100644 --- a/src/config/ReportingConfiguration.cpp +++ b/src/config/ReportingConfiguration.cpp @@ -80,6 +80,7 @@ ReportingConfiguration::ReportingConfiguration() , freedvReporterMsgRowForegroundColor("/Reporting/FreeDV/MsgRowForegroundColor", "#000000") , reportingFrequencyAsKhz("/Reporting/FrequencyAsKHz", false) + , reportingDirectionAsCardinal("/Reporting/DirectionAsCardinal", false) { // Special handling for the frequency list to properly handle locales reportingFrequencyList.setLoadProcessor([this](std::vector list) { @@ -196,6 +197,8 @@ void ReportingConfiguration::load(wxConfigBase* config) load_(config, freedvReporterMsgRowBackgroundColor); load_(config, freedvReporterMsgRowForegroundColor); + load_(config, reportingDirectionAsCardinal); + // Special load handling for reporting below. wxString freqStr = config->Read(reportingFrequency.getElementName(), oldFreqStr); reportingFrequency.setWithoutProcessing(atoll(freqStr.ToUTF8())); @@ -235,6 +238,8 @@ void ReportingConfiguration::save(wxConfigBase* config) save_(config, freedvReporterRxRowForegroundColor); save_(config, freedvReporterMsgRowBackgroundColor); save_(config, freedvReporterMsgRowForegroundColor); + + save_(config, reportingDirectionAsCardinal); // Special save handling for reporting below. wxString tempFreqStr = wxString::Format(wxT("%" PRIu64), reportingFrequency.getWithoutProcessing()); diff --git a/src/config/ReportingConfiguration.h b/src/config/ReportingConfiguration.h index 61fdefadd..bfc0a89fa 100644 --- a/src/config/ReportingConfiguration.h +++ b/src/config/ReportingConfiguration.h @@ -69,6 +69,7 @@ class ReportingConfiguration : public WxWidgetsConfigStore ConfigurationDataElement freedvReporterMsgRowForegroundColor; ConfigurationDataElement reportingFrequencyAsKhz; + ConfigurationDataElement reportingDirectionAsCardinal; virtual void load(wxConfigBase* config) override; virtual void save(wxConfigBase* config) override; diff --git a/src/gui/dialogs/dlg_options.cpp b/src/gui/dialogs/dlg_options.cpp index a896b7ecd..607807fde 100644 --- a/src/gui/dialogs/dlg_options.cpp +++ b/src/gui/dialogs/dlg_options.cpp @@ -146,6 +146,9 @@ OptionsDlg::OptionsDlg(wxWindow* parent, wxWindowID id, const wxString& title, c m_useMetricDistances = new wxCheckBox(m_reportingTab, wxID_ANY, _("Distances in km"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizerReportingFreeDVNoCall->Add(m_useMetricDistances, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + m_useCardinalDirections = new wxCheckBox(m_reportingTab, wxID_ANY, _("Show cardinal directions"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); + sbSizerReportingFreeDVNoCall->Add(m_useCardinalDirections, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + m_ckboxFreeDVReporterForceReceiveOnly = new wxCheckBox(m_reportingTab, wxID_ANY, _("Force RX Only reporting"), wxDefaultPosition, wxDefaultSize, wxCHK_2STATE); sbSizerReportingFreeDVNoCall->Add(m_ckboxFreeDVReporterForceReceiveOnly, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); @@ -880,6 +883,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) m_ckboxFreeDVReporterEnable->SetValue(wxGetApp().appConfiguration.reportingConfiguration.freedvReporterEnabled); m_freedvReporterHostname->SetValue(wxGetApp().appConfiguration.reportingConfiguration.freedvReporterHostname); m_useMetricDistances->SetValue(wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances); + m_useCardinalDirections->SetValue(wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal); m_ckboxFreeDVReporterForceReceiveOnly->SetValue(wxGetApp().appConfiguration.reportingConfiguration.freedvReporterForceReceiveOnly); // Callsign list config @@ -1052,6 +1056,7 @@ void OptionsDlg::ExchangeData(int inout, bool storePersistent) wxGetApp().appConfiguration.reportingConfiguration.freedvReporterHostname = m_freedvReporterHostname->GetValue(); wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances = m_useMetricDistances->GetValue(); wxGetApp().appConfiguration.reportingConfiguration.freedvReporterForceReceiveOnly = m_ckboxFreeDVReporterForceReceiveOnly->GetValue(); + wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal = m_useCardinalDirections->GetValue(); // Callsign list config wxGetApp().appConfiguration.reportingConfiguration.useUTCForReporting = m_ckbox_use_utc_time->GetValue(); @@ -1286,6 +1291,7 @@ void OptionsDlg::updateReportingState() m_ckboxPskReporterEnable->Enable(true); m_ckboxFreeDVReporterEnable->Enable(true); m_ckboxFreeDVReporterForceReceiveOnly->Enable(true); + m_useCardinalDirections->Enable(true); } else { @@ -1296,6 +1302,7 @@ void OptionsDlg::updateReportingState() m_ckboxFreeDVReporterEnable->Enable(false); m_ckboxManualFrequencyReporting->Enable(false); m_ckboxFreeDVReporterForceReceiveOnly->Enable(true); + m_useCardinalDirections->Enable(true); } } else @@ -1311,6 +1318,7 @@ void OptionsDlg::updateReportingState() m_useMetricDistances->Enable(false); m_freedvReporterHostname->Enable(false); m_ckboxFreeDVReporterForceReceiveOnly->Enable(false); + m_useCardinalDirections->Enable(false); m_ckbox_use_utc_time->Enable(false); } diff --git a/src/gui/dialogs/dlg_options.h b/src/gui/dialogs/dlg_options.h index ce21a0fe1..1bb40df8e 100644 --- a/src/gui/dialogs/dlg_options.h +++ b/src/gui/dialogs/dlg_options.h @@ -149,6 +149,7 @@ class OptionsDlg : public wxDialog wxCheckBox *m_ckboxFreeDVReporterEnable; wxTextCtrl *m_freedvReporterHostname; wxCheckBox *m_useMetricDistances; + wxCheckBox *m_useCardinalDirections; wxCheckBox *m_ckboxFreeDVReporterForceReceiveOnly; wxButton* m_BtnFifoReset; diff --git a/src/gui/dialogs/freedv_reporter.cpp b/src/gui/dialogs/freedv_reporter.cpp index 645414fac..6cc1fc164 100644 --- a/src/gui/dialogs/freedv_reporter.cpp +++ b/src/gui/dialogs/freedv_reporter.cpp @@ -425,7 +425,7 @@ void FreeDVReporterDialog::refreshLayout() #endif // defined(WIN32) wxListItem item; - m_listSpots->GetColumn(2 + colOffset, item); + m_listSpots->GetColumn(DISTANCE_COL + colOffset, item); if (wxGetApp().appConfiguration.reportingConfiguration.useMetricDistances) { @@ -436,10 +436,10 @@ void FreeDVReporterDialog::refreshLayout() item.SetText("Miles"); } - m_listSpots->SetColumn(2 + colOffset, item); + m_listSpots->SetColumn(DISTANCE_COL + colOffset, item); // Refresh frequency units as appropriate. - m_listSpots->GetColumn(5 + colOffset, item); + m_listSpots->GetColumn(FREQUENCY_COL + colOffset, item); if (wxGetApp().appConfiguration.reportingConfiguration.reportingFrequencyAsKhz) { item.SetText("kHz"); @@ -448,7 +448,19 @@ void FreeDVReporterDialog::refreshLayout() { item.SetText("MHz"); } - m_listSpots->SetColumn(5 + colOffset, item); + m_listSpots->SetColumn(FREQUENCY_COL + colOffset, item); + + // Change direction/heading column label based on preferences + m_listSpots->GetColumn(HEADING_COL + colOffset, item); + if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal) + { + item.SetText("Dir"); + } + else + { + item.SetText("Hdg"); + } + m_listSpots->SetColumn(HEADING_COL + colOffset, item); std::map colResizeList; for (auto& kvp : allReporterData_) @@ -467,6 +479,19 @@ void FreeDVReporterDialog::refreshLayout() } kvp.second->freqString = frequencyString; + + // Refresh cardinal vs. degree directions. + if (wxGetApp().appConfiguration.reportingConfiguration.reportingGridSquare != kvp.second->gridSquare) + { + if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal) + { + kvp.second->heading = GetCardinalDirection_(kvp.second->headingVal); + } + else + { + kvp.second->heading = wxString::Format("%.0f", kvp.second->headingVal); + } + } addOrUpdateListIfNotFiltered_(kvp.second, colResizeList); } @@ -1328,7 +1353,14 @@ void FreeDVReporterDialog::onUserConnectFn_(std::string sid, std::string lastUpd else { temp->headingVal = calculateBearingInDegrees_(wxGetApp().appConfiguration.reportingConfiguration.reportingGridSquare, gridSquareWxString); - temp->heading = wxString::Format("%.0f", temp->headingVal); + if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal) + { + temp->heading = GetCardinalDirection_(temp->headingVal); + } + else + { + temp->heading = wxString::Format("%.0f", temp->headingVal); + } } } @@ -1897,3 +1929,10 @@ bool FreeDVReporterDialog::isFiltered_(uint64_t freq) freq != filteredFrequency_); } } + +wxString FreeDVReporterDialog::GetCardinalDirection_(int degrees) +{ + int cardinalDirectionNumber( static_cast( ( ( degrees / 360.0 ) * 16 ) + 0.5 ) % 16 ); + const char* const cardinalDirectionTexts[] = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "SW", "WNW", "NW", "NNW" }; + return cardinalDirectionTexts[cardinalDirectionNumber]; +} \ No newline at end of file diff --git a/src/gui/dialogs/freedv_reporter.h b/src/gui/dialogs/freedv_reporter.h index 19933ad39..ec39e6a2a 100644 --- a/src/gui/dialogs/freedv_reporter.h +++ b/src/gui/dialogs/freedv_reporter.h @@ -208,6 +208,7 @@ class FreeDVReporterDialog : public wxFrame static wxCALLBACK int ListCompareFn_(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData); static double DegreesToRadians_(double degrees); static double RadiansToDegrees_(double radians); + static wxString GetCardinalDirection_(int degrees); }; #endif // __FREEDV_REPORTER_DIALOG__ From d813665c485bcbeb100a23d0e37548884baeef88 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sat, 3 Feb 2024 13:39:39 -0800 Subject: [PATCH 2/3] Add PR #685 to changelog. --- USER_MANUAL.md | 1 + 1 file changed, 1 insertion(+) diff --git a/USER_MANUAL.md b/USER_MANUAL.md index 901c73d73..3a85fcf46 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -906,6 +906,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes * Move TX Mode column to left of Status in FreeDV Reporter window. (PR #670) * Add heading column to FreeDV Reporter window. (PR #672, #675) * Prevent FreeDV Reporter window from being above the main window. (PR #679) + * Add support for displaying cardinal directions instead of headings. (PR #685) 3. Code cleanup: * Move FreeDV Reporter dialog code to dialogs section of codebase. (PR #664) From 91965cf1949c0f24a11f0f47d005cc5b7f46f1e6 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sun, 4 Feb 2024 16:45:32 -0800 Subject: [PATCH 3/3] Left-align directions, right-align headings. --- src/gui/dialogs/freedv_reporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/dialogs/freedv_reporter.cpp b/src/gui/dialogs/freedv_reporter.cpp index 6cc1fc164..81cb4a50d 100644 --- a/src/gui/dialogs/freedv_reporter.cpp +++ b/src/gui/dialogs/freedv_reporter.cpp @@ -455,10 +455,12 @@ void FreeDVReporterDialog::refreshLayout() if (wxGetApp().appConfiguration.reportingConfiguration.reportingDirectionAsCardinal) { item.SetText("Dir"); + item.SetAlign(wxLIST_FORMAT_LEFT); } else { item.SetText("Hdg"); + item.SetAlign(wxLIST_FORMAT_RIGHT); } m_listSpots->SetColumn(HEADING_COL + colOffset, item);