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

📄 qiscopepaneltimebase.pas

📁 iocopm3.04源码,一套很好的工控开发工具
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  FCreationComplete := True;
end;
//****************************************************************************************************************************************************
destructor TiScopePanelTimeBase.Destroy;
begin
  inherited Destroy;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.Resize;
begin
  inherited Resize;
  AdjustLayout;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.AdjustLayout;
var
  MaxLabelWidth : Integer;
  LeftStart     : Integer;
  TopStart      : Integer;
begin
  if not FCreationComplete then Exit;

  MaxLabelWidth := 0;

  TopStart  := FLabel.Height + 10;

  if FSecPerDivLabel.Width   > MaxLabelWidth then MaxLabelWidth := FSecPerDivLabel.Width;
  if FPositionLabel.Width    > MaxLabelWidth then MaxLabelWidth := FPositionLabel.Width;
  if FPreCaptureLabel.Width  > MaxLabelWidth then MaxLabelWidth := FPreCaptureLabel.Width;
  if FPostCaptureLabel.Width > MaxLabelWidth then MaxLabelWidth := FPostCaptureLabel.Width;

  LeftStart := Width - 10 - MaxLabelWidth - FSecPerDivSelector.Width - 5;

  FSecPerDivLabel.Left      := LeftStart + MaxLabelWidth - FSecPerDivLabel.Width;
  FPositionLabel.Left       := LeftStart + MaxLabelWidth - FPositionLabel.Width;
  FPreCaptureLabel.Left     := LeftStart + MaxLabelWidth - FPreCaptureLabel.Width;
  FPostCaptureLabel.Left    := LeftStart + MaxLabelWidth - FPostCaptureLabel.Width;

  FSecPerDivSelector.Top    := TopStart;
  FPositionSelector.Top     := FSecPerDivSelector.Top  + FSecPerDivSelector.Height  + 2;
  FPreCaptureSelector.Top   := FPositionSelector.Top   + FPositionSelector.Height   + 2;
  FPostCaptureSelector.Top  := FPreCaptureSelector.Top + FPreCaptureSelector.Height + 2;

  FSecPerDivSelector.Left   := LeftStart + MaxLabelWidth +5;
  FPositionSelector.Left    := FSecPerDivSelector.Left;
  FPreCaptureSelector.Left  := FSecPerDivSelector.Left;
  FPostCaptureSelector.Left := FSecPerDivSelector.Left;

  iAlignVCenterControl(FSecPerDivSelector,   FSecPerDivLabel);
  iAlignVCenterControl(FPositionSelector,    FPositionLabel);
  iAlignVCenterControl(FPreCaptureSelector,  FPreCaptureLabel);
  iAlignVCenterControl(FPostCaptureSelector, FPostCaptureLabel);

  FRequiredHeight := FPostCaptureSelector.Top + FPostCaptureSelector.Height + 10;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.RemoveRawSamples(Value: Integer);
var
  ScopeChannel      : TiScopeChannel;
  ChannelIndex      : Integer;
begin
  for ChannelIndex := 0 to TiScopeAccess(FScope as TiScope).PanelChannels.Count-1 do
    begin
      ScopeChannel := TiScopeAccess(FScope as TiScope).PanelChannels.ScopeChannel[ChannelIndex];
      TiScopeChannelAccess(ScopeChannel).RawData.DeletePoints(Value);
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.DataBlockUpdate;
var
  TriggerChannel    : TiScopeChannel;
  ScopeChannel      : TiScopeChannel;
  ChannelIndex      : Integer;
  TriggerIndex      : Integer;
  DataIndex         : Integer;
  TriggerStartIndex : Integer;
  TriggerStopIndex  : Integer;
  NeededSamples     : Integer;

  StartIndex        : Integer;
  StopIndex         : Integer;
  TimeIndex         : Integer;
  AutoTrigger       : Boolean;
  TriggerFound      : Boolean;
  RawData           : TiPlotDataScopeList;
  XData             : Double;
  YData             : Double;
