{********************************************}
{ TeeChart Pro Charting Library              }
{ Copyright (c) 1995-2020 by Steema Software }
{         All Rights Reserved                }
{                                            }
{  TBase Function Editor form                }
{********************************************}
unit TeeDownSamplingEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, TeeBaseFuncEdit, StdCtrls, ExtCtrls, ComCtrls,
  TeeDownSampling;

type
  TDownSamplingEditor = class(TBaseFunctionEditor)
    RGMethod: TRadioGroup;
    Label1: TLabel;
    ETolerance: TEdit;
    UDTolerance: TUpDown;
    Label2: TLabel;
    LReduced: TLabel;
    procedure RGMethodClick(Sender: TObject);
    procedure EToleranceChange(Sender: TObject);
  private
    { Private declarations }

    function DownSampling:TDownSamplingFunction;
    procedure SetLabelReduced;
  protected
    procedure ApplyFormChanges; override;
    procedure SetFunction; override;
  public
    { Public declarations }
  end;

implementation

{$IFNDEF LCL}
{$R *.DFM}
{$ELSE}
{$R *.lfm}
{$ENDIF}

uses
  TeEngine;

procedure TDownSamplingEditor.RGMethodClick(Sender: TObject);
begin
  EnableApply;
end;

procedure TDownSamplingEditor.EToleranceChange(Sender: TObject);
begin
  EnableApply;
end;

function TDownSamplingEditor.DownSampling:TDownSamplingFunction;
begin
  result:=TDownSamplingFunction(IFunction);
end;

procedure TDownSamplingEditor.SetLabelReduced;
begin
  LReduced.Caption:=IntToStr(DownSampling.ReducedSize);
end;

procedure TDownSamplingEditor.ApplyFormChanges;
begin
  inherited;

  with DownSampling do
  begin
    BeginUpdate;
    try
      DownSampleMethod:=TDownSampleMethod(RGMethod.ItemIndex);
      Tolerance:=UDTolerance.Position;
    finally
      EndUpdate;
      SetLabelReduced;
    end;
  end;
end;

procedure TDownSamplingEditor.SetFunction;
begin
  inherited;

  with DownSampling do
  begin
    RGMethod.ItemIndex:=Ord(DownSampleMethod);
    UDTolerance.Position:=Round(Tolerance);

    SetLabelReduced;
  end;
end;

initialization
  RegisterClass(TDownSamplingEditor);
end.
