-
Notifications
You must be signed in to change notification settings - Fork 12
/
CalibrationUnit.h
206 lines (171 loc) · 6.25 KB
/
CalibrationUnit.h
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
// (c) OneOfEleven 2020
//
// This code can be used on terms of WTFPL Version 2 (http://www.wtfpl.net)
#ifndef CalibrationUnitH
#define CalibrationUnitH
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
#include <System.ImageList.hpp>
#include <Vcl.Buttons.hpp>
#include <Vcl.ComCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Menus.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.Graphics.hpp>
// GDI+ system
//#include <Unknwn.h>
//#include <windows.h>
#include <algorithm>
//using std::min;
//using std::max;
#pragma option push
#pragma warn -8022
#include <gdiplus.h>
// #pragma link "gdiplus.lib"
// #pragma comment (lib, "gdiplus.lib")
// using namespace Gdiplus;
#pragma option pop
#include <vector>
#include "types.h"
#include "median_filter.h"
#include "smoothing_filter.h"
typedef enum : int
{
CAL_TYPE_NONE = 0,
CAL_TYPE_SHORT,
CAL_TYPE_OPEN,
CAL_TYPE_LOAD_ISOLN,
CAL_TYPE_THROUGH
} t_cal_type;
class TCalibrationForm : public TForm
{
__published: // IDE-managed Components
TBitBtn *SaveAsFileBitBtn;
TBitBtn *LoadFileBitBtn;
TGridPanel *GridPanel1;
TButton *ClearCalibrationButton;
TLabel *Label6;
TEdit *CalibrationPathEdit;
TBitBtn *SelectFilePathBitBtn;
TPopupMenu *ListPopupMenu;
TMenuItem *LoadCalibrationFile1;
TMenuItem *DeleteCalibrationFile1;
TMenuItem *N1;
TMenuItem *Cancel1;
TBitBtn *LoadBitBtn;
TImage *CheckImage1;
TImage *CheckImage2;
TMenuItem *RenameCalibrationFile1;
TBitBtn *ExportFilesBitBtn;
TBitBtn *SaveFileBitBtn;
TBitBtn *ShortBitBtn;
TBitBtn *OpenBitBtn;
TMenuItem *CopyCalibrationName1;
TLabel *Label2;
TTrackBar *AverageTrackBar;
TLabel *AverageLabel;
TBitBtn *ThroughBitBtn;
TTrackBar *SmoothingTrackBar;
TLabel *SmoothingLabel;
TLabel *Label40;
TTrackBar *MedianTrackBar;
TLabel *MedianLabel;
TLabel *Label4;
TPopupMenu *CalButtonPopupMenu;
TMenuItem *ClearCal1;
TMenuItem *N2;
TMenuItem *Cancel2;
TMenuItem *Stop1;
TButton *SetMainSweepButton;
TLabel *CalibrationNameLabel;
TListView *CalibrationFilesListView;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
void __fastcall FormShow(TObject *Sender);
void __fastcall FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall FormMouseEnter(TObject *Sender);
void __fastcall LoadFileBitBtnClick(TObject *Sender);
void __fastcall ClearCalibrationButtonClick(TObject *Sender);
void __fastcall CalibrationFilesListViewData(TObject *Sender, TListItem *Item);
void __fastcall CalibrationFilesListViewKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
void __fastcall SelectFilePathBitBtnClick(TObject *Sender);
void __fastcall CalibrationPathEditChange(TObject *Sender);
void __fastcall CalibrationFilesListViewDblClick(TObject *Sender);
void __fastcall ListPopupMenuPopup(TObject *Sender);
void __fastcall LoadCalibrationFile1Click(TObject *Sender);
void __fastcall DeleteCalibrationFile1Click(TObject *Sender);
void __fastcall CalibrationFilesListViewMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall CalTypeBitBtnClick(TObject *Sender);
void __fastcall RenameCalibrationFile1Click(TObject *Sender);
void __fastcall FormHide(TObject *Sender);
void __fastcall ExportFilesBitBtnClick(TObject *Sender);
void __fastcall SaveFileBitBtnClick(TObject *Sender);
void __fastcall SaveAsFileBitBtnClick(TObject *Sender);
void __fastcall CalibrationFilesListViewMouseLeave(TObject *Sender);
void __fastcall CalibrationFilesListViewSelectItem(TObject *Sender, TListItem *Item,
bool Selected);
void __fastcall CopyCalibrationName1Click(TObject *Sender);
void __fastcall AverageTrackBarChange(TObject *Sender);
void __fastcall SmoothingTrackBarChange(TObject *Sender);
void __fastcall MedianTrackBarChange(TObject *Sender);
void __fastcall CalButtonBitBtnMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall CalButtonPopupMenuPopup(TObject *Sender);
void __fastcall ClearCal1Click(TObject *Sender);
void __fastcall SetMainSweepButtonClick(TObject *Sender);
void __fastcall CalibrationFilesListViewChange(TObject *Sender, TListItem *Item,
TItemChange Change);
private: // User declarations
bool m_initialised;
Gdiplus::GdiplusStartupInput m_gdi_plus_startup_input;
ULONG_PTR m_gdi_plus_token;
Gdiplus::Graphics *m_gdi_plus;
Graphics::TBitmap *m_graph_bm;
std::vector <Gdiplus::PointF> m_gdi_points;
int m_cal_button_popup_menu_index;
int m_list_popup_menu_index;
std::vector < complexf > m_cal_samples[MAX_CHANNELS];
typedef struct
{
String filename;
String name;
int64_t start_Hz;
int64_t stop_Hz;
int points;
} t_calibration_file_list;
std::vector <t_calibration_file_list> m_cal_file_list;
t_cal_type m_measure_type;
int m_measure_count;
int m_average_counts;
CMedianFilter m_median_filter;
CSmoothingFilter m_smoothing_filter;
void __fastcall WMWindowPosChanging(TWMWindowPosChanging &msg);
void __fastcall applyCalibration();
void __fastcall updateCalibrationFileList(String directory);
void __fastcall filterValues(std::vector < complexf > &values, const int median_size, const int smooth_level);
bool __fastcall areCalibrationsEqual(const t_calibration *cal1, const t_calibration *cal2);
void __fastcall setButtonGlyph(TBitBtn *but, const int image_index);
void __fastcall setButtonStates();
void __fastcall updateLabels();
protected:
#pragma option push -vi-
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_WINDOWPOSCHANGING, TWMWindowPosMsg, WMWindowPosChanging);
END_MESSAGE_MAP(TForm)
#pragma option pop
public: // User declarations
__fastcall TCalibrationForm(TComponent* Owner);
t_calibration m_calibration;
void __fastcall loadCalibration(String filename);
void __fastcall show();
void __fastcall scanComplete(std::vector <t_data_point> &points);
void __fastcall stop();
__property t_cal_type calType = {read = m_measure_type};
};
extern PACKAGE TCalibrationForm *CalibrationForm;
#endif