-
Notifications
You must be signed in to change notification settings - Fork 0
/
LGSelect.pas
461 lines (420 loc) · 14.1 KB
/
LGSelect.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
UNIT LGSelect;
{$R+}
{
Line graph selection -- ring, file, etc.
v01.01 2003-01-09 Original
v01.02 2003-01-27 Replace IFDEF CLX ELSE->IFDEF LINUX ENDIF IFDEF MSWINDOWS
v01.03 2003-01-31 Change GROUP_*, PERIOD_* to LG_GROUP_*, LG_PERIOD_*
v01.04 2003-01-31 Move LG_*_* from Implementation to Interface section
v01.05 2003-01-31 Transfer these global constants to LGSetup
v01.06 2003-03-14 btnGo: if ring=1 use LineGraf instead of COMDIS
v01.07 2003-03-15 OnClickRadio: SetFocus to ebRecord if Sender is rbHistoric
v01.08 2003-03-18 Replace procedure OnDestroyForm by OnCloseForm
v01.09 2003-03-19 .dfm: make Go-bar width same as groups it applies to
v01.10 2003-05-10 btnGo: if ring=1 AND site=NC1 use LineGraf instead of COMDIS
v01.11 2003-05-25 OnDestroyForm: added back; frmLGSelect := NIL
v01.12 2003-05-27 Replace OnKeyPressForm by OnKeyDownForm
v01.13 2003-05-27 Add USES Classes for TShiftState
v01.14 2003-05-28 comd/Globals changes
v01.15 2003-06-08 in sfil[] replace 1 or 3 by FTLOGG or FTVARR
v01.16 2004-02-29 OnClickRadio: IF created AND (Sender = rbHistoric) ...
}
INTERFACE
USES
{$IFDEF LINUX}
QButtons, QExtCtrls, QForms, QGraphics, QStdCtrls,
Types,
{$ENDIF}
{$IFDEF MSWINDOWS}
Buttons, ExtCtrls, Forms, Graphics, StdCtrls,
Windows, Classes,
{$ENDIF}
SysUtils,
LineGraf, LGSetup, LblForm,
Globals,
comdis, comd;
TYPE
TfrmLGSelect = CLASS(TForm)
gbRing: TGroupBox;
gbFile: TGroupBox;
rbLogg: TRadioButton;
rbVarr: TRadioButton;
rbAux: TRadioButton;
rbSnap: TRadioButton;
lblStatus: TLabel;
lblStatusVal: TLabel;
lblRecords: TLabel;
lblRecordsVal: TLabel;
lblSize: TLabel;
lblSizeVal: TLabel;
lblTStep: TLabel;
lblTStepVal: TLabel;
gbPeriod: TGroupBox;
rbHistoric: TRadioButton;
rbRecent: TRadioButton;
rbCurrent: TRadioButton;
lblHours: TLabel;
ebHours: TEdit;
lblRecord: TLabel;
ebRecord: TEdit;
gpShortcuts: TGroupBox;
btnLogg: TButton;
btnAux: TButton;
rbQuikA: TRadioButton;
rbQuikB: TRadioButton;
rbQuikC: TRadioButton;
rbQuikD: TRadioButton;
rbQuikE: TRadioButton;
rbQuikF: TRadioButton;
btnCancel: TBitBtn;
btnSetup: TBitBtn;
btnHelp: TBitBtn;
lblHot: TLabel;
lbHot: TListBox;
btnGo: TBitBtn;
PROCEDURE Apply;
PROCEDURE Refresh;
PROCEDURE OnCreateForm (Sender: TObject);
PROCEDURE OnCloseForm (Sender: TObject; VAR Action: TCloseAction);
PROCEDURE OnDestroyForm (Sender: TObject);
PROCEDURE OnClickButton (Sender: TObject);
PROCEDURE OnClickRadio (Sender: TObject);
PROCEDURE OnKeyDownForm (Sender: TObject; VAR Key: Word; Shift: TShiftState);
PRIVATE
{ Private declarations }
rbRings: ARRAY [1..maxrings] OF TRadioButton;
PUBLIC
{ Public declarations }
END;
PROCEDURE Select (ring: INTEGER);
FUNCTION HotRingGet: INTEGER;
IMPLEMENTATION
VAR
frmLGSelect: TfrmLGSelect;
frmHelp: TLblForm;
SRing: INTEGER;
SHot: INTEGER;
SGroup: INTEGER;
SPeriod: INTEGER;
SHours: Single;
SRecord: Longint;
SQuik: Single;
created: BOOLEAN;
{$R *.dfm}
{-------------------------------------------------------------}
PROCEDURE debug (where, when: String);
BEGIN
IF NOT ASSIGNED(frmHelp) THEN frmHelp := TLblForm.Create (Application);
frmHelp.Display ('LGSelect: ' + where + ' ' + when,
'SRing = ' + IntToStr(SRing) +CHR(13)+CHR(10)+CHR(13)+CHR(10)+
'SGroup = ' + IntToStr(SGroup) +CHR(13)+CHR(10)+CHR(13)+CHR(10)+
'SPeriod = ' + IntToStr(SPeriod) +CHR(13)+CHR(10)+CHR(13)+CHR(10)+
'SHours = ' + FloatToStr(SHours) +CHR(13)+CHR(10)+CHR(13)+CHR(10)+
'SRecord = ' + IntToStr(SRecord) +CHR(13)+CHR(10)+CHR(13)+CHR(10)+
'SQuik = ' + FloatToStr(SQuik) +CHR(13)+CHR(10)+CHR(13)+CHR(10)+
'SHot = ' + IntToStr(SHot)
);
MessageBox (0, 'debug', 'LGSelect', MB_OK);
frmHelp.Release;
frmHelp := NIL;
END; {of procedure 'debug'}
{-------------------------------------------------------------}
FUNCTION HotRingGet: INTEGER;
BEGIN
HotRingGet := SHot;
END; {of function HotRingGet}
{-------------------------------------------------------------}
PROCEDURE Select (ring: INTEGER);
{Come here when this menu item selected on a form}
BEGIN
SRing := ring;
IF NOT Assigned (frmLGSelect)
THEN frmLGSelect := TfrmLGSelect.Create (Application)
ELSE frmLGSelect.rbRings[SRing].Checked := TRUE;
WITH frmLGSelect DO BEGIN
Refresh;
Show;
SetFocus;
WindowState := wsNormal;
END;
created := TRUE;
END; {of procedure 'Select'}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.Apply;
{Loads working static variables from form controls}
VAR ring: INTEGER;
BEGIN
{debug ('Apply', 'BEFORE');}
FOR ring := 1 TO numrings DO
IF rbRings[ring].Checked THEN SRing := ring;
IF rbLogg.Checked THEN SGroup := LG_GROUP_LOGG;
IF rbVarr.Checked THEN SGroup := LG_GROUP_VARR;
IF rbAux .Checked THEN SGroup := LG_GROUP_AUX;
IF rbSnap.Checked THEN SGroup := LG_GROUP_SNAPSHOT;
IF rbHistoric.Checked THEN SPeriod := LG_PERIOD_HISTORIC;
IF rbRecent .Checked THEN SPeriod := LG_PERIOD_RECENT;
IF rbCurrent .Checked THEN SPeriod := LG_PERIOD_CURRENT;
SHours := StrToFloat (ebHours.Text);
SRecord := StrToInt (ebRecord.Text);
IF rbQuikA.Checked THEN SQuik := rbQuikA.Tag;
IF rbQuikB.Checked THEN SQuik := rbQuikB.Tag;
IF rbQuikC.Checked THEN SQuik := rbQuikC.Tag;
IF rbQuikD.Checked THEN SQuik := rbQuikD.Tag;
IF rbQuikE.Checked THEN SQuik := rbQuikE.Tag;
IF rbQuikF.Checked THEN SQuik := rbQuikF.Tag;
SHot := lbHot.ItemIndex + 1;
{debug ('Apply', 'AFTER');}
END; {of procedure 'Apply'}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.Refresh;
{Loads form controls from working static variables}
BEGIN
ebHours.Text := FloatToStrF (SHours, ffFixed, 3, 1);
ebHours.Visible := (SPeriod <> LG_PERIOD_CURRENT);
lblHours.Visible := ebHours.Visible;
ebRecord.Text := IntToStr (SRecord);
ebRecord.Visible := (SPeriod = LG_PERIOD_HISTORIC);
lblRecord.Visible := ebRecord.Visible;
lbHot.ItemIndex := SHot - 1;
CASE SGroup OF
LG_GROUP_LOGG,
LG_GROUP_AUX:
BEGIN
IF sfil[SRing,FTLOGG]
THEN BEGIN
lblStatusVal.Caption := 'Open';
lblStatusVal.Font.Color := clGreen;
END
ELSE BEGIN
lblStatusVal.Caption := 'Closed';
lblStatusVal.Font.Color := clRed;
END;
IF (recnum[SRing,1] > 0)
THEN BEGIN
lblRecordsVal.Caption := IntToStr (recnum[SRing,1]);
lblRecordsVal.Font.Color := clBlack;
END
ELSE BEGIN
lblRecordsVal.Caption := 'EMPTY';
lblRecordsVal.Font.Color := clRed;
END;
lblSizeVal.Caption := IntToStr (len[SRing,1]);
lblTStepVal.Caption := FloatToStr (timestep[1]);
END;
LG_GROUP_VARR:
BEGIN
IF sfil[SRing,FTVARR]
THEN BEGIN
lblStatusVal.Caption := 'Open';
lblStatusVal.Font.Color := clGreen;
END
ELSE BEGIN
lblStatusVal.Caption := 'Closed';
lblStatusVal.Font.Color := clRed;
END;
IF (recnum[SRing,3] > 0)
THEN BEGIN
lblRecordsVal.Caption := IntToStr (recnum[SRing,3]);
lblRecordsVal.Font.Color := clBlack;
END
ELSE BEGIN
lblRecordsVal.Caption := 'EMPTY';
lblRecordsVal.Font.Color := clRed;
END;
lblSizeVal.Caption := IntToStr (len[SRing,3]);
lblTStepVal.Caption := FloatToStr (timestep[3]);
END;
LG_GROUP_SNAPSHOT:
BEGIN
lblStatusVal.Caption := 'Open';
lblStatusVal.Font.Color := clBlack;
lblRecordsVal.Caption := 'Not appl.';
lblRecordsVal.Font.Color := clBlack;
lblSizeVal.Caption := 'Not appl.';
lblTStepVal.Caption := '2'; {hardwired since toggle used}
END;
END; {case}
END; {of procedure 'Refresh'}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.OnCreateForm (Sender: TObject);
VAR ring: INTEGER;
BEGIN
{Do not execute Apply when radio buttons initialized}
created := FALSE;
{Form gets to look at key strokes first for ring changing}
KeyPreview := TRUE;
{Create ring select radio buttons}
FOR ring := 1 TO numrings DO BEGIN
rbRings[ring] := TRadioButton.Create (Self);
WITH rbRings[ring] DO BEGIN
Parent := gbRing;
Checked := (ring = SRing);
Caption := rlabel[ring];
Left := 10;
Top := ring * 15 + 5;
Width := 30;
OnClick := OnClickRadio;
END;
END;
{Create hot button list}
lbHot.Clear;
FOR ring := 1 TO numrings DO WITH lbHot DO BEGIN
AddItem ('Ring ' + rlabel[ring], NIL);
END;
lbHot.Color := clWhite;
rbLogg.Checked := (SGroup = LG_GROUP_LOGG);
rbVarr.Checked := (SGroup = LG_GROUP_VARR);
rbAux .Checked := (SGroup = LG_GROUP_AUX);
rbSnap.Checked := (SGroup = LG_GROUP_SNAPSHOT);
rbHistoric.Checked := (SPeriod = LG_PERIOD_HISTORIC);
rbRecent .Checked := (SPeriod = LG_PERIOD_RECENT);
rbCurrent .Checked := (SPeriod = LG_PERIOD_CURRENT);
WITH rbQuikA DO BEGIN
Tag := 3;
Caption := IntToStr (Tag) + ' hours';
Checked := (ROUND(SQuik) = Tag);
END;
WITH rbQuikB DO BEGIN
Tag := 6;
Caption := IntToStr (Tag) + ' hours';
Checked := (ROUND(SQuik) = Tag);
END;
WITH rbQuikC DO BEGIN
Tag := 9;
Caption := IntToStr (Tag) + ' hours';
Checked := (ROUND(SQuik) = Tag);
END;
WITH rbQuikD DO BEGIN
Tag := 12;
Caption := IntToStr (Tag) + ' hours';
Checked := (ROUND(SQuik) = Tag);
END;
WITH rbQuikE DO BEGIN
Tag := 18;
Caption := IntToStr (Tag) + ' hours';
Checked := (ROUND(SQuik) = Tag);
END;
WITH rbQuikF DO BEGIN
Tag := 24;
Caption := IntToStr (Tag) + ' hours';
Checked := (ROUND(SQuik) = Tag);
END;
END; {of procedure OnCreateForm}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.OnCloseForm (Sender: TObject; VAR Action: TCloseAction);
{What to do when form closed}
BEGIN
Action := caFree;
frmLGSelect := NIL;
END; {of procedure OnCloseForm}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.OnDestroyForm (Sender: TObject);
{What to do when form destroyed -- probably redundant}
BEGIN
frmLGSelect := NIL;
END; {of procedure OnDestroyForm}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.OnClickButton (Sender: TObject);
{What to do when a button is clicked}
CONST nl = CHR(13) + CHR(10);
nl2 = nl + nl;
VAR header, body: String;
BEGIN
IF (Sender = btnCancel) THEN BEGIN
Self.Release;
frmLGSelect := NIL;
END;
IF (Sender = btnSetup) THEN BEGIN
Apply;
LGSetup.Select (SRing, SGroup);
END;
IF (Sender = btnHelp) THEN BEGIN
header := 'Line graph selection help';
body :=
'This screen will launch a new line graph window.' + nl2 +
'Select a ring from the left panel.' + nl2 +
'Select a file type from the next panel.' + nl +
' LOGG files: [gas] averages, wind speed, proportional valve.' + nl +
' VARR files: [gas] control PID algorithm.' + nl +
' Auxiliary: other variables in LOGG files, e.g. temperature.' + nl +
' Snap shot: selected 1-second data from LOGG && VARR.' + nl2 +
'Select a time period from the third panel.' + nl2 +
' Historic:' + nl +
' Graph variables from any records still stored on disk.' + nl +
' The beginning record number is entered.' + nl +
' Record = 0 shows most recent data.' + nl2 +
' Recent:' + nl +
' Graph variables from stored records in the last 3, 6, etc. hours.' + nl2 +
' Current:' + nl +
' Real time plotting of all samples.' + nl2 +
'Use SETUP button to change display parameters (range, position on' + nl +
' screen, color, etc.) for the selected ring and file type set.' + nl2 +
'HOT BUTTON defines the ring associated with the Main window' + nl +
' QuickGraph feature (LOGG file, Recent 3-hours).' + nl +
' Select a ring and then click on it to latch the value..'
;
frmHelp := TLblForm.Create (Application);
frmHelp.Display (header, body);
END;
IF (Sender = btnGo) THEN BEGIN
Apply;
IF (SRing = 1) AND (site_id = 'NC1') {***TEMPORARY***}
THEN LineGraf.Select (SRing, SGroup, SPeriod)
ELSE comdis.graphics (SRing, SGroup, SPeriod, SHours, SRecord);
END;
IF (Sender = btnLogg) THEN BEGIN
Apply;
comdis.graphics (SRing, LG_GROUP_LOGG, LG_PERIOD_RECENT, SQuik, 0);
END;
IF (Sender = btnAux) THEN BEGIN
Apply;
comdis.graphics (SRing, LG_GROUP_AUX, LG_PERIOD_RECENT, SQuik, 0);
END;
END; {of procedure OnClickButton}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.OnClickRadio (Sender: TObject);
{What to do when a selected radio button is clicked}
BEGIN
IF created THEN Apply;
Refresh;
IF created AND (Sender = rbHistoric) THEN ebRecord.SetFocus;
END; {of procedure OnClickRadio}
{-------------------------------------------------------------}
PROCEDURE TfrmLGSelect.OnKeyDownForm (
Sender: TObject; VAR Key: Word; Shift: TShiftState);
{Keyboard change ring.
A..F not implemented directly due to possible conflict.
However : ; < = > ? might work for these!
}
BEGIN
IF (Key = VK_SUBTRACT) OR (Key = 189) THEN BEGIN
DEC (SRing);
IF (SRing < 1) THEN SRing := numrings;
rbRings[SRing].Checked := TRUE;
END;
IF (Key = VK_ADD) OR (Key = 187) THEN BEGIN
INC (SRing);
IF (SRing > numrings) THEN SRing := 1;
rbRings[SRing].Checked := TRUE;
END;
{Number keys not active if any numeric .Text control has focus}
IF (ActiveControl <> ebHours) AND (ActiveControl <> ebRecord) THEN
IF (((Key And $FF)-ORD('0')) IN [1..numrings]) THEN BEGIN
SRing := ((Key And $FF)-ORD('0'));
rbRings[SRing].Checked := TRUE;
END;
END; {of event handling procedure OnKeyDownForm}
{-------------------------------------------------------------}
INITIALIZATION
BEGIN
SHot := 2; {first NC fumigation ring}
SGroup := LG_GROUP_LOGG;
SPeriod := LG_PERIOD_RECENT;
SHours := 3.0;
SRecord := 0;
SQuik := 3.0;
END;
FINALIZATION
BEGIN
END;
{of form unit LGSelect...} END.