unit FMXTee.Editor.Tools.GridTranspose;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  FMXTee.Procs,
  FMX.ListBox, FMXTee.Tools.Transpose, FMX.Edit, FMX.TabControl, FMX.Colors;

type
  TGridTransposeToolEdit = class(TForm)
    Label2: TLabel;
    CBSeries: TComboBox;
    BTranspose: TButton;
    procedure FormActivate(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
    procedure BTransposeClick(Sender: TObject);
  private
    { Private declarations }
    GridTranspose : TGridTransposeTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Engine, FMXTee.Series.Surface;

procedure TGridTransposeToolEdit.BTransposeClick(Sender: TObject);
begin
  if Assigned(GridTranspose) then
    GridTranspose.Transpose;
end;

procedure TGridTransposeToolEdit.CBSeriesChange(Sender: TObject);
begin
  if Assigned(GridTranspose) and (CBSeries.ItemIndex<>-1) then
  begin
    GridTranspose.Series:=TCustom3DGridSeries(CBSeries.Items.Objects[CBSeries.ItemIndex]);
    BTranspose.Enabled:=True;
  end;
end;

procedure TGridTransposeToolEdit.FormActivate(Sender: TObject);
var tmp : TChartSeriesList;
    t: Integer;
begin
  if not Assigned(GridTranspose) then
  begin
    GridTranspose:=TGridTransposeTool(TagObject);

    if Assigned(GridTranspose) and Assigned(GridTranspose.ParentChart) then
    With GridTranspose do
    begin
      CBSeries.Items.Clear;
      tmp:=ParentChart.SeriesList;
      for t:=0 to tmp.Count-1 do
      if tmp[t] is TCustom3DGridSeries then
        CBSeries.Items.AddObject(SeriesTitleOrName(tmp[t]),tmp[t]);

      CBSeries.ItemIndex:=CBSeries.Items.IndexOfObject(GridTranspose.Series);

      BTranspose.Enabled:=CBSeries.ItemIndex<>-1;
    end;
  end;
end;

initialization
  RegisterSeriesEditor(TGridTransposeToolEdit);
end.
