-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit1.pas
225 lines (187 loc) · 6.49 KB
/
unit1.pas
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
222
223
224
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Menus;
type
{ TForm1 }
TForm1 = class(TForm)
calculateButton: TButton;
customSensorDimensionsCheckBox: TCheckBox;
FOVDiagonalEdit: TEdit;
FOVVerticalEdit: TEdit;
FOVHorizontalEdit: TEdit;
focalLengthMMLabel: TLabel;
FOVLabel: TLabel;
FOVHorizontalLabel: TLabel;
FOVVerticalLabel: TLabel;
FOVDiagonalLabel: TLabel;
sensorXLabel: TLabel;
sensorYLabel: TLabel;
sensorXEdit: TEdit;
sensorYEdit: TEdit;
lensEquivalent: TEdit;
lensFocalLengthEquivalentLabel: TLabel;
lensMultiplicationFactor: TEdit;
lensMultiplicationFactorLabel: TLabel;
sensorSizesComboBox: TComboBox;
focalLength: TEdit;
focalLengthLabel: TLabel;
sensorSizeLabel: TLabel;
procedure calculateButtonClick(Sender: TObject);
procedure customSensorDimensionsCheckBoxChange(Sender: TObject);
procedure focalLengthKeyPress(Sender: TObject; var Key: char);
procedure FormCreate(Sender: TObject);
procedure sensorSizesComboBoxChange(Sender: TObject);
procedure sensorSizesComboBoxSelect(Sender: TObject);
procedure sensorXEditKeyPress(Sender: TObject; var Key: char);
procedure sensorYEditKeyPress(Sender: TObject; var Key: char);
procedure calculate;
private
public
end;
var
Form1: TForm1;
implementation
uses focalLengthCounter, sensorsdb;
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
j : integer;
sns : sensorsdb.pSensor;
begin
Form1.Caption:= 'focal length calculator';
focalLengthLabel.Caption:= 'focal length:';
focalLength.Text:= '';
focalLengthMMLabel.Caption:= 'mm';
sensorSizeLabel.Caption:= 'sensor size:';
sensorSizesComboBox.Text:= 'choose sensor';
sensorsdb.initialize;
for j := 0 to sensorsdb.sensors.Count - 1 do begin
sns := sensorsdb.pSensor(sensorsdb.sensors[j]);
sensorSizesComboBox.Items.Add(sns^.desc);
end;
lensMultiplicationFactorLabel.Caption := 'lens multiplication factor:';
lensMultiplicationFactor.Text:= '';
lensMultiplicationFactor.ReadOnly:= true;
lensFocalLengthEquivalentLabel.Caption:= '35mm focal length equivalent:';
lensEquivalent.Text:= '';
lensEquivalent.ReadOnly:= true;
calculateButton.Caption:= 'calculate!';
customSensorDimensionsCheckBox.Caption := 'enter custom sensor sizes';
customSensorDimensionsCheckBox.Checked := false;
sensorXLabel.Caption := 'mm';
sensorYLabel.Caption := 'mm';
sensorXEdit.Text := '';
sensorYEdit.Text := '';
sensorXEdit.Enabled:= false;
sensorYEdit.Enabled:= false;
sensorSizesComboBox.Enabled:= true;
FOVLabel.Caption:= 'FOV:';
FOVHorizontalLabel.Caption:= 'horizontal:';
FOVHorizontalEdit.Text:= '';
FOVHorizontalEdit.ReadOnly:= true;
FOVVerticalLabel.Caption:= 'vertical:';
FOVVerticalEdit.Text:= '';
FOVVerticalEdit.ReadOnly:= true;
FOVDiagonalLabel.Caption:= 'diagonal:';
FOVDiagonalEdit.Text:= '';
FOVDiagonalEdit.ReadOnly:= true;
end;
procedure TForm1.sensorXEditKeyPress(Sender: TObject; var Key: char);
begin
if not (Key in [#8, '0'..'9']) then begin
//ShowMessage('Invalid key');
// Discard the key
Key := #0;
end; //if
end;
procedure TForm1.sensorYEditKeyPress(Sender: TObject; var Key: char);
begin
if not (Key in [#8, '0'..'9']) then begin
//ShowMessage('Invalid key');
// Discard the key
Key := #0;
end; //if
end;
procedure TForm1.customSensorDimensionsCheckBoxChange(Sender: TObject);
begin
if customSensorDimensionsCheckBox.Checked then begin
sensorXEdit.Enabled:= true;
sensorYEdit.Enabled:= true;
sensorSizesComboBox.Enabled:= false;
end
else
begin
sensorXEdit.Enabled:= false;
sensorYEdit.Enabled:= false;
sensorSizesComboBox.Enabled:= true;
end;
end;
procedure TForm1.calculate;
var
cf: real;
sns: sensorsdb.pSensor;
begin
if focalLength.GetTextLen > 0 then begin
if customSensorDimensionsCheckBox.Checked then begin
if (sensorXEdit.GetTextLen > 0) and (sensorYEdit.GetTextLen > 0) then begin
cf := focalLengthCounter.cropFactor(StrToInt(sensorXEdit.Text), StrToInt(sensorYEdit.Text));
lensMultiplicationFactor.Text:= FloatToStr(cf);
lensEquivalent.Text:= IntToStr(focalLengthCounter.focalLengthEquivalent(StrToFloat(focalLength.Text), cf));
FOVHorizontalEdit.Text:= FloatToStr(focalLengthCounter.horizontalFOV(StrToFloat(sensorXEdit.Text), StrToFloat(focalLength.Text)));
FOVVerticalEdit.Text:= FloatToStr(focalLengthCounter.verticalFOV(StrToFloat(sensorYEdit.Text), StrToFloat(focalLength.Text)));
FOVDiagonalEdit.Text:= FloatToStr(focalLengthCounter.diagonalFOV(focalLengthCounter.diagonal(StrToFloat(sensorXEdit.Text),StrToFloat(sensorYEdit.Text)), StrToFloat(focalLength.Text)));
end
else
begin
Dialogs.ShowMessage ('enter sensor sizes!');
end
end
else
begin
//Dialogs.ShowMessage(IntToStr(sensorSizesComboBox.ItemIndex));
if sensorSizesComboBox.ItemIndex = -1 then begin
Dialogs.ShowMessage('choose sensor size!');
end
else
begin
sns := sensorsdb.pSensor(sensorsdb.sensors[sensorSizesComboBox.ItemIndex]);
lensMultiplicationFactor.Text:= FloatToStr(sns^.mfact);
lensEquivalent.Text:= IntToStr(focalLengthCounter.focalLengthEquivalent(StrToFloat(focalLength.Text), sns^.mfact));
FOVHorizontalEdit.Text:= FloatToStr(focalLengthCounter.horizontalFOV(sns^.width, StrToFloat(focalLength.Text)));
FOVVerticalEdit.Text:= FloatToStr(focalLengthCounter.verticalFOV(sns^.height, StrToFloat(focalLength.Text)));
FOVDiagonalEdit.Text:= FloatToStr(focalLengthCounter.diagonalFOV(sns^.diag, StrToFloat(focalLength.Text)));
end;
end;
end
else
begin
Dialogs.ShowMessage ('focal length emty!');
end;
end; //tform1.calculate
procedure TForm1.calculateButtonClick(Sender: TObject);
begin
calculate;
end;
procedure TForm1.sensorSizesComboBoxChange(Sender: TObject);
begin
calculate;
end;
procedure TForm1.sensorSizesComboBoxSelect(Sender: TObject);
begin
end;
procedure TForm1.focalLengthKeyPress(Sender: TObject; var Key: char);
begin
if not (Key in [#8, '0'..'9', Sysutils.DefaultFormatSettings.DecimalSeparator]) then begin
//ShowMessage('Invalid key: ' + Key);
Key := #0;
end
else if (Key = Sysutils.DefaultFormatSettings.DecimalSeparator) and
(Pos(Key, focalLength.Text) > 0) then begin
//ShowMessage('Invalid Key: twice ' + Key);
Key := #0;
end;
end;
end.