menu action cleanup/refactoring

This commit is contained in:
Charles J. Cliffe 2019-03-19 00:06:01 -04:00
parent 58d4f484e4
commit c67330e985
2 changed files with 348 additions and 298 deletions

View File

@ -1269,6 +1269,31 @@ void AppFrame::dismissRigControlPortDialog() {
#endif #endif
void AppFrame::OnMenu(wxCommandEvent &event) {
actionOnMenuAbout(event)
|| actionOnMenuSDRStartStop(event)
|| actionOnMenuPerformance(event)
|| actionOnMenuTips(event)
|| actionOnMenuIQSwap(event)
|| actionOnMenuFreqOffset(event)
|| actionOnMenuDBOffset(event)
|| actionOnMenuAGC(event)
|| actionOnMenuSDRDevices(event)
|| actionOnMenuSetPPM(event)
|| actionOnMenuLoadSave(event)
|| actionOnMenuReset(event)
|| actionOnMenuClose(event)
|| actionOnMenuSettings(event)
|| actionOnMenuSampleRate(event)
|| actionOnMenuAudioSampleRate(event)
|| actionOnMenuRecording(event)
|| actionOnMenuDisplay(event)
//Optional : Rig
|| actionOnMenuRig(event);
}
bool AppFrame::actionOnMenuDisplay(wxCommandEvent& event) { bool AppFrame::actionOnMenuDisplay(wxCommandEvent& event) {
//by default, is managed. //by default, is managed.
@ -1806,12 +1831,10 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
rigSDRIF = devConfig->getRigIF(rigModel); rigSDRIF = devConfig->getRigIF(rigModel);
if (rigSDRIF) { if (rigSDRIF) {
wxGetApp().lockFrequency(rigSDRIF); wxGetApp().lockFrequency(rigSDRIF);
} } else {
else {
wxGetApp().unlockFrequency(); wxGetApp().unlockFrequency();
} }
} } else {
else {
wxGetApp().unlockFrequency(); wxGetApp().unlockFrequency();
} }
resetRig = true; resetRig = true;
@ -1839,8 +1862,7 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
resetRig = false; resetRig = false;
if (!wxGetApp().rigIsActive()) { if (!wxGetApp().rigIsActive()) {
enableRig(); enableRig();
} } else {
else {
disableRig(); disableRig();
} }
@ -1851,15 +1873,15 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
if (devInfo != nullptr) { if (devInfo != nullptr) {
std::string deviceId = devInfo->getDeviceId(); std::string deviceId = devInfo->getDeviceId();
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId); DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId);
long long freqRigIF = wxGetNumberFromUser("Rig SDR-IF Frequency", "Frequency (Hz)", "Frequency", devConfig->getRigIF(rigModel), 0, 2000000000); long long freqRigIF = wxGetNumberFromUser("Rig SDR-IF Frequency", "Frequency (Hz)", "Frequency",
devConfig->getRigIF(rigModel), 0, 2000000000);
if (freqRigIF != -1) { if (freqRigIF != -1) {
rigSDRIF = freqRigIF; rigSDRIF = freqRigIF;
devConfig->setRigIF(rigModel, rigSDRIF); devConfig->setRigIF(rigModel, rigSDRIF);
} }
if (rigSDRIF && wxGetApp().rigIsActive()) { if (rigSDRIF && wxGetApp().rigIsActive()) {
wxGetApp().lockFrequency(rigSDRIF); wxGetApp().lockFrequency(rigSDRIF);
} } else {
else {
wxGetApp().unlockFrequency(); wxGetApp().unlockFrequency();
} }
} }
@ -1872,8 +1894,7 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
rt->setControlMode(!rt->getControlMode()); rt->setControlMode(!rt->getControlMode());
rigControlMenuItem->Check(rt->getControlMode()); rigControlMenuItem->Check(rt->getControlMode());
wxGetApp().getConfig()->setRigControlMode(rt->getControlMode()); wxGetApp().getConfig()->setRigControlMode(rt->getControlMode());
} } else {
else {
wxGetApp().getConfig()->setRigControlMode(rigControlMenuItem->IsChecked()); wxGetApp().getConfig()->setRigControlMode(rigControlMenuItem->IsChecked());
} }
bManaged = true; bManaged = true;
@ -1885,8 +1906,7 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
rt->setFollowMode(!rt->getFollowMode()); rt->setFollowMode(!rt->getFollowMode());
rigFollowMenuItem->Check(rt->getFollowMode()); rigFollowMenuItem->Check(rt->getFollowMode());
wxGetApp().getConfig()->setRigFollowMode(rt->getFollowMode()); wxGetApp().getConfig()->setRigFollowMode(rt->getFollowMode());
} } else {
else {
wxGetApp().getConfig()->setRigFollowMode(rigFollowMenuItem->IsChecked()); wxGetApp().getConfig()->setRigFollowMode(rigFollowMenuItem->IsChecked());
} }
@ -1899,8 +1919,7 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
rt->setCenterLock(!rt->getCenterLock()); rt->setCenterLock(!rt->getCenterLock());
rigCenterLockMenuItem->Check(rt->getCenterLock()); rigCenterLockMenuItem->Check(rt->getCenterLock());
wxGetApp().getConfig()->setRigCenterLock(rt->getCenterLock()); wxGetApp().getConfig()->setRigCenterLock(rt->getCenterLock());
} } else {
else {
wxGetApp().getConfig()->setRigCenterLock(rigCenterLockMenuItem->IsChecked()); wxGetApp().getConfig()->setRigCenterLock(rigCenterLockMenuItem->IsChecked());
} }
@ -1913,8 +1932,7 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
rt->setFollowModem(!rt->getFollowModem()); rt->setFollowModem(!rt->getFollowModem());
rigFollowModemMenuItem->Check(rt->getFollowModem()); rigFollowModemMenuItem->Check(rt->getFollowModem());
wxGetApp().getConfig()->setRigFollowModem(rt->getFollowModem()); wxGetApp().getConfig()->setRigFollowModem(rt->getFollowModem());
} } else {
else {
wxGetApp().getConfig()->setRigFollowModem(rigFollowModemMenuItem->IsChecked()); wxGetApp().getConfig()->setRigFollowModem(rigFollowModemMenuItem->IsChecked());
} }
@ -1930,23 +1948,88 @@ bool AppFrame::actionOnMenuRig(wxCommandEvent& event) {
return bManaged; return bManaged;
} }
bool AppFrame::actionOnMenuClose(wxCommandEvent &event) {
if (event.GetId() == wxID_CLOSE || event.GetId() == wxID_EXIT) {
Close(false);
return true;
}
return false;
}
void AppFrame::OnMenu(wxCommandEvent& event) { bool AppFrame::actionOnMenuSetPPM(wxCommandEvent &event) {
if (event.GetId() == wxID_SET_PPM) {
long ofs = wxGetNumberFromUser(
"Frequency correction for device in PPM.\ni.e. -51 for -51 PPM\n\nNote: you can adjust PPM interactively\nby holding ALT over the frequency tuning bar.\n",
"Parts per million (PPM)",
"Frequency Correction", wxGetApp().getPPM(), -1000, 1000, this);
wxGetApp().setPPM(ofs);
if (actionOnMenuAbout(event)) { settingsMenuItems[wxID_SET_PPM]->SetItemLabel(
return; getSettingsLabel("Device PPM", to_string(wxGetApp().getPPM()), "ppm"));
return true;
} }
else if (event.GetId() == wxID_SDR_START_STOP) { return false;
if (!wxGetApp().getSDRThread()->isTerminated()) {
wxGetApp().stopDevice(true, 2000);
} else {
SDRDeviceInfo *dev = wxGetApp().getDevice();
if (dev != nullptr) {
wxGetApp().setDevice(dev, 0);
} }
bool AppFrame::actionOnMenuSDRDevices(wxCommandEvent &event) {
if (event.GetId() == wxID_SDR_DEVICES) {
wxGetApp().deviceSelector();
return true;
} }
return false;
} }
else if (event.GetId() >= wxID_PERF_BASE && event.GetId() <= wxID_PERF_BASE + (int)AppConfig::PERF_HIGH) {
bool AppFrame::actionOnMenuDBOffset(wxCommandEvent &event) {
if (event.GetId() == wxID_SET_DB_OFFSET) {
long ofs = wxGetNumberFromUser("Shift the displayed RF power level by this amount.\ni.e. -30 for -30 dB",
"Decibels (dB)",
"Power Level Offset", wxGetApp().getConfig()->getDBOffset(), -1000, 1000, this);
if (ofs != -1) {
wxGetApp().getConfig()->setDBOffset(ofs);
settingsMenuItems[wxID_SET_DB_OFFSET]->SetItemLabel(
getSettingsLabel("Power Level Offset", to_string(wxGetApp().getConfig()->getDBOffset()), "dB"));
}
return true;
}
return false;
}
bool AppFrame::actionOnMenuFreqOffset(wxCommandEvent &event) {
if (event.GetId() == wxID_SET_FREQ_OFFSET) {
//enter in KHz to accomodate > 2GHz shifts for down/upconverters on 32 bit platforms.
long ofs = wxGetNumberFromUser(
"Shift the displayed frequency by this amount of KHz.\ni.e. -125000 for -125 MHz", "Frequency (KHz)",
"Frequency Offset", (long long) (wxGetApp().getOffset() / 1000.0), -2000000000, 2000000000, this);
if (ofs != -1) {
wxGetApp().setOffset((long long) ofs * 1000);
settingsMenuItems[wxID_SET_FREQ_OFFSET]->SetItemLabel(
getSettingsLabel("Frequency Offset", to_string(wxGetApp().getOffset() / 1000), "KHz"));
}
return true;
}
return false;
}
bool AppFrame::actionOnMenuIQSwap(wxCommandEvent &event) {
if (event.GetId() == wxID_SET_IQSWAP) {
wxGetApp().getSDRThread()->setIQSwap(!wxGetApp().getSDRThread()->getIQSwap());
return true;
}
return false;
}
bool AppFrame::actionOnMenuTips(wxCommandEvent &event) {
if (event.GetId() == wxID_SET_TIPS) {
wxGetApp().getConfig()->setShowTips(!wxGetApp().getConfig()->getShowTips());
return true;
}
return false;
}
bool AppFrame::actionOnMenuPerformance(wxCommandEvent &event) {
if (event.GetId() >= wxID_PERF_BASE && event.GetId() <= wxID_PERF_BASE + (int) AppConfig::PERF_HIGH) {
int perfEnumAsInt = event.GetId() - wxID_PERF_BASE; int perfEnumAsInt = event.GetId() - wxID_PERF_BASE;
AppConfig::PerfModeEnum perfEnumSet = AppConfig::PERF_NORMAL; AppConfig::PerfModeEnum perfEnumSet = AppConfig::PERF_NORMAL;
@ -1962,84 +2045,34 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
//update Channelizer mode: //update Channelizer mode:
if (perfEnumSet == AppConfig::PERF_HIGH) { if (perfEnumSet == AppConfig::PERF_HIGH) {
wxGetApp().setChannelizerType(SDRPostThreadChannelizerType::SDRPostPFBCH2); wxGetApp().setChannelizerType(SDRPostPFBCH2);
} else { } else {
wxGetApp().setChannelizerType(SDRPostThreadChannelizerType::SDRPostPFBCH); wxGetApp().setChannelizerType(SDRPostPFBCH);
} }
//update UI //update UI
wxMenuItem *selectedPerfModeItem = performanceMenuItems[event.GetId()]; wxMenuItem *selectedPerfModeItem = performanceMenuItems[event.GetId()];
performanceMenuItems[wxID_PERF_CURRENT]->SetItemLabel(getSettingsLabel("CPU usage", selectedPerfModeItem->GetItemLabel().ToStdString())); performanceMenuItems[wxID_PERF_CURRENT]->SetItemLabel(
getSettingsLabel("CPU usage", selectedPerfModeItem->GetItemLabel().ToStdString()));
return true;
} }
else if (event.GetId() == wxID_SET_TIPS ) { return false;
if (wxGetApp().getConfig()->getShowTips()) { }
wxGetApp().getConfig()->setShowTips(false);
bool AppFrame::actionOnMenuSDRStartStop(wxCommandEvent &event) {
if (event.GetId() == wxID_SDR_START_STOP) {
if (!wxGetApp().getSDRThread()->isTerminated()) {
wxGetApp().stopDevice(true, 2000);
} else { } else {
wxGetApp().getConfig()->setShowTips(true); SDRDeviceInfo *dev = wxGetApp().getDevice();
if (dev != nullptr) {
wxGetApp().setDevice(dev, 0);
} }
} }
else if (event.GetId() == wxID_SET_IQSWAP) { return true;
wxGetApp().getSDRThread()->setIQSwap(!wxGetApp().getSDRThread()->getIQSwap());
}
else if (event.GetId() == wxID_SET_FREQ_OFFSET) {
//enter in KHz to accomodate > 2GHz shifts for down/upconverters on 32 bit platforms.
long ofs = wxGetNumberFromUser("Shift the displayed frequency by this amount of KHz.\ni.e. -125000 for -125 MHz", "Frequency (KHz)",
"Frequency Offset", (long long)(wxGetApp().getOffset() / 1000.0) , -2000000000, 2000000000, this);
if (ofs != -1) {
wxGetApp().setOffset((long long) ofs * 1000);
settingsMenuItems[wxID_SET_FREQ_OFFSET]->SetItemLabel(getSettingsLabel("Frequency Offset", std::to_string(wxGetApp().getOffset() / 1000), "KHz"));
}
}
else if (event.GetId() == wxID_SET_DB_OFFSET) {
long ofs = wxGetNumberFromUser("Shift the displayed RF power level by this amount.\ni.e. -30 for -30 dB", "Decibels (dB)",
"Power Level Offset", wxGetApp().getConfig()->getDBOffset(), -1000, 1000, this);
if (ofs != -1) {
wxGetApp().getConfig()->setDBOffset(ofs);
settingsMenuItems[wxID_SET_DB_OFFSET]->SetItemLabel(getSettingsLabel("Power Level Offset", std::to_string(wxGetApp().getConfig()->getDBOffset()), "dB"));
}
}
else if (actionOnMenuAGC(event)) {
return;
}
else if (event.GetId() == wxID_SDR_DEVICES) {
wxGetApp().deviceSelector();
}
else if (event.GetId() == wxID_SET_PPM) {
long ofs = wxGetNumberFromUser("Frequency correction for device in PPM.\ni.e. -51 for -51 PPM\n\nNote: you can adjust PPM interactively\nby holding ALT over the frequency tuning bar.\n", "Parts per million (PPM)",
"Frequency Correction", wxGetApp().getPPM(), -1000, 1000, this);
wxGetApp().setPPM(ofs);
settingsMenuItems[wxID_SET_PPM]->SetItemLabel(getSettingsLabel("Device PPM", std::to_string(wxGetApp().getPPM()), "ppm"));
}
else if (actionOnMenuLoadSave(event)) {
return;
}
else if (actionOnMenuReset(event)) {
return;
}
else if (event.GetId() == wxID_CLOSE || event.GetId() == wxID_EXIT) {
Close(false);
}
else if (actionOnMenuSettings(event)) {
return;
}
else if (actionOnMenuSampleRate(event)) {
return;
}
else if (actionOnMenuAudioSampleRate(event)) {
return;
}
else if (actionOnMenuRecording(event)) {
return;
}
else if (actionOnMenuDisplay(event)) {
return;
}
//Optional : Rig
else if (actionOnMenuRig(event)) {
return;
} }
return false;
} }
void AppFrame::OnClose(wxCloseEvent& event) { void AppFrame::OnClose(wxCloseEvent& event) {
@ -2153,7 +2186,8 @@ void AppFrame::handleTXAntennaChange() {//Refresh the current TX antenna on, if
if (currentTXantennaName != actualTxAntenna) { if (currentTXantennaName != actualTxAntenna) {
currentTXantennaName = actualTxAntenna; currentTXantennaName = actualTxAntenna;
antennaMenuItems[wxID_ANTENNA_CURRENT_TX]->SetItemLabel(getSettingsLabel("TX Antenna", currentTXantennaName)); antennaMenuItems[wxID_ANTENNA_CURRENT_TX]->SetItemLabel(
getSettingsLabel("TX Antenna", currentTXantennaName));
} }
} }
} }
@ -2238,7 +2272,8 @@ void AppFrame::handleScopeSpectrumProcessors() {
spectrumAvgMeter->setLevel(val); spectrumAvgMeter->setLevel(val);
proc->setFFTAverageRate(val); proc->setFFTAverageRate(val);
GetStatusBar()->SetStatusText(wxString::Format(wxT("Spectrum averaging speed changed to %0.2f%%."), val * 100.0)); GetStatusBar()->SetStatusText(
wxString::Format(wxT("Spectrum averaging speed changed to %0.2f%%."), val * 100.0));
} }
SpectrumVisualProcessor *dproc = wxGetApp().getDemodSpectrumProcessor(); SpectrumVisualProcessor *dproc = wxGetApp().getDemodSpectrumProcessor();
@ -2259,7 +2294,8 @@ void AppFrame::handleScopeSpectrumProcessors() {
wxString::Format(wxT("Waterfall max speed changed to %d lines per second."), (int) ceil(val * val))); wxString::Format(wxT("Waterfall max speed changed to %d lines per second."), (int) ceil(val * val)));
} }
wproc->setView(waterfallCanvas->getViewState(), waterfallCanvas->getCenterFrequency(), waterfallCanvas->getBandwidth()); wproc->setView(waterfallCanvas->getViewState(), waterfallCanvas->getCenterFrequency(),
waterfallCanvas->getBandwidth());
proc->setView(wproc->isView(), wproc->getCenterFrequency(), wproc->getBandwidth()); proc->setView(wproc->isView(), wproc->getCenterFrequency(), wproc->getBandwidth());
} }
@ -2270,7 +2306,8 @@ void AppFrame::handleScopeProcessor() {
wxGetApp().getScopeProcessor()->setScopeEnabled(scopeCanvas->scopeVisible()); wxGetApp().getScopeProcessor()->setScopeEnabled(scopeCanvas->scopeVisible());
wxGetApp().getScopeProcessor()->setSpectrumEnabled(scopeCanvas->spectrumVisible()); wxGetApp().getScopeProcessor()->setSpectrumEnabled(scopeCanvas->spectrumVisible());
wxGetApp().getAudioVisualQueue()->set_max_num_items((scopeCanvas->scopeVisible() ? 1 : 0) + (scopeCanvas->spectrumVisible() ? 1 : 0)); wxGetApp().getAudioVisualQueue()->set_max_num_items(
(scopeCanvas->scopeVisible() ? 1 : 0) + (scopeCanvas->spectrumVisible() ? 1 : 0));
wxGetApp().getScopeProcessor()->run(); wxGetApp().getScopeProcessor()->run();
} }
@ -2289,7 +2326,8 @@ void AppFrame::handleMuteButton() {
} }
void AppFrame::handleSpectrumWaterfall() { void AppFrame::handleSpectrumWaterfall() {
if (spectrumCanvas->getViewState() && abs(wxGetApp().getFrequency() - spectrumCanvas->getCenterFrequency()) > (wxGetApp().getSampleRate() / 2)) { if (spectrumCanvas->getViewState() &&
abs(wxGetApp().getFrequency() - spectrumCanvas->getCenterFrequency()) > (wxGetApp().getSampleRate() / 2)) {
spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency()); spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency());
waterfallCanvas->setCenterFrequency(wxGetApp().getFrequency()); waterfallCanvas->setCenterFrequency(wxGetApp().getFrequency());
} }
@ -2354,7 +2392,9 @@ void AppFrame::handleCurrentModem() {
if (demod->isTracking()) { if (demod->isTracking()) {
if (spectrumCanvas->getViewState()) { if (spectrumCanvas->getViewState()) {
long long diff = abs(demod->getFrequency() - spectrumCanvas->getCenterFrequency()) + (demod->getBandwidth() / 2) + (demod->getBandwidth() / 4); long long diff =
abs(demod->getFrequency() - spectrumCanvas->getCenterFrequency()) + (demod->getBandwidth() / 2) +
(demod->getBandwidth() / 4);
if (diff > spectrumCanvas->getBandwidth() / 2) { if (diff > spectrumCanvas->getBandwidth() / 2) {
if (demod->getBandwidth() > (int) spectrumCanvas->getBandwidth()) { if (demod->getBandwidth() > (int) spectrumCanvas->getBandwidth()) {
@ -2362,7 +2402,8 @@ void AppFrame::handleCurrentModem() {
} else { } else {
diff = diff - spectrumCanvas->getBandwidth() / 2; diff = diff - spectrumCanvas->getBandwidth() / 2;
} }
spectrumCanvas->moveCenterFrequency((demod->getFrequency() < spectrumCanvas->getCenterFrequency()) ? diff : -diff); spectrumCanvas->moveCenterFrequency(
(demod->getFrequency() < spectrumCanvas->getCenterFrequency()) ? diff : -diff);
demod->setTracking(false); demod->setTracking(false);
} }
} else { } else {

View File

@ -254,9 +254,19 @@ private:
bool actionOnMenuLoadSave(wxCommandEvent& event); bool actionOnMenuLoadSave(wxCommandEvent& event);
bool actionOnMenuRecording(wxCommandEvent& event); bool actionOnMenuRecording(wxCommandEvent& event);
bool actionOnMenuRig(wxCommandEvent& event); bool actionOnMenuRig(wxCommandEvent& event);
bool actionOnMenuSDRStartStop(wxCommandEvent &event);
bool actionOnMenuPerformance(wxCommandEvent &event);
bool actionOnMenuTips(wxCommandEvent &event);
bool actionOnMenuIQSwap(wxCommandEvent &event);
bool actionOnMenuFreqOffset(wxCommandEvent &event);
bool actionOnMenuDBOffset(wxCommandEvent &event);
bool actionOnMenuSDRDevices(wxCommandEvent &event);
bool actionOnMenuSetPPM(wxCommandEvent &event);
bool actionOnMenuClose(wxCommandEvent &event);
/** /**
* UI Action Handlers * UI Activity Handlers
*/ */
void handleUpdateDeviceParams(); void handleUpdateDeviceParams();
void handleTXAntennaChange(); void handleTXAntennaChange();
@ -302,7 +312,6 @@ private:
#endif #endif
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();
}; };