⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ispectrumdisplay.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*******************************************************}
{                                                       }
{       TiSpectrumDisplay Component                     }
{                                                       }
{       Copyright (c) 1997,2003 Iocomp Software         }
{                                                       }
{*******************************************************}
{$I iInclude.inc}

{$ifdef iVCL}unit  iSpectrumDisplay;{$endif}
{$ifdef iCLX}unit QiSpectrumDisplay;{$endif}

interface

uses
  {$I iIncludeUses.inc}
  {$IFDEF iVCL} iTypes,  iGPFunctions,  iCustomComponent, iThreadTimers, iOPCItem;{$ENDIF}
  {$IFDEF iCLX}QiTypes, QiGPFunctions, QiCustomComponent, QiThreadTimers;         {$ENDIF}

type
  TiSpectrumData = record
    Value          : Double;
    Peak           : Double;
    PeakUpdateTime : TDateTime;
    Color          : TColor;
  end;

  TiSpectrumDisplay = class(TiCustomComponent)
  private
    FData              : array[0..1023] of TiSpectrumData;

    FDecayTimer        : TiThreadTimers;

    FBarWidth          : Integer;
    FBarSpacing        : Integer;
    FBarHeight         : Integer;
    FBarBottom         : Integer;
    FStartLeft         : Integer;

    FAutoSize          : Boolean;
    FOnAutoSize        : TNotifyEvent;
    FDoingAutoSize     : Boolean;
    FBarCount          : Integer;
    FDecayEnabled      : Boolean;
    FDecayInterval     : Integer;
    FDecayInitialDelay : Integer;
    FBarColor          : TColor;
    FOuterMarginLeft   : Integer;
    FOuterMarginRight  : Integer;
    FOuterMarginBottom : Integer;
    FOuterMarginTop    : Integer;
    FPeakLineColor     : TColor;
    FPeakShow          : Boolean;
    FScaleMax          : Double;
    FScaleMin          : Double;
  protected
    procedure SetBarCount         (const Value: Integer);
    procedure iSetAutoSize        (const Value: Boolean);
    procedure SetDecayInitialDelay(const Value: Integer);
    procedure SetDecayEnabled     (const Value: Boolean);
    procedure SetDecayInterval    (const Value: Integer);
    procedure SetBarSpacing       (const Value: Integer);
    procedure SetBarWidth         (const Value: Integer);
    procedure SetBarColor         (const Value: TColor);
    procedure SetOuterMarginBottom(const Value: Integer);
    procedure SetOuterMarginLeft  (const Value: Integer);
    procedure SetOuterMarginRight (const Value: Integer);
    procedure SetOuterMarginTop   (const Value: Integer);
    procedure SetPeakLineColor    (const Value: TColor);
    procedure SetPeakShow         (const Value: Boolean);
    procedure SetScaleMax         (const Value: Double);
    procedure SetScaleMin         (const Value: Double);

    function  GetBarValue (Index: Integer): Double;
    function  GetBarXColor(Index: Integer): TColor;

    procedure SetBarValue (Index: Integer; const Value: Double);
    procedure SetBarXColor(Index: Integer; const Value: TColor);

    procedure CalcRects;
    procedure DecayTimerEvent(Sender : TObject);

    procedure SetBorderStyle(const Value: TiBevelStyle); override;

    property  OnAutoSize : TNotifyEvent read FOnAutoSize write FOnAutoSize;

    procedure DoAutoSize;
    procedure iPaintTo(Canvas: TCanvas);     override;
    procedure Loaded;                        override;

    {$ifdef iVCL}
    procedure UpdateOPCSpecialList;                            override;
    function  OPCNewDataSpecial(iOPCItem: TiOPCItem): Boolean; override;
    {$endif}
  public
    constructor Create(AOwner: TComponent);  override;
    destructor  Destroy;                     override;

    procedure Clear;

    property BarValue [Index : Integer]  : Double  read GetBarValue        write SetBarValue;
    property BarXColor[Index : Integer]  : TColor  read GetBarXColor       write SetBarXColor;
  published
    property AutoSize                    : Boolean read FAutoSize          write iSetAutoSize         default True;
    property OuterMarginLeft             : Integer read FOuterMarginLeft   write SetOuterMarginLeft   default 5;
    property OuterMarginTop              : Integer read FOuterMarginTop    write SetOuterMarginTop    default 0;
    property OuterMarginRight            : Integer read FOuterMarginRight  write SetOuterMarginRight  default 5;
    property OuterMarginBottom           : Integer read FOuterMarginBottom write SetOuterMarginBottom default 0;

    property DecayEnabled                : Boolean read FDecayEnabled      write SetDecayEnabled      default True;
    property DecayInterval               : Integer read FDecayInterval     write SetDecayInterval     default 40;
    property DecayInitialDelay           : Integer read FDecayInitialDelay write SetDecayInitialDelay default 750;

    property BarCount                    : Integer read FBarCount          write SetBarCount          default 32;
    property BarWidth                    : Integer read FBarWidth          write SetBarWidth          default 6;
    property BarSpacing                  : Integer read FBarSpacing        write SetBarSpacing        default 1;
    property BarColor                    : TColor  read FBarColor          write SetBarColor          default $0000B000;

    property PeakShow                    : Boolean read FPeakShow          write SetPeakShow          default True;
    property PeakLineColor               : TColor  read FPeakLineColor     write SetPeakLineColor     default clWhite;

    property ScaleMin                    : Double  read FScaleMin          write SetScaleMin;
    property ScaleMax                    : Double  read FScaleMax          write SetScaleMax;

    property BorderStyle      default ibsLowered;
    property BackGroundColor  default clBlack;
    property Transparent;
    property Width            default 238;
    property Height           default 125;
  end;

implementation
//****************************************************************************************************************************************************
constructor TiSpectrumDisplay.Create(AOwner: TComponent);
var
  x : Integer;
begin
  inherited Create(AOwner);

  Width           := 238;
  Height          := 125;
  BorderStyle     := ibsLowered;
  BackGroundColor := clBlack;

  FAutoSize          := True;
  
  FOuterMarginLeft   := 5;
  FOuterMarginRight  := 5;

  FDecayEnabled      := True;
  FDecayInitialDelay := 750;
  FDecayInterval     := 40;

  FBarCount          := 32;
  FBarSpacing        := 1;
  FBarWidth          := 6;
  FBarColor          := $0000B000;

  FPeakShow          := True;
  FPeakLineColor     := clWhite;

  FScaleMax          := 100;

  for x := 0  to 1023 do
    begin
      FData[x].Value := Random(90) + 10;
      FData[x].Color := FBarColor;
    end;

  FDecayTimer           := TiThreadTimers.Create(Self);
  FDecayTimer.Interval1 := 40;
  FDecayTimer.OnTimer1  := DecayTimerEvent;
end;
//****************************************************************************************************************************************************
destructor TiSpectrumDisplay.Destroy;
begin
  FDecayTimer.Free;
  inherited;
end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.Loaded;
begin
  inherited;
  if FDecayEnabled and not(csDesigning in ComponentState) then
    begin
      FDecayTimer.Enabled1 := True;
    end;
end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.Clear;
var
  x : Integer;
begin
  for x := 0 to FBarCount - 1 do
    begin
      FData[x].Value := 0;
      FData[x].Peak  := 0;
      FData[x].PeakUpdateTime := Now;
    end;
end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.SetBorderStyle(const Value: TiBevelStyle);
begin
  inherited;
  DoAutoSize;
end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.SetDecayInitialDelay(const Value:Integer);begin SetIntegerProperty(Value,FDecayInitialDelay,irtInvalidate);end;
procedure TiSpectrumDisplay.SetPeakLineColor    (const Value:TColor );begin SetColorProperty  (Value,FPeakLineColor,    irtInvalidate);end;
procedure TiSpectrumDisplay.SetPeakShow         (const Value:Boolean);begin SetBooleanProperty(Value,FPeakShow,         irtInvalidate);end;
procedure TiSpectrumDisplay.SetScaleMax         (const Value:Double );begin SetDoubleProperty(Value, FScaleMax,         irtInvalidate);end;
procedure TiSpectrumDisplay.SetScaleMin         (const Value:Double );begin SetDoubleProperty(Value, FScaleMin,         irtInvalidate);end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.SetBarColor(const Value: TColor);
var
  x : Integer;
begin
  if FBarColor <> Value then
   begin
     FBarColor := Value;
     for x := 0 to 1023 do
       FData[x].Color := FBarColor;
     InvalidateChange;
   end;
end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.SetDecayEnabled(const Value: Boolean);
begin
  if FDecayEnabled <> Value then
    begin
      FDecayEnabled := Value;

      if not(csDesigning in ComponentState) then
        begin
          FDecayTimer.Enabled1 := Value;
        end
    end;
end;
//****************************************************************************************************************************************************
procedure TiSpectrumDisplay.SetDecayInterval(const Value:Integer);
begin
  if FDecayInterval <> Value then
    begin
      FDecayInterval := Value;
      FDecayTimer.Interval1 := Value;
    end;
end;
//****************************************************************************************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -