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

📄 iscope.pas

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

{$ifdef iVCL}unit  iScope;{$endif}
{$ifdef iCLX}unit QiScope;{$endif}

interface

uses
  {$I iIncludeUses.inc}
  {$IFDEF iVCL} iTypes,  Printers,  iGPFunctions,  iComponent,  iPlot,  iPlotDataCursor,  iPlotAxis,  iPlotChannelCustom,  iPlotChannel,  iPlotAnnotation,{$ENDIF}
  {$IFDEF iCLX}QiTypes, QPrinters, QiGPFunctions, QiComponent, QiPlot, QiPlotDataCursor, QiPlotAxis, QiPlotChannelCustom, QiPlotChannel, QiPlotAnnotation,{$ENDIF}

  {$IFDEF iVCL} iScopeEditor,  iScopePanelTimeBase,  iScopePanelTrigger,  iScopePanelChannels,  iScopePanelToolBar,{$ENDIF}
  {$IFDEF iCLX}QiScopeEditor, QiScopePanelTimeBase, QiScopePanelTrigger, QiScopePanelChannels, QiScopePanelToolBar,{$ENDIF}

  {$IFDEF iVCL} iScopeChannel,  iScopeTimeBase,  iScopeTrigger,  iScopeToolBar,  iScopeDisplay;{$ENDIF}
  {$IFDEF iCLX}QiScopeChannel, QiScopeTimeBase, QiScopeTrigger, QiScopeToolBar, QiScopeDisplay;{$ENDIF}


type
  TiScope = class(TCustomControl)
  private
    FCreationComplete       : Boolean;

    FPlot                   : TiPlot;
    FPanelChannels          : TiScopePanelChannels;
    FPanelTimeBase          : TiScopePanelTimeBase;
    FPanelTrigger           : TiScopePanelTrigger;
    FPanelToolBar           : TiScopePanelToolBar;
    FDisplay                : TiScopeDisplay;

    FScopeEditor            : TiScopeEditorForm;

    FTransferringData       : Boolean;

    FTimeBase               : TiScopeTimeBase;
    FTrigger                : TiScopeTrigger;
    FToolBar                : TiScopeToolBar;

    FEditorControlPageIndex : Integer;
    FHideControlPanels      : Boolean;
 protected
    function GetAutoFrameRate    : Boolean;
    function GetUpdateFrameRate  : Integer;
    function GetPrintDocumentName: String;
    function GetPrinterName      : String;
    function GetPrintMarginBottom: Double;
    function GetPrintMarginLeft  : Double;
    function GetPrintMarginRight : Double;
    function GetPrintMarginTop   : Double;
    function GetPrintOrientation : TPrinterOrientation;
    function GetPrintShowDialog  : Boolean;
    function GetSamplesPerSecond : Integer;

    procedure SetAutoFrameRate    (const Value: Boolean);
    procedure SetUpdateFrameRate  (const Value: Integer);
    procedure SetPrintDocumentName(const Value: String);
    procedure SetPrinterName      (const Value: String);
    procedure SetPrintMarginBottom(const Value: Double);
    procedure SetPrintMarginLeft  (const Value: Double);
    procedure SetPrintMarginRight (const Value: Double);
    procedure SetPrintMarginTop   (const Value: Double);
    procedure SetPrintOrientation (const Value: TPrinterOrientation);
    procedure SetPrintShowDialog  (const Value: Boolean);
    procedure SetSamplesPerSecond (const Value: Integer);
    procedure SetHideControlPanels(const Value: Boolean);

    function GetChannel(Index: Integer): TiScopeChannel;
    function GetChannelCount           : Integer;
    function GetNeedPacketsNow         : Boolean;
    function GetDataBlockActive        : Boolean;
    function GetDataBlockSynchronized  : Boolean;
    function GetDataCursor             : TiPlotDataCursor;
    function GetTransferringActve      : Boolean;

    procedure DataCursorCustomizeHintEvent    (Index: Integer; var AText: String);
    procedure LimitLine1PositionChangeEvent   (Index: Integer; OldValue, NewValue : Double);
    procedure AnnotationCoordinatesChangeEvent(Index: Integer);
    procedure ClickAnnotationEvent            (Index: Integer);

    procedure Resize;  override;
    procedure AdjustLayout;
    procedure Loaded;                       override;

    procedure DefineProperties(Filer: TFiler); override;

    procedure ReadFromStreamChannels(Reader: TReader);
    procedure ReadFromStreamDisplay (Reader: TReader);
    procedure ReadFromStreamTimeBase(Reader: TReader);
    procedure ReadFromStreamTrigger (Reader: TReader);

    procedure WriteToStreamChannels (Writer: TWriter);
    procedure WriteToStreamDisplay  (Writer: TWriter);
    procedure WriteToStreamTimeBase (Writer: TWriter);
    procedure WriteToStreamTrigger  (Writer: TWriter);

    procedure DoEditClick(Sender: TObject);

    property PanelChannels : TiScopePanelChannels read FPanelChannels;
    property PanelTimeBase : TiScopePanelTimeBase read FPanelTimeBase;
    property PanelTrigger  : TiScopePanelTrigger  read FPanelTrigger;
    property Plot          : TiPlot               read FPlot;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy;                    override;

    procedure PrintDisplay;

    procedure DataBlockBegin;
    procedure DataBlockEnd;
    procedure DataBlockClear;

    procedure AddChannelData     (Channel: Integer; Y    : Double );
    procedure AddDataBlockChannel(Index  : Integer; Data : Variant);
    procedure AddDataBlock       (                  Data : Variant);

    function  AddChannel: Integer;
    procedure DeleteChannel(Index: Integer);
    procedure RemoveAllChannels;

    property Channel[Index: Integer] : TiScopeChannel      read GetChannel;
    property ChannelCount            : Integer             read GetChannelCount;

    property TimeBase                : TiScopeTimeBase     read FTimeBase;
    property Trigger                 : TiScopeTrigger      read FTrigger;
    property ToolBar                 : TiScopeToolBar      read FToolBar;
    property Display                 : TiScopeDisplay      read FDisplay;

    property DataCursor              : TiPlotDataCursor    read GetDataCursor;

    property TransferringActve       : Boolean             read GetTransferringActve;

    property DataBlockActive         : Boolean             read GetDataBlockActive;
    property DataBlockSynchronized   : Boolean             read GetDataBlockSynchronized;
    property NeedPacketsNow          : Boolean             read GetNeedPacketsNow;
  published
    property Align;

    property SamplesPerSecond        : Integer             read GetSamplesPerSecond     write SetSamplesPerSecond;

    property AutoFrameRate           : Boolean             read GetAutoFrameRate        write SetAutoFrameRate      default True;
    property UpdateFrameRate         : Integer             read GetUpdateFrameRate      write SetUpdateFrameRate    default 20;

    property HideControlPanels       : Boolean             read FHideControlPanels      write SetHideControlPanels;

    property PrintOrientation        : TPrinterOrientation read GetPrintOrientation     write SetPrintOrientation   default poLandscape;
    property PrintMarginLeft         : Double              read GetPrintMarginLeft      write SetPrintMarginLeft;
    property PrintMarginTop          : Double              read GetPrintMarginTop       write SetPrintMarginTop;
    property PrintMarginRight        : Double              read GetPrintMarginRight     write SetPrintMarginRight;
    property PrintMarginBottom       : Double              read GetPrintMarginBottom    write SetPrintMarginBottom;
    property PrintShowDialog         : Boolean             read GetPrintShowDialog      write SetPrintShowDialog    default True;
    property PrintDocumentName       : String              read GetPrintDocumentName    write SetPrintDocumentName;
    property PrinterName             : String              read GetPrinterName          write SetPrinterName;

    property Visible;
    property Enabled;           
    property ShowHint;
    property PopupMenu;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnStartDrag;
    property OnEndDrag;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnEnter;
    property OnExit;
  end;

implementation

type
  TiComponentAccess      = class(TiComponent     )end;
  TiPlotDataCursorAccess = class(TiPlotDataCursor)end;
  TiPlotAnnotationAccess = class(TiPlotAnnotation)end;
  TWriterAccess          = class(TWriter         )end;
  TReaderAccess          = class(TReader         )end;
  TiScopeChannelAccess   = class(TiScopeChannel  )end;
  TiScopeDisplayAccess   = class(TiScopeDisplay  )end;
//****************************************************************************************************************************************************
constructor TiScope.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := [csCaptureMouse, csClickEvents, csDoubleClicks, csReplicatable, csOpaque, csAcceptsControls];

  Width   := 725;
  Height  := 310;

  FPlot := TiPlot.Create(Self);
  with FPlot do
    begin
      Parent := Self;
      RemoveAllChannels;

      DataView[0].GridLineColor := clTeal;
      DataView[0].Enabled       := False;

      XAxis[0].CartesianStyle   := ipcsMaster;
      XAxis[0].LabelsVisible    := False;
      XAxis[0].LabelSeparation  := 0;
      XAxis[0].DesiredIncrement := 0.1;
      XAxis[0].ScaleLinesColor  := DataView[0].GridLineColor;
      XAxis[0].MinorCount       := 4;
      XAxis[0].Enabled          := False;
      XAxis[0].Span             := 1;
      XAxis[0].TrackingEnabled  := False;

      YAxis[0].CartesianStyle   := ipcsMaster;
      YAxis[0].LabelsVisible    := False;
      YAxis[0].LabelSeparation  := 0;
      YAxis[0].DesiredIncrement := 12.5;
      YAxis[0].ScaleLinesColor  := DataView[0].GridLineColor;
      YAxis[0].MinorCount       := 4;
      YAxis[0].Enabled          := False;
      YAxis[0].TrackingEnabled  := False;

      ToolBar[0].Visible := False;
      ToolBar[0].DoButtonClickSelect;

      Legend [0].Visible := False;

      TitleVisible       := False;           

      AddXAxis;
      XAxis[1].Name                := 'TimeBase';
      XAxis[1].Visible             := False;
      XAxis[1].TrackingEnabled     := False;

      AddChannel;
      Channel[0].XAxisName := XAxis[0].Name;
      Channel[0].YAxisName := YAxis[0].Name;
      Channel[0].Visible   := False;

      AddAnnotation;
      Annotation[0].Style         := ipasRectangle;
      Annotation[0].Height        := 2;
      Annotation[0].X             := 0.5;
      Annotation[0].Width         := 1;
      Annotation[0].Y             := 3;
      Annotation[0].BrushStyle    := bsClear;
      Annotation[0].Reference     := iprtChannel;
      Annotation[0].ChannelName   := Channel[0].Name;
      Annotation[0].UserCanMove   := True;
      Annotation[0].ShowFocusRect := False;

      AddAnnotation;
      Annotation[1].Style         := ipasText;
      Annotation[1].X             := 90;
      Annotation[1].Y             := 7;
      Annotation[1].Reference     := iprtDataView;
      Annotation[1].Text          := 'Time';
      Annotation[1].Font.Style    := [fsBold];

      DataCursor[0].Color                    := clYellow;
      DataCursor[0].Style                    := ipcsInverseDeltaX;
      DataCursor[0].Pointer2Position         := 60;
      DataCursor[0].Pointer1Position         := 40;
      DataCursor[0].PointerPenWidth          := 3;
      DataCursor[0].ChannelAllowAll          := False;
      DataCursor[0].UserCanEdit              := False;
      DataCursor[0].MenuUserCanChangeOptions := False;
      DataCursor[0].MenuItemVisibleValueXY   := False;

      TiPlotDataCursorAccess(DataCursor[0]).ScopeStyle := True;

      OnDataCursorCustomizeHint     := DataCursorCustomizeHintEvent;
      OnLimitLine1PositionChange    := LimitLine1PositionChangeEvent;
      OnAnnotationCoordinatesChange := AnnotationCoordinatesChangeEvent;
      OnClickAnnotation             := ClickAnnotationEvent;

     UpdateFrameRate := 20;
    end;

  FPanelToolBar := TiScopePanelToolBar.Create(Self);
  with FPanelToolBar do
    begin
      Parent      := Self;
      Scope       := Self;
      OnEditClick := DoEditClick;
    end;

  FPanelChannels := TiScopePanelChannels.Create(Self);
  with FPanelChannels do
    begin
      Parent := Self;
      Scope  := Self;
    end;

⌨️ 快捷键说明

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