unit ksimmot;
{------------------------------------------------------------------------------}
{
  KSimMot - This file include Kave 2000 Simulation for motor-components:
    TsMotorObject

   Author:  Vesa Lappalainen
   Date:    9.9.1996
   Changes: 15.3.1998/vl
            + saved as own unit with edit form
}
{------------------------------------------------------------------------------}


interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  kavesimu, savepos, StdCtrls, kinicomp, KParam, kComp, ExtCtrls, kavesimf;

type
  {----------------------------------------------------------------------------}
  TsMotorObject = class(TaSimuObject)
  private
    FSpeed : double;
    FRpm : double;
    FRatio : double;
    FTimer : TTimer;
  protected
  public
    constructor Create(AOwner:TComponent); override;
    procedure SetSpeed(s:Double); virtual;
    property Timer:TTimer read FTimer;
    procedure DoTimer(Sender: TObject); virtual;
    function GetEditForm : TEditFormClass; override;
    function  GetAsString : string; override;
    procedure ExtAsString(var value:string); override;
  published
    property Rpm : double read FRpm write FRpm;
    property Ratio : double read FRatio write FRatio;
    property Speed : double read FSpeed write SetSpeed;
  end; { TsMotorObject }


procedure Register;
implementation
uses kdouble, ksimmotf;

{------------------------------------------------------------------------------}
procedure Register;
begin
//  RegisterComponents('Kave2000', []);
end;

{------------------------------------------------------------------------------}
{ TsMotorObject ===============================================================}
{------------------------------------------------------------------------------}

{------------------------------------------------------------------------------}
procedure TsMotorObject.DoTimer(Sender: TObject);
begin
end;

{------------------------------------------------------------------------------}
procedure TsMotorObject.SetSpeed(s:Double);
begin
  FSpeed := s;
  if ( Assigned(FTimer) ) then
    FTimer.Enabled := ( s <> 0 );
end;

{------------------------------------------------------------------------------}
constructor TsMotorObject.Create(AOwner:TComponent);
begin
  Inherited Create(AOwner);
  FTimer := TTimer.Create(Self);
  FTimer.Enabled := False;
  FTimer.OnTimer := DoTimer;
  FTimer.Interval := 20;
  FSpeed := 0;
end;


//-----------------------------------------------------------------------------
function TsMotorObject.GetEditForm : TEditFormClass; //  override;
begin
  Result := TFormEditKSimMot;
end;


//-----------------------------------------------------------------------------
function  TsMotorObject.GetAsString : string; //  override;
begin
  Result := inherited GetAsString +
            DoubleToIniStr(Rpm,1) + ',' + DoubleToIniStr(Ratio,6)
            + '|';

end;


//-----------------------------------------------------------------------------
procedure TsMotorObject.ExtAsString(var value:string); //  override;
var val : string;
begin
  inherited ExtAsString(value);
  val := ExtractString(Value,'|','');
  if ( val = '' ) then exit;
  Rpm := ExtractIniDouble(val,',',Rpm);
  Ratio := ExtractIniDouble(val,',',Ratio);
end;



end.
