1
0
mirror of https://github.com/rene-dev/stmbl.git synced 2024-12-28 11:32:24 +00:00
stmbl/term/main.cpp

120 lines
3.2 KiB
C++
Raw Permalink Normal View History

2014-08-19 21:40:31 +00:00
#include <wx/wx.h>
#include <wx/aboutdlg.h>
#include <wx/filedlg.h>
2015-01-27 21:06:24 +00:00
#include <fstream>
2014-08-19 21:40:31 +00:00
#include "mainframe.hpp"
2015-01-04 01:34:04 +00:00
#include "dqframe.hpp"
2014-08-19 21:40:31 +00:00
2014-08-20 11:08:02 +00:00
class Servoterm: public wxApp
2014-08-19 21:40:31 +00:00
{
public:
bool OnInit();
2015-01-27 21:06:24 +00:00
void OnOpen(wxCommandEvent& WXUNUSED(event));
2015-01-29 21:09:28 +00:00
void OnWrite(wxCommandEvent& WXUNUSED(event));
void OnRead(wxCommandEvent& WXUNUSED(event));
void OnSave(wxCommandEvent& WXUNUSED(event));
2015-01-30 10:29:50 +00:00
void OnDq(wxCommandEvent& WXUNUSED(event));
2014-08-19 21:40:31 +00:00
private:
2015-01-27 21:06:24 +00:00
ServoFrame* servoframe;
wxString filename;
2015-01-04 01:34:04 +00:00
dqFrame* dqframe;
2015-01-29 21:09:28 +00:00
int writeID;
int readID;
2015-01-30 10:29:50 +00:00
int dqID;
2014-08-19 21:40:31 +00:00
void OnAbout(wxCommandEvent& WXUNUSED(event));
};
2014-08-20 11:08:02 +00:00
IMPLEMENT_APP(Servoterm)
2014-08-19 21:40:31 +00:00
2015-01-27 21:06:24 +00:00
using std::cout;
using std::endl;
using std::ifstream;
using std::string;
2014-08-20 11:08:02 +00:00
bool Servoterm::OnInit()
2014-08-19 21:40:31 +00:00
{
2015-01-27 21:06:24 +00:00
servoframe = new ServoFrame(wxT("Servoterm"));
2014-08-19 21:40:31 +00:00
wxMenuBar *menuBar = new wxMenuBar;
2015-01-27 21:06:24 +00:00
wxMenu *fileMenu = new wxMenu;
2015-01-30 10:29:50 +00:00
wxMenu *viewMenu = new wxMenu;
2015-01-27 21:06:24 +00:00
filename = "";
2015-01-29 21:09:28 +00:00
writeID = wxNewId();
readID = wxNewId();
2015-01-30 10:29:50 +00:00
dqID = wxNewId();
2015-10-28 16:21:42 +00:00
2015-01-27 21:06:24 +00:00
menuBar->Append(fileMenu, "&File");
fileMenu->Append(wxID_OPEN);
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnOpen, this, wxID_OPEN);
2015-01-29 21:09:28 +00:00
//fileMenu->Append(wxID_SAVE);
//Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnSave, this, wxID_SAVE);
fileMenu->Append(writeID, "&Write");
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnWrite, this, writeID);
fileMenu->Append(readID, "&Read");
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnRead, this, readID);
2015-10-28 16:21:42 +00:00
2015-01-30 10:29:50 +00:00
menuBar->Append(viewMenu, "&View");
viewMenu->Append(dqID, "&DQsim");
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnDq, this, dqID);
2015-10-28 16:21:42 +00:00
2014-08-19 21:40:31 +00:00
wxMenu *helpMenu = new wxMenu;
menuBar->Append(helpMenu, "&Help" );
helpMenu->Append(wxID_ABOUT);
2014-08-20 11:08:02 +00:00
Bind(wxEVT_COMMAND_MENU_SELECTED, &Servoterm::OnAbout, this, wxID_ABOUT);
2014-08-19 21:40:31 +00:00
2015-01-04 01:34:04 +00:00
servoframe->SetMenuBar( menuBar );
2014-08-19 21:40:31 +00:00
2014-09-16 23:25:27 +00:00
//frame->CreateStatusBar();
//frame->SetStatusText("Statuskram und so");
2015-10-28 16:21:42 +00:00
2015-01-04 01:34:04 +00:00
servoframe->Show(TRUE);
2014-08-19 21:40:31 +00:00
return TRUE;
}
2015-01-30 10:29:50 +00:00
void Servoterm::OnDq(wxCommandEvent& WXUNUSED(event)){
dqframe = new dqFrame(wxT("dq"));
dqframe->Show(TRUE);
}
2015-01-29 21:09:28 +00:00
void Servoterm::OnRead(wxCommandEvent& WXUNUSED(event)){
2015-11-26 22:33:47 +00:00
servoframe->send("conf");
2015-01-27 21:06:24 +00:00
}
2015-01-29 21:09:28 +00:00
void Servoterm::OnWrite(wxCommandEvent& WXUNUSED(event)){
ifstream infile(filename);
2015-01-27 21:06:24 +00:00
string line;
while (std::getline(infile, line))
{
2015-11-26 22:33:47 +00:00
servoframe->send(line);
2015-01-27 21:06:24 +00:00
}
2015-01-29 21:09:28 +00:00
}
void Servoterm::OnSave(wxCommandEvent& WXUNUSED(event)){
2015-10-28 16:21:42 +00:00
2015-01-29 21:09:28 +00:00
}
void Servoterm::OnOpen(wxCommandEvent& WXUNUSED(event)){
2015-11-26 22:33:47 +00:00
wxFileDialog openFileDialog(servoframe, wxEmptyString, SRCDIR"/../conf", "","*", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
2015-01-29 21:09:28 +00:00
if (openFileDialog.ShowModal() == wxID_CANCEL)
return;
filename = openFileDialog.GetPath();
servoframe->SetTitle(filename);
2015-01-27 21:06:24 +00:00
}
2014-08-20 11:08:02 +00:00
void Servoterm::OnAbout(wxCommandEvent& WXUNUSED(event)){
2014-09-17 11:57:57 +00:00
/*
2014-08-19 21:40:31 +00:00
wxAboutDialogInfo aboutInfo;
aboutInfo.SetName("Servoterm");
aboutInfo.SetVersion("git");
aboutInfo.SetDescription(_("Servoterm"));
aboutInfo.SetCopyright("(C) 2010-2014");
aboutInfo.SetWebSite("https://github.com/rene-dev/stmbl");
aboutInfo.AddDeveloper("Crinq");
aboutInfo.AddDeveloper("Rene-dev");
wxAboutBox(aboutInfo);
2014-09-17 11:57:57 +00:00
*/
2015-10-28 16:21:42 +00:00
}