-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
174 lines (153 loc) · 6.5 KB
/
Main.cpp
File metadata and controls
174 lines (153 loc) · 6.5 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "Main.h"
wxBEGIN_EVENT_TABLE(Main, wxFrame)
EVT_MENU(101, Main::OnMenuQuit)
wxEND_EVENT_TABLE()
Main::Main() : wxFrame(nullptr, wxID_ANY, "Flowchart2Code") {
// Icons for Windows OS
#ifdef __WXMSW__
wxIcon mainicon;
mainicon.LoadFile("Flowchart2Code.ico", wxBITMAP_TYPE_ICO);
SetIcon(mainicon);
#endif
// Icons for Linux OS
#ifdef __WXGTK__
wxIcon mainicon;
mainicon.LoadFile("Flowchart2Code.png", wxBITMAP_TYPE_PNG);
SetIcon(mainicon);
#endif
wxMenuBar* menubar = new wxMenuBar;
wxMenu* fileMenu = new wxMenu;
fileMenu->Append(101, "Quit");
menubar->Append(fileMenu, "File");
SetMenuBar(menubar);
wxFont font_head = wxFont(26, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false);
wxFont font_head2 = wxFont(9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false);
wxFont font_head3 = wxFont(14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false);
wxString lang[] = { "C", "C++", "Python" };
wxString input_type[] = { "Image", "XML" };
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText* heading = new wxStaticText(this, 501, "FLOWCHART2CODE", wxDefaultPosition, wxDefaultSize);
wxStaticText* heading2 = new wxStaticText(this, 502, "Created By: Sanyog Gupta", wxDefaultPosition, wxDefaultSize);
wxStaticText* heading3 = new wxStaticText(this, 503, "Select Input File Location:", wxDefaultPosition, wxDefaultSize);
wxStaticText* heading4 = new wxStaticText(this, 504, "Select Code File Location:", wxDefaultPosition, wxDefaultSize);
Main::file = new wxFileDialog(this, "Open Input File", wxEmptyString, wxEmptyString, "JPG files (*.jpg)|*.jpg|PNG files (*.png)|*.png|TIFF files (*.tiff)|*.tiff", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
Main::code = new wxFileDialog(this, "Save Code As", wxEmptyString, wxEmptyString, "C files (*.c)|*.c", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
Main::inputbox = new wxRadioBox(this, 301, "Input Type", wxDefaultPosition, wxDefaultSize, 2, input_type, 2, wxRA_SPECIFY_COLS);
Main::langbox = new wxRadioBox(this, 302, "Language", wxDefaultPosition, wxDefaultSize, 3, lang, 3, wxRA_SPECIFY_COLS);
wxButton* gen = new wxButton(this, 201, "Generate Code");
wxButton* guidelines = new wxButton(this, 202, "Guidelines");
wxButton* choosefile = new wxButton(this, 203, "Select Input File");
wxButton* choosecode = new wxButton(this, 204, "Select Output File");
gen->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Main::OnCreateCode, this);
choosefile->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Main::OnChooseInp, this);
choosecode->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Main::OnChooseCode, this);
inputbox->Bind(wxEVT_RADIOBOX, &Main::OnInputbox, this);
langbox->Bind(wxEVT_RADIOBOX, &Main::OnLangbox, this);
guidelines->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Main::OnGuidelines, this);
//Problem with setting font style in Linux
#ifndef __WXGTK__
heading->SetFont(font_head);
heading2->SetFont(font_head2);
heading3->SetFont(font_head3);
heading4->SetFont(font_head3);
#endif
sizer->Add(heading, 0, wxALIGN_CENTER | wxUP, 30);
sizer->Add(heading2, 0, wxALIGN_CENTER | wxDOWN, 30);
sizer->Add(guidelines, 0, wxEXPAND | wxLEFT | wxRIGHT, 20);
sizer->Add(inputbox, 0, wxEXPAND | wxLEFT | wxRIGHT, 20);
sizer->Add(heading3, 0, wxALIGN_LEFT | wxUP | wxLEFT, 20);
sizer->Add(choosefile, 0, wxEXPAND | wxLEFT | wxRIGHT, 20);
sizer->Add(langbox, 0, wxEXPAND | wxALL, 20);
sizer->Add(heading4, 0, wxALIGN_LEFT | wxLEFT, 20);
sizer->Add(choosecode, 0, wxEXPAND | wxLEFT | wxRIGHT | wxDOWN, 20);
sizer->Add(gen, 0, wxEXPAND, 0);
sizer->SetSizeHints(this);
SetSizer(sizer);
}
void Main::OnMenuQuit(wxCommandEvent& evt) {
Close();
evt.Skip();
}
void Main::OnCreateCode(wxCommandEvent& evt) {
Main::filepath = file->GetPath();
Main::codepath = code->GetPath();
std::string check1 = std::string(codepath.mb_str());
// Check if output file selected or not
if (check1.empty()) {
wxMessageDialog* dial = new wxMessageDialog(NULL, wxT("Output File Not Selected!"), wxT("Error"), wxOK | wxCENTER | wxICON_ERROR);
dial->ShowModal();
}
else {
Main::lang_sel = langbox->GetSelection();
Main::inp_sel = inputbox->GetSelection();
std::string path = std::string(filepath.mb_str());
std::ifstream check(path);
// Check if input file selected or not
if (!check) {
wxMessageDialog* dial = new wxMessageDialog(NULL, wxT("Input File Not Found!"), wxT("Error"), wxOK | wxCENTER | wxICON_ERROR);
dial->ShowModal();
}
else {
if (Main::inp_sel == 0) {
imagefile = new img(Main::filepath, Main::codepath, Main::lang_sel);
delete imagefile;
imagefile = nullptr;
}
else if (Main::inp_sel == 1) {
xmlfile = new xml(Main::filepath, Main::codepath, Main::lang_sel);
delete xmlfile;
xmlfile = nullptr;
}
}
check.close();
}
evt.Skip();
}
void Main::OnGuidelines(wxCommandEvent& evt) {
std::ifstream check("Guidelines.pdf");
// Checking the presence of guidelines file
if (!check) {
wxMessageDialog* dial = new wxMessageDialog(NULL, wxT("Guidelines File Not Found!"), wxT("Error"), wxOK | wxCENTER | wxICON_ERROR);
dial->ShowModal();
}
else {
wxLaunchDefaultApplication("Guidelines.pdf");
}
check.close();
evt.Skip();
}
void Main::OnChooseInp(wxCommandEvent& evt) {
Main::file->ShowModal();
evt.Skip();
}
void Main::OnChooseCode(wxCommandEvent& evt) {
Main::code->ShowModal();
evt.Skip();
}
void Main::OnInputbox(wxCommandEvent& evt) {
Main::inp_sel = inputbox->GetSelection();
Main::file->SetPath("");
// Sets file type to search
if (Main::inp_sel == 0) {
Main::file->SetWildcard("JPG files (*.jpg)|*.jpg|PNG files (*.png)|*.png|TIFF files (*.tiff)|*.tiff");
}
else {
Main::file->SetWildcard("XML files (*.xml)|*.xml");
}
evt.Skip();
}
void Main::OnLangbox(wxCommandEvent& evt) {
Main::lang_sel = langbox->GetSelection();
Main::code->SetPath("");
// Sets file type to save
if (Main::lang_sel == 0) {
Main::code->SetWildcard("C files (*.c)|*.c");
}
else if (Main::lang_sel == 1) {
Main::code->SetWildcard("C++ files (*.cpp)|*.cpp");
}
else {
Main::code->SetWildcard("Python files (*.py)|*.py");
}
evt.Skip();
}