unit bauelemente;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs;

type
  TBETYP = (Diode, FET, Kondensator, Spannungsregler, Transistor, Resistor, ZDiode);
  TBEAllg = record
    _Type, _Bauform: String;
  end;
  TBauelemente = class(TGraphicControl)
  private
    { Private declarations }
    fDatensatz: Array [0..6] of String;
    fBEName: TBETYP;
    fBEBezeichner: String;
    fBECount: Byte;
//    fEinheit : String;
  strict protected
    BEAllg: TBEAllg;
  protected
    { Protected declarations }
  public
    { Public declarations }
    function GetBEName: TBETYP;
    function GetBEBezeichner: String;
    function GetBECount: Byte;
    function GetBEAllg(Value: Boolean): String;
//    function GetBEAllg: TBEAllg;
    function GetDatensatz(Value: Byte): String;
    procedure SetBEName(Value: TBETYP);
    procedure SetBEBezeichner(Value: String);
    procedure SetBECount(Value: Byte);
    Procedure SetBEAllg(Value: TBEAllg);
    Procedure SetDatensatz(_Index: Byte; Value: String);
    property Datensatz[Value:Byte]: String read GetDatensatz write SetDatensatz;
 published
    { Published declarations }
    Constructor Create(AOwner: TComponent); Override;
  end;
  TDType = (#&1N4001, _1N4001SMD, _1N4002, _1N4002SMD, _1N4003, _1N4003SMD, _1N4004, _1N4004SMD, _1N4005, _1N4005SMD, _1N4006, _1N4006SMD, _1N4007, _1N4007SMD,
            _1N4148, _1N4148SMD, _1N4148WS, _1N4149, _1N4150, _1N4151, _1N4448, _1N4448WS, _1N4933, _1N4934, _1N4935, _1N4936, _1N4937,
            _1N5059, _1N5060, _1N5061, _1N5062, _1N5400, _1N5401, _1N5402, _1N5403, _1N5404, _1N5405, _1N5406, _1N5407);
  TDBauform = (DO41, DO312AB, DO35, Mini_Melf, SOD323F, DO15, DO201AD);
  TBEDiode = Record
    _Einheit : Array[0..3] of String;
    _Uf, _Ubr, _If, _Ptot: Double;
  end;
  T_Diode = class(TBauelemente)
  strict private
    {Klasseninterne Vertraulichkeit}
    BEDiode: TBEDiode;
    fDType: TDType;
  public
    function GetUf: String;
    function GetUbr: String;
    function GetIf: String;
    function GetPtot: String;
    function GetDiodenType: TDType;
    Procedure SetUf(Value: String);
    Procedure SetUbr(Value: String);
    Procedure SetIf(Value: String);
    Procedure Setptot(Value: String);
    Procedure SetDiodenType(Value: TDType);
    property Betriebsstrom: String read GetIf write SetIf;
    property Flussspannung: String read GetUbr write SetUbr;
    property Leistungsgrenze: String read GetPtot write SetPtot;
    property Spannungsabfall: String read GetUf write SetUf;
  published
    { Published declarations }
    property DiodenTyp: TDType read GetDiodenType write SetDiodenType;
    procedure Paint; Override;
    Constructor Create(AOwner: TComponent); Override;
  end;

{  TBEFET = Record
    _Einheit : Array[0..6] of String;
    _Udss, _Ugs, _Igss, _Rds_on, _Ciss, _Coss, _Crss, _Ptot: Double;
  end;

  TBEVREG = Record
    _Einheit : Array[0..4] of String;
    Ui, _Io, _Out, _Uref, _Ptot: Double;
  end;

  TBETransistor = Record
    _Einheit : Array[0..5] of String;
    _Uce, _Ic, _Ube, _Hfe, _Ib, _Ft, _Ptot: Double;
  end;

  TBEResistor = Record
    _Einheit : Array[0..1] of String;
    _R, _Ptot: Double;
  end;

  TBEZDiode = Record
    _Einheit : Array[0..3] of String;
    _Uz, _Rz, _Itm, _Ptot: Double;
  end;

  TBEKondi = Record
    _Type, _Bauform: String;
    _Einheit : Array[0..2] of String;
    _U, _C,  _Ptot: Double;
  end;
 }

procedure Register;

implementation

Constructor TBauelemente.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Left:= 10;
  Top:= 10;
  Height:= 50;
  Width:= 50;
end;

function TBauelemente.GetBEName: TBETYP;
begin
  Result:= fBEName;
end;

function TBauelemente.GetBEBezeichner: String;
begin
  Result:= fBEBezeichner;
end;

function TBauelemente.GetBECount: Byte;
begin
  result:= fBECount;
end;

function TBauelemente.GetBEAllg(Value: Boolean): String;
begin
  if Value then result:= BEAllg._Type;
  if not Value then result:= BEAllg._BauForm;
end;

function TBauelemente.GetDatensatz(Value: Byte): String;
begin
  result:= fDatensatz[Value];
