unit U_DimLineDialog;

interface

uses
  Windows, U_LNG, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxLookAndFeelPainters, StdCtrls, cxButtons, cxControls,
  cxContainer, cxEdit, cxTextEdit, cxMaskEdit, siComp, siLngLnk, cxGraphics,
  cxLookAndFeels, Menus;

type
  TF_DimLineDialog = class(TForm)
    edDimValue: TcxMaskEdit;
    bOK: TcxButton;
    bCancel: TcxButton;
    Label1: TLabel;
    lbMessage: TLabel;
    lng_Forms: TsiLangLinked;
    procedure bCancelClick(Sender: TObject);
    procedure edDimValueExit(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure edDimValueKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    ResValM: Double;
    function Execute(const aCaption, aPrompt: string; AValM: Double): Boolean;
  end;

var
  F_DimLineDialog: TF_DimLineDialog;

implementation
uses U_BaseCommon, U_Constants, U_Common;

{$R *.dfm}

procedure TF_DimLineDialog.bCancelClick(Sender: TObject);
begin
  try
    Close;
  except
    on E: Exception do AddExceptionToLogEx('TF_DimLineDialog.bCancelClick', E.Message);
  end;
end;

procedure TF_DimLineDialog.edDimValueExit(Sender: TObject);
begin
  try
    if edDimValue.Text = '' then
      edDimValue.Text := '0';
  except
    on E: Exception do AddExceptionToLogEx('TF_DimLineDialog.edDimValueExit', E.Message);
  end;
end;

procedure TF_DimLineDialog.FormShow(Sender: TObject);
begin
  try
    //Tolik 21/01/2022 -- тут вместо обозначения выведем наименование единицы измерения
    // (Рома сказал, а то обозначения фута, например каа апостроф - ни хрена не видно
    // и не информативно для пользователя)
    // система измерений
    {
    if GCurrProjUnitOfMeasure = umSM then
      Label1.Caption := cMetric_sm;
    if GCurrProjUnitOfMeasure = umM then
      Label1.Caption := cMetric_m;
    if GCurrProjUnitOfMeasure = umIn then
      Label1.Caption := cWhitworth_in;
    if GCurrProjUnitOfMeasure = umFt then
      Label1.Caption := cWhitworth_ft;
    }
    {
    if GCurrProjUnitOfMeasure = umSM then
      Label1.Caption := fMetric_sm;
    if GCurrProjUnitOfMeasure = umM then
      Label1.Caption := fMetric_m;
    if GCurrProjUnitOfMeasure = umIn then
      Label1.Caption := fWhitworth_in;
    if GCurrProjUnitOfMeasure = umFt then
      Label1.Caption := fWhitworth_ft;
    }
    Label1.Caption := GetNormalSTRUom;
    //
    // EditMask
    edDimValue.Properties.EditMask := '\d?\d?\d?\d?\d?' + DecimalSeparator + '\d?\d?\d?';
    edDimValue.SetFocus;
    edDimValue.SelStart := 0;
    edDimValue.SelLength := Length(edDimValue.Text) + 1;
  except
    on E: Exception do AddExceptionToLogEx('TF_DimLineDialog.FormShow', E.Message);
  end;
end;

procedure TF_DimLineDialog.edDimValueKeyPress(Sender: TObject; var Key: Char);
begin
  try
    if (Key = '.') or (Key = ',') then
      if Key <> DecimalSeparator then
        Key := #0;

    if Key = #13 then
    begin
      bOK.SetFocus;
      bOK.Click;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_DimLineDialog.edDimValueKeyPress', E.Message);
  end;
end;

function TF_DimLineDialog.Execute(const aCaption, aPrompt: string; AValM: Double): Boolean;
begin
  Result := false;
  ResValM := 0;
  Caption := aCaption;
  lbMessage.Caption := aPrompt;
  //Tolik 13/10/2020 --
  //edDimValue.Properties.EditMask := '\d?\d?\d?' + DecimalSeparator + '\d?\d?';
  edDimValue.Properties.EditMask := '\d?\d?\d?\d?\d?\d?' + DecimalSeparator + '\d?\d?\d?';
  //edDimValue.Text := FormatFloat(ffMask, MetreToUOM(AValM));
  edDimValue.Text := FormatFloat('0.000', MetreToUOM(AValM));
  //
  if ShowModal = mrOk then
  begin
    Result := true;
    ResValM := UOMToMetre(StrToFloat_My(edDimValue.Text));
  end;
end;

end.
