unit Vis3D_ModelSettings;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, TextEditor, Vcl.StdCtrls, rgl,
  UxPanel, Vcl.ExtCtrls, ColorContainer, ScrollBoxEx;

type
  TVis3D_ModelSettingsFrm = class(TDrawableOptionsFrm3D)
    pnGeneral: TPanel;
    pnToolbar: TUxClient;
    btnModel: TUxButton;
    btnGeneral: TUxButton;
    pnModel: TPanel;
    teModel: TTextEditor;
    btnApply: TUxButton;
    procedure btnApplyClick(Sender: TObject);
    procedure SetPage(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  strict private
    FPageButtons: TArray<TUxButton>;
    FGeneral: TDrawableOptionsFrm3D;
  public
    procedure Initialize; override;
    procedure UpdateDrawable; override;
  end;

implementation

{$R *.dfm}

uses
  Vis3D_AxisSettings, Vis3D_GeoObjSettings;

procedure TVis3D_ModelSettingsFrm.btnApplyClick(Sender: TObject);
begin
  UpdateDrawable;
end;

procedure TVis3D_ModelSettingsFrm.FormCreate(Sender: TObject);
begin

  var Model := FDrawable as TObjModel;

  btnGeneral.Tag := NativeInt(pnGeneral);
  btnModel.Tag := NativeInt(pnModel);
  FPageButtons := [btnGeneral, btnModel];

  SetPage(btnGeneral);

  FGeneral := TVis3D_GeoObjSettingsFrm.Create(Self, Model);
  (FGeneral as TVis3D_GeoObjSettingsFrm).Customize(True, True, True);
  FGeneral.Parent := pnGeneral;
  FGeneral.BorderStyle := bsNone;
  FGeneral.Align := alClient;
  FGeneral.Show;

end;

procedure TVis3D_ModelSettingsFrm.Initialize;
begin
  inherited;
  var Model := FDrawable as TObjModel;
  teModel.PlainText := Model.Source;
  teModel.ClearUndoHistory;
  teModel.MakeUndoRoot;
  teModel.TextFile.GotoSOF;
end;

procedure TVis3D_ModelSettingsFrm.SetPage(Sender: TObject);
begin
  for var B in FPageButtons do
  begin
    if B.Tag = 0 then
      Continue;
    var P := TObject(B.Tag) as TWinControl;
    P.Align := alClient;
    P.Visible := B = Sender;
    B.Down := B = Sender;
    if (B = Sender) and Visible and P.Visible and P.CanFocus then
      P.SetFocus;
  end;
  btnApply.Visible := pnModel.Visible;
end;

procedure TVis3D_ModelSettingsFrm.UpdateDrawable;
begin
  if not FInitialized then
    Exit;
  var Model := FDrawable as TObjModel;
  Model.Source := teModel.PlainText;
  inherited;
end;

end.
