📄 ezcmdline.pas
字号:
Function TEzCmdLine.PreviousAction: TEzAction;
Begin
Result := FTheDefaultAction;
If ( FActionList = Nil ) Or ( FActionList.Count < 2 ) Then Exit;
Result := TEzAction( FActionList[FActionList.Count - 2] );
End;
Procedure TEzCmdLine.KillAction( var Action: TEzAction );
begin
FDeletingActionID := Action.FActionID ;
{ fires event OnFinished }
if ( Action.FLauncher <> Nil ) And Assigned( TEzActionLauncher( Action.FLauncher ).OnFinished ) then
begin
TEzActionLauncher( Action.FLauncher ).OnFinished( Action.FLauncher );
end;
FreeAndNil( Action );
FDeletingActionID := '' ;
end;
Procedure TEzCmdLine.Push( Action: TEzAction; ClearBefore: Boolean;
Const Cmd, ActionID: String );
var
TmpCursor: TCursor;
Begin
{ can this Action be pushed to the top of the list ? }
If ( ActiveDrawBox = Nil ) Or Not ( CurrentAction.CanBeSuspended ) Or Not ( Action.AcceptDrawBox ) Then
Begin
KillAction( Action );
If ActiveDrawBox <> Nil Then
All_Cursor( CurrentAction.Cursor );
CaptionChange( CurrentAction.Caption );
Exit;
End;
FAccuDraw.Showing:= False;
If EqualPoint2d( FAccuDraw.FAccuOrigin, INVALID_POINT ) Then
{ move the accudraw at the center of the screen if it is undefined }
FAccuDraw.ChangeOrigin(ActiveDrawBox.Grapher.CurrentParams.MidPoint);
{ must clear all stacked Actions ? }
If ClearBefore Then
Clear
Else
CurrentAction.SuspendOperation;
{ retrieve a custom cursor for this action with the event }
if Assigned(OnGetCursor) then
begin
TmpCursor:= Action.Cursor;
OnGetCursor(Self, Cmd, ActionID, TmpCursor );
if Action.Cursor <> TmpCursor then
Action.Cursor:= TmpCursor;
end;
{ set the cursor for this Action }
If (mdCursor in Action.FMouseDrawElements) Or Not FUseFullViewCursor Then
All_Cursor( Action.Cursor )
Else
All_Cursor( crHidden );
{ add to the list of Actions }
FActionList.Add( Action );
{ update the identifier }
Action.FActionID := ActionID;
FLastActionID := ActionID;
if Length(Cmd) > 0 then FLastCommand := Cmd;
{ defines an initial caption for the command line }
FLabel.Caption := Action.Caption;
FEdit.Text := '';
If Action.CanDoAccuDraw Then
Begin
FAccuDraw.Reset;
FAccuDraw.Showing:= True;
End;
All_Invalidate;
{ notify to TEzCmdLine of the change on Action }
If Assigned( FOnActionChange ) Then
FOnActionChange( Self );
End;
Procedure TEzCmdLine.Pop;
Var
Index: Integer;
Info: String;
FinishedAction: TEzAction;
ChainedTo: TEzAction;
Begin
Assert( ActiveDrawBox <> Nil );
Index := FActionList.Count - 1;
If Index < 0 Then Exit;
FAccuSnap.EraseFromScreen;
FAccuSnap.OverrideOsnap:= False;
{ get the finished Action }
FinishedAction := TEzAction( FActionList[Index] );
{ is there some info for next Action ?}
Info := FinishedAction.FInfoForPrevious;
FAccuDraw.Showing:= False;
ChainedTo := FinishedAction.FChainedTo;
If ChainedTo <> Nil Then
Begin
If Assigned( ChainedTo.OnInitialize ) Then
ChainedTo.OnInitialize( Self );
ChainedTo.FActionID := FinishedAction.FActionID;
FActionList.Add( ChainedTo );
End;
FActionList.Delete( Index );
{ free the finished Action }
KillAction( FinishedAction );
{ set the cursor for the current Action }
If mdCursor in CurrentAction.FMouseDrawElements Then
All_Cursor( CurrentAction.Cursor )
Else
All_Cursor( crHidden );
{ pass the infor from the previous to the new one }
If Length( Info ) > 0 Then
CurrentActionDoCommand( Info );
{ allow current Action to continue }
CurrentAction.ContinueOperation;
{ update the command line caption }
If FActionList.Count = 0 Then
Begin
FEdit.Text := '';
FLabel.Caption := SCommand;
End;
{ Don't do OSNAP if the current state cannot do it }
If ( FAccuSnap.FCurrentSnapInfo.Picture <> Nil ) And Not CurrentAction.CanDoOSNAP Then
FAccuSnap.EraseFromScreen;
FAccuDraw.Showing:= CurrentAction.CanDoAccuDraw;
All_Invalidate();
{ notify of Action change to the TEzCmdLine event handler }
If Assigned( FOnActionChange ) Then
FOnActionChange( Self );
End;
Procedure TEzCmdLine.AddPointToCurrentAction( const P: TEzPoint );
Begin
{ in most cases 0,0 will work because if I try to change P to device coords, it
can cause AV errors for very large pixels }
DoMouseMove( Self, [], 0, 0, P.X, P.Y );
DoMouseDown( Self, mbLeft, [], 0, 0, P.X, P.Y );
DoMouseUp( Self, mbLeft, [], 0, 0, P.X, P.Y );
End;
Procedure TEzCmdLine.AddPointListToCurrentAction( const P: TEzVector );
var
I: Integer;
Begin
For I:= 0 to P.Count-1 do
AddPointToCurrentAction( P[I] );
End;
Procedure TEzCmdLine.AddRelativePointToCurrentAction( const P: TEzPoint );
Begin
If Not EqualPoint2d(CurrentAction.FLastClicked,INVALID_POINT) then
Begin
AddPointToCurrentAction( Point2d( CurrentAction.FLastClicked.X + P.X, CurrentAction.FLastClicked.Y + P.Y) );
End;
End;
{ angle is in degrees }
Procedure TEzCmdLine.AddRelativeAngleToCurrentAction( const Dist, Angle: Double );
var
DeltaX,DeltaY,AngRad:Double;
Begin
If Not EqualPoint2d(CurrentAction.FLastClicked,INVALID_POINT) then
begin
AngRad:= DegToRad( Angle );
DeltaX:= Dist * Cos(AngRad);
DeltaY:= Dist * Sin(AngRad);
AddPointToCurrentAction( Point2d( CurrentAction.FLastClicked.X + DeltaX, CurrentAction.FLastClicked.Y + DeltaY) );
end;
End;
Procedure TEzCmdLine.DoMouseDown( Sender: TObject; Button: TMouseButton; Shift:
TShiftState; X, Y: Integer; Const WX, WY: Double );
var
TmpPt: TEzPoint;
{$IFNDEF SUBCLASS_DRAWBOX}
Item: TEzDrawBoxItem;
{$ENDIF}
Begin
FIsMouseDown := True;
{ define the active drawbox }
{$IFNDEF SUBCLASS_DRAWBOX}
Item := FDrawBoxList.FindCurrent;
If Assigned( Item.FSavedMouseDown ) Then
Item.FSavedMouseDown( Sender, Button, Shift, X, Y, WX, WY );
{$ENDIF}
If Button = mbLeft Then
FCurrentPoint := Point2D( WX, WY );
with FAccuSnap.FCurrentSnapInfo do
begin
If (Button = mbLeft) And FAccuSnap.Enabled And FAccuDraw.Enabled And Showing
And (Picture = FAccuSnapPicFocused) And
(FAccuSnap.GetCurrentOsnapSetting = osParallel) then
begin
If Not EqualPoint2d(CurrentAction.FLastClicked,INVALID_POINT) then
begin
CurrentAction.EraseFullViewCursor;
If Assigned(CurrentAction.OnSuspendOperation) Then
CurrentAction.OnSuspendOperation( Self );
FAccuDraw.ChangeOrigin( FAccuDraw.FAccuOrigin, Angle2d(RefFrom,RefTo));
FAccuDraw.DeltaY:= 0;
FAccuDraw.DeltaYLocked:= True;
If Assigned(CurrentAction.OnContinueOperation) Then
CurrentAction.OnContinueOperation( Self );
CurrentAction.DrawFullViewCursor;
end else
begin
IsNextParallel:= True;
end;
Exit;
end;
end;
Try
{ erase from screen our full view cursor or frame cursor in case changed something }
CurrentAction.EraseFullViewCursor;
If Assigned( CurrentAction.OnMouseDown ) Then
CurrentAction.OnMouseDown( Sender, Button, Shift, X, Y, WX, WY );
{ restore the full view cursor or frame cursor }
CurrentAction.DrawFullViewCursor;
If CurrentAction.Finished Then
Self.Pop
else If Button = mbLeft Then
with FAccuSnap.FCurrentSnapInfo do
begin
{ check for parallel snap }
If FAccuSnap.Enabled And FAccuDraw.Enabled And IsNextParallel then
begin
CurrentAction.EraseFullViewCursor;
If Assigned(CurrentAction.OnSuspendOperation) Then
CurrentAction.OnSuspendOperation( Self );
FAccuDraw.ChangeOrigin( FAccuDraw.FAccuOrigin, Angle2d(RefFrom,RefTo));
If Assigned(CurrentAction.OnContinueOperation) Then
CurrentAction.OnContinueOperation( Self );
CurrentAction.DrawFullViewCursor;
end;
IsNextParallel:= False;
{ check for perpendicular }
If FAccuSnap.Enabled And FAccuDraw.Enabled And Showing And
(Picture = FAccuSnapPicFocused) And
(FAccuSnap.GetCurrentOsnapSetting = osPerpend) then
begin
CurrentAction.EraseFullViewCursor;
If Assigned(CurrentAction.OnSuspendOperation) Then
CurrentAction.OnSuspendOperation( Self );
TmpPt:= Perpend( Point2d(WX,WY), RefFrom,RefTo);
FAccuDraw.ChangeOrigin( TmpPt, Angle2d(RefFrom,RefTo));
FAccuDraw.DeltaX:= 0;
FAccuDraw.DeltaXLocked:= True;
If Assigned(CurrentAction.OnContinueOperation) Then
CurrentAction.OnContinueOperation( Self );
CurrentAction.DrawFullViewCursor;
end;
end;
If Button = mbLeft Then
Begin
FLastClicked := Point2D( WX, WY );
CurrentAction.FLastClicked:= Point2D( WX, WY );
End;
{ this fires event OnAccuSnapChange }
FAccuSnap.OverrideOsnap:= False;
Except
{ Cancel all Actions if exception }
Clear;
Raise;
End;
End;
Procedure TEzCmdLine.DoMouseMove( Sender: TObject; Shift: TShiftState;
X, Y: Integer; Const WX, WY: Double );
{$IFNDEF SUBCLASS_DRAWBOX}
Var
Item: TEzDrawBoxItem;
{$ENDIF}
Begin
{ define the active drawbox }
{$IFNDEF SUBCLASS_DRAWBOX}
Item := FDrawBoxList.FindCurrent;
If Assigned( Item.FSavedMouseMove ) Then
Item.FSavedMouseMove( Sender, Shift, X, Y, WX, WY );
{$ENDIF}
{ accudraw auxiliary snap lines }
If Not FIsMouseDown Then
Begin
{ erase accudraw previous auxiliary snap lines }
If FAccuDraw.Showing Then
FAccuDraw.EraseAuxLines;
End;
FCurrentPoint := Point2D( WX, WY );
If Not FIsMouseDown Then
Begin
{ update the accusnap entity }
FAccuSnap.UpdateAccuSnapEntity;
{ accudraw draw new position auxiliary snap lines }
If FAccuDraw.Showing Then
Begin
FAccuDraw.DrawAuxLines;
FAccuDraw.Change;
End;
End;
Try
{ erase full view cursor and frame cursor }
CurrentAction.EraseFullViewCursor;
If Assigned( CurrentAction.OnMouseMove ) Then
CurrentAction.OnMouseMove( Sender, Shift, X, Y, WX, WY );
If CurrentAction.Finished Then
Self.Pop
Else
Begin
{ set new position of cursor and draw again }
CurrentAction.SetFullViewCursorPos(Point2D(WX, WY));
CurrentAction.DrawFullViewCursor;
End;
Except
Clear;
Raise;
End;
End;
Procedure TEzCmdLine.DoMouseUp( Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer; Const WX, WY: Double );
{$IFNDEF SUBCLASS_DRAWBOX}
Var
Item: TEzDrawBoxItem;
{$ENDIF}
Begin
FIsMouseDown := False;
{ define the active drawbox }
{$IFNDEF SUBCLASS_DRAWBOX}
Item := FDrawBoxList.FindCurrent;
If Assigned( Item.FSavedMouseUp ) Then
Item.FSavedMouseUp( Sender, Button, Shift, X, Y, WX, WY );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -