forked from General-Embedded/function-draw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUIMyFrame1.cpp
More file actions
221 lines (189 loc) · 4.69 KB
/
GUIMyFrame1.cpp
File metadata and controls
221 lines (189 loc) · 4.69 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "GUIMyFrame1.h"
#include "perspectivic.h"
#include <vector>
#include <fstream>
GUIMyFrame1::GUIMyFrame1(wxWindow* parent)
:
MyFrame1(parent)
{
}
void GUIMyFrame1::showInfo(wxMouseEvent& event)
{
//uzupe³niæ o instrukcjê!
wxMessageDialog* infoDialog = new wxMessageDialog(this, "-> use \"sqrt()\" as aquare root\n->use \"^n\" to raise to the n-th power",
"How to plot?", wxOK | wxICON_INFORMATION);
infoDialog->ShowModal();
infoDialog->Destroy();
}
bool GUIMyFrame1::checkFunction()
{
//sprawdzanie porpawnosci wprowadzonej funkcji!
if (false) {
textCtrlFunkcja->SetValue("");
return false;
}
return true;
}
bool GUIMyFrame1::checkNumbers()
{
try {
xMin = stod(textCtrlXMin->GetValue().ToStdString());
textCtrlXMin->SetValue(to_string(xMin));
}
catch (const std::invalid_argument&) {
textCtrlXMin->SetValue("");
return false;
}
catch (const std::out_of_range&) {
textCtrlXMin->SetValue("");
return false;
}
try {
xMax = stod(textCtrlXMax->GetValue().ToStdString());
textCtrlXMax->SetValue(to_string(xMax));
}
catch (const std::invalid_argument&) {
textCtrlXMax->SetValue("");
return false;
}
catch (const std::out_of_range&) {
textCtrlXMax->SetValue("");
return false;
}
try {
yMin = stod(textCtrlYMin->GetValue().ToStdString());
textCtrlYMin->SetValue(to_string(yMin));
}
catch (const std::invalid_argument&) {
textCtrlYMin->SetValue("");
return false;
}
catch (const std::out_of_range&) {
textCtrlYMin->SetValue("");
return false;
}
try {
yMax = stod(textCtrlYMax->GetValue().ToStdString());
textCtrlYMax->SetValue(to_string(yMax));
}
catch (const std::invalid_argument&) {
textCtrlYMax->SetValue("");
return false;
}
catch (const std::out_of_range&) {
textCtrlYMax->SetValue("");
return false;
}
try {
zMin = stod(textCtrlZMin->GetValue().ToStdString());
textCtrlZMin->SetValue(to_string(zMin));
}
catch (const std::invalid_argument&) {
textCtrlZMin->SetValue("");
return false;
}
catch (const std::out_of_range&) {
textCtrlZMin->SetValue("");
return false;
}
try {
zMax = stod(textCtrlZMax->GetValue().ToStdString());
textCtrlZMax->SetValue(to_string(zMax));
}
catch (const std::invalid_argument&) {
textCtrlZMax->SetValue("");
return false;
}
catch (const std::out_of_range&) {
textCtrlZMax->SetValue("");
return false;
}
return true;
}
void GUIMyFrame1::perspectiveClick(wxMouseEvent& event)
{
if (radioRzut->GetValue()) {
radioMapa->SetValue(false);
inPerspective = true;
inMap = false;
//generujemy wykres!
if (isGenerated)
Repaint();
}
else {
radioRzut->SetValue(true);
}
}
void GUIMyFrame1::outlineClick(wxMouseEvent& event)
{
if (radioMapa->GetValue()) {
radioRzut->SetValue(false);
inPerspective = false;
inMap = true;
//generujemy wykres!
if (isGenerated)
Repaint();
}
else {
radioMapa->SetValue(true);
}
}
void GUIMyFrame1::printClick(wxMouseEvent& event)
{
wxClientDC dc(panelNaWykres);
wxSize size = panelNaWykres->GetSize();
wxBitmap bitmap(size);
wxMemoryDC memDC;
memDC.SelectObject(bitmap);
memDC.Blit(0, 0, size.GetWidth(), size.GetHeight(), &dc, 0, 0);
memDC.SelectObject(wxNullBitmap);
wxImage printPicture = bitmap.ConvertToImage();
printPicture.AddHandler(new wxJPEGHandler);
printPicture.AddHandler(new wxPNGHandler);
wxPrinter printer;
ImagePrintout printout("Image Printout", printPicture);
if (!printer.Print(this, &printout, true)) {
if (wxPrinter::GetLastError() == wxPRINTER_ERROR) {
wxMessageBox("There was a problem with printing.", "Error", wxOK);
}
else {
wxMessageBox("The printing was cancelled.", "Info", wxOK);
}
}
}
void GUIMyFrame1::saveClick(wxMouseEvent& event)
{
wxFileDialog saveFileDialog(this, "Choose a file", "", "", "PNG files (*.png)|*.png", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (saveFileDialog.ShowModal() == wxID_CANCEL) return;
wxClientDC dc(panelNaWykres);
wxSize size = panelNaWykres->GetSize();
wxBitmap bitmap(size);
wxMemoryDC memDC;
memDC.SelectObject(bitmap);
memDC.Blit(0, 0, size.GetWidth(), size.GetHeight(), &dc, 0, 0);
memDC.SelectObject(wxNullBitmap);
wxImage savePicture = bitmap.ConvertToImage();
savePicture.AddHandler(new wxJPEGHandler);
savePicture.AddHandler(new wxPNGHandler);
savePicture.SaveFile(saveFileDialog.GetPath());
}
void GUIMyFrame1::generateClick(wxMouseEvent& event)
{
if (!checkFunction() || !checkNumbers()) return;
//gerneruj wykres
if (isPerspective()) {
//generuj rzut perspektywiczny
Perspectivic obj;
vector<vector<double>> vec{ 5 };
obj.RecountFunctionIntoData(vec);
obj.Repaint(panelNaWykres);
}
else {
//generuj mape konturowa
}
isGenerated = true;
}
void GUIMyFrame1::Repaint() {
wxClientDC DC(WxPanel);
wxBufferedDC BufferedDC(&DC);
}