📄 adstmach.pas
字号:
(Point.y >= State.Top) and
(Point.y <= State.Top + State.Height) then
Exit;
end;
end;
if (Msg.Keys and MK_SHIFT) <> 0 then
AddType := atAdd
else if (Msg.Keys and MK_CONTROL) <> 0 then
AddType := atSub
else
AddType := atNone;
ConnectoidAtPoint (AddType, Point);
end;
end;
procedure TApdCustomStateMachine.ConnectoidAtPoint (
AddType : TApdConnectAddType;
Point : TPoint);
function PointInRect (Point : TPoint; Rect : TRect;
Offset : Integer) : Boolean;
var
t : Integer;
begin
Result := False;
{ Sort the rectangle points }
if (Rect.Left > Rect.Right) then begin
t := Rect.Right;
Rect.Right := Rect.Left;
Rect.Left := t;
end;
if (Rect.Top > Rect.Bottom) then begin
t := Rect.Bottom;
Rect.Bottom := Rect.Top;
Rect.Top := t;
end;
if (Point.x >= Rect.Left - Offset) and
(Point.x <= Rect.Right + Offset) and
(Point.y >= Rect.Top - Offset) and
(Point.y <= Rect.Bottom + Offset) then
Result := True;
end;
function CheckConnectoid (State, DestState: TApdCustomState) : Boolean;
const
ApdCCOffset = 4;
var
StartAt : TPoint;
EndAt : TPoint;
MidPoint : TPoint;
MinPoint : TPoint;
MaxPoint : TPoint;
begin
Result := False;
if Assigned (State) and Assigned(DestState) and
(State <> nil) and (DestState <> nil) then begin
StartAt.x := State.Left + (State.Width div 2);
StartAt.y := State.Top + (State.Height div 2);
EndAt.x := DestState.Left + (DestState.Width div 2);
EndAt.y := DestState.Top + (DestState.Height div 2);
if StartAt.x > EndAt.x then begin
MinPoint.x := EndAt.x;
MaxPoint.x := StartAt.x;
end else begin
MinPoint.x := StartAt.x;
MaxPoint.x := EndAt.x;
end;
if StartAt.y > EndAt.y then begin
MinPoint.y := EndAt.y;
MaxPoint.y := StartAt.y;
end else begin
MinPoint.y := StartAt.y;
MaxPoint.y := EndAt.y;
end;
MidPoint.x := (MaxPoint.x - MinPoint.x) div 2 + MinPoint.x;
MidPoint.y := (MaxPoint.y - MinPoint.y) div 2 + MinPoint.y;
{ Important note:
If the mechanism by which the connectoids are drawn is changed,
this code must be changed to reflect the drawing mechanism }
if DestState = State then begin
Dec (StartAt.x, 8);
if PointInRect (Point, Rect (State.Left + State.Width - 14,
State.Top - 6,
State.Left + State.Width - 8,
State.Top),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (State.Left + State.Width + 12,
State.Top - 12,
State.Left + State.Width - 12,
State.Top + 12),
ApdCCOffset) then
Result := True;
{ Check Arrow }
if PointInRect (Point, Rect (DestState.Left + DestState.Width + 4,
State.Top + 14,
DestState.Left + DestState.Width,
State.Top + 6),
ApdCCOffset) then
Result := True;
end else if (DestState.Top > State.Top + State.Height) then begin
Dec (StartAt.x, 8);
Dec (EndAt.x, 8);
Dec (MidPoint.y, 4);
{ Check Start }
if PointInRect (Point, Rect (StartAt.x - 3,
State.Top + State.Height + 6,
StartAt.x + 3,
State.Top + State.Height),
ApdCCOffset) then
Result := True;
{ Check Connectoid }
if PointInRect (Point, Rect (StartAt.x, StartAt.y,
StartAt.x, MidPoint.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (StartAt.x, MidPoint.y,
EndAt.x, MidPoint.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (EndAt.x, MidPoint.y,
EndAt.x, EndAt.y),
ApdCCOffset) then
Result := True;
{ Check Arrow }
if PointInRect (Point, Rect (EndAt.x - 4, DestState.Top,
EndAt.x + 4, DestState.Top - 4),
ApdCCOffset) then
Result := True;
end else if (DestState.Top + DestState.Height < State.Top) then begin
Inc (StartAt.x, 8);
Inc (EndAt.x, 8);
Inc (MidPoint.y, 4);
{ Check Start }
if PointInRect (Point, Rect (StartAt.x - 3, State.Top - 6,
StartAt.x + 3, State.Top),
ApdCCOffset) then
Result := True;
{ Check Connectoid }
if PointInRect (Point, Rect (StartAt.x, StartAt.y,
StartAt.x, MidPoint.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (StartAt.x, MidPoint.y,
EndAt.x, MidPoint.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (EndAt.x, MidPoint.y,
EndAt.x, EndAt.y),
ApdCCOffset) then
Result := True;
{ Check Arrow }
if PointInRect (Point, Rect (EndAt.x - 4,
DestState.Top + DestState.Height,
EndAt.x + 4,
DestState.Top + DestState.Height + 4),
ApdCCOffset) then
Result := True;
end else if (DestState.Left > State.Left + State.Width) then begin
Dec (StartAt.y, 8);
Dec (EndAt.y, 8);
Dec (MidPoint.x, 4);
{ Check Start }
if PointInRect (Point, Rect (State.Left + State.Width,
StartAt.y - 3,
State.Left + State.Width + 6,
StartAt.y + 3),
ApdCCOffset) then
Result := True;
{ Check Connectoid }
if PointInRect (Point, Rect (StartAt.x, StartAt.y,
MidPoint.x, StartAt.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (MidPoint.x, StartAt.y,
MidPoint.x, EndAt.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (MidPoint.x, EndAt.y,
EndAt.x, EndAt.y),
ApdCCOffset) then
Result := True;
{ Check Arrow }
if PointInRect (Point, Rect (DestState.Left - 4, EndAt.y - 4,
DestState.Left, EndAt.y + 4),
ApdCCOffset) then
Result := True;
end else if (DestState.Left + DestState.Width < State.Left) then begin
Inc (StartAt.y, 8);
Inc (EndAt.y, 8);
Inc (MidPoint.x, 4);
{ Check Start }
if PointInRect (Point, Rect (State.Left - 6, StartAt.y - 3,
State.Left, StartAt.y + 3),
ApdCCOffset) then
Result := True;
{ Check Connectoid }
if PointInRect (Point, Rect (StartAt.x, StartAt.y,
MidPoint.x, StartAt.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (MidPoint.x, StartAt.y,
MidPoint.x, EndAt.y),
ApdCCOffset) then
Result := True;
if PointInRect (Point, Rect (MidPoint.x, EndAt.y, EndAt.x, EndAt.y),
ApdCCOffset) then
Result := True;
{ Check Arrow }
if PointInRect (Point, Rect (DestState.Left + DestState.Width,
EndAt.y - 4,
DestState.Left + DestState.Width + 4,
EndAt.y + 4),
ApdCCOffset) then
Result := True;
end;
end;
end;
var
i : Integer;
c : Integer;
State : TApdCustomState;
begin
for i := 0 to pred(ControlCount) do begin
if Controls[i] is TApdCustomState then begin
State := TApdCustomState(Controls[i]);
if State.Conditions.Count > 0 then begin
for c := 0 to pred(State.Conditions.Count) do
if State.Conditions[c].NextState <> nil then begin
if AddType = atNone then
State.Conditions[c].Connectoid.FSelected := False;
if CheckConnectoid (State, State.Conditions[c].NextState) then begin
if AddType <> atSub then begin
State.Conditions[c].Connectoid.FSelected := True;
if not (csDesigning in ComponentState) then begin
if Assigned (FConnectoidClickEvent) then
FConnectoidClickEvent (Self,
State.Conditions[c].Connectoid);
end;
end else
State.Conditions[c].Connectoid.FSelected := False;
end;
end;
end;
end;
end;
Invalidate;
end;
constructor TApdCustomStateMachine.Create(AOwner: TComponent);
begin
inherited;
ControlStyle := [csOpaque, csAcceptsControls, csFramed, csCaptureMouse,
csClickEvents, csSetCaption, csDoubleClicks];
{create our canvas}
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self;
FBorderStyle := bsSingle;
FMovableStates := False;
ConnectoidClickStyle := [];
Color := clWhite;
Height := 200;
Width := 200;
{PacketList := TList.Create; }
{FComPort := SearchComPort(Owner); }
FDefaultDataSource := TApdStateComPortSource.Create (Self);
FDefaultDataSource.ComPort := SearchComPort (Owner);
FDataSource := nil;
// FDataSource := SearchDataSource (Owner);
end;
procedure TApdCustomStateMachine.CreateParams(var Params: TCreateParams);
const
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or BorderStyles[FBorderStyle];
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
begin
Style := Style and not WS_BORDER;
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
end;
end;
destructor TApdCustomStateMachine.Destroy;
begin
if Assigned (CurrentState) then
DoDeactivate;
{PacketList.Free;}
FDefaultDataSource.Free;
FDefaultDataSource := nil;
FCanvas.Free;
inherited;
end;
procedure TApdCustomStateMachine.DoActivate(NewState : TApdCustomState);
function GetRealNextState (NextState : TApdCustomState) : TApdCustomState;
var
i : Integer;
Done : Boolean;
GotOne : Boolean;
begin
Result := NextState;
Done := False;
while not Done do begin
GotOne := False;
for i := 0 to Result.Conditions.Count - 1 do
if (Result.Conditions[i].DefaultNext) and
(Assigned (Result.Conditions[i].NextState)) then begin
Result.Deactivate;
Result := Result.Conditions[i].NextState;
Result.Activate;
GotOne := True;
Break;
end;
if not GotOne then
Done := True;
end;
end;
var
I : Integer;
begin
if Paused then
Exit;
if (NewState.Conditions.Count = 0) or
(NewState = TerminalState) then begin
{ no conditions set, must be done }
FCurrentState := NewState;
NewState.Activate;
if Assigned(FOnStateMachineFinish) then
FOnStateMachineFinish(Self, FLastErrorCode);
FActive := False; {!!.02}
end else begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -