unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, ComCtrls, OleCtrls, SPIRITLib_TLB, StdCtrls, Spin, ExtCtrls,
  Buttons, Gauges, ExtDlgs;

type
  TMainForm = class(TForm)
    MainMenu: TMainMenu;
    MenuFoMenu: TMenuItem;
    MenuBeallitasok: TMenuItem;
    MenuProgramInfo: TMenuItem;
    MenuLogoInfo: TMenuItem;
    N1: TMenuItem;
    MenuKilepes: TMenuItem;
    SP: TSpirit;
    MenuRendszerEll: TMenuItem;
    MenuKalibralas: TMenuItem;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    SP1: TSpinEdit;
    SP2: TSpinEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    TSScan: TTabSheet;
    BBSCStart: TButton;
    BBSCStop: TButton;
    GBSC: TGroupBox;
    SHSC: TShape;
    Image: TImage;
    BBRendszer: TButton;
    BBKalibralStart: TButton;
    BBKalibralStop: TButton;
    Gauge: TGauge;
    RE: TRichEdit;
    Label5: TLabel;
    SPScanSeb: TSpinEdit;
    SPForgatIdo: TSpinEdit;
    BBKepJavitas: TButton;
    BBKepBetoltes: TBitBtn;
    BBKepMentes: TBitBtn;
    OPD: TOpenPictureDialog;
    SPD: TSavePictureDialog;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    BitBtn2: TBitBtn;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    LIdoEltelt: TLabel;
    LIdoHatra: TLabel;
    LIdoOssz: TLabel;
    procedure MenuKilepesClick(Sender: TObject);
    procedure MenuLogoInfoClick(Sender: TObject);
    procedure MenuRendszerEllClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure MenuKalibralasClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BBSCStartClick(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BBSCStopClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure BBKalibralStopClick(Sender: TObject);
    procedure BBKepBetoltesClick(Sender: TObject);
    procedure BBKepMentesClick(Sender: TObject);
    procedure BBKepJavitasClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var MainForm          :TMainForm;

implementation

{$R *.DFM}

uses Esemeny, Vezerles;

const KeretTavolsag = 2;

var IsFirstActivate   :boolean = true;

procedure TMainForm.FormActivate(Sender: TObject);
begin
   if IsFirstActivate then begin
      IsFirstActivate    := false;
      SHSC.Left          := 4;
      SHSC.Top           := 24;
      SHSC.Width         := MaxX*NagyitX+KeretTavolsag*2;
      SHSC.Height        := MaxY*NagyitY+KeretTavolsag*2;
      Image.Left         := SHSC.Left+KeretTavolsag;
      Image.Top          := SHSC.Top+KeretTavolsag;
      Image.Width        := MaxX*NagyitX;
      Image.Height       := MaxY*NagyitY;
      LIdoEltelt.Caption := '';
      LIdoHatra.Caption  := '';
      LIdoOssz.Caption   := '';
   end;
end;

procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
   if IsInitComm then SP.CloseComm;
end;

procedure TMainForm.MenuKilepesClick(Sender: TObject);
begin
   Close;
end;

procedure TMainForm.MenuLogoInfoClick(Sender: TObject);
begin
   SP.AboutBox;
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}

procedure TMainForm.MenuRendszerEllClick(Sender: TObject);
begin
   IsOKTesztInit := RendszerTeszt;
end;

procedure TMainForm.MenuKalibralasClick(Sender: TObject);
begin
   IsOKTesztKalib := KalibralasTeszt;
end;

procedure TMainForm.BBKalibralStopClick(Sender: TObject);
begin
   IsKalibralas := false;
   BBKalibralStart.Enabled := true;
   BBKalibralStop.Enabled  := false;
end;

procedure TMainForm.BBSCStartClick(Sender: TObject);
begin
   Esemeny.Scanneles;
end;

procedure TMainForm.BBSCStopClick(Sender: TObject);
begin
   IsScanneles := false;
   BBSCStart.Enabled := true;
   BBSCStop.Enabled  := false;
end;

procedure TMainForm.BBKepJavitasClick(Sender: TObject);
begin
   Esemeny.KepJavitasa;
end;

procedure TMainForm.BBKepBetoltesClick(Sender: TObject);
begin
   if OPD.Execute then Image.Picture.LoadFromFile(OPD.FileName);
end;

procedure TMainForm.BBKepMentesClick(Sender: TObject);
begin
   if SPD.Execute then Image.Picture.SaveToFile(SPD.FileName);
end;

{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------}

procedure TMainForm.Button1Click(Sender: TObject);
begin
   MoveTheHead(SP1.Value,SP2.Value);
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
   MoveTheHead2(SP1.Value,SP2.Value);
end;

procedure TMainForm.BitBtn2Click(Sender: TObject);
var s    :string;
begin
   str(dtxp:0:20,s);
   MainForm.Label1.Caption := s;
   str(dtyp:0:20,s);
   MainForm.Label2.Caption := s;
   str(dtxn:0:20,s);
   MainForm.Label3.Caption := s;
   str(dtyn:0:20,s);
   MainForm.Label4.Caption := s;
end;

procedure TMainForm.Button3Click(Sender: TObject);
begin
   fejbeallit(fejScanner,SPForgatIdo.Value*EgySec);
end;

procedure TMainForm.Button4Click(Sender: TObject);
begin
   fejbeallit(fejIras,SPForgatIdo.Value*EgySec);
end;

end.
