Skip to content

Commit

Permalink
Save METAR information to file
Browse files Browse the repository at this point in the history
  • Loading branch information
fboes committed May 14, 2019
1 parent a9ebcf6 commit 883dc17
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change log
==========

1.2.4
-----

* 🎁 Save METAR information to file

1.2.3
-----

Expand Down
42 changes: 41 additions & 1 deletion src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ Frame::Frame(const wxString& title, int argc, char * argv[]) : wxFrame(nullptr,

wxMenuBar *menubar = new wxMenuBar;
{
wxMenu *file = new wxMenu;
wxMenu* file = new wxMenu;
file->Append(wxID_OPEN, wxT("&Open METAR file..."));
file->Append(wxID_SAVEAS, wxT("&Save METAR file..."));
file->Append(EL_MENU_RELOAD, wxT("&Load 'main.mcf'"));
file->AppendSeparator();
file->Append(wxID_EXIT, wxT("&Exit"));
Expand Down Expand Up @@ -419,6 +420,44 @@ void Frame::actionOpenMetarFile(wxCommandEvent& WXUNUSED(event))
this->markAsDirty();
}

void Frame::actionSaveMetarFile(wxCommandEvent& WXUNUSED(event))
{
auto date = this->utcDateInput->GetValue();
auto year = date.GetYear();
auto month = date.GetMonth() + 1;
auto day = date.GetDay();

auto time = this->utcTimeInput->GetValue();
auto hour = time.GetHour();
auto minute = time.GetMinute();

char timestamp[25];
sprintf(timestamp, "%04d-%02d-%02d_%02d%02dZ", year, month, day, hour, minute);
wxString defaultFilename = this->icaoInput->GetValue() + "_" + timestamp + ".rwx";

wxFileDialog saveFileDialog(this, _("Save METAR file"), "", defaultFilename, "Text files (*.txt, *.rwx)|*.txt;*.rwx", wxFD_SAVE);
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
return;
}

sprintf(timestamp, "%04d/%02d/%02d %02d:%02d", year, month, day, hour, minute);
auto metarInput = this->metarInput->GetValue();
wxTextFile tfile(saveFileDialog.GetPath());
if (!tfile.Exists()) {
tfile.Create();
}
else {
tfile.Open();
tfile.Clear();
}

tfile.AddLine(timestamp);
tfile.AddLine(metarInput);

tfile.Write();
tfile.Close();
}

void Frame::actionLoadMainMcf(wxCommandEvent& WXUNUSED(event))
{
this->loadMainMcf();
Expand Down Expand Up @@ -453,6 +492,7 @@ 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::actionOpenMetarFile)
EVT_MENU(wxID_SAVEAS, Frame::actionSaveMetarFile)
EVT_MENU(Frame::EL_MENU_RELOAD, Frame::actionLoadMainMcf)
EVT_TEXT(Frame::EL_CTRL_METAR, Frame::actionParse)
EVT_SLIDER(Frame::EL_CTRL_SLIDER, Frame::actionMarkAsDirty)
Expand Down
3 changes: 3 additions & 0 deletions src/WettergeraetDesktop/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class Frame : public wxFrame
// Show file dialogue, copy METAR information from file to METAR input field
virtual void actionOpenMetarFile(wxCommandEvent&);

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/WettergeraetLib/Argumentor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sstream>
#include <iterator>

const char* Argumentor::APP_VERSION = "1.2.3";
const char* Argumentor::APP_VERSION = "1.2.4";
#if _WIN64
const char* Argumentor::APP_TARGET = "64-bit";
#else
Expand Down

0 comments on commit 883dc17

Please sign in to comment.