unit ParameterDetailsWin;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, ExtCtrls;

type
  TParameterDetailsWindow = class(TForm)
    PageControl1: TPageControl;
    TrackBar1: TTrackBar;
    TabSheet1: TTabSheet;
    ListView1: TListView;
    Panel1: TPanel;
    ListBox1: TListBox;
    TabSheet2: TTabSheet;
    Panel2: TPanel;
    TreeView1: TTreeView;
    ListView2: TListView;
    TabSheet3: TTabSheet;
    ListView3: TListView;
    procedure TrackBar1Change(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
    procedure FormHide(Sender: TObject);
  private
    { Private declarations }
  public
    Procedure BuildFields;
  end;

var
  ParameterDetailsWindow: TParameterDetailsWindow;
  FirstRun: Boolean = true;

implementation

{$R *.dfm}

Uses Main, CM2EditorSupportInterface, ObjectInspector;

procedure TParameterDetailsWindow.TrackBar1Change(Sender: TObject);
begin
  AlphaBlendValue := TrackBar1.Position;
end;

procedure TParameterDetailsWindow.FormResize(Sender: TObject);
begin
 ListBox1.Height := Panel1.Height - 24;
 Treeview1.Height := Listbox1.Height;
end;

procedure TParameterDetailsWindow.FormShow(Sender: TObject);
begin
 oeMain.actionParameterDetails.Checked := True;
 If firstrun then begin
  firstrun := False;
  BuildFields;
 end;
end;

procedure TParameterDetailsWindow.BuildFields;
Var
 I, II: Integer;
 Node: TTreeNode;
 LI: TListItem;
 S: String;
begin
 For I := 0 to oeMain.vpl.Count - 1 do begin
  Listbox1.Items.Add(oeMain.vpl[I].Name);
 end;
 For I := 0 to oeMain.gpl.Count - 1 do begin
  Node := TreeView1.Items.Add(nil, oeMain.gpl[I].Name);
  For II := 0 to oeMain.gpl[I].SensorList.Count - 1 do begin
   TreeView1.Items.AddChild(node, oeMain.gpl[I].SensorList[II].Name);
  end;
 end;
 For I := 0 to oeMain.FESL.Count - 1 do begin
  LI := Listview3.Items.Add;
  LI.Caption := oeMain.FESL[I].Name;
  LI.SubItems.Add(BoolToStr(oeMain.FESL[I].Required, true));
  LI.SubItems.Add(oeMain.FESL[I].Description);
  LI.SubItems.Add(oeMain.FESL[I].Value);
  Case oeMain.FESL[I].ValueType of
   vtUnknown: S := 'None';
   vtFixed: S := 'Fixed List';
   vtRange: S := 'Ranged (Min|Max)';
   vtColor: S := 'Color';
   vtFont: S := 'Font Name';
   vtFile: S := 'File Path';
   vtFontEx: S := 'Font Extended';
  end;
  LI.Subitems.Add(S);
  LI.SubItems.Add(oeMain.FESL[I].ValueRange);
 end;
end;

procedure TParameterDetailsWindow.ListBox1Click(Sender: TObject);
Var
 I: Integer;
 LI: TListItem;
 Sel: Integer;
 S: String;
begin
 ListView1.Items.BeginUpdate;
 Listview1.Items.Clear;
 Sel := -1;
 For I := 0 to oeMain.VESL.Count - 1 do begin
  If oeMain.VESL[I].Name = Listbox1.Items[Listbox1.ItemIndex] then Sel := I;
 end;
 If Sel = -1 then exit;
 For I := 0 to oeMain.VESL[Sel].Count - 1 do begin
  LI := Listview1.Items.Add;
  LI.Caption := oeMain.VESL[Sel].VisPlugEditorInfo[I].Name;
  LI.SubItems.Add(BoolToStr(oeMain.VESL[Sel].VisPlugEditorInfo[I].Required, true));
  LI.SubItems.Add(oeMain.VESL[Sel].VisPlugEditorInfo[I].Description);
  LI.SubItems.Add(oeMain.VESL[Sel].VisPlugEditorInfo[I].Value);
  Case oeMain.VESL[Sel].VisPlugEditorInfo[I].ValueType of
   vtUnknown: S := 'None';
   vtFixed: S := 'Fixed List';
   vtRange: S := 'Ranged (Min|Max)';
   vtColor: S := 'Color';
   vtFont: S := 'Font Name';
   vtFile: S := 'File Path';
   vtFontEx: S := 'Font Extended';
   vtEditor: S := 'Editor';
  end;
  LI.Subitems.Add(S);
  LI.SubItems.Add(oeMain.VESL[Sel].VisPlugEditorInfo[I].ValueRange);
 end;

 ListView1.Items.EndUpdate;
end;

procedure TParameterDetailsWindow.TreeView1Change(Sender: TObject;
  Node: TTreeNode);
Var
 SName, PName, S: String;
 I, PSel, SSel: Integer;
 LI: TListItem;
begin
 if Node.Level <> 1 then exit;
 SName := Node.Text;
 PName := Node.Parent.Text;
 ListView2.Items.BeginUpdate;
 ListView2.Items.Clear;
 PSel := -1;
 For I := 0 to oeMain.GESL.Count - 1 do begin
  If oeMain.GESL[I].Name = PName then begin
   PSel := I;
   break;
  end;
 end;
 If PSel = -1 then exit;
 SSel := -1;
 For I := 0 to oeMain.GESL[PSel].Count - 1 do begin
  If oeMain.GESL[PSel].SensorParamEditorSupportList[I].SensorName = SName then begin
   SSel := I;
   break;
  end;
 end;
 If SSel = -1 then exit;
 For I := 0 to oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].Count - 1 do begin
  LI := Listview2.Items.Add;
  LI.Caption := oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].SensorParamEditorSupport[I].Name;
  LI.SubItems.Add(BoolToStr(oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].SensorParamEditorSupport[I].Required, true));
  LI.SubItems.Add(oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].SensorParamEditorSupport[I].Description);
  LI.SubItems.Add(oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].SensorParamEditorSupport[I].Value);
  Case oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].SensorParamEditorSupport[I].ValueType of
   vtUnknown: S := 'None';
   vtFixed: S := 'Fixed List';
   vtRange: S := 'Ranged (Min|Max)';
   vtColor: S := 'Color';
   vtFont: S := 'Font Name';
   vtFile: S := 'File Path';
   vtFontEx: S := 'Font Extended';
  end;
  LI.Subitems.Add(S);
  LI.SubItems.Add(oeMain.GESL[PSel].SensorParamEditorSupportList[SSel].SensorParamEditorSupport[I].ValueRange);
 end;
 ListView2.Items.EndUpdate;
end;

procedure TParameterDetailsWindow.FormHide(Sender: TObject);
begin
 oeMain.actionParameterDetails.Checked := False;
end;

end.
