
! script name: circles.d/centertangent
! topic: construct circle defined by center and tangent element

!A
!A NAME:
!A
!A 	Center: Tangent
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of unknown radius about a point
!A 	tangent to an element.
!A
!A~ image location - images/centertan.gif
!A
!B INSTRUCTIONS:
!B
!B 	INPUT CENTER ABS X,Y: Enter the X,Y coordinates of the center
!B 		point of the circle.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	PICK TANGENT ELEMENT: Pick the entity that will be tangent
!B 		to the circle constructed.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: center: tangent ")

DIM Destination$[256]
DIM Answer$[256]
REAL Params(0:10)


Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)

DEG
ActivateUndo
Start:!
stat= SetInputFormat("n4","")
Circle_loop:!
Pt=XyzInput("INPUT CENTER",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

IF NOT Graphical_mode THEN 
E1=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
Pickpt=LastPickPoint

C1=CenterTangent(Pt,E1,Pickpt)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Pickpt)

ActivateUndo
Stat= AdvanceUndoNumber("circle")
Stat= AddItemToUndo(WsUBCreateMode,C1)
GOTO Circle_loop

ELSE
PlotOff
Pc= ParameterPt(Pt,0.0)
C1= RadiusCenter(1.0,Pc)
Stat= MakeInvisible(C1)
PlotOn

Vnum= LastPickView
Params(0)= 0
G1= CreateGroup("temp")
Stat= AddToGroup(G1,Pc)
Num_params=1

stat= SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Pc,Pt,WsDynCenterTangent,"PICK TANGENT",Params,Num_params,G1)
IF (ExitScript(Destination$)) THEN
	Stat=DeleteEntity(Pt)
	Stat=DeleteEntity(Pc)
        Stat=DeleteEntity(C1,WsTrue)
	Stat=DeleteEntity(G1)
        IF Destination$= "BACKUP" THEN Start
        GOTO Leave
END IF
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(G1)
Stat= MakeVisible(C1)
IF IsEntityMarked(C1) THEN
	Stat= DeleteEntity(C1)
ELSE
	Stat= PlotEntity(C1)
	ActivateUndo
	Stat= AdvanceUndoNumber("circle")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
END IF
GOTO Circle_loop
END IF


Leave:!
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Pc)
IF (NOT LEN(Destination$)) THEN
         LOAD "typecontrol"
ELSE
    IF Destination$= "SCRIPTSTART" THEN Start
    IF Destination$= "BACKUP" THEN Start
            LOAD Destination$
END IF
END
END
