-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
147 lines (106 loc) · 4.33 KB
/
main.cpp
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
#include "interpolator.h"
#include "integrator.h"
#include <wx/wx.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class MyApp : public wxApp {
public:
virtual bool OnInit();
};
class MainFrame : public wxFrame {
public:
explicit MainFrame(const wxString &title);
private:
wxPanel *pnl;
wxButton *btnCalculate;
wxBoxSizer *mainSizer, *inputSizer, *memoSizer;
wxTextCtrl *edtFirst, *edtLast;
wxTextCtrl *memoInput, *memoOutput;
private:
void OnPressbtnCalculate(wxMouseEvent& event);
void onClickTextCtrl(wxMouseEvent& event);
};
IMPLEMENT_APP(MyApp)
[[maybe_unused]] bool MyApp::OnInit() {
MainFrame *frame = new MainFrame(_("wxSolarCurrent"));
frame->Show(true);
return true;
}
MainFrame::MainFrame(const wxString &title):wxFrame(NULL, wxID_ANY, title) {
CreateStatusBar(1);
SetStatusText(wxT("To start enter or paste x,y data to the left field"), 0);
pnl = new wxPanel(this, wxID_ANY);
btnCalculate = new wxButton(pnl, wxID_ANY, "Calculate");
btnCalculate->Bind(wxEVT_LEFT_UP, &MainFrame::OnPressbtnCalculate, this);
edtFirst = new wxTextCtrl(pnl, wxID_ANY, wxT("300"));
edtLast = new wxTextCtrl(pnl, wxID_ANY, wxT("1200"));
memoInput = new wxTextCtrl(pnl, wxID_ANY, wxT(""),
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH,
wxDefaultValidator, wxTextCtrlNameStr);
memoOutput = new wxTextCtrl(pnl, wxID_ANY, wxT(""),
wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_RICH,
wxDefaultValidator, wxTextCtrlNameStr);
edtFirst->Bind(wxEVT_LEFT_UP, &MainFrame::onClickTextCtrl, this);
edtLast->Bind(wxEVT_LEFT_UP, &MainFrame::onClickTextCtrl, this);
inputSizer = new wxBoxSizer(wxHORIZONTAL);
inputSizer->Add(edtFirst, 1, wxEXPAND | wxALL, 5);
inputSizer->Add(edtLast, 1, wxEXPAND | wxALL, 5);
inputSizer->Add(btnCalculate, 0, wxALL, 5);
memoSizer = new wxBoxSizer(wxHORIZONTAL);
memoSizer->Add(memoInput, 1, wxEXPAND | wxALL, 5);
memoSizer->Add(memoOutput, 1, wxEXPAND | wxALL, 5);
mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(inputSizer, 0, wxALL, 5);
mainSizer->Add(memoSizer, 1, wxEXPAND | wxALL, 5);
pnl->SetSizer(mainSizer);
mainSizer->Fit(this); // resize (fit) main window based on elements inside sizer
wxSize ws = this->GetSize();
SetMinSize(wxSize(ws.GetWidth(), 500));
SetMaxSize(wxSize(ws.GetWidth(), 500));
Centre();
*memoInput << "Example:\nWavelength (nm)\tEQE\n300\t1\n1200\t1\n";
*memoOutput << "Results:\n";
}
void MainFrame::OnPressbtnCalculate(wxMouseEvent& event) {
event.Skip(); // if skip it - bugs with text selection appear
SetStatusText("", 0);
wxString tFirst = edtFirst->GetValue();
wxString tLast = edtLast->GetValue();
double dFirst, dLast;
if(!tFirst.ToCDouble(&dFirst) or
!tLast.ToCDouble(&dLast)) {
SetStatusText("Error! Please enter real numbers", 0);
return;
}
if (dLast < dFirst) {
SetStatusText("Error! Last value mast be greater that First", 0);
return;
}
wxString wxMemoText = MainFrame::memoInput->GetValue();
std::string solarFluxFile = "amst.dat"s;
Integrator solarCurrent(dFirst, dLast, std::string(wxMemoText.mb_str()), '\n', '\t', solarFluxFile);
if (solarCurrent.getAmstDataSize() == 0) {
SetStatusText("Error! No amst.dat found or incorrect file format", 0);
}
string str_value = to_string(solarCurrent.getSolarCurrent());
// Memo output displays digits with zeros. This trick removes them
constexpr int digits = 2; // after point
std::size_t pos = str_value.find('.');
if (pos != std::string::npos && str_value.size() > (pos + digits)) {
str_value = str_value.substr(0, pos + digits);
}
*memoOutput << str_value << " mA/cm2\n";
}
// If entered any char then the field is cleared
void MainFrame::onClickTextCtrl(wxMouseEvent& event) {
// get object where the event was generated
wxTextCtrl *tc = (wxTextCtrl*)event.GetEventObject();
event.Skip();
wxString textValue = tc->GetValue();
double nd = 0; // double value of number
if(!textValue.ToCDouble(&nd)) tc->Clear();
}