
! script name: circles.d/radpointent
! topic: construct circle defined by radius and tangent point

!A
!A NAME:
!A
!A 	Rad: Point: Tangent
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of a known radius tangent to an
!A 	element and passing though a specified point.
!A 
!A~ image location - images/radpttan.gif
!A
!B INSTRUCTIONS:
!B
!B 	CIRCLE RADIUS: Enter radius of circle to be constructed.
!B 
!B 	INPUT ABS X,Y: Enter the X,Y coordinates of the point, through
!B 		which the circle constructed will pass.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	PICK TANGENT ELEMENT: Pick element that will be tangent to
!B 		the circle constructed.
!B
!B 	PICK LEFT/RIGHT OF TANGENT ELEMENT: Pick side of
!B 		tangent element that the circle should be constructed on.
!B 		NOTE: This question will only be asked if there is a choice.
!B
!B		Ctrl B will allow the user to input the radius ralue.
!B		An existing radius may be selected graphically.
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: rad: point: tangent ")


DIM Destination$[256]
DIM Answer$[256]

Radius=NamedVarVal("circle radius",WsSystemVars,1.0)
Ask_radius=NamedVarVal("ask circle radius",WsSystemVars,0.0)

DEG

ActivateUndo
Ask_radius:!
IF Ask_radius THEN
   stat= SetInputFormat("n4","")
   Radius=InputRadius("CIRCLE RADIUS")
   IF (ExitScript(Destination$)) THEN Leave
END IF

Circle_loop:!
stat= SetInputFormat("n4b","")
Stat=DynLabel("Radius:"&VAL$(Radius))
P1=XyzInput("INPUT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
T1=0

stat= SetInputFormat("n4b","")
E2=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
T2=LastPickPara

Dist=DistPtEntity(P1,E2)

IF (Dist>0.0001) THEN
	Radius= DynBufferValue(0,Radius)
	C1=PickRadTwoTan(Radius,E2,T2,P1,T1,WsUNTRIMMED)
ELSE
	Pt=InputFreePoint("PICK LEFT/RIGHT OF TANGENT ELEMENT")
	IF (ExitScript(Destination$)) THEN Leave

	S1=PtLeftRight(E2,Pt)

	Radius= DynBufferValue(0,Radius)
	C1=Fillet(Radius,P1,1,E2,S1,1,WsUNTRIMMED)

END IF
Stat=DeleteEntity(P1)
Stat=DeleteEntity(Pt)
ActivateUndo
Stat= AdvanceUndoNumber("circle")
Stat= AddItemToUndo(WsUBCreateMode,C1)
Vrad=CreateVariable("circle radius",WsSystemVars,Radius)
GOTO Circle_loop

Ask_data:!
Stat=DynLabel("")
Stat=SetInputFormat("n4b=","")
Radius=InputRadius("CIRCLE RADIUS")
IF (ExitScript(Destination$)) THEN Leave
GOTO Circle_loop

Leave:!
Stat=DynLabel("")
Stat=DeleteEntity(P1)
Stat=DeleteEntity(Pt)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
         IF Destination$= "BACKUP" THEN Ask_data
	 LOAD Destination$
END IF
END
