AppFrame Cleanup: Move config, menubar inits

This commit is contained in:
Charles J. Cliffe 2019-03-16 17:44:41 -04:00
parent 8d09d9c329
commit 5f3de57bd8
2 changed files with 124 additions and 108 deletions

View File

@ -69,21 +69,23 @@ public:
}; };
/* split a string by 'seperator' into a vector of string */
std::vector<std::string> str_explode(const std::string &seperator, const std::string &in_str);
#define APPFRAME_MODEMPROPS_MINSIZE 20 #define APPFRAME_MODEMPROPS_MINSIZE 20
#define APPFRAME_MODEMPROPS_MAXSIZE 240 #define APPFRAME_MODEMPROPS_MAXSIZE 240
AppFrame::AppFrame() : AppFrame::AppFrame() :
wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(nullptr) { wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(nullptr) {
#if defined(__linux__) || defined(__FreeBSD__) initIcon();
SetIcon(wxICON(cubicsdr));
#endif devInfo = NULL;
deviceChanged.store(false);
modemPropertiesUpdated.store(false);
saveDisabled = false;
aboutDlg = nullptr;
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
demodTray = new wxBoxSizer(wxHORIZONTAL); demodTray = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *demodTunerTray = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *demodTunerTray = new wxBoxSizer(wxHORIZONTAL);
@ -136,8 +138,6 @@ AppFrame::AppFrame() :
demodTray->Add(demodModeSelectorAdv, 3, wxEXPAND | wxALL, 0); demodTray->Add(demodModeSelectorAdv, 3, wxEXPAND | wxALL, 0);
#endif #endif
modemPropertiesUpdated.store(false);
// Modem properties panel // Modem properties panel
modemProps = makeModemProperties(demodPanel); modemProps = makeModemProperties(demodPanel);
@ -171,7 +171,6 @@ AppFrame::AppFrame() :
demodVisuals->SetMinSize(wxSize(128,-1)); demodVisuals->SetMinSize(wxSize(128,-1));
demodTray->Add(demodVisuals, 30, wxEXPAND | wxALL, 0); demodTray->Add(demodVisuals, 30, wxEXPAND | wxALL, 0);
demodTray->AddSpacer(1); demodTray->AddSpacer(1);
#else #else
demodSpectrumCanvas = nullptr; demodSpectrumCanvas = nullptr;
@ -181,13 +180,11 @@ AppFrame::AppFrame() :
// Demod Signal/Squelch Meter // Demod Signal/Squelch Meter
demodSignalMeter = makeSignalMeter(demodPanel, attribList); demodSignalMeter = makeSignalMeter(demodPanel, attribList);
demodTray->Add(demodSignalMeter, 1, wxEXPAND | wxALL, 0); demodTray->Add(demodSignalMeter, 1, wxEXPAND | wxALL, 0);
demodTray->AddSpacer(1); demodTray->AddSpacer(1);
#if CUBICSDR_ENABLE_VIEW_SCOPE #if CUBICSDR_ENABLE_VIEW_SCOPE
// Scope // Scope
scopeCanvas = makeScopeCanvas(demodPanel, attribList); scopeCanvas = makeScopeCanvas(demodPanel, attribList);
demodScopeTray->Add(scopeCanvas, 8, wxEXPAND | wxALL, 0); demodScopeTray->Add(scopeCanvas, 8, wxEXPAND | wxALL, 0);
wxGetApp().getScopeProcessor()->setup(DEFAULT_SCOPE_FFT_SIZE); wxGetApp().getScopeProcessor()->setup(DEFAULT_SCOPE_FFT_SIZE);
@ -206,13 +203,10 @@ AppFrame::AppFrame() :
// Modem Tuner // Modem Tuner
demodTuner = makeModemTuner(demodPanel, attribList); demodTuner = makeModemTuner(demodPanel, attribList);
demodTunerTray->Add(demodTuner, 1, wxEXPAND | wxALL, 0); demodTunerTray->Add(demodTuner, 1, wxEXPAND | wxALL, 0);
demodScopeTray->Add(demodTunerTray, 1, wxEXPAND | wxALL, 0); demodScopeTray->Add(demodTunerTray, 1, wxEXPAND | wxALL, 0);
demodTray->Add(demodScopeTray, 30, wxEXPAND | wxALL, 0); demodTray->Add(demodScopeTray, 30, wxEXPAND | wxALL, 0);
demodTray->AddSpacer(1); demodTray->AddSpacer(1);
wxBoxSizer *demodGainTray = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodGainTray = new wxBoxSizer(wxVERTICAL);
@ -220,13 +214,11 @@ AppFrame::AppFrame() :
// Demod Gain Meter // Demod Gain Meter
demodGainMeter = makeModemGainMeter(demodPanel, attribList); demodGainMeter = makeModemGainMeter(demodPanel, attribList);
demodGainTray->Add(demodGainMeter, 8, wxEXPAND | wxALL, 0); demodGainTray->Add(demodGainMeter, 8, wxEXPAND | wxALL, 0);
demodGainTray->AddSpacer(1); demodGainTray->AddSpacer(1);
// Solo Button // Solo Button
soloModeButton = makeSoloModeButton(demodPanel, attribList); soloModeButton = makeSoloModeButton(demodPanel, attribList);
demodGainTray->Add(soloModeButton, 1, wxEXPAND | wxALL, 0); demodGainTray->Add(soloModeButton, 1, wxEXPAND | wxALL, 0);
demodGainTray->AddSpacer(1); demodGainTray->AddSpacer(1);
// Mute Button // Mute Button
@ -261,38 +253,36 @@ AppFrame::AppFrame() :
// Peak Hold // Peak Hold
peakHoldButton = makePeakHoldButton(spectrumPanel, attribList); peakHoldButton = makePeakHoldButton(spectrumPanel, attribList);
spectrumCtlTray->Add(peakHoldButton, 1, wxEXPAND | wxALL, 0); spectrumCtlTray->Add(peakHoldButton, 1, wxEXPAND | wxALL, 0);
spectrumCtlTray->AddSpacer(1); spectrumCtlTray->AddSpacer(1);
// Spectrum Average Meter // Spectrum Average Meter
spectrumAvgMeter = makeSpectrumAvgMeter(spectrumPanel, attribList); spectrumAvgMeter = makeSpectrumAvgMeter(spectrumPanel, attribList);
spectrumCtlTray->Add(spectrumAvgMeter, 8, wxEXPAND | wxALL, 0); spectrumCtlTray->Add(spectrumAvgMeter, 8, wxEXPAND | wxALL, 0);
spectrumSizer->Add(spectrumCtlTray, 1, wxEXPAND | wxALL, 0); spectrumSizer->Add(spectrumCtlTray, 1, wxEXPAND | wxALL, 0);
spectrumPanel->SetSizer(spectrumSizer); spectrumPanel->SetSizer(spectrumSizer);
wxPanel *waterfallPanel = new wxPanel(mainVisSplitter, wxID_ANY); wxPanel *waterfallPanel = new wxPanel(mainVisSplitter, wxID_ANY);
wxBoxSizer *wfSizer = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *waterfallSizer = new wxBoxSizer(wxHORIZONTAL);
// Waterfall // Waterfall
waterfallCanvas = makeWaterfall(waterfallPanel, attribList); waterfallCanvas = makeWaterfall(waterfallPanel, attribList);
// Create and connect the FFT visual data thread
waterfallDataThread = new FFTVisualDataThread(); waterfallDataThread = new FFTVisualDataThread();
waterfallDataThread->setInputQueue("IQDataInput", wxGetApp().getWaterfallVisualQueue()); waterfallDataThread->setInputQueue("IQDataInput", wxGetApp().getWaterfallVisualQueue());
waterfallDataThread->setOutputQueue("FFTDataOutput", waterfallCanvas->getVisualDataQueue()); waterfallDataThread->setOutputQueue("FFTDataOutput", waterfallCanvas->getVisualDataQueue());
waterfallDataThread->getProcessor()->setHideDC(true); waterfallDataThread->getProcessor()->setHideDC(true);
t_FFTData = new std::thread(&FFTVisualDataThread::threadMain, waterfallDataThread); t_FFTData = new std::thread(&FFTVisualDataThread::threadMain, waterfallDataThread);
// Waterfall speed meter // Waterfall speed meter
waterfallSpeedMeter = makeWaterfallSpeedMeter(waterfallPanel, attribList); waterfallSpeedMeter = makeWaterfallSpeedMeter(waterfallPanel, attribList);
wfSizer->Add(waterfallCanvas, 63, wxEXPAND | wxALL, 0); waterfallSizer->Add(waterfallCanvas, 63, wxEXPAND | wxALL, 0);
wfSizer->AddSpacer(1); waterfallSizer->AddSpacer(1);
wfSizer->Add(waterfallSpeedMeter, 1, wxEXPAND | wxALL, 0); waterfallSizer->Add(waterfallSpeedMeter, 1, wxEXPAND | wxALL, 0);
waterfallPanel->SetSizer(wfSizer); waterfallPanel->SetSizer(waterfallSizer);
mainVisSplitter->SplitHorizontally( spectrumPanel, waterfallPanel, 0 ); mainVisSplitter->SplitHorizontally( spectrumPanel, waterfallPanel, 0 );
@ -300,18 +290,16 @@ AppFrame::AppFrame() :
bookmarkView = new BookmarkView(bookmarkSplitter, wxID_ANY, wxDefaultPosition, wxSize(120,-1)); bookmarkView = new BookmarkView(bookmarkSplitter, wxID_ANY, wxDefaultPosition, wxSize(120,-1));
bookmarkSplitter->SplitVertically( bookmarkView, mainVisSplitter ); bookmarkSplitter->SplitVertically( bookmarkView, mainVisSplitter );
mainSplitter->SplitHorizontally( demodPanel, bookmarkSplitter ); mainSplitter->SplitHorizontally( demodPanel, bookmarkSplitter );
if (!wxGetApp().getConfig()->getBookmarksVisible()) {
bookmarkSplitter->Unsplit(bookmarkView);
bookmarkSplitter->Layout();
}
vbox->Add(mainSplitter, 1, wxEXPAND | wxALL, 0);
// TODO: refactor these.. // TODO: refactor these..
waterfallCanvas->attachSpectrumCanvas(spectrumCanvas); waterfallCanvas->attachSpectrumCanvas(spectrumCanvas);
spectrumCanvas->attachWaterfallCanvas(waterfallCanvas); spectrumCanvas->attachWaterfallCanvas(waterfallCanvas);
// Primary sizer for the window
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
vbox->Add(mainSplitter, 1, wxEXPAND | wxALL, 0);
/* * / /* * /
vbox->AddSpacer(1); vbox->AddSpacer(1);
testCanvas = new UITestCanvas(this, attribList); testCanvas = new UITestCanvas(this, attribList);
@ -320,7 +308,36 @@ AppFrame::AppFrame() :
this->SetSizer(vbox); this->SetSizer(vbox);
// File Menu // Load and apply configuration
initConfigurationSettings();
// Initialize menu
initMenuBar();
// Create status bar
CreateStatusBar();
// Show the window
Show();
// Force refresh of all
Refresh();
// Pop up the device selector
wxGetApp().deviceSelector();
}
void AppFrame::initIcon() {
#if defined(__linux__) || defined(__FreeBSD__)
SetIcon(wxICON(cubicsdr));
#endif
#ifdef _WIN32
SetIcon(wxICON(frame_icon));
#endif
}
void AppFrame::initMenuBar() {// File Menu
menuBar = new wxMenuBar; menuBar = new wxMenuBar;
fileMenu = makeFileMenu(); fileMenu = makeFileMenu();
menuBar->Append(fileMenu, wxT("&File")); menuBar->Append(fileMenu, wxT("&File"));
@ -336,16 +353,12 @@ AppFrame::AppFrame() :
// Audio Sample Rate Menu // Audio Sample Rate Menu
menuBar->Append(makeAudioSampleRateMenu(), wxT("Audio &Sample Rate")); menuBar->Append(makeAudioSampleRateMenu(), wxT("Audio &Sample Rate"));
//Add a Recording menu //Add a Recording menu
recordingMenu = makeRecordingMenu(); recordingMenu = makeRecordingMenu();
menuBar->Append(recordingMenu, wxT("Recordin&g")); menuBar->Append(recordingMenu, wxT("Recordin&g"));
updateRecordingMenu(); updateRecordingMenu();
#ifdef USE_HAMLIB #ifdef USE_HAMLIB
rigModel = wxGetApp().getConfig()->getRigModel();
rigSerialRate = wxGetApp().getConfig()->getRigRate();
rigPort = wxGetApp().getConfig()->getRigPort();
rigPortDialog = nullptr; rigPortDialog = nullptr;
// Rig Menu // Rig Menu
@ -359,7 +372,20 @@ AppFrame::AppFrame() :
SetMenuBar(menuBar); SetMenuBar(menuBar);
CreateStatusBar(); wxAcceleratorEntry entries[3];
entries[0].Set(wxACCEL_CTRL, (int) 'O', wxID_OPEN);
entries[1].Set(wxACCEL_CTRL, (int) 'S', wxID_SAVE);
entries[2].Set(wxACCEL_CTRL, (int) 'A', wxID_SAVEAS);
wxAcceleratorTable accel(3, entries);
SetAcceleratorTable(accel);
}
void AppFrame::initConfigurationSettings() {
// Init Theme
ThemeMgr::mgr.setTheme(wxGetApp().getConfig()->getTheme());
bookmarkView->updateTheme();
// Init Font Scale // Init Font Scale
int fontScale = wxGetApp().getConfig()->getFontScale(); int fontScale = wxGetApp().getConfig()->getFontScale();
@ -368,73 +394,66 @@ AppFrame::AppFrame() :
// Init window position from configuration // Init window position from configuration
wxRect *win = wxGetApp().getConfig()->getWindow(); wxRect *win = wxGetApp().getConfig()->getWindow();
if (win) { if (win) {
this->SetPosition(win->GetPosition()); SetPosition(win->GetPosition());
this->SetClientSize(win->GetSize()); SetClientSize(win->GetSize());
} else { } else {
SetClientSize(1280, 600); SetClientSize(1280, 600);
Centre(); Centre();
} }
// Maximized last time? // Init maximize state
if (wxGetApp().getConfig()->getWindowMaximized()) { if (wxGetApp().getConfig()->getWindowMaximized()) {
this->Maximize(); Maximize();
} }
// Init frequency snap
wxGetApp().setFrequencySnap(wxGetApp().getConfig()->getSnap()); wxGetApp().setFrequencySnap(wxGetApp().getConfig()->getSnap());
// Init spectrum average speed
float spectrumAvg = wxGetApp().getConfig()->getSpectrumAvgSpeed(); float spectrumAvg = wxGetApp().getConfig()->getSpectrumAvgSpeed();
spectrumAvgMeter->setLevel(spectrumAvg); spectrumAvgMeter->setLevel(spectrumAvg);
wxGetApp().getSpectrumProcessor()->setFFTAverageRate(spectrumAvg); wxGetApp().getSpectrumProcessor()->setFFTAverageRate(spectrumAvg);
// Init waterfall speed
int wflps =wxGetApp().getConfig()->getWaterfallLinesPerSec(); int wflps =wxGetApp().getConfig()->getWaterfallLinesPerSec();
waterfallSpeedMeter->setLevel(sqrtf(wflps));
waterfallSpeedMeter->setLevel(sqrt(wflps));
waterfallDataThread->setLinesPerSecond(wflps); waterfallDataThread->setLinesPerSecond(wflps);
waterfallCanvas->setLinesPerSecond(wflps); waterfallCanvas->setLinesPerSecond(wflps);
ThemeMgr::mgr.setTheme(wxGetApp().getConfig()->getTheme());
bookmarkView->updateTheme();
// Init modem property collapsed state
int mpc =wxGetApp().getConfig()->getModemPropsCollapsed(); int mpc =wxGetApp().getConfig()->getModemPropsCollapsed();
if (mpc) { if (mpc) {
modemProps->setCollapsed(true); modemProps->setCollapsed(true);
} }
// Init main splitter position (separates top/bottom area horizontally)
int msPos = wxGetApp().getConfig()->getMainSplit(); int msPos = wxGetApp().getConfig()->getMainSplit();
if (msPos != -1) { if (msPos != -1) {
mainSplitter->SetSashPosition(msPos); mainSplitter->SetSashPosition(msPos);
} }
// Init bookmark splitter position (separates bookmark/main vis vertically)
int bsPos = wxGetApp().getConfig()->getBookmarkSplit(); int bsPos = wxGetApp().getConfig()->getBookmarkSplit();
if (bsPos != -1) { if (bsPos != -1) {
bookmarkSplitter->SetSashPosition(bsPos); bookmarkSplitter->SetSashPosition(bsPos);
} }
// Init vis splitter position (separates spectrum/waterfall horizontally)
int vsPos = wxGetApp().getConfig()->getVisSplit(); int vsPos = wxGetApp().getConfig()->getVisSplit();
if (vsPos != -1) { if (vsPos != -1) {
mainVisSplitter->SetSashPosition(vsPos); mainVisSplitter->SetSashPosition(vsPos);
} }
Show();
#ifdef _WIN32 if (!wxGetApp().getConfig()->getBookmarksVisible()) {
SetIcon(wxICON(frame_icon)); bookmarkSplitter->Unsplit(bookmarkView);
bookmarkSplitter->Layout();
}
#ifdef USE_HAMLIB
rigModel = wxGetApp().getConfig()->getRigModel();
rigSerialRate = wxGetApp().getConfig()->getRigRate();
rigPort = wxGetApp().getConfig()->getRigPort();
#endif #endif
wxAcceleratorEntry entries[3];
entries[0].Set(wxACCEL_CTRL, (int) 'O', wxID_OPEN);
entries[1].Set(wxACCEL_CTRL, (int) 'S', wxID_SAVE);
entries[2].Set(wxACCEL_CTRL, (int) 'A', wxID_SAVEAS);
wxAcceleratorTable accel(3, entries);
SetAcceleratorTable(accel);
deviceChanged.store(false);
devInfo = NULL;
wxGetApp().deviceSelector();
saveDisabled = false;
aboutDlg = nullptr;
//Force refresh of all
Refresh();
} }
ModemProperties *AppFrame::makeModemProperties(wxPanel *parent) { ModemProperties *AppFrame::makeModemProperties(wxPanel *parent) {

View File

@ -228,12 +228,8 @@ private:
//depending on context, maps the item id to wxMenuItem*, //depending on context, maps the item id to wxMenuItem*,
//OR the submenu item id to its parent wxMenuItem*. //OR the submenu item id to its parent wxMenuItem*.
std::map<int, wxMenuItem *> settingsMenuItems; std::map<int, wxMenuItem *> settingsMenuItems;
std::map<int, wxMenuItem *> performanceMenuItems; std::map<int, wxMenuItem *> performanceMenuItems;
std::map<int, wxMenuItem *> audioSampleRateMenuItems; std::map<int, wxMenuItem *> audioSampleRateMenuItems;
//
std::map<int, wxMenuItem *> recordingMenuItems; std::map<int, wxMenuItem *> recordingMenuItems;
wxMenuBar *menuBar; wxMenuBar *menuBar;
@ -273,34 +269,8 @@ private:
bool saveDisabled; bool saveDisabled;
AboutDialog *aboutDlg; AboutDialog *aboutDlg;
std::string lastToolTip; std::string lastToolTip;
#ifdef USE_HAMLIB
void enableRig();
void disableRig();
wxMenu *rigMenu;
wxMenuItem *rigEnableMenuItem;
wxMenuItem *rigPortMenuItem;
wxMenuItem *rigControlMenuItem;
wxMenuItem *rigFollowMenuItem;
wxMenuItem *rigCenterLockMenuItem;
wxMenuItem *rigFollowModemMenuItem;
std::map<int, wxMenuItem *> rigSerialMenuItems;
std::map<int, wxMenuItem *> rigModelMenuItems;
int rigModel;
int rigSerialRate;
long long rigSDRIF;
std::vector<int> rigSerialRates;
std::string rigPort;
int numRigs;
PortSelectorDialog *rigPortDialog;
#endif
wxDECLARE_EVENT_TABLE();
ModeSelectorCanvas *makeModemSelectorPanel(wxWindow *parent, const wxGLAttributes &attribList); ModeSelectorCanvas *makeModemSelectorPanel(wxWindow *parent, const wxGLAttributes &attribList);
WaterfallCanvas *makeWaterfallCanvas(wxWindow *parent, const wxGLAttributes &attribList); WaterfallCanvas *makeWaterfallCanvas(wxWindow *parent, const wxGLAttributes &attribList);
SpectrumCanvas *makeDemodSpectrumCanvas(wxWindow *parent, const wxGLAttributes &attribList); SpectrumCanvas *makeDemodSpectrumCanvas(wxWindow *parent, const wxGLAttributes &attribList);
@ -319,11 +289,12 @@ private:
ModeSelectorCanvas *makeModemAdvSelectorPanel(wxPanel *parent, const wxGLAttributes &attribList); ModeSelectorCanvas *makeModemAdvSelectorPanel(wxPanel *parent, const wxGLAttributes &attribList);
ModemProperties *makeModemProperties(wxPanel *parent); ModemProperties *makeModemProperties(wxPanel *parent);
void initConfigurationSettings();
void initMenuBar();
void initIcon();
wxMenu *makeAudioSampleRateMenu(); wxMenu *makeAudioSampleRateMenu();
wxMenu *makeDisplayMenu(); wxMenu *makeDisplayMenu();
#ifdef USE_HAMLIB
wxMenu *makeRigMenu();
#endif
void handleTXAntennaChange(); void handleTXAntennaChange();
void handleCurrentModem(); void handleCurrentModem();
@ -337,7 +308,33 @@ private:
void handleModemProperties(); void handleModemProperties();
void handlePeakHold(); void handlePeakHold();
#if USE_HAMLIB
#ifdef USE_HAMLIB
void enableRig();
void disableRig();
wxMenu *rigMenu;
wxMenuItem *rigEnableMenuItem;
wxMenuItem *rigPortMenuItem;
wxMenuItem *rigControlMenuItem;
wxMenuItem *rigFollowMenuItem;
wxMenuItem *rigCenterLockMenuItem;
wxMenuItem *rigFollowModemMenuItem;
std::map<int, wxMenuItem *> rigSerialMenuItems;
std::map<int, wxMenuItem *> rigModelMenuItems;
int rigModel;
int rigSerialRate;
long long rigSDRIF;
std::vector<int> rigSerialRates;
std::string rigPort;
int numRigs;
PortSelectorDialog *rigPortDialog;
wxMenu *makeRigMenu();
void handleRigMenu(); void handleRigMenu();
#endif #endif
wxDECLARE_EVENT_TABLE();
}; };