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

📄 qiscopepanelchannels.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetCouplingText(Value: TiScopeChannelCoupling): String;
begin
  case Value of
    isccDC     : Result := 'DC';
    isccAC     : Result := 'AC';
    isccGround : Result := 'GND';
  end;
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetVoltsPerDivText(Value: Double): String;
begin
  Result := FVoltageSelector.GetItemCaptionByValue(Value) + '/DIV';
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetPositionText(Value: Double): String;
begin
  Result := FPositionSelector.GetItemCaptionByValue(Value);
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.ChannelListPaintSetup(Sender: TObject; Canvas: TCanvas);
var
  x : Integer;
begin
  FMaxWidthTitle       := 0;
  FMaxWidthCoupling    := 0;
  FMaxWidthVoltsPerDiv := 0;
  FMaxWidthPosition    := 0;

  with Canvas do
    begin
      for x := 0 to Count-1 do
        if TextWidth(ScopeChannel[x].TitleText) > FMaxWidthTitle then FMaxWidthTitle := TextWidth(ScopeChannel[x].TitleText);

      FMaxWidthCoupling    := FCouplingSelector.GetMaxItemsWidth(Canvas);
      FMaxWidthVoltsPerDiv := FVoltageSelector.GetMaxItemsWidth (Canvas) + TextWidth('/DIV');
      FMaxWidthPosition    := FPositionSelector.GetMaxItemsWidth(Canvas);
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.ChannelListPaintItem(Sender: TObject; Canvas: TCanvas; ARect: TRect; State: TOwnerDrawState; Index: Integer; AText: String; var Handled: Boolean);
var
  ATextRect   : TRect;
  AColorRect  : TRect;
  AFocusRect  : TRect;
begin
  AFocusRect     := ARect;
  ATextRect      := ARect;

  AColorRect.Top    := ARect.Top    + 2;
  AColorRect.Bottom := ARect.Bottom - 2;
  AColorRect.Left   := ARect.Left   + 2;
  AColorRect.Right  := AColorRect.Left + AColorRect.Bottom - AColorRect.Top;

  ATextRect.Left := AColorRect.Right + 5;

  with Canvas do
    begin
      if odSelected in State then
        begin
          Brush.Style := bsSolid;
          Brush.Color := (Sender as TiLinkedListBox).SelectedColor;
          Pen.Style   := psSolid;
          Pen.Color   := Brush.Color;
          Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
          Font.Color := (Sender as TiLinkedListBox).SelectedFontColor;
        end;

      iDrawText(Canvas, AText, ATextRect, [itfVCenter, itfHLeft, itfSingleLine]);

      //------------------------------------------------------------------------------
      AText          := GetCouplingText(ScopeChannel[Index].Coupling);
      ATextRect.Left := AColorRect.Right + 5 + FMaxWidthTitle + 5 + FMaxWidthCoupling - TextWidth(AText);

      iDrawText(Canvas, AText, ATextRect, [itfVCenter, itfHLeft, itfSingleLine]);
      //------------------------------------------------------------------------------
      AText          := GetVoltsPerDivText(ScopeChannel[Index].VoltsPerDivision);
      ATextRect.Left := AColorRect.Right + 5 + FMaxWidthTitle + 5 + FMaxWidthCoupling + 5 + FMaxWidthVoltsPerDiv - TextWidth(AText);

      iDrawText(Canvas, AText, ATextRect, [itfVCenter, itfHLeft, itfSingleLine]);
      //------------------------------------------------------------------------------
      AText          := GetPositionText(ScopeChannel[Index].Position);
      ATextRect.Left := AColorRect.Right + 5 + FMaxWidthTitle + 5 + FMaxWidthCoupling + 5 + FMaxWidthVoltsPerDiv + 5 + FMaxWidthPosition - TextWidth(AText);

      iDrawText(Canvas, AText, ATextRect, [itfVCenter, itfHLeft, itfSingleLine]);
      //------------------------------------------------------------------------------
      Brush.Style := bsSolid;
      Brush.Color := TiScopeChannelAccess(ScopeChannel[Index]).Channel.Color;
      Pen.Style   := psSolid;
      Pen.Color   := Brush.Color;
      Rectangle(AColorRect.Left, AColorRect.Top, AColorRect.Right, AColorRect.Bottom);

      if odFocused in State then
        begin
          iDrawFocusRect(Canvas, AFocusRect, clNavy);
        end;
    end;

  Handled := True;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.Paint;
var
  DrawRect : TRect;
