📄 iscopepanelchannels.pas
字号:
{*******************************************************}
{ }
{ TiScopePanelChannels Component }
{ }
{ Copyright (c) 1997,2003 Iocomp Software }
{ }
{*******************************************************}
{$I iInclude.inc}
{$ifdef iVCL}unit iScopePanelChannels;{$endif}
{$ifdef iCLX}unit QiScopePanelChannels;{$endif}
interface
uses
{$I iIncludeUses.inc}
{$IFDEF iVCL} iTypes, iGPFunctions, Buttons, iEditorBasicComponents, iSpinSelector, iLinkedListBox, iCheckBox,{$ENDIF}
{$IFDEF iCLX}QiTypes, QiGPFunctions, QButtons, QiEditorBasicComponents, QiSpinSelector, QiLinkedListBox, QiCheckBox,{$ENDIF}
{$IFDEF iVCL} iPlot, iPlotChannel, iPlotChannelCustom, iScopeChannel, iPlotAxis, iPlotDataScopeList;{$ENDIF}
{$IFDEF iCLX}QiPlot, QiPlotChannel, QiPlotChannelCustom, QiScopeChannel, QiPlotAxis, QiPlotDataScopeList;{$ENDIF}
type
TiScopePanelChannels = class(TCustomControl)
private
FScope : TWinControl;
FScopeChannelList : TStringList;
FBlockActive : Boolean;
FLabel : TLabel;
FVoltageLabel : TLabel;
FPositionLabel : TLabel;
FCouplingLabel : TLabel;
FChannelListDisplay : TiLinkedListBox;
FVoltageSelector : TiSpinSelector;
FPositionSelector : TiSpinSelector;
FCouplingSelector : TiSpinSelector;
FVisibleCheckBox : TiCheckBox;
FRefLineCheckBox : TiCheckBox;
FMaxWidthTitle : Integer;
FMaxWidthCoupling : Integer;
FMaxWidthVoltsPerDiv : Integer;
FMaxWidthPosition : Integer;
FCreationComplete : Boolean;
function GetDataBlockSynchronized: Boolean;
protected
procedure Paint; override;
procedure Resize; override;
procedure AdjustLayout;
procedure AdjustAnnotations;
function GetScopeChannel(Index: Integer): TiScopeChannel;
function GetCount: Integer;
procedure VoltageSelectorChange (Sender: TObject);
procedure PositionSelectorChange(Sender: TObject);
procedure CouplingChange (Sender: TObject);
procedure VisibleClick (Sender: TObject);
procedure RefLineClick (Sender: TObject);
procedure ChannelChange (Sender: TObject);
function GetCouplingText (Value: TiScopeChannelCoupling): String;
function GetVoltsPerDivText(Value: Double) : String;
function GetPositionText (Value: Double) : String;
procedure ChannelListGetItemCount (Sender: TObject; var Value : Integer);
procedure ChannelListGetItemString(Sender: TObject; Index: Integer; var Value : String );
procedure ChannelListPaintItem (Sender: TObject; Canvas: TCanvas; ARect: TRect; State: TOwnerDrawState; Index: Integer; AText: String; var Handled: Boolean);
procedure ChannelListChange (Sender: TObject);
procedure ChannelListPaintSetup (Sender: TObject; Canvas: TCanvas);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure DataBlockBegin;
procedure DataBlockEnd;
procedure DataBlockClear;
property DataBlockActive : Boolean read FBlockActive;
property DataBlockSynchronized : Boolean read GetDataBlockSynchronized;
procedure AddChannelData(Channel: Integer; Y: Double);
function GetScopeChannelFromLimitIndex(Index: Integer): TiScopeChannel;
function GetScopeChannelFromAnnotation (Index: Integer): TiScopeChannel;
procedure CheckForSynchronizedData;
procedure UpdateDisplay;
function AddChannel: Integer;
procedure RemoveAllChannels;
procedure DeleteChannel(Index: Integer);
property ScopeChannel[Index: Integer]: TiScopeChannel read GetScopeChannel;
property Count : Integer read GetCount;
property Scope : TWinControl read FScope write FScope;
property VoltageSelector : TiSpinSelector read FVoltageSelector;
property PositionSelector : TiSpinSelector read FPositionSelector;
property CouplingSelector : TiSpinSelector read FCouplingSelector;
end;
implementation
uses
{$IFDEF iVCL} iScope;{$ENDIF}
{$IFDEF iCLX}QiScope;{$ENDIF}
type
TiScopeAccess = class(TiScope )end;
TiScopeChannelAccess = class(TiScopeChannel)end;
//****************************************************************************************************************************************************
constructor TiScopePanelChannels.Create(AOwner: TComponent);
var
x : Integer;
begin
inherited Create(AOwner);
Width := 210;
Height := 125;
FLabel := TLabel.Create(Self);
with FLabel do
begin
Parent := Self;
Top := 3;
Left := 3;
Font.Size := 10;
Font.Style := [fsBold, fsItalic, fsUnderline];
Caption := 'Channels';
Transparent := True;
end;
FChannelListDisplay := TiLinkedListBox.Create(Self);
with FChannelListDisplay do
begin
Parent := Self;
Color := clBlack;
Font.Color := clWhite;
ShowFocusNoSelection := False;
OnGetItemCount := ChannelListGetItemCount;
OnGetItemString := ChannelListGetItemString;
OnPaintItem := ChannelListPaintItem;
OnPaintSetup := ChannelListPaintSetup;
OnChange := ChannelListChange;
end;
FVoltageLabel := TLabel.Create(Self);
with FVoltageLabel do
begin
Parent := Self;
Font.Size := 8;
Font.Style := [fsBold];
Caption := 'Volts/DIV';
Transparent := True;
end;
FVoltageSelector := TiSpinSelector.Create(Self);
with FVoltageSelector do
begin
Parent := Self;
Height := 24;
Width := 93;
RepeatInterval := 200;
DefaultValue := 5;
OnChange := VoltageSelectorChange;
AddItem('1 礦', 0.000001);
AddItem('2 礦', 0.000002);
AddItem('5 礦', 0.000005);
AddItem('10 礦', 0.000010);
AddItem('20 礦', 0.000020);
AddItem('50 礦', 0.000050);
AddItem('100 礦', 0.000100);
AddItem('1 mV', 0.001000);
AddItem('2 mV', 0.002000);
AddItem('5 mV', 0.005000);
AddItem('10 mV', 0.010000);
AddItem('20 mV', 0.020000);
AddItem('50 mV', 0.050000);
AddItem('100 mV', 0.100000);
AddItem('200 mV', 0.200000);
AddItem('500 mV', 0.500000);
AddItem('1 V', 1.000000);
AddItem('2 V', 2.000000);
AddItem('5 V', 5.000000);
AddItem('10 V', 10.000000);
AddItem('20 V', 20.000000);
AddItem('50 V', 50.000000);
end;
FPositionLabel := TLabel.Create(Self);
with FPositionLabel do
begin
Parent := Self;
Font.Size := 8;
Font.Style := [fsBold];
Caption := 'Position';
Transparent := True;
end;
FPositionSelector := TiSpinSelector.Create(Self);
with FPositionSelector do
begin
Parent := Self;
Height := 24;
Width := 93;
RepeatInterval := 50;
FastIncrement := 10;
DefaultValue := 0;
OnChange := PositionSelectorChange;
for x := -1000 to 1000 do
AddItem(FormatFloat('0.0%', x/10), x/10);
end;
FCouplingLabel := TLabel.Create(Self);
with FCouplingLabel do
begin
Parent := Self;
Font.Size := 8;
Font.Style := [fsBold];
Caption := 'Coupling';
Transparent := True;
end;
FCouplingSelector := TiSpinSelector.Create(Self);
with FCouplingSelector do
begin
Parent := Self;
Height := 24;
Width := 93;
RepeatInterval := 5;
DefaultValue := 1;
OnChange := CouplingChange;
AddItem('DC', 0.000);
AddItem('AC', 1.000);
AddItem('GND', 2.000);
end;
FVisibleCheckBox := TiCheckBox.Create(Self);
with FVisibleCheckBox do
begin
Parent := Self;
Width := 75;
Caption := 'Visible';
OnChange := VisibleClick;
end;
FRefLineCheckBox := TiCheckBox.Create(Self);
with FRefLineCheckBox do
begin
Parent := Self;
Width := 75;
Caption := 'Ref Line';
OnChange := RefLineClick;
end;
FScopeChannelList := TStringList.Create;
FCreationComplete := True;
end;
//****************************************************************************************************************************************************
destructor TiScopePanelChannels.Destroy;
begin
while FScopeChannelList.Count <> 0 do
begin
FScopeChannelList.Objects[0].Free;
FScopeChannelList.Delete(0);
end;
FScopeChannelList.Free;
inherited;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.Resize;
begin
inherited Resize;
AdjustLayout;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.AdjustLayout;
var
MaxLabelWidth : Integer;
LeftStart : Integer;
TopStart : Integer;
begin
if not FCreationComplete then Exit;
MaxLabelWidth := 0;
TopStart := FLabel.Height + 10;
FChannelListDisplay.Left := 10;
FChannelListDisplay.Top := TopStart;
FChannelListDisplay.Width := Width div 3;
FChannelListDisplay.Height := Height - FChannelListDisplay.Top - 10;
if FVoltageLabel.Width > MaxLabelWidth then MaxLabelWidth := FVoltageLabel.Width;
if FPositionLabel.Width > MaxLabelWidth then MaxLabelWidth := FPositionLabel.Width;
if FCouplingLabel.Width > MaxLabelWidth then MaxLabelWidth := FCouplingLabel.Width;
LeftStart := Width - 10 - MaxLabelWidth - FVoltageSelector.Width - 5;
FVoltageLabel.Left := LeftStart + MaxLabelWidth - FVoltageLabel.Width;
FPositionLabel.Left := LeftStart + MaxLabelWidth - FPositionLabel.Width;
FCouplingLabel.Left := LeftStart + MaxLabelWidth - FCouplingLabel.Width;
FVoltageSelector.Left := FVoltageLabel.Left + FVoltageLabel.Width + 5;
FPositionSelector.Left := FPositionLabel.Left + FPositionLabel.Width + 5;
FCouplingSelector.Left := FCouplingLabel.Left + FCouplingLabel.Width + 5;
FVoltageSelector.Top := FChannelListDisplay.Top;
FPositionSelector.Top := FVoltageSelector.Top + FVoltageSelector.Height + 2;
FCouplingSelector.Top := FPositionSelector.Top + FPositionSelector.Height + 2;
iAlignVCenterControl(FPositionSelector, FPositionLabel);
iAlignVCenterControl(FVoltageSelector, FVoltageLabel);
iAlignVCenterControl(FCouplingSelector, FCouplingLabel);
FChannelListDisplay.Width := FVoltageLabel.Left - 10 - FChannelListDisplay.Left;
FVisibleCheckBox.Top := FCouplingSelector.Top + FCouplingSelector.Height + 5;
FVisibleCheckBox.Left := FChannelListDisplay.Left + FChannelListDisplay.Width + 10;
FRefLineCheckBox.Top := FVisibleCheckBox.Top;
FRefLineCheckBox.Left := FVisibleCheckBox.Left + FVisibleCheckBox.Width + 5;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.ChannelListGetItemCount(Sender: TObject; var Value: Integer);
begin
if Assigned(FScopeChannelList) then
Value := FScopeChannelList.Count
else Value := 0;
end;
//****************************************************************************************************************************************************
procedure TiScopePanelChannels.ChannelListGetItemString(Sender: TObject; Index: Integer; var Value: String);
begin
if Assigned(TiScopeChannelAccess(ScopeChannel[Index]).Channel) then
begin
Value := TiScopeChannelAccess(ScopeChannel[Index]).Channel.TitleText;
end
else Value := 'Unassigned';
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -