unit UFFT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls, Buttons, Registry, UGlobal;

type
  TFFTForm = class(TForm)
    XMLDocEchange: TXMLDocument;
    OkBitBtn: TBitBtn;
    Label1: TLabel;
    NbPtsEdit: TEdit;
    EntreeComboBox: TComboBox;
    Label4: TLabel;
    Label2: TLabel;
    SortieComboBox: TComboBox;
    Label3: TLabel;
    Memo1: TMemo;
    CoeffEdit: TEdit;

    procedure FormShow(Sender: TObject);
    procedure EntreeComboBoxChange(Sender: TObject);
    procedure SortieComboBoxChange(Sender: TObject);
    procedure NbPtsEditChange(Sender: TObject);
    procedure CoeffEditChange(Sender: TObject);
    procedure OkBitBtnClick(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques } 
    procedure MAJIHM;
  end;

var
  FFTForm: TFFTForm;

implementation

uses XMLClassesEchanges;

const Mess = 'Cette fonction n''est pas totalement configurée.'+
          #13'Quitter tout de même';

var DocEchange : IXMLEChangeROOTType;
    //Rep_Racine,Rep_Traitements,Rep_Actions,Rep_Fonctions : string;

{$R *.dfm}

procedure TFFTForm.MAJIHM;
begin
  EntreeComboBox.ItemIndex := EntreeComboBox.Items.IndexOf(DocEchange.FONCTION.ENTREE.Items[0].NOM);
  SortieComboBox.ItemIndex := SortieComboBox.Items.IndexOf(DocEchange.FONCTION.SORTIE.Items[0].NOM);

  NbPtsEdit.Text := DocEchange.FONCTION.PARAM[0].NOM;
  CoeffEdit.Text := DocEchange.FONCTION.PARAM[1].NOM;

end;

procedure TFFTForm.FormShow(Sender: TObject);
var i : integer;
begin
  Readconfig;

  XMLDocEchange.LoadFromFile(Rep_Fonctions+'Echange.xml');
  DocEchange := GetRootEchange(XMLDocEchange);

  EntreeComboBox.Clear;
  SortieComboBox.Clear;
  for i := 0 to DocEchange.CANAL.Count - 1 do
  begin
    EntreeComboBox.Items.Add(DocEchange.CANAL.Items[i].NOM);
    SortieComboBox.Items.Add(DocEchange.CANAL.Items[i].NOM);
  end;

  if DocEchange.FONCTION.ENTREE.Count = 0
  then DocEchange.FONCTION.ENTREE.Add;

  if DocEchange.FONCTION.SORTIE.Count = 0
  then DocEchange.FONCTION.SORTIE.Add;

  if DocEchange.FONCTION.PARAM.Count = 0 then
  begin
    DocEchange.FONCTION.PARAM.Add;
    DocEchange.FONCTION.PARAM.Add;
    DocEchange.FONCTION.PARAM.Add;
    DocEchange.FONCTION.PARAM[0].NOM := '100';
    DocEchange.FONCTION.PARAM[1].NOM := '0.9975';
    DocEchange.FONCTION.PARAM[2].NOM := '200';
  end;

  MAJIHM;
end;

procedure TFFTForm.EntreeComboBoxChange(Sender: TObject);
var Entree : IXMLEchangeEntreeType;
begin
  Entree := DocEchange.FONCTION.ENTREE.Items[0];
  Entree.NOM := EntreeCombobox.Text;
end;

procedure TFFTForm.SortieComboBoxChange(Sender: TObject);
var Sortie : IXMLEchangeSortieType;
begin
  Sortie := DocEchange.FONCTION.SORTIE.Items[0];
  Sortie.NOM := SortieCombobox.Text;
end;

procedure TFFTForm.NbPtsEditChange(Sender: TObject);
var NbPtsParam : IXMLEchangeParamType;
    temp : integer;
begin
  NbPtsParam := DocEchange.FONCTION.PARAM.Items[0];
  NbPtsParam.NOM := NbPtsEdit.Text;
  temp := strtoint(NbPtsParam.NOM);
  temp := 2*temp;
  DocEchange.FONCTION.PARAM[2].NOM := inttostr(temp);

end;

procedure TFFTForm.CoeffEditChange(Sender: TObject);
var CoeffParam : IXMLEchangeParamType;
begin
  CoeffParam := DocEchange.FONCTION.PARAM.Items[1];
  CoeffParam.NOM := CoeffEdit.Text;
end;

procedure TFFTForm.OkBitBtnClick(Sender: TObject);
var reponse : integer;
    InfoNotOK : boolean;
begin
  reponse := mrYes;
  InfoNotOK := (DocEchange.FONCTION.ENTREE.Items[0].NOM = '') or
               (DocEchange.FONCTION.SORTIE.Items[0].NOM = '') or
               (DocEchange.FONCTION.PARAM.Items[0].NOM = '') or
               (DocEchange.FONCTION.PARAM.Items[1].NOM = '') or
               (DocEchange.FONCTION.PARAM.Items[2].NOM = '');
  if InfoNotOk
  then reponse := messagedlg(Mess,mtInformation,[mbYes,mbNo],0);
  if reponse = mrYes then
  begin
    XMLDocEchange.SaveToFile(Rep_Fonctions+'Echange.xml');
    FFTForm.Close;
  end;
end;

end.
