unit uFileManagerTest;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, AbNumEdit, Vcl.ExtCtrls;

type
  TfrmFileManagerTest = class(TForm)
    Button1: TButton;
    Button2: TButton;
    RadioGroup: TRadioGroup;
    btnGetLastSML: TButton;
    Button3: TButton;
    btnTitleToSML: TButton;
    moSML: TMemo;
    btnShowSML: TButton;
    btnShowFileManager: TButton;
    btnSetFreq123456: TButton;
    btnsetWAVFileName: TButton;
    btnsetJPGFileName: TButton;
    btnAddSMLToStream: TButton;
    btnShowStream: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);
    procedure btnShowSMLClick(Sender: TObject);
    procedure btnShowFileManagerClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnSetFreq123456Click(Sender: TObject);
    procedure btnsetWAVFileNameClick(Sender: TObject);
    procedure btnsetJPGFileNameClick(Sender: TObject);
    procedure btnAddSMLToStreamClick(Sender: TObject);
    procedure btnShowStreamClick(Sender: TObject);
    procedure btnGetLastSMLClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmFileManagerTest: TfrmFileManagerTest;

implementation

{$R *.dfm}

uses
  uFileManager, uTime, uSETITypes, uJPGComments, uTestStreams;

procedure TfrmFileManagerTest.btnAddSMLToStreamClick(Sender: TObject);
var
  SML: string;
  msJPG: TmemoryStream;
  msXML:TmemoryStream;
begin
  // procedure AddCommentToStream(SML: String; msXML: TmemoryStream);
  SML := 'This is the SML';
  msJPG := TmemoryStream.Create;
  try
    msJPG.LoadFromFile('c:\test.jpg');
  except
    ShowMessage('Failure to load c:\test.jpg');
  end;

  msXML := Tmemorystream.Create;


// procedure AddCommentToStream(FileName: String; var msJPG: TmemoryStream; msXML: TmemoryStream);
  AddCommentToStream(SML, msJPG,msXML);

end;

procedure TfrmFileManagerTest.btnGetLastSMLClick(Sender: TObject);
var
ansiSML:AnsiString;
begin
   ansiSML := frmFileManager.GetSML;
end;

procedure TfrmFileManagerTest.btnSetFreq123456Click(Sender: TObject);
begin
  frmFileManager.Frequency := 1234567890;
end;

procedure TfrmFileManagerTest.btnsetJPGFileNameClick(Sender: TObject);
begin
  frmFileManager.edJPGFileName.text := 'c:\Jimmy.WAV'
end;

procedure TfrmFileManagerTest.btnsetWAVFileNameClick(Sender: TObject);
begin
  frmFileManager.edWAVFileName.text := 'c:\test.WAV'
end;

procedure TfrmFileManagerTest.btnShowFileManagerClick(Sender: TObject);
begin
  frmFileManager.Visible := true;
  frmFileManager.left := 2100;
end;

procedure TfrmFileManagerTest.btnShowSMLClick(Sender: TObject);
begin
  moSML.Lines.text := frmFileManager.GetSML;
end;

procedure TfrmFileManagerTest.btnShowStreamClick(Sender: TObject);
var
   ABuffer: TStrings;
  ID: String;
 AStream: TmemoryStream;
begin
  AStream :=TmemoryStream.Create;
  AStream.LoadFromFile('c:\test.jpg');
  frmStreamDemo.ShowStreamData(AStream, moSML.Lines, 'Jim Jim Jim');

end;

procedure TfrmFileManagerTest.Button1Click(Sender: TObject);
begin
  with frmFileManager do
  begin
    Visible := true;
    Constellation := 'Test conn';
    Target := 'TestTarget';
    ConstellationID := 123;
    TargetID := 456;
    ScanID := 999;
    HitID := 666;
    //
    // function getCurrentUTCDateTime: string;
    // SMLCreateDateTime := Now;
    OperatingMode := 'Fuck All';
    Latitude := 12.34;
    Longitude := 56.7;
    StationGridSquare := 'JimJimJim';

  end;

end;

procedure TfrmFileManagerTest.Button2Click(Sender: TObject);
// TMountType = (mtDrift, mtAllSky,mtBirdBath);
begin
  with frmFileManager do
  begin
    Visible := true;
    MountType := TMount(RadioGroup.ItemIndex);

    AzimuthMinimum := 300.12;
    AzimuthMaximum := 66.12;
    ElevationMinimum := 89.12;
    ElevationMaximum := 6.12;
    Azimuth := 11.11;
    Elevation := 22.22;
    Declination := 33.33;
    RightAscension := 44.44;
    SkyMapLocked := true;

    VerticalRange := 55.55;
    FFTSize := 6666;
    Integration := 7777;
    Threshold := 888;
    SegmentSize := 999;

    Frequency := 123456;
    CenterFrequency := 987654321;
    ETBin := 12345;
    Amplitude := 121.343;
    Ambiant := 5454.54;
    BandWidth := 13000;
    Chirp := 13.45;

  end;

end;

procedure TfrmFileManagerTest.Button3Click(Sender: TObject);
begin
  with frmFileManager do
  begin

  end;
end;

procedure TfrmFileManagerTest.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  frmFileManager.docSML.Active := false; // Without this an exception is generated
end;

end.
