unit Unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls, ComCtrls,AccPampa, Unit6;

type

  { Form2 }   {BLANCO}

  { TForm2 }

  TForm2 = class(TForm)
    Button1: TButton;
    Button4: TButton;
    Button5: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    GroupBox4: TGroupBox;
    Label1: TLabel;
    Label10: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure Edit4Change(Sender: TObject);
    procedure Edit5Change(Sender: TObject);
    procedure Edit6Change(Sender: TObject);
    procedure Form2Activate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Form2new();
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form2    :TForm2;

implementation

{$R *.lfm}

{ Form2 }

{ TForm2 }

procedure TForm2.FormCreate(Sender: TObject);
   Var i:Integer;
begin
   Espesor:=0;
   EspesorFilm:=0;
   Ndet:=0;
   Nnodet:=0;
   Nfdet:=0;
   Nfnodet:=0;
   For i:=0 To 30 Do Begin
     Zd1[i]:=TEdit.Create(Self);
     Zd1[i].parent:=Groupbox3;
     Zd1[i].Visible:=False;
     Zd1[i].Caption:='0';
     Znd1[i]:=TEdit.Create(Self);
     Znd1[i].parent:=Groupbox3;
     Znd1[i].Visible:=False;
     Znd1[i].Caption:='0';
     Zd2[i]:=TEdit.Create(Self);
     Zd2[i].parent:=Groupbox4;
     Zd2[i].Visible:=False;
     Zd2[i].Caption:='0';
     Znd2[i]:=TEdit.Create(Self);
     Znd2[i].parent:=Groupbox4;
     Znd2[i].Visible:=False;
     Znd2[i].Caption:='0';
   end;
end;

procedure TForm2.Form2Activate(Sender: TObject);
   Var i:Integer;
begin
   Edit1.Text := FloatToStr(Espesor);
   Edit2.Text := FloatToStr(EspesorFilm);
   Edit3.Text := FloatToStr(Ndet);
   Edit4.Text := FloatToStr(Nnodet);
   Edit5.Text := FloatToStr(Nfdet);
   Edit6.Text := FloatToStr(Nfnodet);
   {Para que se muestren los cuadros para llenar con los numeros atomicos}
   For i:=0 To 30 Do Zd1[i].Text:='0';
   For i:=0 To Ndet-1 Do Begin
       Zd1[i].Text:=FloatToStr(Zdet[i+1]);
       Zd1[i].Visible:=True;
       Zd1[i].Left:=22;
       Zd1[i].Top:=30+28*i;
       Zd1[i].height:=27;
       Zd1[i].width:=48;
   end;
   For i:=0 To 30 Do Znd1[i].Text:='0';
   For i:=0 To Nnodet-1 Do Begin
       Znd1[i].Text:=FloatToStr(Znodet[i+1]);
       Znd1[i].Visible:=True;
       Znd1[i].Left:=150;
       Znd1[i].Top:=30+28*i;
       Znd1[i].height:=27;
       Znd1[i].width:=48;
   end;
   For i:=0 To 30 Do Zd2[i].Text:='0';
   For i:=Ndet To Ndet+Nfdet-1 Do Begin
       Zd2[i-Ndet].Text:=FloatToStr(Zdet[i+1]);
       Zd2[i-Ndet].Visible:=True;
       Zd2[i-Ndet].Left:=22;
       Zd2[i-Ndet].Top:=30+28*(i-Ndet);
       Zd2[i-Ndet].height:=27;
       Zd2[i-Ndet].width:=48;
   end;
   For i:=0 To 30 Do Znd2[i].Text:='0';
   For i:=Nnodet To Nnodet+Nfnodet-1 Do Begin
       Znd2[i-Nnodet].Text:=FloatToStr(Znodet[i+1]);
       Znd2[i-Nnodet].Visible:=True;
       Znd2[i-Nnodet].Left:=150;
       Znd2[i-Nnodet].Top:=30+28*(i-Nnodet);
       Znd2[i-Nnodet].height:=27;
       Znd2[i-Nnodet].width:=48;
   end;
   if(GroupBox3.Height>GroupBox4.Height) Then PageControl1.Height:=GroupBox3.Height+200
   else PageControl1.Height:=GroupBox4.Height+200;
   Button1.Top:=PageControl1.Height+10;
end;

procedure TForm2.Form2new();      {Para volver todo a cero en la ventana}
   Var i:Integer;