begin
  inherited;
  with Canvas do
    begin
      Brush.Color := clBtnFace;
      Brush.Style := bsSolid;
      DrawRect := Rect(0, 0, Width, Height);
      FillRect(DrawRect);
      iDrawEdge(Canvas, DrawRect, idesRaised);
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.AddChannelData(Channel: Integer; Y: Double);
begin
  if not FBlockActive then raise Exception.Create('Error Adding Channel Data: Data Block not Active');
  TiScopeChannelAccess(FScopeChannelList.Objects[Channel]).AddData(Y);
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.DataBlockBegin;
begin
  if FBlockActive then raise Exception.Create('Begin Data Block Error: Data Block already Active');
  FBlockActive := True;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.DataBlockEnd;
begin
  if FBlockActive then
    begin
      FBlockActive := False;
      CheckForSynchronizedData;
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.CheckForSynchronizedData;
begin
  if not DataBlockSynchronized then raise Exception.Create('End Data Block Error: All Channels must have the same Number of Data Elements');
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetDataBlockSynchronized: Boolean;
var
  ChannelIndex : Integer;
  RefCount     : Integer;
begin
  Result := True;
  if Count > 1 then
    begin
      RefCount := TiScopeChannelAccess(ScopeChannel[0]).RawData.Count;
      for ChannelIndex := 1 to Count-1 do
        if TiScopeChannelAccess(ScopeChannel[ChannelIndex]).RawData.Count <> RefCount then
          begin
            Result := False;
            Exit;
          end;
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.DataBlockClear;
var
  ChannelIndex : Integer;
begin
  for ChannelIndex := 0 to Count-1 do
    TiScopeChannelAccess(ScopeChannel[ChannelIndex]).RawData.Clear;
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetScopeChannel(Index: Integer): TiScopeChannel;
begin
  Result := FScopeChannelList.Objects[Index] as TiScopeChannel;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.ChannelListChange(Sender: TObject);
begin
  UpdateDisplay;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.UpdateDisplay;
begin
  if FChannelListDisplay.ItemIndex = -1 then
    begin
      FVoltageSelector.Enabled  := False;
      FPositionSelector.Enabled := False;
      FCouplingSelector.Enabled := False;
      FVisibleCheckBox.Enabled  := False;
      FRefLineCheckBox.Enabled  := False;
    end
  else
    begin
      FVoltageSelector.Enabled  := True;
      FPositionSelector.Enabled := True;
      FCouplingSelector.Enabled := True;
      FVisibleCheckBox.Enabled  := True;
      FRefLineCheckBox.Enabled  := True;

      FVoltageSelector.Value  := ScopeChannel[FChannelListDisplay.ItemIndex].VoltsPerDivision;
      FPositionSelector.Value := ScopeChannel[FChannelListDisplay.ItemIndex].Position;
      FCouplingSelector.Value :=(ord(ScopeChannel[FChannelListDisplay.ItemIndex].Coupling));
      FVisibleCheckBox.Checked := ScopeChannel[FChannelListDisplay.ItemIndex].TraceVisible;
      FRefLineCheckBox.Checked := ScopeChannel[FChannelListDisplay.ItemIndex].RefLineShow;

      //FChannelListDisplay.Invalidate;
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.VoltageSelectorChange(Sender: TObject);
begin
  if FChannelListDisplay.ItemIndex = -1 then Exit;
  ScopeChannel[FChannelListDisplay.ItemIndex].VoltsPerDivision := FVoltageSelector.GetItemValue(FVoltageSelector.ItemIndex);
  FChannelListDisplay.Invalidate;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.PositionSelectorChange(Sender: TObject);
begin
  if FChannelListDisplay.ItemIndex = -1 then Exit;
  ScopeChannel[FChannelListDisplay.ItemIndex].Position := FPositionSelector.GetItemValue(FPositionSelector.ItemIndex);
  FChannelListDisplay.Invalidate;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.CouplingChange(Sender: TObject);
begin
  if FChannelListDisplay.ItemIndex = -1 then Exit;
  ScopeChannel[FChannelListDisplay.ItemIndex].Coupling := TiScopeChannelCoupling(Round(FCouplingSelector.GetItemValue(FCouplingSelector.ItemIndex)));
  FChannelListDisplay.Invalidate;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.VisibleClick(Sender: TObject);
begin
  if FChannelListDisplay.ItemIndex = -1 then Exit;
  ScopeChannel[FChannelListDisplay.ItemIndex].TraceVisible := FVisibleCheckBox.Checked;
  FChannelListDisplay.Invalidate;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.RefLineClick(Sender: TObject);
