📄 abmtrend.pas
字号:
procedure TAbMiniTrend.SetValueCh1(Value: Single);
begin
FValueCh1 := Value;
FDigitCh1 := Round(SignalSettingsCh1.DigitalFrom +
(FValueCh1 - SignalSettingsCh1.ValueFrom) *
SignalSettingsCh1.DigitPerValue);
end;
procedure TAbMiniTrend.SetValueCh2(Value: Single);
begin
FValueCh2 := Value;
FDigitCh2 := Round(SignalSettingsCh2.DigitalFrom +
(FValueCh2 - SignalSettingsCh2.ValueFrom) *
SignalSettingsCh2.DigitPerValue);
end;
destructor TAbMiniTrend.Destroy;
begin
DelControl(self);
FSignalSettingsCh1.Free;
FSignalSettingsCh2.Free;
FBevelInner.Free;
FBevelOuter.Free;
FCaptionFont.Free;
TrendBmp.Free;
inherited Destroy;
end;
procedure TAbMiniTrend.WMFlash(var Message: TMessage);
var
TempBmp : TBitmap;
n : Smallint;
PPTCh1 : Single;
PPTCh2 : Single;
begin
if FirstPuls then
begin
AddControl(self, Interval);
FirstPuls := false;
end;
if Painting then Exit;
TempBmp := TBitmap.Create;
TempBmp.Canvas.Brush.Color := BkColor;
TempBmp.Canvas.Brush.Style := bsSolid;
TempBmp.Width := TrendBmp.Width;
TempBmp.Height := TrendBmp.Height;
TempBmp.Canvas.Font := Font;
PPTCh1 := (1000 / SignalSettingsCh1.TotalValue) *
(FValueCh1 - SignalSettingsCh1.ValueFrom);
yPosCh1 := TempBmp.Height - Round(((TempBmp.Height - 1) / 1000) * PPTCh1) - 1;
PPTCh2 := (1000 / SignalSettingsCh2.TotalValue) *
(FValueCh2 - SignalSettingsCh2.ValueFrom);
yPosCh2 := TempBmp.Height - Round(((TempBmp.Height - 1) / 1000) * PPTCh2) - 1;
with TempBmp.Canvas do
begin
Pen.Color := BkColor;
Brush.Color := BkColor;
Brush.Style := bsSolid;
Rectangle(TempBmp.Width - PixelNo, 0, TempBmp.Width, TempBmp.Height);
Draw(0 - PixelNo, 0, TrendBmp);
Count := Count + PixelNo;
if opGrid in Options then
begin
TempBmp.Canvas.Pen.Color := GridColor;
if Count >= GridX_Pixel then
begin
TempBmp.Canvas.Pen.Color := GridColor;
Inc(TimeStamp);
if (TimeStamp >= 5) and (opTimeLine in Options) then
begin
TempBmp.Canvas.Pen.Color := TimeLineColor;
TempBmp.Canvas.Font.Color := TimeLineColor;
AbTextOut(TempBmp.Canvas, TempBmp.Width, TempBmp.Height - 3, ' ' +
TimeDiv + ' - ' + TimeToStr(Now) + '>', toBotRight);
TimeStamp := 0;
end;
moveTo(TempBmp.Width - 1, 0);
LineTo(TempBmp.Width - 1, TempBmp.Height);
Count := 0;
end;
for n := 1 to 9 do
begin
moveTo(TempBmp.Width - PixelNo, Gridy[n]);
LineTo(TempBmp.Width, Gridy[n]);
end;
end;
Pen.Color := SignalColorCh1;
moveTo(TempBmp.Width - 1 - PixelNo, yLastPosCh1);
LineTo(TempBmp.Width - 1, yLastPosCh1);
LineTo(TempBmp.Width - 1, yPosCh1);
Pen.Color := SignalColorCh2;
moveTo(TempBmp.Width - 1 - PixelNo, yLastPosCh2);
LineTo(TempBmp.Width - 1, yLastPosCh2);
LineTo(TempBmp.Width - 1, yPosCh2);
yLastPosCh1 := yPosCh1;
yLastPosCh2 := yPosCh2;
end;
TrendBmp.Canvas.Draw(0, 0, TempBmp);
if Visible or (csDesigning in Componentstate) then
Canvas.Draw(xOrg, yOrg, TrendBmp);
TempBmp.Free;
end;
procedure TAbMiniTrend.Paint;
var
r : TRect;
n, h, Pos, x1pos, x2pos, ysigdef: Smallint;
Text, text1, text2, text3, text4: string;
THeight : Smallint;
begin
if Painting then exit;
Painting := true;
ysigdef := 0;
x1pos := 0;
x2pos := 0;
if (Width < 150) or (Height < 150) then
begin
if (Width < 150) then Width := 150;
if (Height < 150) then Height := 150;
Repaint;
end;
r := ClientRect;
if opBevelOuter in FOptions then
begin
FBevelOuter.PaintFilledBevel(Canvas, r);
end;
if opCaption in FOptions then
begin
Canvas.Font := CaptionFont;
AbTextOut(Canvas, Width div 2, r.Top, Caption, toTopCenter);
r.Top := r.Top + Canvas.Textheight(Caption) + FBevelOuter.Spacing;
end;
Canvas.Font := Font;
THeight := Canvas.Textheight('H');
if (opSignDescCh1 in FOptions) or (opSignDescCh2 in FOptions) then
begin
ysigdef := r.Bottom;
r.Bottom := r.Bottom - THeight - BevelOuter.Spacing;
;
end;
if opScaleCh1 in FOptions then
begin
text1 := FormatFloat(SignalSettingsCh1.ValueFormat,
SignalSettingsCh1.ValueTo);
text2 := FormatFloat(SignalSettingsCh1.ValueFormat,
SignalSettingsCh1.ValueFrom);
n := AbMaxInt(Canvas.TextWidth(text1), Canvas.TextWidth(text2));
x1pos := r.Left + n div 2;
r.Left := r.Left + 12 + n;
end;
if opScaleCh2 in FOptions then
begin
text3 := FormatFloat(SignalSettingsCh2.ValueFormat,
SignalSettingsCh2.ValueTo);
text4 := FormatFloat(SignalSettingsCh2.ValueFormat,
SignalSettingsCh2.ValueFrom);
n := AbMaxInt(Canvas.TextWidth(text3), Canvas.TextWidth(text4));
x2pos := r.Right - n div 2;
r.Right := r.Right - 12 - n;
end;
if (opScaleCh1 in FOptions) or (opScaleCh2 in FOptions) then
begin
if not (opCaption in FOptions) then r.Top := r.Top + THeight div 3;
r.Bottom := r.Bottom - THeight div 2;
end;
if opBevelInner in FOptions then FBevelInner.PaintFilledBevel(Canvas, r);
if opSignDescCh1 in FOptions then
begin
Canvas.Pen.Color := BkColor;
Canvas.Brush.Color := SignalColorCh1;
if opBevelOuter in FOptions then
n := BevelOuter.TotalWidth
else
n := 0;
Canvas.Rectangle(n, ysigdef - THeight + 1, n + THeight - 2, ysigdef - 1);
Canvas.Brush.Style := bsClear;
Text := 'Ch1 : ' + SignalSettingsCh1.Name1 + ' - ' +
SignalSettingsCh1.Name2;
AbTextOut(Canvas, n + THeight + 3, ysigdef, Text, tobotLeft);
end;
if opSignDescCh2 in FOptions then
begin
Canvas.Pen.Color := BkColor;
Canvas.Brush.Color := SignalColorCh2;
if opBevelOuter in FOptions then
n := Width - BevelOuter.TotalWidth
else
n := Width;
Canvas.Rectangle(n, ysigdef - THeight + 1, n - THeight + 2, ysigdef - 1);
Canvas.Brush.Style := bsClear;
Text := 'Ch2 : ' + SignalSettingsCh2.Name1 + ' - ' +
SignalSettingsCh2.Name2;
AbTextOut(Canvas, n - THeight - 3, ysigdef, Text, toBotRight);
end;
h := r.Bottom - r.Top - 1;
Canvas.Pen.Color := clBlack;
if opScaleCh1 in FOptions then
begin
for n := 0 to 10 do
begin
Pos := Round(r.Top + ((h / 10) * n));
Canvas.moveTo(r.Left - 10, Pos);
Canvas.LineTo(r.Left, Pos);
end;
AbTextOut(Canvas, x1pos, r.Top, text1, toMidCenter);
AbTextOut(Canvas, x1pos, r.Top + THeight, SignalSettingsCh1.ValueUnit,
toMidCenter);
AbTextOut(Canvas, x1pos, r.Bottom, text2, toMidCenter);
end;
if opScaleCh2 in FOptions then
begin
for n := 0 to 10 do
begin
Pos := Round(r.Top + ((h / 10) * n));
Canvas.moveTo(r.Right, Pos);
Canvas.LineTo(r.Right + 10, Pos);
end;
AbTextOut(Canvas, x2pos, r.Top, text3, toMidCenter);
AbTextOut(Canvas, x2pos, r.Top + THeight, SignalSettingsCh2.ValueUnit,
toMidCenter);
AbTextOut(Canvas, x2pos, r.Bottom, text4, toMidCenter);
end;
if (TrendBmp.Width <> (r.Right - r.Left)) or (TrendBmp.Height <> (r.Bottom -
r.Top)) then
begin
TrendBmp.Width := (r.Right - r.Left);
TrendBmp.Height := (r.Bottom - r.Top);
xOrg := r.Left;
yOrg := r.Top;
DrawBackground;
end;
Canvas.Draw(xOrg, yOrg, TrendBmp);
FirstDraw := false;
Painting := False;
end;
procedure TAbMiniTrend.DrawBackground;
var
n : Smallint;
SecDiv, MinDiv, hDiv: LongInt;
begin
with TrendBmp.Canvas do
begin
Pen.Color := BkColor;
Brush.Color := BkColor;
Brush.Style := bsSolid;
Rectangle(0, 0, TrendBmp.Width, TrendBmp.Height);
yLastPosCh1 := TrendBmp.Height;
yLastPosCh2 := TrendBmp.Height;
if TimeScale = 1 then
PixelNo := 2
else
PixelNo := 1;
GridX_Pixel := Round(((TrendBmp.Width) / (10 * PixelNo)) - 0.49) * PixelNo;
Interval := Round(((TimeScale * 60000 * PixelNo) / (GridX_Pixel * 10)));
SecDiv := Round(GridX_Pixel * Interval / 1000 / PixelNo);
MinDiv := SecDiv div 60;
SecDiv := SecDiv - MinDiv * 60;
hDiv := MinDiv div 60;
MinDiv := MinDiv - hDiv * 60;
TimeDiv := '';
if hDiv > 0 then TimeDiv := TimeDiv + IntToStr(hDiv) + 'h';
if MinDiv > 0 then TimeDiv := TimeDiv + IntToStr(MinDiv) + 'min';
if SecDiv > 0 then TimeDiv := TimeDiv + IntToStr(SecDiv) + 's';
TimeDiv := TimeDiv + '/div';
if opGrid in Options then
begin
Pen.Color := GridColor;
for n := 1 to 9 do
begin
Gridy[n] := Round(((TrendBmp.Height - 1) / 10) * n);
moveTo(0, Gridy[n]);
LineTo(TrendBmp.Width, Gridy[n]);
end;
for n := 1 to 10 do
begin
if (n = 5) and (opTimeLine in Options) then
Pen.Color := TimeLineColor
else
Pen.Color := GridColor;
moveTo(TrendBmp.Width - n * GridX_Pixel, 0);
LineTo(TrendBmp.Width - n * GridX_Pixel, TrendBmp.Height);
end;
end;
TrendBmp.Canvas.Font.Color := TimeLineColor;
AbTextOut(TrendBmp.Canvas, TrendBmp.Width, TrendBmp.Height - 3, ' ' +
TimeDiv + ' - ' + TimeToStr(Now) + '>', toBotRight);
end;
Count := GridX_Pixel;
if not FirstDraw then
begin
Canvas.Draw(xOrg, yOrg, TrendBmp);
end;
end;
procedure TAbMiniTrend.ParamChange(Sender: TObject);
begin
inherited ParamChange(self);
Invalidate;
end;
procedure TAbMiniTrend.SetOptions(Value: TMiniTrendOptions);
begin
FOptions := Value;
if (UpdateCount = 0) then
begin
DrawBackground;
Change;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -