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

📄 iplotchannelcustom.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 5 页
字号:
begin
  if VarArrayDimCount(XData) <> 1 then raise Exception.Create('X-Data array must be 1 dimensional');
  if VarArrayDimCount(YData) <> 1 then raise Exception.Create('Y-Data array must be 1 dimensional');

  LowBoundX  := VarArrayLowBound (XData, 1);
  LowBoundY  := VarArrayLowBound (YData, 1);
  HighBoundX := VarArrayHighBound(XData, 1);
  HighBoundY := VarArrayHighBound(YData, 1);

  if LowBoundX  <> LowBoundY  then raise Exception.Create('X-Data and Y-Data low bound dimension must match');
  if HighBoundX <> HighBoundY then raise Exception.Create('X-Data and Y-Data hogh bound dimension must match');

  for x := LowBoundX to HighBoundX do
    AddXY(XData[x], YData[x]);
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.AddXYArray(Data: Variant);
var
  x                 : Integer;

  LowBoundColumn    : Integer;
  HighBoundColumn   : Integer;

  LowBoundElements  : Integer;
  HighBoundElements : Integer;
begin
  if VarArrayDimCount(Data) <> 2 then raise Exception.Create('Array Must Be 2 Dimensional');

  LowBoundColumn    := VarArrayLowBound (Data, 1);
  HighBoundColumn   := VarArrayHighBound(Data, 1);

  if (HighBoundColumn - LowBoundColumn) <> 1 then raise Exception.Create('Array First Dimension Must Be 2 Elements');

  LowBoundElements  := VarArrayLowBound (Data, 2);
  HighBoundElements := VarArrayHighBound(Data, 2);

  for x := LowBoundElements to HighBoundElements do
    AddXY(Data[LowBoundColumn, x], Data[HighBoundColumn, x]);
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.GetXYEmptyNull(const Index: Integer; var X, Y: Double; var Empty, Null: Boolean);
begin
  DataList.GetXYEmptyNull(Index, X, Y, Empty, Null);
end;
//****************************************************************************************************************************************************
function TiPlotChannelCustom.GetCount: Integer;
begin
  Result := DataList.Count;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.SetCount(const Value: Integer);
begin
  DataList.SetCapacity(Value);
  TriggerChange(Self);
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.SetLegendRect(const Value: TRect);
begin
  FLegendRect := Value;
end;
//****************************************************************************************************************************************************
function TiPlotChannelCustom.GetDataXDrawMax(Index: Integer): Double;
begin
  if DataNull[Index] then raise Exception.Create('Data Point Null');
  Result := DataList.X[Index];
  if MarkersVisible then
    begin
      if not Assigned(XAxis) then raise Exception.Create('X-Axis not assigned');
      Result := Result + ABS((XAxis.PixelsToPosition(2*MarkersSize) - XAxis.PixelsToPosition(0))/2);
    end;
end;
//****************************************************************************************************************************************************
function TiPlotChannelCustom.GetDataXDrawMin(Index: Integer): Double;
begin
  if DataNull[Index] then raise Exception.Create('Data Point Null');
  Result := DataList.X[Index];
  if MarkersVisible then
    begin
      if not Assigned(XAxis) then raise Exception.Create('X-Axis not assigned');
      Result := Result - ABS((XAxis.PixelsToPosition(2*MarkersSize) - XAxis.PixelsToPosition(0))/2);
    end;
end;
//****************************************************************************************************************************************************
function TiPlotChannelCustom.GetDataYDrawMax(Index: Integer): Double;
begin
  if DataNull[Index] then raise Exception.Create('Data Point Null');
  Result := DataList.Y[Index];
  if MarkersVisible then
    begin
      if not Assigned(YAxis) then raise Exception.Create('Y-Axis not assigned');
      Result := Result + ABS((YAxis.PixelsToPosition(2*MarkersSize) - YAxis.PixelsToPosition(0))/2);
    end;
end;
//****************************************************************************************************************************************************
function TiPlotChannelCustom.GetDataYDrawMin(Index: Integer): Double;
begin
  if DataNull[Index] then raise Exception.Create('Data Point Null');
  Result := DataList.Y[Index];
  if MarkersVisible then
    begin
      if not Assigned(YAxis) then raise Exception.Create('Y-Axis not assigned');
      Result := Result - ABS((YAxis.PixelsToPosition(2*MarkersSize) - YAxis.PixelsToPosition(0))/2);
    end;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.SetRingBufferSize(const Value: Integer);
begin
  DataList.RingBufferSize := Value;
  TriggerChange(Self);
end;
//****************************************************************************************************************************************************
function TiPlotChannelCustom.GetRingBufferSize: Integer;
begin
  Result := DataList.RingBufferSize;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.SavePropertiesToFile(FileName: String);
var
  AList      : TStringList;
  IgnoreList : TStringList;
begin
  try
    AList := TStringList.Create;
    IgnoreList := TStringList.Create;
    try
    IgnoreList.Add('Name');
    try
      AList.Add('File Type = Plot Channel Config');

      SaveObjectToStringList(Self, 'Channel', AList, IgnoreList);
      AList.SaveToFile(FileName);
    finally
      AList.Free;
    end;
  finally
    IgnoreList.Free;
  end;
  except
    on e: Exception do raise Exception.Create('Error Saving Properties - ' + e.message);
  end;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.LoadPropertiesFromFile(FileName: String);
var
  AList   : TStringList;
  Found   : Boolean;
  AString : String;
begin
  try
  AList := TStringList.Create;
  AList.LoadFromFile(FileName);

  Found := GetPropertyValueString('File Type', AString, AList);
  if (not Found) or (UpperCase(AString) <> UpperCase('Plot Channel Config')) then
    raise Exception.Create('Incompatible Plot Channel Configuration File Type');
  try
    LoadObjectFromStringList(Self, 'Channel', AList);
  finally
    AList.Free;
  end;
  except
    on e: Exception do raise Exception.Create('Error Loading Properties - ' + e.message);
  end;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.SaveDataToFile(FileName: String);
var
  x     : Integer;
  AList : TStringList;
begin
  AList := TStringList.Create;
  try
    for x := 0 to Count-1 do
      begin
        if      DataEmpty[x] then Continue
        else if DataNull[x]  then AList.Add(FloatToStr(DataX[x]) + TiPlotComponentAccess(Owner).GetSavingSeparator + 'Null')
        else                      AList.Add(FloatToStr(DataX[x]) + TiPlotComponentAccess(Owner).GetSavingSeparator + FloatToStr(DataY[x]));
      end;
    AList.SaveToFile(FileName);
  finally
    AList.Free;
  end;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.LoadDataFromFile(FileName: String; ClearPreviousData: Boolean);
var
  x         : Integer;
  AList     : TStringList;
  XString   : String;
  YString   : String;
begin
  if FLoggingActive then LogDeactivate;
  AList := TStringList.Create;
  try
    AList.LoadFromFile(FileName);
    if ClearPreviousData then Clear;

    if AList.Count <> 0 then if AnsiPos(#9, AList.Strings[0]) <> 0 then FLoadingSeparator := #9 else FLoadingSeparator := ',';

    for x := 0 to AList.Count-1 do
      begin
        SeparateStrings(AList.Strings[x], FLoadingSeparator, XString, YString);
        if XString = '' then Continue;
        if UpperCase(YString) = UpperCase('Null') then
          begin
            AddXY(StrToFloat(XString), 0);
            DataNull[Count-1] := True;
          end
        else
          AddXY(StrToFloat(XString), StrToFloat(YString));
      end;
  finally
    AList.Free;
  end;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.LogActivate(Append: Boolean);
var
  FileStream : TFileStream;
begin
  if Trim(FLogFileName) = '' then raise Exception.Create('Log File Name not Defined');
  if FLoggingActive          then raise Exception.Create('Logging Already Active');

  if Append then
    FileStream := TFileStream.Create(FLogFileName, fmOpenReadWrite)
  else
    begin
      FileStream := TFileStream.Create(FLogFileName, fmCreate);
      FileStream.Size := 0;
    end;

  FileStream.Free;

  FLoggingActive  := True;
  FLogBufferCount := 0;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.LogDeactivate;
begin
  if not FLoggingActive then raise Exception.Create('Logging not Active');

  FLoggingActive := False;
  if FLogBufferCount > 0 then WriteLog;
end;
//****************************************************************************************************************************************************
procedure TiPlotChannelCustom.WriteLog;
var
  x          : Integer;
  FileStream : TFileStream;
  OutString  : ShortString;
begin
  FileStream := TFileStream.Create(FLogFileName, fmOpenReadWrite);
  try
    FileStream.Position := FileStream.Size;
    for x := Count-FLogBufferCount to Count-1 do
      begin
        OutString := FloatToStr(DataX[x]) + TiPlotComponentAccess(Owner).GetSavingSeparator + FloatToStr(DataY[x]) + #13+#10;
        FileStream.Write(OutString[1],Length(OutString));
      end;
    FLogBufferCount := 0;
  finally
    FileStream.Free;
  end;
end;
//*************************************************************************

⌨️ 快捷键说明

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