Skip to content

Commit

Permalink
Read METAR information from file
Browse files Browse the repository at this point in the history
Supports *.txt & *.rwx
  • Loading branch information
fboes committed May 13, 2019
1 parent b9925f9 commit 5c110d2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Change log

* 🎁 Add sample ICAO airport codes to combobox
* 🎁 Interpret date `YYYY/MM/DD` prepended to METAR string
* 🎁 Read METAR information from file

1.2.2
-----
Expand Down
27 changes: 25 additions & 2 deletions src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <wx/aboutdlg.h>
#include <wx/icon.h>
#include <wx/event.h>
#include <wx/filedlg.h>
#include <wx/textfile.h>
#include <math.h>
#include <tuple>
#include "Frame.h"
Expand Down Expand Up @@ -35,7 +37,8 @@ Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr,
wxMenuBar *menubar = new wxMenuBar;
{
wxMenu *file = new wxMenu;
file->Append(wxID_OPEN, wxT("&Load 'main.mcf'"));
file->Append(wxID_OPEN, wxT("&Open METAR file..."));
file->Append(EL_MENU_RELOAD, wxT("&Load 'main.mcf'"));
file->AppendSeparator();
file->Append(wxID_EXIT, wxT("&Exit"));
menubar->Append(file, wxT("&File"));
Expand Down Expand Up @@ -397,6 +400,25 @@ void Frame::actionAbout(wxCommandEvent& WXUNUSED(event))
wxAboutBox(aboutInfo);
}

void Frame::actionOpenMetarFile(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog openFileDialog(this, _("Open METAR file"), "", "", "Text files (*.txt, *.rwx)|*.txt;*.rwx", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL) {
return;
}

wxTextFile tfile;
tfile.Open(openFileDialog.GetPath());

auto metarString = tfile.GetFirstLine();
if (!tfile.Eof()) {
metarString += "\n" + tfile.GetNextLine();
}
this->metarInput->SetValue(metarString);
this->saveButton->SetFocus();
this->markAsDirty();
}

void Frame::actionLoadMainMcf(wxCommandEvent& WXUNUSED(event))
{
this->loadMainMcf();
Expand Down Expand Up @@ -430,7 +452,8 @@ EVT_MENU(Frame::EL_MENU_UPDATE, Frame::actionUpdate)
EVT_MENU(Frame::EL_MENU_FIND_ICAO, Frame::actionFindIcao)
EVT_MENU(wxID_ABOUT, Frame::actionAbout)
EVT_MENU(wxID_EXIT, Frame::actionExit)
EVT_MENU(wxID_OPEN, Frame::actionLoadMainMcf)
EVT_MENU(wxID_OPEN, Frame::actionOpenMetarFile)
EVT_MENU(Frame::EL_MENU_RELOAD, Frame::actionLoadMainMcf)
EVT_TEXT(Frame::EL_CTRL_METAR, Frame::actionParse)
EVT_SLIDER(Frame::EL_CTRL_SLIDER, Frame::actionMarkAsDirty)
//EVT_DATE_CHANGED(Frame::EL_CTRL_DATETIME, Frame::actionMarkAsDirty)
Expand Down
5 changes: 5 additions & 0 deletions src/WettergeraetDesktop/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Frame : public wxFrame
static const unsigned short EL_CTRL_SLIDER = 6;
static const unsigned short EL_MENU_UPDATE = 7;
static const unsigned short EL_MENU_FIND_ICAO = 8;
static const unsigned short EL_MENU_RELOAD = 9;

Frame(const wxString& title, int argc, char * argv[]);
virtual ~Frame();
Expand Down Expand Up @@ -86,6 +87,10 @@ class Frame : public wxFrame

virtual void actionAbout(wxCommandEvent&);

// Show file dialogue, copy METAR information from file to METAR input field
virtual void actionOpenMetarFile(wxCommandEvent&);

// Reload main.mcf and copy values to main windows
virtual void actionLoadMainMcf(wxCommandEvent&);

virtual void actionUpdate(wxCommandEvent&);
Expand Down

0 comments on commit 5c110d2

Please sign in to comment.