unit U_ArchNicheParams;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
  U_BaseCommon, U_BaseConstants, U_ArchCommon, RzButton, ExtCtrls, RzPanel,
  siComp, siLngLnk, Mask, RzEdit;

type
  TF_ArchNicheParams = class(TForm)
    pnOkCancel: TRzPanel;
    btOk: TRzBitBtn;
    btCancel: TRzBitBtn;
    lng_Forms: TsiLangLinked;
    RzPanel1: TRzPanel;
    lbCoordz: TLabel;
    lbWidth: TLabel;
    lbHeight: TLabel;
    fCoordz: TRzNumericEdit;
    fWidth: TRzNumericEdit;
    fHeight: TRzNumericEdit;
    lbDepth: TLabel;
    fDepth: TRzNumericEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure pnOkCancelResize(Sender: TObject);

  private
    GForm: TForm;
    FPropsUOM: TStringList;
    FType: Integer;

    procedure SetCaptions;
    procedure SetControls;
  public
    Constructor Create(AOwner: TComponent; AForm: TForm);
    Destructor Destroy; override;

    function Execute(AType: Integer; AArchWndInfo: TComponent): TArchNicheInfo;
  published
    property PropMainForm: TForm read GForm;
    property PropsUOM: TStringList read FPropsUOM;
  end;

  function ShowArchNicheParams(AType: Integer; AArchWndInfo: TComponent): TArchNicheInfo;

var
  F_ArchNicheParams: TF_ArchNicheParams;

implementation
Uses U_Main;

{$R *.dfm}

constructor TF_ArchNicheParams.Create(AOwner: TComponent; AForm: TForm);
begin
  GForm := AForm;
  inherited Create(AOwner);
end;

destructor TF_ArchNicheParams.Destroy;
begin
  inherited;
end;

function TF_ArchNicheParams.Execute(AType: Integer; AArchWndInfo: TComponent): TArchNicheInfo;
var
  NicheInfo: TArchNicheInfo;
begin
  Result := nil;
  FType := AType;

  SetCaptions;
  SetControls;

  NicheInfo := TArchNicheInfo.Create(nil);
  if AArchWndInfo <> nil then
    NicheInfo.Assign(AArchWndInfo)
  else
  begin
    if LoadArchObjDefaultParams(NicheInfo, AType) = nil then
    begin
      NicheInfo.Height := 2.0;
      NicheInfo.Width := 1;
      NicheInfo.Depth := 0.1;
    end;
  end;

  ObjectPropsToForm(NicheInfo, Self);
  NicheInfo.Free;

  if ShowModal = mrOk then
  begin
    Result := TArchNicheInfo.Create(nil);
    ObjectPropsFromForm(Result, Self);

    // Сохраняем параметры как по-умолчанию
    SetArchObjToDefaultParams(Result, AType);
  end;
end;

procedure TF_ArchNicheParams.SetCaptions;
begin
  if FType = ctArhNiche then
    Caption := cArchNicheParams_Msg01
  else if FType = ctArhArc then
    Caption := cArchNicheParams_Msg02;

  //lbWidth.Caption := cArchParams_Msg02 +', '+ GetNameUOM(TF_Main(GForm).FUOM, true);
  //lbHeight.Caption := cArchParams_Msg06 +', '+ GetNameUOM(TF_Main(GForm).FUOM, true);
  //lbCoordz.Caption := cArchParams_Msg05 +', '+ GetNameUOM(TF_Main(GForm).FUOM, true);
  //lbDepth.Caption := cArchParams_Msg07 +', '+ GetNameUOM(TF_Main(GForm).FUOM, true);
  //lbLength.Caption := cArchParams_Msg10 +', '+ GetNameUOM(TF_Main(GForm).FUOM, true);
  SetLableCaptions(Self, TF_Main(GForm).FUOM);
end;

procedure TF_ArchNicheParams.SetControls;
begin
  lbCoordz.Visible := FType = ctArhNiche;
  fCoordz.Visible := lbCoordz.Visible;
end;

procedure TF_ArchNicheParams.FormCreate(Sender: TObject);
begin
  pnOkCancelResize(pnOkCancel);

  FPropsUOM := TStringList.Create;
  SetFormControlDisplayFormat(Self);
end;

procedure TF_ArchNicheParams.FormDestroy(Sender: TObject);
begin
  FPropsUOM.Free;
end;


function ShowArchNicheParams(AType: Integer; AArchWndInfo: TComponent): TArchNicheInfo;
begin
  Result := nil;
  try
    if F_ArchNicheParams = nil then
      F_ArchNicheParams := TF_ArchNicheParams.Create(F_ProjMan, F_ProjMan);

    Result := F_ArchNicheParams.Execute(AType, AArchWndInfo);
  except
    on E: Exception do AddExceptionToLogEx('ShowArchNicheParams', E.Message);
  end;
end;

procedure TF_ArchNicheParams.pnOkCancelResize(Sender: TObject);
begin
  SetMiddleControlChilds(TControl(Sender), TControl(Self));
end;

end.