end;

procedure TBauelemente.SetBEName(Value: TBETYP);
begin
  fBEName:= Value;

end;

procedure TBauelemente.SetBEBezeichner(Value: String);
begin
  fBEBezeichner:= Value;
end;

procedure TBauelemente.SetBECount(Value: Byte);
begin
  fBECount:= Value;
end;

procedure TBauelemente.SetBEAllg(Value: TBEAllg);
begin
  BEAllg:= Value;
end;

Procedure TBauelemente.SetDatensatz(_Index: Byte; Value: String);
begin
  fDatensatz[_Index]:= Value;
end;

Constructor T_Diode.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
//  Left:= 10;
//  Top:= 10;
//  Height:= 50;
//  Width:= 50;

end;

function T_Diode.GetUf: String;
begin
  result:= FloattoStr(BEDiode._Uf) + ' ' + BEDiode._Einheit[0];
end;

function T_Diode.GetUbr: String;
begin
  result:= FloatToStr(BEDiode._Ubr) + ' ' + BEDiode._Einheit[1];
end;

function T_Diode.GetIf: String;
begin
  result:= FloatToStr(BEDiode._If) + ' ' + BEDiode._Einheit[2];
end;

function T_Diode.GetPtot: String;
begin
  result:= FloatToStr(BEDiode._Ptot) + ' ' + BEDiode._Einheit[3];
end;

function T_Diode.GetDiodenType: TDType;
begin
  result:= fDType;
end;

Procedure T_Diode.SetUf(Value: String);
var FloatValue: Double;
begin
  FloatValue:= StrToFloat(Value);
  if FloatValue <= 1.0 then
     begin
     BEDiode._Einheit[0]:= 'mV';
     BEDiode._Uf:= FloatValue*1000;
     end;
  if FloatValue >= 1.0 then
     begin
     BEDiode._Einheit[0]:= 'V';
     BEDiode._Uf:= FloatValue;
     end;
end;

Procedure T_Diode.SetUbr(Value: String);
var FloatValue: Double;
begin
  FloatValue:= StrToFloat(Value);
  if FloatValue <= 1.0 then
     begin
     BEDiode._Einheit[0]:= 'mV';
     BEDiode._Uf:= FloatValue*1000;
     end;
  if FloatValue >= 1.0 then
     begin
     BEDiode._Einheit[1]:= 'V';
     BEDiode._Ubr:= FloatValue;
     end;
end;

Procedure T_Diode.SetIf(Value: String);
var FloatValue: Double;
begin
  FloatValue:= StrToFloat(Value);
  if (FloatValue > 0.000000) and (FloatValue < 0.0001) then
     begin
     BEDiode._Einheit[2]:= 'µA';
     BEDiode._If:= FloatValue*1000*1000;
     end;
  if (FloatValue >= 0.001) and (FloatValue <= 1.0) then
     begin
     BEDiode._Einheit[2]:= 'mA';
     BEDiode._If:= FloatValue*1000;
     end;
  if FloatValue >= 1.0 then
     begin
     BEDiode._Einheit[2]:= 'A';
     BEDiode._If:= FloatValue;
     end;
end;

Procedure T_Diode.SetPtot(Value: String);
var FloatValue: Double;
begin
  FloatValue:= StrToFloat(Value);
  if FloatValue <= 1.0 then BEDiode._Einheit[3]:= 'mW';
  if FloatValue >= 1.0 then BEDiode._Einheit[3]:= 'W';
  BEDiode._Ptot:= FloatValue;
end;

