unit KSimMot; {------------------------------------------------------------------------------} { KSimMot - This file include Kave 2000 Simulation for motor-components: TsMotorObject TsLine Author: Vesa Lappalainen Date: 9.9.1996 Changes: } {------------------------------------------------------------------------------} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, kavesimu; 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; published property Rpm : double read FRpm write FRpm; property Ratio : double read FRatio write FRatio; property Speed : double read FSpeed write SetSpeed; end; { TsMotorObject } TsLine = class(TsMotorObject) private FSheet : TaSimuObject; FRollCount : integer; protected procedure SetRollCount(c:integer); virtual; public constructor Create(AOwner:TComponent); override; procedure Paint; override; procedure DoTimer(Sender: TObject); override; published property Sheet : TaSimuObject read FSheet write FSheet; property RollCount : integer read FRollCount write SetRollCount default 5; end; { TsLine } procedure Register; implementation {------------------------------------------------------------------------------} { 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; {------------------------------------------------------------------------------} { TsLine ======================================================================} {------------------------------------------------------------------------------} procedure TsLine.SetRollCount(c:integer); begin FRollCount := c; Invalidate; end; {------------------------------------------------------------------------------} procedure TsLine.DoTimer(Sender: TObject); begin if ( Assigned(Sheet) ) then Sheet.Advance(speed*Ratio*Rpm); end; {------------------------------------------------------------------------------} procedure TsLine.Paint; var iWid, ix, iy, ih, dx, nc: Integer; begin CheckScale; with Canvas do begin Canvas.Pen := Self.Pen; Canvas.Brush := Self.Brush; ix := Pen.Width div 2; iy := ix; ih := Height - Pen.Width + 1; if Pen.Width = 0 then begin Dec(ih); end; iWid := Width - ih; if ( RollCount <= 1 ) then dx := 0 { |----iWid---| } else dx := Trunc(iWid/(RollCount-1)); { o o o o } nc := 1; while ( nc <= RollCount ) do begin Ellipse(ix, iy, ix + ih, iy + ih); ix := ix + dx; nc := nc + 1; end; end; end; {------------------------------------------------------------------------------} constructor TsLine.Create(AOwner:TComponent); begin Inherited Create(AOwner); FSheet := NIL; FRollCount := 5; { Brush.Color := clNavy;} end; procedure Register; begin RegisterComponents('Kave2000', [TsLine]); end; end.