begin
  TiScopeAccess(FScope as TiScope).Plot.BeginUpdate;

  UpdateAll;

  TriggerChannel := TiScopeAccess(FScope as TiScope).PanelChannels.ScopeChannel[TiScopeAccess(FScope as TiScope).PanelTrigger.SourceIndex];
  RawData        := TiScopeChannelAccess(TriggerChannel).RawData;

  NeededSamples := FSweepSamples;

  AutoTrigger   := TiScopeAccess(FScope as TiScope).PanelTrigger.Auto;

  if FSamplesPerFrame = 0 then
    begin
      TiScopeAccess(FScope as TiScope).Plot.ClearAllData;
      RemoveRawSamples(RawData.Count);
      Exit;
    end;

  while RawData.Count > NeededSamples do
    begin
      TriggerFound := False;
      if AutoTrigger then                    
        begin
          TriggerStartIndex := FPreSamples;
          TriggerStopIndex  := RawData.Count - (FSamplesPerFrame + FPostSamples);

          RawData.UpdateLevel(TriggerStartIndex, TriggerStopIndex);
          TriggerFound := TiScopeAccess(FScope as TiScope).PanelTrigger.CheckForTrigger(RawData, TriggerStartIndex, TriggerStopIndex, TriggerIndex);
        end
      else if FNeedsManualTrigger then
        begin
          TriggerIndex := RawData.Count - (FSamplesPerFrame + FPostSamples);
          TriggerFound := True;
          FNeedsManualTrigger := False;
        end
      else
        begin
          if (RawData.Count > 3*NeededSamples) then
            RemoveRawSamples(RawData.Count - 2*NeededSamples)
          else
            Break;
        end;

      if TriggerFound then
        begin
          TiScopeAccess(FScope as TiScope).Plot.ClearAllData;

          StartIndex := TriggerIndex - FPreSamples;
          StopIndex  := TriggerIndex + FSamplesPerFrame -1 + FPostSamples;

          for ChannelIndex := 0 to TiScopeAccess(FScope as TiScope).PanelChannels.Count-1 do
            begin
              ScopeChannel := TiScopeAccess(FScope as TiScope).PanelChannels.ScopeChannel[ChannelIndex];

              for DataIndex := StartIndex to StopIndex do
                begin
                  TimeIndex := DataIndex - StartIndex - FPreSamples;
                  XData     := TimeIndex*FSampleInterval;
                  YData     := TiScopeChannelAccess(ScopeChannel).GetYDisplay(DataIndex);
                  TiPlotChannelCustomAccess(TiScopeChannelAccess(ScopeChannel).Channel).DataList.Add(XData, YData);
                end;
            end;

          FLastTransferTime := Now;

          RemoveRawSamples(StopIndex);
        end
      else
        begin
          if (RawData.Count > 2*NeededSamples) then
            RemoveRawSamples(RawData.Count - NeededSamples)
          else
            Break;
        end;
    end;
  TiScopeAccess(FScope as TiScope).Plot.EndUpdate;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.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 TiScopePanelTimeBase.SecondsPerDivisionSelectorChange(Sender: TObject);
begin                                          
  if not Assigned(FScope) then Exit;
                                                                    
  TiScopeAccess(FScope as TiScope).Plot.ClearAllData;
  FDisplayAnnotation.Text := FSecPerDivSelector.Text;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.PositionSelectorChangeEvent(Sender: TObject);
begin
  if FEventActive then Exit;
  FEventActive := True;
  try
    if Assigned(FScrollAnnotation) then FScrollAnnotation.X := -FPositionSelector.Value/100 + 0.5;
  finally
    FEventActive := False;
  end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.SetSamplesPerSecond    (const Value:Integer    );begin if FSamplesPerSecond    <>Value then FSamplesPerSecond    := Value;end;
procedure TiScopePanelTimeBase.SetMaxContinuousSamples(const Value:Integer    );begin if FMaxContinuousSamples<>Value then FMaxContinuousSamples:= Value;end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.SetXAxis            (const Value:TiPlotXAxis);     begin FXAxis             := Value;end;
procedure TiScopePanelTimeBase.SetScrollAnnotation (const Value:TiPlotAnnotation);begin FScrollAnnotation  := Value;end;
procedure TiScopePanelTimeBase.SetDisplayAnnotation(const Value:TiPlotAnnotation);begin FDisplayAnnotation := Value; FDisplayAnnotation.Text := FSecPerDivSelector.Text end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.SetSecPerDiv  (const Value:Double);begin FSecPerDivSelector.Value   := Value;end;
procedure TiScopePanelTimeBase.SetPreCapture (const Value:Double);begin FPreCaptureSelector.Value  := Value;end;
procedure TiScopePanelTimeBase.SetPostCapture(const Value:Double);begin FPostCaptureSelector.Value := Value;end;
//****************************************************************************************************************************************************
function TiScopePanelTimeBase.GetPosition   : Double;begin Result := FPositionSelector.Value;   end;
function TiScopePanelTimeBase.GetSecPerDiv  : Double;begin Result := FSecPerDivSelector.Value;  end;
function TiScopePanelTimeBase.GetPostCapture: Double;begin Result := FPostCaptureSelector.Value;end;
function TiScopePanelTimeBase.GetPreCapture : Double;begin Result := FPreCaptureSelector.Value; end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.SetPosition(const Value:Double);
begin
  if FPositionSelector.Value <> Value then
    begin
      FPositionSelector.Value := Value;
    end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.UpdateAll;
begin
  FFrameTime       := 10 * FSecPerDivSelector.Value;
  FSamplesPerFrame := Round(FSamplesPerSecond * FFrameTime) +1;
  FPreSamples      := Round(FSamplesPerFrame/10 * FPreCaptureSelector.Value);
  FPostSamples     := Round(FSamplesPerFrame/10 * FPostCaptureSelector.Value);
  FSweepSamples    := FPreSamples + FSamplesPerFrame + FPostSamples;

  if not Assigned(FXAxis) then Exit;
  XAxis.Span := FFrameTime;
  XAxis.Min  := (XAxis.Span * FPositionSelector.Value)/100;

  if FSamplesPerSecond = 0 then Exit;
  FSampleInterval  := 1/FSamplesPerSecond;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.ScrollEvent;
var
  NewPosition : Double;
begin
  if FEventActive then Exit;
  FEventActive := True;
  try
    NewPosition := -(FScrollAnnotation.X -0.5)*100;
    if NewPosition >= 0 then
      NewPosition := Trunc(NewPosition*10  + 0.0001)/10
    else
      NewPosition := Trunc(NewPosition*10)/10;
    Position := NewPosition;
  finally
    FEventActive := False;
  end;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelTimeBase.DoManualTrigger(Sender: Tobject);
begin
  FNeedsManualTrigger := True;
  TiScopeAccess(FScope as TiScope).Plot.ClearAllData;
  DataBlockUpdate;
end;
//****************************************************************************************************************************************************
end.


⌨️ 快捷键说明

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