begin
   Espesor:=0;
   EspesorFilm:=0;
   Ndet:=0;
   Nnodet:=0;
   Nfdet:=0;
   Nfnodet:=0;
   For i:=1 To 100 Do Zdet[i]:=0;
   For i:=1 To 100 Do Znodet[i]:=0;
   For i:=1 To 100 Do Z[i]:=0;
   For i:=0 To 30 Do Begin
       Zd1[i].Visible:=False;
       {Zd1[i].Caption:='0';}
       Znd1[i].Visible:=False;
       {ZNd1[i].Caption:='0';}
       Zd2[i].Visible:=False;
       {Zd2[i].Caption:='0';}
       Znd2[i].Visible:=False;
       {Znd2[i].Caption:='0';}
   end;
   if(GroupBox3.Height>GroupBox4.Height) Then PageControl1.Height:=GroupBox3.Height+200
   else PageControl1.Height:=GroupBox4.Height+200;
   Button1.Top:=PageControl1.Height+10;
end;

procedure TForm2.Button5Click(Sender: TObject);  {Aplicar en la capa 1}
   Var
       i:Integer;
begin
   {Ndet:=StrToInt(Edit3.Text);
   Nnodet:=StrToInt(Edit4.Text);    }
   {Para que se muestren los cuadros para llenar con los numeros atomicos}
   For i:=0 To 30 Do Zd1[i].Visible:=False;
   For i:=0 To Ndet-1 Do Begin
     Zd1[i].Visible:=True;
     Zd1[i].Left:=22;
     Zd1[i].Top:=30+28*i;
     Zd1[i].height:=27;
     Zd1[i].width:=48;
   end;
   For i:=0 To 30 Do Znd1[i].Visible:=False;
   For i:=0 To Nnodet-1 Do Begin
     Znd1[i].Visible:=True;
     Znd1[i].Left:=150;
     Znd1[i].Top:=30+28*i;
     Znd1[i].height:=27;
     Znd1[i].width:=48;
   end;
   if(GroupBox3.Height>GroupBox4.Height) Then PageControl1.Height:=GroupBox3.Height+200
   else PageControl1.Height:=GroupBox4.Height+200;
   Button1.Top:=PageControl1.Height+10;

end;

procedure TForm2.Button4Click(Sender: TObject);     {Aplicar en la capa 2}
   Var
       i:Integer;
begin
   {Nfdet:=StrToInt(Edit5.Text);
   Nfnodet:=StrToInt(Edit6.Text);  }
   {Para que se muestren los cuadros para llenar con los numeros atomicos}
   For i:=0 To 30 Do Zd2[i].Visible:=False;
   For i:=0 To Nfdet-1 Do Begin
     Zd2[i].Visible:=True;
     Zd2[i].Left:=22;
     Zd2[i].Top:=30+28*i;
     Zd2[i].height:=27;
     Zd2[i].width:=48;
   end;
   For i:=0 To 30 Do Znd2[i].Visible:=False;
   For i:=0 To Nfnodet-1 Do Begin
     Znd2[i].Visible:=True;
     Znd2[i].Left:=150;
     Znd2[i].Top:=30+28*i;
     Znd2[i].height:=27;
     Znd2[i].width:=48;
   end;
   if(GroupBox3.Height>GroupBox4.Height) Then PageControl1.Height:=GroupBox3.Height+200
   else PageControl1.Height:=GroupBox4.Height+200;
   Button1.Top:=PageControl1.Height+10;
end;

procedure TForm2.Edit1Change(Sender: TObject);     {Espesor capa 1}
begin
   If(Edit1.Caption<>'') Then Begin
     if(StrToFloat(Edit1.Caption)<>0) Then C1:=True
     else C1:=False;
   end;
end;

procedure TForm2.Edit2Change(Sender: TObject);     {Espesor capa 2}
begin
   If(Edit2.Caption<>'') Then Begin
     if(StrToFloat(Edit2.Caption)<>0) Then C2:=True
     else C2:=False;
   end;
end;

procedure TForm2.Edit3Change(Sender: TObject);     {Nro de detectables capa 1}
begin
   if(Edit3.Caption<>'') Then Ndet:=StrToInt(Edit3.Caption);
end;

procedure TForm2.Edit4Change(Sender: TObject);     {Nro de no detectables capa 1}
begin
   if(Edit4.Caption<>'') Then Nnodet:=StrToInt(Edit4.Caption);
end;


procedure TForm2.Edit5Change(Sender: TObject);     {Nro de detectables capa 2}
begin
   if(Edit5.Caption<>'') Then Nfdet:=StrToInt(Edit5.Caption);
end;

procedure TForm2.Edit6Change(Sender: TObject);     {Nro de no detectables capa 2}
begin
   if(Edit6.Caption<>'') Then Nfnodet:=StrToInt(Edit6.Caption);
end;


procedure TForm2.Button1Click(Sender: TObject);{Boton de Aceptar}
  Var i:Integer;
