unit Unit7;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, RTTICtrls, RTTIGrids, Forms, Controls, Graphics,
  Dialogs, Grids, CheckLst, ValEdit, ComCtrls, StdCtrls, ExtCtrls, types,AccPampa, Unit6, Refinar;

type

  { TForm6 }      {PARAMETROS CAPA 2}

  TForm6 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    PageControl1: TPageControl;
    PageControl2: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Form6new();
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form6: TForm6;

implementation

{ TForm6 }

{$R *.lfm}

procedure TForm6.FormCreate(Sender: TObject);
   Var i,j:Integer;
begin

     For i:=0 To 30 Do Begin
     Cd2[i]:=TEdit.Create(Self);
     Cd2[i].parent:=Groupbox1;
     Cd2[i].Visible:=False;
     ChCd2[i]:=TCheckbox.Create(Self);
     ChCd2[i].Parent:=Groupbox1;
     ChCd2[i].Visible:=False;
     ChCd2[i].Autosize:=True;
     Cnd2[i]:=TEdit.Create(Self);
     Cnd2[i].parent:=Groupbox2;
     Cnd2[i].Visible:=False;
     ChCnd2[i]:=TCheckBox.Create(Self);
     ChCnd2[i].parent:=Groupbox2;
     ChCnd2[i].Visible:=False;

     Eld2[i]:=TLabel.Create(Self);
     Eld2[i].parent:=Groupbox1;
     Eld2[i].Visible:=False;
     Elnd2[i]:=TLabel.Create(Self);
     Elnd2[i].parent:=Groupbox2;
     Elnd2[i].Visible:=False;

     NL2[i]:=TEdit.Create(Self);
     NL2[i].parent:=Groupbox3;
     NL2[i].Visible:=False;

     Elem2[i]:=TLabel.Create(Self);
     Elem2[i].parent:=Groupbox3;
     Elem2[i].Visible:=False;

     PEl2[i]:=TTabsheet.Create(Self);
     PEl2[i].Parent:=PageControl2;
     PEl2[i].Visible:=False;

     CLineas2[i]:=TGroupbox.Create(Self);
     CLineas2[i].Parent:=PEl2[i];
     CLineas2[i].Visible:=False;
     CLineas2[i].Autosize:=True;

     CBordes2[i]:=TGroupbox.Create(Self);
     CBordes2[i].Parent:=PEl2[i];
     CBordes2[i].Visible:=False;
     CBordes2[i].Autosize:=True;

     CEnergy2[i]:=TGroupBox.Create(Self);
     CEnergy2[i].Parent:=PEl2[i];
     CEnergy2[i].Visible:=False;
     CEnergy2[i].Autosize:=True;

     Crtps2[i]:=TGroupBox.Create(Self);
     Crtps2[i].Parent:=PEl2[i];
     Crtps2[i].Visible:=False;
     Crtps2[i].Autosize:=True;

     CTail2[i]:=TGroupBox.Create(Self);
     CTail2[i].Parent:=PEl2[i];
     CTail2[i].Visible:=False;
     CTail2[i].Autosize:=True;

     CBeta2[i]:=TGroupBox.Create(Self);
     CBeta2[i].Parent:=PEl2[i];
     CBeta2[i].Visible:=False;
     CBeta2[i].Autosize:=True;

     CPerfil2[i]:=TGroupBox.Create(Self);
     CPerfil2[i].Parent:=PEl2[i];
     CPerfil2[i].Visible:=False;
     CPerfil2[i].Autosize:=True;
   end;

   For i:=0 To 30 Do Begin
     For j:=0 To 20 Do Begin
       Lineas2[i,j]:=TEdit.Create(Self);
       Lineas2[i,j].Parent:=CLineas2[i];
       Lineas2[i,j].Visible:=False;

       Bordes2[i,j]:=TEdit.Create(Self);
       Bordes2[i,j].Parent:=CBordes2[i];
       Bordes2[i,j].Visible:=False;

       Energias2[i,j]:=TEdit.Create(Self);
       Energias2[i,j].Parent:=CEnergy2[i];
       Energias2[i,j].Visible:=False;
       ChEnergias2[i,j]:=TCheckBox.Create(Self);
       ChEnergias2[i,j].Parent:=CEnergy2[i];
       ChEnergias2[i,j].Visible:=False;

       Rtps2[i,j]:=TEdit.Create(Self);
       Rtps2[i,j].Parent:=CRtps2[i];
       Rtps2[i,j].Visible:=False;
       ChRtps2[i,j]:=TCheckbox.Create(Self);
       ChRtps2[i,j].Parent:=CRtps2[i];
       ChRtps2[i,j].Visible:=False;

       Tail2[i,j]:=TEdit.Create(Self);
       Tail2[i,j].Parent:=CTail2[i];
       Tail2[i,j].Visible:=False;
       ChTail2[i,j]:=TCheckbox.Create(Self);
       ChTail2[i,j].Parent:=CTail2[i];
       ChTail2[i,j].Visible:=False;

       Beta2[i,j]:=TEdit.Create(Self);
       Beta2[i,j].Parent:=CBeta2[i];
       Beta2[i,j].Visible:=False;
       ChBeta2[i,j]:=TCheckbox.Create(Self);
       ChBeta2[i,j].Parent:=CBeta2[i];
       ChBeta2[i,j].Visible:=False;

       Perfil2[i,j]:=TEdit.Create(Self);
       Perfil2[i,j].Parent:=CPerfil2[i];
       Perfil2[i,j].Visible:=False;
     end;
   end;
   For i:=0 To 30 Do Begin
      Cd2[i].Visible:=False;
      ChCd2[i].Visible:=False;
      Eld2[i].Visible:=False;
      Cnd2[i].Visible:=False;
      ChCnd2[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;
      CTail2[i].Visible:=False;
      CBeta2[i].Visible:=False;
      CPerfil2[i].Visible:=False;
    end;

end;

procedure TForm6.Form6new();
  Var i,j:Integer;
begin
 { For i:=1 To 30 Do Nlin[i]:=0;
  For i:=1 To 300 Do Desc[i]:='';
  For i:=1 To Np Do Begin
      P0[i]:=0.0;
      Cod[i]:=0;
  end;
  For i:=1 To 30 Do For j:=1 To 20 Do Begin
      Perf[i,j]:=' ';
  end;                 }
  For i:=0 To 30 Do For j:=0 To 20 Do Begin
    Lineas2[i,j].Visible:=False;
    Bordes2[i,j].Visible:=False;
    Energias2[i,j].Visible:=False;
    ChEnergias2[i,j].Visible:=False;
    ChEnergias2[i,j].Checked:=False;
    Rtps2[i,j].Visible:=False;
    ChRtps2[i,j].Visible:=False;
    ChRtps2[i,j].Checked:=False;
    Tail2[i,j].Visible:=False;
    ChTail2[i,j].Visible:=False;
    ChTail2[i,j].Checked:=False;
    Beta2[i,j].Visible:=False;
    ChBeta2[i,j].Visible:=False;
    ChBeta2[i,j].Checked:=False;
    Perfil2[i,j].Visible:=False;
  end;
  For i:=0 To 30 Do Begin
    Cd2[i].Visible:=False;
    Cd2[i].Caption:='0';
    ChCd2[i].Visible:=False;
    Eld2[i].Visible:=False;
    Eld2[i].Caption:='';
    Cnd2[i].Visible:=False;
    ChCnd2[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;
    CTail2[i].Visible:=False;
    CBeta2[i].Visible:=False;
    CPerfil2[i].Visible:=False;
  end;
end;

procedure TForm6.Button1Click(Sender: TObject);  {Aceptar}
  Var i,j,l:Integer;
begin
  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);
  NLF:=0;
  For i:=1 To Nfdet Do NLF:=NLF+StrToInt(NL2[i-1].Text);
  For i:=NPG+NG+4*NL+4*NLF+Nel+1 to NPG+NG+4*NL+4*NLF+Nel+Nfdet Do Begin
    P0[i]:=StrToFloat(Cd2[i-NPG-1-NG-4*NL-4*NLF-Nel].Text);
    if ChCd2[i-NPG-1-NG-4*NL-4*NLF-Nel].Checked=True then Cod[i]:=1
    else Cod[i]:=0;
  end;
  For i:=NPG+1+NG+4*NL+4*NLF+Nel+Nfdet to NPG+NG+4*NL+4*NLF+Nel+Nfdet+Nfilm Do Begin
    P0[i]:=StrToFloat(Cnd2[i-NPG-1-NG-4*NL-4*NLF-Nfdet-Nel].Text);
    if ChCnd2[i-NPG-1-NG-4*NL-4*NLF-Nfdet-Nel].Checked=True then  Cod[i]:=1
    else  Cod[i]:=0;
  end;
  For i:=1 To Nfdet Do Nlin[i+Ndet]:=StrToInt(NL2[i-1].Text);
  l:=0;
  For i:=0 To Nfdet-1 Do Begin
     For j:=0 To Nlin[i+Ndet+1]-1 do Begin
         Inc(l);
         Desc[l+NL]:=Lineas2[i,j].Text;
         Borde[i+Ndet+1,j+1]:=Bordes2[i,j].Text;
         P0[4*NL+NG+Nel+l+NPG]:=StrToFloat(Energias2[i,j].Text);
         if ChEnergias2[i,j].Checked=True then Cod[4*NL+NG+Nel+l+NPG]:=1
         else  Cod[4*NL+NG+Nel+l+NPG]:=0;
         P0[4*NL+NG+Nel+NLF+l+NPG]:=StrToFloat(Rtps2[i,j].Text);
         if ChRtps2[i,j].Checked=True  then  Cod[4*NL+NG+Nel+NLF+l+NPG]:=1
         else  Cod[4*NL+NG+Nel+NLF+l+NPG]:=0;
         P0[4*NL+NG+Nel+2*NLF+l+NPG]:=StrToFloat(Tail2[i,j].Text);
         if ChTail2[i,j].Checked=True then  Cod[4*NL+NG+Nel+2*NLF+l+NPG]:=1
         else   Cod[4*NL+NG+Nel+2*NLF+l+NPG]:=0;
         P0[4*NL+NG+Nel+3*NLF+l+NPG]:=StrToFloat(Beta2[i,j].Text);
         if ChBeta2[i,j].Checked=True then  Cod[4*NL+NG+Nel+3*NLF+l+NPG]:=1
         else   Cod[4*NL+NG+Nel+3*NLF+l+NPG]:=0;
         Perf[i+Ndet+1,j+1]:=Perfil2[i,j].Text[1];
     end;
  end;
  ContNPR;
  Form6.Close;
end;

procedure TForm6.Button2Click(Sender: TObject); {Aplicar}
  Var i,j,NLmayor:Integer;
begin

  For i:=0 To 30 Do For j:=0 To 20 Do Lineas2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do Bordes2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do Energias2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do ChEnergias2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do Rtps2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do ChRtps2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do Tail2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do ChTail2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do Beta2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do ChBeta2[i,j].Visible:=False;
  For i:=0 To 30 Do For j:=0 To 20 Do Perfil2[i,j].Visible:=False;
  For i:=0 To Nfdet-1 Do Begin
     For j:=0 To StrToInt(NL2[i].Caption)-1 Do Begin
       Lineas2[i,j].Visible:=True;
       Lineas2[i,j].Left:=2;
       Lineas2[i,j].Top:=2+30*j;
       Lineas2[i,j].height:=27;
       Lineas2[i,j].width:=80;

       Bordes2[i,j].Visible:=True;
       Bordes2[i,j].Left:=2;
       Bordes2[i,j].Top:=2+30*j;
       Bordes2[i,j].height:=27;
       Bordes2[i,j].width:=80;

       ChEnergias2[i,j].Visible:=True;
       ChEnergias2[i,j].Left:=2;
       ChEnergias2[i,j].Top:=2+30*j;
       Energias2[i,j].Visible:=True;
       Energias2[i,j].Left:=2+30;
       Energias2[i,j].Top:=2+30*j;
       Energias2[i,j].height:=27;
       Energias2[i,j].width:=80;

       ChRtps2[i,j].Visible:=True;
       ChRtps2[i,j].Left:=2;
       ChRtps2[i,j].Top:=2+30*j;
       Rtps2[i,j].Visible:=True;
       Rtps2[i,j].Left:=2+30;
       Rtps2[i,j].Top:=2+30*j;
       Rtps2[i,j].height:=27;
       Rtps2[i,j].width:=80;

       ChTail2[i,j].Visible:=True;
       ChTail2[i,j].Left:=2;
       ChTail2[i,j].Top:=2+30*j;
       Tail2[i,j].Visible:=True;
       Tail2[i,j].Left:=2+30;
       Tail2[i,j].Top:=2+30*j;
       Tail2[i,j].height:=27;
       Tail2[i,j].width:=80;

       ChBeta2[i,j].Visible:=True;
       ChBeta2[i,j].Left:=2;
       ChBeta2[i,j].Top:=2+30*j;
       Beta2[i,j].Visible:=True;
       Beta2[i,j].Left:=2+30;
       Beta2[i,j].Top:=2+30*j;
       Beta2[i,j].height:=27;
       Beta2[i,j].width:=80;

       Perfil2[i,j].Visible:=True;
       Perfil2[i,j].Left:=2;
       Perfil2[i,j].Top:=2+30*j;
       Perfil2[i,j].height:=27;
       Perfil2[i,j].width:=45;
     end;
  end;
  NLmayor:=StrToInt(NL2[0].Caption);
  For i:=1 To Nfdet-1 Do Begin
     if(StrToInt(NL2[i].Caption)>NLmayor) Then
     NLmayor:=StrToInt(NL2[i].Caption);
  end;
  If(NLMayor>=7) Then Begin
     PageControl1.Height:= 312+(29*(NLmayor-7));
     PageControl2.Height:= 272+(29*(NLmayor-7));
  end;
  If (NLmayor<7)Then Begin
     PageControl1.Height:=312;
     PageControl2.Height:=272;
  end;
  Button1.Top:=PageControl1.Height+12;
end;

procedure TForm6.FormActivate(Sender: TObject);
  Var i,j,l:Integer;
begin
  Button2.Top:=40+30*Nfdet;
  For i:=Ndet To Ndet+Nfdet-1 Do Zd2[i-Ndet].Text:=FloatToStr(Zdet[i+1]);
  For i:=Nnodet To Nnodet+Nfnodet-1 Do Znd2[i-Nnodet].Text:=FloatToStr(Znodet[i+1]);
  {Para que se muestren los cuadros con las concentraciones, el numero de lineas, etc, de Form5 y Form7  }
  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;

     ChCd2[i].Visible:=True;
     ChCd2[i].Left:=2;
     ChCd2[i].Top:=30+28*i;

     Eld2[i].Visible:=True;
     Eld2[i].Caption:=Sim[StrToInt(Zd2[i].Text)]+':';
     Eld2[i].Left:=25;
     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:=Sim[StrToInt(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:=Sim[StrToInt(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;

     CTail2[i].Visible:=True;
     CTail2[i].Caption:='Tail';
     CTail2[i].Height:=268;
     CTail2[i].Width:=90;
     CTail2[i].Top:=2;
     CTail2[i].Left:=430;

     CBeta2[i].Visible:=True;
     CBeta2[i].Caption:='Beta';
     CBeta2[i].Height:=268;
     CBeta2[i].Width:=90;
     CBeta2[i].Top:=2;
     CBeta2[i].Left:=552;

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

     ChCnd2[i].Visible:=True;
     ChCnd2[i].Left:=2;
     ChCnd2[i].Top:=30+28*i;

     Elnd2[i].Visible:=True;
     Elnd2[i].Caption:=Sim[StrToInt(Znd2[i].Text)]+':';
     Elnd2[i].Left:=25;
     Elnd2[i].Top:=35+28*i;
     Elnd2[i].height:=18;
     Elnd2[i].width:=46;
   end;
   For i:=NPG+1+NG+4*NL+4*NLF+Nel to NPG+NG+4*NL+4*NLF+Nel+Nfdet Do Begin
       Cd2[i-NPG-1-NG-4*NL-4*NLF-Nel].Text:=FloatToStr(P0[i]);
       if Cod[i]=1 then  ChCd2[i-NPG-1-NG-4*NL-4*NLF-Nel].Checked:=True
       else  ChCd2[i-NPG-1-NG-4*NL-4*NLF-Nel].Checked:=False;
   end;
   For i:=NPG+1+NG+4*NL+4*NLF++Nel+Nfdet to NPG+NG+4*NL+4*NLF+Nel+Nfdet+Nfilm Do Begin
      Cnd2[i-NPG-1-NG-4*NL-4*NLF-Nfdet-Nel].Text:=FloatToStr(P0[i]);
      if Cod[i]=1 then  ChCnd2[i-NPG-1-NG-4*NL-4*NLF-Nfdet-Nel].Checked:=True
      else  ChCnd2[i-NPG-1-NG-4*NL-4*NLF-Nfdet-Nel].Checked:=False;
   end;
   For i:=0 To Nfdet Do NL2[i].Text:=FloatToStr(Nlin[i+Ndet+1]);
   Form6.Button2Click(Form6);
   l:=0;
   For i:=0 To 30 Do For j:=0 To 20 Do Begin
      Lineas2[i,j].Text:='';
      Bordes2[i,j].Text:='';
      Energias2[i,j].Text:='';
      ChEnergias2[i,j].Checked:= False;
      Rtps2[i,j].Text:='';
      ChRtps2[i,j].Checked:= False;
      Tail2[i,j].Text:='';
      ChTail2[i,j].Checked:= False;
      Beta2[i,j].Text:='';
      ChBeta2[i,j].Checked:= False;
      Perfil2[i,j].Text:='';
   end;
   For i:=0 To Nfdet-1 Do Begin       {i:=Ndet+1 To Ndet+Nfdet}
      For j:=0 To Nlin[i+Ndet+1]-1 do Begin
          Inc(l);
          Lineas2[i,j].Text:=Desc[l+NL];
          Bordes2[i,j].Text:=Borde[i+Ndet+1,j+1];
          Energias2[i,j].Text:=FloatToStr(P0[4*NL+NG+Nel+l+NPG]);
          if Cod[4*NL+NG+Nel+l+NPG]=1 then  ChEnergias2[i,j].Checked:=True
          else  ChEnergias2[i,j].Checked:= False;
          Rtps2[i,j].Text:=FloatToStr(P0[4*NL+NG+Nel+NLF+l+NPG]);
          if Cod[4*NL+NG+Ndet+Nnodet+NLF+l+NPG]=1 then  ChRtps2[i,j].Checked:=True
          else  ChRtps2[i,j].Checked:= False;
          Tail2[i,j].Text:=FloatToStr(P0[4*NL+NG+Nel+2*NLF+l+NPG]);{P0[NL+l+NPG]);}
          if Cod[4*NL+NG+Nel+2*NLF+NPG+l]=1 then  ChTail2[i,j].Checked:=True
          else  ChTail2[i,j].Checked:= False;
          Beta2[i,j].Text:=FloatToStr(P0[4*NL+NG+Nel+3*NLF+l+NPG]);{P0[NL+l+NPG]);}
          if Cod[4*NL+NG+Nel+3*NLF+l+NPG]=1 then  ChBeta2[i,j].Checked:=True
          else  ChBeta2[i,j].Checked:= False;
          Perfil2[i,j].Text:=Perf[i+Ndet+1,j+1];
      end;
   end;
  if(GroupBox3.Height>PageControl1.Height) Then Begin
     PageControl1.Height:=GroupBox3.Height+60;
     Button1.Top:=PageControl1.Height+30
  end;

end;


end.