begin
  if FChannelListDisplay.ItemIndex = -1 then Exit;
  ScopeChannel[FChannelListDisplay.ItemIndex].RefLineShow := FRefLineCheckBox.Checked;
  FChannelListDisplay.Invalidate;
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetCount: Integer;
begin
  Result := FScopeChannelList.Count;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.AdjustAnnotations;
var
  x : Integer;
begin
  for x := 0 to Count-1 do
    begin
      TiScopeChannelAccess(ScopeChannel[x]).Annotation.X := X*20 + 3;
    end;
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.AddChannel: Integer;
var
  ScopeChannel : TiScopeChannel;
begin
  ScopeChannel := TiScopeChannel.Create;
  TiScopeChannelAccess(ScopeChannel).OnChange := ChannelChange;

  Result := FScopeChannelList.AddObject('', ScopeChannel);

  if Assigned(FScope) then
    with TiScopeChannelAccess(ScopeChannel) do
      begin                                           
        Channel              := TiScopeAccess(FScope as TiScope).Plot.Channel[TiScopeAccess(FScope as TiScope).Plot.AddChannel];
        Channel.DataStyle    := ipdsCompactInterval;
        Channel.PopupEnabled := False;

        Scope                 := FScope;
        Channel.TitleText     := 'CH' + IntToStr(FScopeChannelList.Count);
        YAxis                 := TiScopeAccess(FScope as TiScope).Plot.YAxis[TiScopeAccess(FScope as TiScope).Plot.AddYAxis];
        YAxis.Visible         := False;
        YAxis.TrackingEnabled := False;
        Channel.XAxisName     := TiScopeAccess(FScope as TiScope).Plot.XAxis[1].Name;

        Channel.YAxisName := YAxis.Name;

        Channel.XAxisTrackingEnabled := False;
        Channel.YAxisTrackingEnabled := False;

        Annotation         := TiScopeAccess(FScope as TiScope).Plot.Annotation[TiScopeAccess(FScope as TiScope).Plot.AddAnnotation];
        Annotation.Visible := TiScopeAccess(FScope as TiScope).Display.TextShow;
        Annotation.Text    := FVoltageSelector.GetItemCaptionByValue(VoltsPerDivision) + ' ' +
                              FCouplingSelector.GetItemCaptionByValue(ord(Coupling));

        RefLine := TiScopeAccess(FScope as TiScope).Plot.Limit[TiScopeAccess(FScope as TiScope).Plot.AddLimit];

        if FChannelListDisplay.ItemIndex = -1 then FChannelListDisplay.ItemIndex := 0;
        FChannelListDisplay.Invalidate;
      end;
  AdjustAnnotations;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.RemoveAllChannels;
begin
  while Count > 0 do
    DeleteChannel(0);
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.DeleteChannel(Index: Integer);
begin
  FScopeChannelList.Objects[Index].Free;
  FScopeChannelList.Delete(Index);
  ChannelListChange(Self);
  FChannelListDisplay.Invalidate;
  AdjustAnnotations;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.ChannelChange(Sender: TObject);
begin
  UpdateDisplay;
  with TiScopeChannelAccess(Sender as TiScopeChannel) do
    begin
      Annotation.Text := FVoltageSelector.GetItemCaptionByValue(VoltsPerDivision) + ' ' + FCouplingSelector.GetItemCaptionByValue(ord(Coupling));
    end;
  FChannelListDisplay.Invalidate;
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetScopeChannelFromLimitIndex(Index: Integer): TiScopeChannel;
var
  x : Integer;
begin
  Result := nil;
  for x := 0 to Count-1 do
    if TiScopeChannelAccess(ScopeChannel[x]).RefLine = TiScopeAccess(FScope as TiScope).Plot.Limit[Index] then
      begin
        Result := ScopeChannel[x];
        Break;
      end;
end;
//****************************************************************************************************************************************************
function TiScopePanelChannels.GetScopeChannelFromAnnotation(Index: Integer): TiScopeChannel;
var
  x : Integer;
begin
  Result := nil;
  for x := 0 to Count-1 do
    if TiScopeChannelAccess(ScopeChannel[x]).Annotation = TiScopeAccess(FScope as TiScope).Plot.Annotation[Index] then
      begin
        Result := ScopeChannel[x];
        Break;
      end;
end;
//****************************************************************************************************************************************************
end.


⌨️ 快捷键说明

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