begin
   Ndet:=StrToInt(Edit3.Caption);
   Nnodet:=StrToInt(Edit4.Caption);
   Nel:=Ndet+Nnodet;
   Nfdet:=StrToInt(Edit5.Caption);
   Nfnodet:=StrToInt(Edit6.Caption);
   Nfilm:=Nfdet+Nfnodet;
   {Se ocultan los cuadros con las concentraciones en las ventanas Form5 y Form7}
   For i:=0 To 30 Do Begin
     Cd1[i].Visible:=False;
     Eld1[i].Visible:=False;
     Cnd1[i].Visible:=False;
     Elnd1[i].Visible:=False;
     NL1[i].Visible:=False;
     Elem1[i].Visible:=False;
     PEl1[i].Visible:=False;
     PEl1[i].Caption:='';
     CLineas1[i].Visible:=False;
     CBordes1[i].Visible:=False;
     CEnergy1[i].Visible:=False;
     Crtps1[i].Visible:=False;
     CPerfil1[i].Visible:=False;
     Cd2[i].Visible:=False;
     Eld2[i].Visible:=False;
     Cnd2[i].Visible:=False;
     Elnd2[i].Visible:=False;
     NL2[i].Visible:=False;
     Elem2[i].Visible:=False;
     PEl2[i].Visible:=False;
     PEl2[i].Caption:='';
     CLineas2[i].Visible:=False;
     CBordes2[i].Visible:=False;
     CEnergy2[i].Visible:=False;
     Crtps2[i].Visible:=False;
     CPerfil2[i].Visible:=False;
   end;
   {Para que se muestren los cuadros con las concentraciones, el numero de lineas, etc, de Form5 y Form7  }
   For i:=0 To Ndet-1 Do Begin
     Cd1[i].Visible:=True;
     Cd1[i].Left:=70;
     Cd1[i].Top:=30+28*i;
     Cd1[i].height:=27;
     Cd1[i].width:=100;

     Eld1[i].Visible:=True;
     Eld1[i].Caption:=Zd1[i].Text+':';
     Eld1[i].Left:=6;
     Eld1[i].Top:=35+28*i;
     Eld1[i].height:=18;
     Eld1[i].width:=46;
   {Numero de lineas y simbolo para cada elemento de la capa 1}
     NL1[i].Visible:=True;
     NL1[i].Left:=50;
     NL1[i].Top:=40+30*i;
     NL1[i].height:=27;
     NL1[i].width:=80;

     Elem1[i].Visible:=True;
     Elem1[i].Caption:=Zd1[i].Text+':';
     Elem1[i].Left:=6;
     Elem1[i].Top:=45+30*i;
     Elem1[i].height:=18;
     Elem1[i].width:=46;
    {Pestaña con la informacion de cada elemento para la capa 1}
     PEl1[i].Visible:=True;
     PEl1[i].Caption:=Zd1[i].Text;
    {cuadros con informacion de los elementos (nombre de la linea, borde, energia,
    RTP, ancho) para la capa 1}
     CLineas1[i].Visible:=True;
     CLineas1[i].Caption:='Lineas';
     CLineas1[i].Height:=268;
     CLineas1[i].Width:=90;
     CLineas1[i].Top:=2;
     CLineas1[i].Left:=2;

     CBordes1[i].Visible:=True;
     CBordes1[i].Caption:='Bordes';
     CBordes1[i].Height:=268;
     CBordes1[i].Width:=90;
     CBordes1[i].Top:=2;
     CBordes1[i].Left:=94;

     CEnergy1[i].Visible:=True;
     CEnergy1[i].Caption:='Energia';
     CEnergy1[i].Height:=268;
     CEnergy1[i].Width:=90;
     CEnergy1[i].Top:=2;
     CEnergy1[i].Left:=186;

     Crtps1[i].Visible:=True;
     Crtps1[i].Caption:='RTP';
     Crtps1[i].Height:=268;
     Crtps1[i].Width:=90;
     Crtps1[i].Top:=2;
     Crtps1[i].Left:=308;

     CPerfil1[i].Visible:=True;
     CPerfil1[i].Caption:='Perfil';
     CPerfil1[i].Height:=20;
     CPerfil1[i].Width:=90;
     CPerfil1[i].Top:=2;
     CPerfil1[i].Left:=430;
   end;
   For i:=0 To Nnodet-1 Do Begin
     Cnd1[i].Visible:=True;
     Cnd1[i].Left:=70;
     Cnd1[i].Top:=30+30*i;
     Cnd1[i].height:=27;
     Cnd1[i].width:=100;

     Elnd1[i].Visible:=True;
     Elnd1[i].Caption:=Znd1[i].Text+':';
     Elnd1[i].Left:=6;
     Elnd1[i].Top:=35+30*i;
     Elnd1[i].height:=18;
     Elnd1[i].width:=46;
   end;
   For i:=0 To Nfdet-1 Do Begin
     Cd2[i].Visible:=True;
     Cd2[i].Left:=70;
     Cd2[i].Top:=30+28*i;
     Cd2[i].height:=27;
     Cd2[i].width:=100;

     Eld2[i].Visible:=True;
     Eld2[i].Caption:=Zd2[i].Text+':';
     Eld2[i].Left:=6;
     Eld2[i].Top:=35+28*i;
     Eld2[i].height:=18;
     Eld2[i].width:=46;
   {Numero de lineas y simbolo para cada elemento de la capa 1 (detectables y
   no detectables)}
     NL2[i].Visible:=True;
     NL2[i].Left:=50;
     NL2[i].Top:=40+30*i;
     NL2[i].height:=27;
     NL2[i].width:=80;

     Elem2[i].Visible:=True;
     Elem2[i].Caption:=Zd2[i].Text+':';
     Elem2[i].Left:=6;
     Elem2[i].Top:=45+30*i;
     Elem2[i].height:=18;
     Elem2[i].width:=46;
    {Pestaña con la informacion de cada elemento para la capa 1}
     PEl2[i].Visible:=True;
     PEl2[i].Caption:=Zd2[i].Text;
    {cuadros con informacion de los elementos (nombre de la linea, borde, energia,
    RTP, ancho) para la capa 1}
     CLineas2[i].Visible:=True;
     CLineas2[i].Caption:='Lineas';
     CLineas2[i].Height:=268;
     CLineas2[i].Width:=90;
     CLineas2[i].Top:=2;
     CLineas2[i].Left:=2;

     CBordes2[i].Visible:=True;
     CBordes2[i].Caption:='Bordes';
     CBordes2[i].Height:=268;
     CBordes2[i].Width:=90;
     CBordes2[i].Top:=2;
     CBordes2[i].Left:=94;

     CEnergy2[i].Visible:=True;
     CEnergy2[i].Caption:='Energia';
     CEnergy2[i].Height:=268;
     CEnergy2[i].Width:=90;
     CEnergy2[i].Top:=2;
     CEnergy2[i].Left:=186;

     Crtps2[i].Visible:=True;
     Crtps2[i].Caption:='RTP';
     Crtps2[i].Height:=268;
     Crtps2[i].Width:=90;
     Crtps2[i].Top:=2;
     Crtps2[i].Left:=308;

     CPerfil2[i].Visible:=True;
     CPerfil2[i].Caption:='Perfil';
     CPerfil2[i].Height:=20;
     CPerfil2[i].Width:=90;
     CPerfil2[i].Top:=2;
     CPerfil2[i].Left:=430;
   end;
   For i:=0 To Nfnodet-1 Do Begin
     Cnd2[i].Visible:=True;
     Cnd2[i].Left:=70;
     Cnd2[i].Top:=30+30*i;
     Cnd2[i].height:=27;
     Cnd2[i].width:=100;

     Elnd2[i].Visible:=True;
     Elnd2[i].Caption:=Znd2[i].Text+':';
     Elnd2[i].Left:=6;
     Elnd2[i].Top:=35+30*i;
     Elnd2[i].height:=18;
     Elnd2[i].width:=46;
   end;
   {Se iguala la informacion de la ventana con los parametros de PAMPA}
   Espesor:=StrToFloat(Edit1.Text);
   EspesorFilm:=StrToFloat(Edit2.Text);
   For i:=0 To Ndet-1 Do  Zdet[i+1]:=StrToInt(Zd1[i].Text);
   For i:=0 To Nnodet-1 Do  Znodet[i+1]:=StrToInt(Znd1[i].Text);
   For i:=Ndet To Ndet+Nfdet-1 Do  Zdet[i+1]:=StrToInt(Zd2[i-Ndet].Text);
   For i:=Nnodet To Nnodet+Nfnodet-1 Do  Znodet[i+1]:=StrToInt(Znd2[i-Nnodet].Text);
   {Se da valores al Z}
   For i:=1 To Ndet Do Z[i]:=Zdet[i];
   For i:=Ndet+1 To Nel Do Z[i]:=Znodet[i-Ndet];
   For i:=Nel+1 To Nel+Nfdet Do Z[i]:=Zdet[i-Nnodet];
   For i:=Nel+Nfdet+1 To Nel+Nfilm Do Z[i]:=Znodet[i-Ndet-Nfdet];
   Form2.close;
end;



end.

