diff --git a/src/ncvis.cpp b/src/ncvis.cpp index 5fac5f1..d091314 100644 --- a/src/ncvis.cpp +++ b/src/ncvis.cpp @@ -49,6 +49,8 @@ bool wxNcVisApp::OnInit() { // Process command line arguments if (argc < 2) { std::cout << "Usage: " << argv[0] << " [options] [filename] ... " << std::endl; + std::cout << "Options:" << std::endl; + std::cout << " -var Load variable on startup" << std::endl; exit(-1); } @@ -60,7 +62,8 @@ bool wxNcVisApp::OnInit() { if ((wxString("-g") == argv[iarg]) || (wxString("-uxc") == argv[iarg]) || (wxString("-uyc") == argv[iarg]) || - (wxString("-mcr") == argv[iarg]) + (wxString("-mcr") == argv[iarg]) || + (wxString("-var") == argv[iarg]) ) { if (iarg+1 == argc) { std::cout << "Option " << argv[iarg] << " missing required parameter" << std::endl; @@ -89,6 +92,8 @@ bool wxNcVisApp::OnInit() { if (vecFilenames.size() == 0) { std::cout << "ERROR: No filenames specified" << std::endl; std::cout << "Usage: " << argv[0] << " [options] [filename] ... " << std::endl; + std::cout << "Options:" << std::endl; + std::cout << " -var Load variable on startup" << std::endl; exit(-1); } diff --git a/src/wxNcVisFrame.cpp b/src/wxNcVisFrame.cpp index a9ede95..1d18c8e 100644 --- a/src/wxNcVisFrame.cpp +++ b/src/wxNcVisFrame.cpp @@ -133,6 +133,11 @@ wxNcVisFrame::wxNcVisFrame( m_fRegional = true; } + auto itVar = mapOptions.find("-var"); + if (itVar != mapOptions.end()) { + m_strStartupVariable = itVar->second; + } + auto itMCS = mapOptions.find("-mcr"); if (itMCS != mapOptions.end()) { m_dMaxCellRadius = stof(itMCS->second.ToStdString()); @@ -845,6 +850,37 @@ void wxNcVisFrame::InitializeWindow() { //customvarsizer->Add(new wxTextCtrl(this, (-1), _T(""), wxDefaultPosition, wxSize(240,m_wxDataTransButton->GetSize().GetHeight()+4), wxTE_PROCESS_ENTER), 2, wxEXPAND | wxALL, 4); + if (!m_strStartupVariable.IsEmpty()) { + bool fFound = false; + + for (int vc = 0; vc < NcVarMaximumDimensions; vc++) { + if (m_vecwxVarSelector[vc] == NULL) { + continue; + } + + int ix = m_vecwxVarSelector[vc]->FindString(m_strStartupVariable); + if (ix != wxNOT_FOUND) { + m_vecwxVarSelector[vc]->SetSelection(ix); + + wxCommandEvent evt(wxEVT_COMBOBOX, ID_VARSELECTOR + vc); + evt.SetEventObject(m_vecwxVarSelector[vc]); + evt.SetInt(ix); + wxPostEvent(this, evt); + + fFound = true; + break; + } + } + + if (!fFound) { + wxMessageBox( + wxString::Format("Startup variable \"%s\" not found.", m_strStartupVariable), + "Variable not found", + wxOK | wxICON_WARNING + ); + } + } + // Dimensions m_vardimsizer = new wxFlexGridSizer(NcVarMaximumDimensions+1, 4, 0, 0); diff --git a/src/wxNcVisFrame.h b/src/wxNcVisFrame.h index ac85ded..fb84d55 100644 --- a/src/wxNcVisFrame.h +++ b/src/wxNcVisFrame.h @@ -676,6 +676,11 @@ class wxNcVisFrame : public wxFrame { /// VariableNameFileIxMap m_mapVarNames[10]; + /// + /// Startup variable name. + /// + wxString m_strStartupVariable; + private: /// /// ColorMap index.