-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.cpp
More file actions
91 lines (86 loc) · 1.83 KB
/
MainFrame.cpp
File metadata and controls
91 lines (86 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "MainFrame.h"
#include "Document.h"
#include "DocumentFrame.h"
#include "AlgorithmDocumentFrame.h"
#include "AlgorithmInstanceFrame.h"
#include "MainView.h"
#include "Interpreter.h"
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame)
EVT_MENU(wxID_EXIT, MainFrame::OnExit)
EVT_MENU(ID_New, MainFrame::OnNew)
wxEND_EVENT_TABLE()
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, wxID_ANY, title, pos, size)
{
CreateMenuBar();
_interpreter = new Interpreter();
}
MainFrame::~MainFrame()
{
DestroyChildren();
delete _interpreter;
}
void MainFrame::OnExit(wxCommandEvent& event)
{
Close();
}
void MainFrame::CreateMenuBar()
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(wxID_EXIT);
menuFile->AppendSeparator();
menuFile->Append(ID_New, L"&New...");
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, "&File" );
SetMenuBar( menuBar );
}
void MainFrame::OnNew(wxCommandEvent& event)
{
if(_childWindows.size()<DOCUMENT_LIMIT)
{
AddChildWindow();
}
}
void MainFrame::AddChildWindow()
{
AlgorithmDocumentFrame *dlg = new AlgorithmDocumentFrame(this);
dlg->CreateDocument();
_childWindows.push_back(dlg);
dlg->Show();
}
void MainFrame::RemoveChildWindow(DocumentFrame *child)
{
doc_iter it = _childWindows.begin();
for(;it!=_childWindows.end();it++)
{
if(*it==child)
{
_childWindows.remove(child);
return;
}
}
}
void MainFrame::InterpretDocument(Document* doc)
{
try
{
_interpreter->InterpretDocument(doc);
OpenSolutionBox();
}
catch(std::invalid_argument const& ex)
{
//TODO handle errors
exit(0);
}
catch(std::bad_typeid const& ex)
{
//TODO handle errors
exit(0);
}
//TODO load results of interpreter into algorithm data structure
}
void MainFrame::OpenSolutionBox()
{
AlgorithmInstanceFrame *dlg = new AlgorithmInstanceFrame(this);
dlg->Show();
}