Procedure T_Diode.SetDiodenType(Value: TDType);
begin
  fDType:= Value;
  case Value of
    _1N4001: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 50.0;
             BEDIode._If:= 1.0;
             end;
    _1N4001SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 50.0;
                BEDIode._If:= 1.0;
                end;
    _1N4002: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 100.0;
             BEDIode._If:= 1.0;
             end;
    _1N4002SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 100.0;
                BEDIode._If:= 1.0;
                end;
    _1N4003: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 200.0;
             BEDIode._If:= 1.0;
             end;
    _1N4003SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 200.0;
                BEDIode._If:= 1.0;
                end;
    _1N4004: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 400.0;
             BEDIode._If:= 1.0;
             end;
    _1N4004SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 400.0;
                BEDIode._If:= 1.0;
                end;
    _1N4005: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 600.0;
             BEDIode._If:= 1.0;
             end;
    _1N4005SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 600.0;
                BEDIode._If:= 1.0;
                end;
    _1N4006: begin
             BEDiode._Uf:= 0.7;
             BEDiode._Ubr:= 800.0;
             BEDiode._If:= 1.0;
             end;
    _1N4006SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 800.0;
                BEDIode._If:= 1.0;
                end;
    _1N4007: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 1000.0;
             BEDIode._If:= 1.0;
             end;
    _1N4007SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 1000.0;
                BEDIode._If:= 1.0;
                end;
    _1N4148: begin
             BEDiode._Uf:= 0.7;
             BEDIode._Ubr:= 100.0;
             BEDIode._If:= 0.300;
             end;
    _1N4148SMD: begin
                BEDiode._Uf:= 0.7;
                BEDIode._Ubr:= 100.0;
                BEDIode._If:= 0.300;
                end;
    _1N4148WS: begin
               BEDiode._Uf:= 1.0;
               BEDiode._Ubr:= 75.0;
               BEDiode._If:= 0.150;
    end;
    _1N4149: begin
             BEDiode._Uf:= 1.0;
             BEDiode._Ubr:= 75;
             BEDiode._If:= 0.500;
             end;
    _1N4150: begin
             BEDiode._Uf:= 0.86;
             BEDiode._Ubr:= 50.0;
             BEDiode._If:= 0.6;
             end;
    _1N4151: begin
             BEDiode._Uf:= 1.0;
             BEDiode._Ubr:= 50.0;
             BEDiode._If:= 0.45;
             end;
    _1N4448: begin
             BEDiode._Uf:= 1.0;
             BEDiode._Ubr:= 75.0;
             BEDiode._If:= 0.150;
             end;
    _1N4448WS: begin
               BEDiode._Uf:= 1.0;
               BEDiode._Ubr:= 75.0;
               BEDiode._If:= 0.150;
               end;
    _1N4933: begin
             BEDiode._Uf:= 1.3;
             BEDiode._Ubr:= 50.0;
             BEDiode._If:= 1.0;
             end;
    _1N4934: begin
             BEDiode._Uf:= 1.3;
             BEDiode._Ubr:= 100.0;
             BEDiode._If:= 1.0;
             end;
    _1N4935: begin
             BEDiode._Uf:= 1.3;
             BEDiode._Ubr:= 200.0;
             BEDiode._If:= 1.0;
             end;
    _1N4936: begin
             BEDiode._Uf:= 1.3;
             BEDiode._Ubr:= 400.0;
             BEDiode._If:= 1.0;
             end;
    _1N4937: begin
             BEDiode._Uf:= 1.3;
             BEDiode._Ubr:= 600.0;
             BEDiode._If:= 1.0;
             end;
    _1N5059: begin
             BEDiode._Uf:= 0.9;
             BEDiode._Ubr:= 200.0;
             BEDiode._If:= 2.0;
             end;
    _1N5060: begin
             BEDiode._Uf:= 0.9;
             BEDiode._Ubr:= 400.0;
             BEDiode._If:= 2.0;
             end;
    _1N5061: begin
             BEDiode._Uf:= 0.9;
             BEDiode._Ubr:= 600.0;
             BEDiode._If:= 2.0;
             end;
    _1N5062: begin
             BEDiode._Uf:= 0.9;
             BEDiode._Ubr:= 800.0;
             BEDiode._If:= 3.0;
             end;
    _1N5400: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 50.0;
             BEDiode._If:= 3.0;
             end;
    _1N5401: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 100.0;
             BEDiode._If:= 3.0;
             end;
    _1N5402: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 200.0;
             BEDiode._If:= 3.0;
             end;
    _1N5403: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 400.0;
             BEDiode._If:= 3.0;
             end;
    _1N5404: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 600.0;
             BEDiode._If:= 3.0;
             end;
    _1N5405: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 600.0;
             BEDiode._If:= 3.0;
             end;
    _1N5406: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 800.0;
             BEDiode._If:= 3.0;
             end;
    _1N5407: begin
             BEDiode._Uf:= 1.2;
             BEDiode._Ubr:= 1000.0;
             BEDiode._If:= 3.0;
             end;
  end;
  SetPtot(FloatToStr(BEDiode._Uf*BEDiode._If));
  SetUf(FloatToStr(BEDiode._Uf));
  SetUbr(FloatToStr(BEDiode._Ubr));
  SetIf(FloatToStr(BEDiode._If));
  Betriebsstrom;
  Flussspannung;
  Leistungsgrenze;
  Spannungsabfall;
end;

Procedure T_Diode.Paint;
begin
     Canvas.Pen.Color:= clSilver;
     Canvas.Brush.Color:= clSilver;
     Canvas.Pen.Width:= 1;
     Canvas.rectangle(1, 1, Height, Width);
     Canvas.brush.Color:= clGray;
     Canvas.Pen.color:= clGray;
     Canvas.rectangle(2, 2, Height, Width);
     Canvas.Pen.Color:= clSilver;
     Canvas.Brush.Color:= clSilver;
     Canvas.Pen.Width:= 1;
     Canvas.rectangle(2, 2 , Height-1, Width-1);
     Canvas.brush.Color:= clGray;
     Canvas.Pen.color:= clGray;
     Canvas.rectangle(3, 3, Height-1, Width-1);
end;

{
procedure Paint; Override;
Constructor Create(AOwner: TComponent); Override;
 }

procedure Register;
begin
  RegisterComponents('Elektro',[T_Diode]);
end;

end.
