-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhdspeconf.cpp
158 lines (132 loc) · 3.8 KB
/
hdspeconf.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
148
149
150
151
152
153
154
155
156
157
158
/*! \file hdspeconf.cpp
*! \brief hdspeconf main.
* 20210809,10,11,12,0907,08,15,16 - [email protected] */
// TODO: catch runtime errors in a Error dialog.
#include <iostream>
#include <thread>
#include <chrono>
#include <functional>
#include <stdexcept>
#include <mutex>
#include <condition_variable>
#include <queue>
#include <sys/types.h>
#include <wx/choicebk.h>
#include "NoCardsPanel.h"
#include "HDSPeConf.h"
#include "HDSPeCard.h"
//! \brief Main window: a notebook containing pages for each HDSPe card
//! and TCO.
class MainWindow: public wxFrame {
public:
HDSPeCardEnumerator cardEnumerator; // enumerates HDSPe cards on construction
MainWindow()
: wxFrame(nullptr, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE)
{
SetTitle(wxT("hdspeconf"));
wxPanel* panel_1 = new wxPanel(this, wxID_ANY);
wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
notebook_1 = new wxChoicebook(panel_1, wxID_ANY);
sizer_1->Add(notebook_1, 1, wxEXPAND, 0);
// Add a notebook page for each hdspe card + TCO expansion module.
std::vector<HDSPeCard*>& cards = cardEnumerator.getCards();
if (cards.size() == 0) {
// Add page with message if no hdspe driven cards are available
notebook_1->AddPage(new NoCardsPanel(notebook_1, wxID_ANY), wxT(""));
} else {
for (auto card: cards) {
wxPanel *panel = card->makePanel(notebook_1);
notebook_1->AddPage(panel, card->getPrettyName());
if (card->hasTco())
notebook_1->AddPage(card->makeTcoPanel(notebook_1),
std::string(card->getPrettyName()) + " TCO");
}
}
// TODO: add "About" panel.
panel_1->SetSizer(sizer_1);
sizer_1->Fit(panel_1);
Layout();
// Need to set proper initial and minimal window size ourselves, it seems.
wxSize sz = panel_1->GetBestSize();
int h = sz.GetHeight(), w = sz.GetWidth();
sz.SetHeight(h < 300 ? 300 : h+48);
sz.SetWidth(w < 400 ? 400 : w+16);
SetInitialSize(ClientToWindowSize(sz));
}
~MainWindow()
{
}
protected:
wxChoicebook *notebook_1 { nullptr };
};
//! \brief The application.
class HDSPeConf: public wxApp {
public:
bool OnInit() override
{
wxInitAllImageHandlers();
try {
mainWindow = new MainWindow;
SetTopWindow(mainWindow);
mainWindow->Show();
} catch (std::exception &e) {
std::cerr << "OnInit C++ exception caught: " << e.what() << "\n";
return false;
} catch (...) {
std::cerr << "OnInit: unhandled exception caught.\n";
}
return true;
}
int OnExit() override
{
return 0;
}
bool OnExceptionInMainLoop() override
{
try {
throw;
} catch(std::exception &e) {
std::cerr << "MainLoop C++ exception caught: " << e.what() << "\n";
// MessageBoxA(NULL, e.what(), "C++ Exception Caught", MB_OK);
} catch (...) {
std::cerr << "OnExceptionInMainLoop: unhandled exception caught.\n";
}
return true; // continue on. Return false to abort program
}
void OnUnhandledException() override
{
try {
throw;
} catch(std::exception &e) {
std::cerr << "Unhandled C++ exception caught: " << e.what() << "\n";
} catch (...) {
std::cerr << "Unhandled exception caught.\n";
}
}
//! \brief Post callback function.
void post(std::function<void(void)> cb)
{
CallAfter(cb);
}
protected:
MainWindow* mainWindow {nullptr};
};
IMPLEMENT_APP(HDSPeConf)
void PostCB(std::function<void(void)> cb)
{
::wxGetApp().post(cb);
}
#ifdef NEVER
#include <time.h>
double GetTime(void)
{
struct timespec t;
clock_gettime(CLOCK_MONOTONIC_RAW, &t);
double time = (double)t.tv_sec + (double)t.tv_nsec * 1e-9;
static double starttime = 0.0;
if (starttime == 0.0)
starttime = time;
return time - starttime;
}
#endif /*NEVER*/