-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFProfile.pas
More file actions
329 lines (279 loc) · 9.39 KB
/
FProfile.pas
File metadata and controls
329 lines (279 loc) · 9.39 KB
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
// Dive Profile Chart
// Date 12.06.22
unit FProfile;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls, gl_base, DepthChart,
USystem, UGraphic, URegistry, SYS, Global, Data, Texts, Clock, FLog, UPidi;
type
TProfile = class(TForm)
ProfileLoop: TTimer;
ProfileStatus: TStatusBar;
ProfilePanel: TPanel;
ProfileChart: TDepthChart; // 12.06.22 nk upd to Dive Charts Vers 2.0
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormMoving(var Msg: TwmMoving); message WM_MOVING;
procedure ProfileLoopTimer(Sender: TObject);
procedure ProfileChartMouseMoveInChart(Sender: TObject; InChart: Boolean; Shift: TShiftState; rMousePosX, rMousePosY: Double);
private
TimeMax: Long; //[min]
DepthMax: Long; //[m]
ScaleMult: Long;
DepthLimit: Double; //[cm]
DepthMult: Double;
DepthUnit: string;
TimeUnit: string;
public
procedure InitDiveProfile(Points: Long);
procedure DrawDiveProfile;
procedure DrawDivePoint(DiverTime, DiverDepth, DiverCeil: Long; DoShow: Boolean);
procedure AddDivePoint(Point, DiverTime, DiverDepth, DiverCeil: Word); //22.05.07 nk add
end;
var
Profile: TProfile;
implementation
uses FMain, FDaq;
{$R *.dfm}
procedure TProfile.FormCreate(Sender: TObject);
begin
HideMaxButton(self); // hide maximize button
HideCloseButton(self); // hide close button
with Profile do begin
Width := 435;
Height := 283;
Left := MainRect.Right - MainRect.Left - Width - MAINMARGIN;
Top := MAINMARGIN;
GetFormParameter(self);
WindowState := wsMinimized;
Show;
end;
with ProfileStatus do begin
Panels[0].Text := sEMPTY;
Panels[1].Text := sEMPTY;
Panels[2].Text := sEMPTY;
end;
with ProfilePanel do begin
Align := alClient;
AutoSize := False;
BevelInner := bvNone;
BevelOuter := bvNone;
Ctl3D := False;
Caption := sEMPTY;
Cursor := crDefault;
DoubleBuffered := True;
UseDockManager := False;
end;
with ProfileChart do begin
ClearGraf;
LRim := 40;
RRim := 20;
TRim := 20;
BRim := 40;
Align := alClient;
AutoRedraw := True;
Isometric := False;
Caption := sEMPTY;
ChartColor := COLORWATER;
DataColor := COLORTRACK;
GridColor := COLORGRID;
GridDx := 0;
GridDy := 0;
LineWidth := 1;
MouseCursorFixed := False; //20.10.07 nk add
MouseAction := maNone;
PenStyle := psSolid;
//20.10.07 nk upd ff to SDL 9.0
with Scale1X do begin //old vers 7.1 properties
Caption := sEMPTY; //IdAbscissa := sEMPTY;
DecPlaces := 0; //DecPlaceX := 0;
MinTicks := MINTIMERANGE; //MinTickX := 5;
ShortTicks := False; //ShortTicksX := False;
RangeLow := HOMEPOS; //RangeLoX := HOMEPOS;
RangeHigh := DEFTIMERANGE; //RangeHiX := DEFTIMERANGE;
end;
with Scale1Y do begin //old vers 7.1 properties
Caption := sEMPTY; //IdOrdinate := sEMPTY;
DecPlaces := 0; //DecPlaceY := 0;
MinTicks := MINDEPTHRANGE; //MinTickY := 5;
ShortTicks := False; //ShortTicksY := False;
RangeLow := -DEFDEPTHRANGE; //RangeLoY := -DEFDEPTHRANGE;
RangeHigh := MINDEPTHRANGE; //RangeHiY := 5.0;
end;
MoveTo(HOMEPOS, HOMEPOS);
CrossHairSetPos(PENDEPTH, HOMEPOS, HOMEPOS); //depth
CrossHairSetPos(PENCEIL, HOMEPOS, HOMEPOS); //ceiling
CrossHairSetPos(PENLIMIT, HOMEPOS, HOMEPOS); //limit
Refresh;
end;
end;
procedure TProfile.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ProfileLoop.Enabled := False;
SetFormParameter(self);
Action := caFree;
end;
procedure TProfile.FormMoving(var Msg: TwmMoving);
begin
LimitFormMove(MainRect, Msg);
end;
procedure TProfile.ProfileLoopTimer(Sender: TObject);
begin // 26.07.17 nk rem - obsolete
if WindowFromPoint(Mouse.CursorPos) <> ProfilePanel.Handle then begin
Screen.Cursor := crDefault;
if DivePhase > PHASEPREDIVE then Exit;
with ProfileStatus do begin
Panels[0].Text := Format(FORMHIPREC, [HOMEPOS, TimeUnit]);
Panels[1].Text := Format(FORMHIPREC, [HOMEPOS, DepthUnit]);
Panels[2].Text := Format(FORMRANGE, [DepthMax * ScaleMult, DepthUnit, TimeMax, TimeUnit]);
end;
end;
end;
procedure TProfile.InitDiveProfile(Points: Long);
var
p: Word;
begin
TimeUnit := TIMEUNIT_ISO;
TimeMax := DEFTIMERANGE;
DepthMax := Round(1.2 * WarnDepth / CENTI); //20% more than warn depth [m]
if Points >= 0 then begin
SetLength(ArrDiveTime, Points + 1);
SetLength(ArrDiveDepth, Points + 1);
SetLength(ArrDecoCeil, Points + 1);
for p := 0 to Points do begin
ArrDiveTime[p] := cCLEAR;
ArrDiveDepth[p] := cCLEAR;
ArrDecoCeil[p] := cCLEAR;
end;
end;
if UnitFlag = cOFF then begin
DepthUnit := DEPTHUNIT_EU;
DepthMult := 1.0;
DepthLimit := 1.0 * WarnDepth;
ScaleMult := SCALE_METER;
end else begin
DepthUnit := DEPTHUNIT_US;
DepthMult := FEET / 100.0;
DepthLimit := WarnDepth * TENFEET / 1000.0;
ScaleMult := SCALE_FEET;
end;
with ProfileChart do begin //20.10.07 nk upd ff to SDL vers. 9.0
ClearGraf;
with Scale1X do begin
Caption := MakeCaption(131, TimeUnit);
RangeLow := HOMEPOS;
RangeHigh := TimeMax;
end;
with Scale1Y do begin
Caption := MakeCaption(130, DepthUnit);
RangeLow := -DepthMax * ScaleMult;
RangeHigh := MINDEPTHRANGE * ScaleMult;
end;
MoveTo(HOMEPOS, HOMEPOS);
CrossHairSetPos(PENDEPTH, HOMEPOS, HOMEPOS); // depth
CrossHairSetPos(PENCEIL, HOMEPOS, HOMEPOS); // ceiling
CrossHairSetPos(PENLIMIT, -10.0, -DepthLimit / CENTI);
CrossHairSetup(PENLIMIT, COLORMAXDEPTH, chBoth, psDash, 1); // show WarnDepth line
end;
with ProfileStatus do begin
Panels[0].Text := Format(FORMHIPREC, [HOMEPOS, TimeUnit]);
Panels[1].Text := Format(FORMHIPREC, [HOMEPOS, DepthUnit]);
Panels[2].Text := Format(FORMRANGE, [DepthMax * ScaleMult, DepthUnit, TimeMax, TimeUnit]);
end;
if Points = cNEG then DrawDiveProfile; //13.05.07 nk opt - update chart
ProfileLoop.Enabled := False; // 26.07.17 nk old=True
Application.ProcessMessages;
end;
procedure TProfile.DrawDiveProfile;
var
p, points, ltime: Long;
begin
DisableTsw; //01.06.07 nk add
points := High(ArrDiveTime);
for p := 0 to points do begin
ExpandTime(ArrDiveTime[p], ltime);
DrawDivePoint(ltime, ArrDiveDepth[p], ArrDecoCeil[p], False);
end;
ProfileChart.ShowGraf;
EnableTsw;
end;
procedure TProfile.DrawDivePoint(DiverTime, DiverDepth, DiverCeil: Long; DoShow: Boolean);
var
dMax: Long;
dTime, dDepth, dCeil: Double;
begin
if DiverTime <= 0 then Exit; //ignore invalid dive point
dTime := DiverTime / SEC_MIN; // dive time [s -> min]
dDepth := DepthMult * DiverDepth / CENTI; // dive depth [cm -> m/ft]
dCeil := DepthMult * DiverCeil / CENTI; // deco ceiling [cm -> m/ft]
with ProfileChart do begin //20.10.07 nk upd ff to SDL vers. 9.0
with Scale1X do begin //re-scale time axis on overflow
dMax := Round(TIMERESCALE * RangeHigh);
if dTime > (RangeHigh - dMax) then begin
TimeMax := TimeMax + dMax;
RangeHigh := TimeMax;
end;
end;
with Scale1Y do begin //re-scale depth axis on overflow
if dDepth > (-RangeLow - DEPTHRESCALE) then begin
DepthMax := DepthMax + DEPTHRESCALE;
RangeLow := -DepthMax * ScaleMult;
end;
end;
//draw ceiling graph
DataColor := COLORCEILING;
MoveTo(CrossHairPosX[PENCEIL], CrossHairPosY[PENCEIL]);
DrawTo(dTime, -dCeil);
CrossHairSetPos(PENCEIL, dTime, -dCeil);
//draw depth graph
DataColor := COLORDEPT;
MoveTo(CrossHairPosX[PENDEPTH], CrossHairPosY[PENDEPTH]);
DrawTo(dTime, -dDepth);
CrossHairSetPos(PENDEPTH, dTime, -dDepth);
if DoShow then ShowGraf; //update graph
end;
with ProfileStatus do begin
if DoShow then begin
Panels[0].Text := Format(FORMHIPREC, [dTime, TimeUnit]);
Panels[1].Text := Format(FORMHIPREC, [-dDepth, DepthUnit]);
end;
Panels[2].Text := Format(FORMRANGE, [DepthMax * ScaleMult, DepthUnit, TimeMax, TimeUnit]);
end;
Application.ProcessMessages;
end;
procedure TProfile.AddDivePoint(Point, DiverTime, DiverDepth, DiverCeil: Word);
var
p: Long;
begin
if Point = AUTOINC then begin
p := High(ArrDiveTime) + 1; // auto array increment
end else begin
p := Point;
end;
SetLength(ArrDiveTime, p + 1);
SetLength(ArrDiveDepth, p + 1);
SetLength(ArrDecoCeil, p + 1);
ArrDiveTime[p] := DiverTime; // log time [s/min]
ArrDiveDepth[p] := DiverDepth; // dive depth [cm]
ArrDecoCeil[p] := DiverCeil; // deco ceiling [cm]
end;
procedure TProfile.ProfileChartMouseMoveInChart(Sender: TObject; InChart: Boolean; Shift: TShiftState; rMousePosX, rMousePosY: Double);
var
dTime, dDepth: Double;
begin
if DivePhase > PHASEPREDIVE then Exit;
with ProfileStatus do begin
if (rMousePosX < HOMEPOS) or (rMousePosX > TimeMax) or
(rMousePosY > HOMEPOS) or (rMousePosY < (-DepthMax * ScaleMult)) then begin
dTime := HOMEPOS;
dDepth := HOMEPOS;
end else begin
dTime := rMousePosX;
dDepth := rMousePosY;
end;
Panels[0].Text := Format(FORMHIPREC, [dTime, TimeUnit]);
Panels[1].Text := Format(FORMHIPREC, [dDepth, DepthUnit]);
end;
end;
end.