
! script name: vcircles.d/rad2points
! var_topic: construct arc defined by end points and radius

!A
!A NAME:
!A
!A 	Rad: Two Points		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs an arc of known radius with the two end points
!A 	defined.
!A
!A~ image location - images/rad2points.jpg
!B INSTRUCTIONS:
!B
!B 	CIRCLE RADIUS: Enter radius of arc to be constructed.
!B
!B 	STARTING POINT: Pick one of the points which will be an endpoint of
!B 		the arc constructed.
!B
!B 	ENDING POINT: Pick the point which will be the other endpoint of the
!B 		arc constructed.
!B
!B 	PICK LEFT/RIGHT OF LINE JOINING POINTS: Pick side of line that the
!B 		arc will be constructed on.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: rad: two points ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Radius_var$[256]


DEG
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Circle_loop:Stat=SetInputFormat("n4=","")
Radius=InputRadius("CIRCLE RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
	IF NOT ValidDependency(C1) THEN Circle_loop
	No_radius_var=0
	Stat= EntityNameCheck(C1,Radius_var$)
END IF

Pick_loop:E1=PickEntity("STARTING POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_loop
IF NOT ValidDependency(E1) THEN Pick_loop
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(E1,Point1$)
Ps= ParameterReturnPt(E1,T1,Pick_return1)

Stat=SetLastPoint(Ps)
E2=PickEntity("ENDING POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(E2) THEN Pick_loop
IF NOT ValidDependency(E2) THEN Pick_loop
T2= LastPickPara
Pick_return2= CurrPickReturn
Stat= EntityNameCheck(E2,Point2$)
Pe= ParameterReturnPt(E2,T2,Pick_return2)
Stat=SetLastPoint(Pe)

Ptdist=DistTwoPts(Ps,Pe)
IF Ptdist<.000098 THEN 
	Stat=DeleteEntity(P2)
	GOTO Pick_loop
END IF

Line1: !
L1=LineTwoPoints(Ps,Pe,WsTRIMMED)

Pt=InputFreePoint("PICK LEFT/RIGHT OF LINE JOINING POINTS")
IF ExitScript(Destination$) THEN Leave
S1=PtLeftRight(L1,Pt)
IF S1=1 THEN
	Which_one=1
ELSE
	Which_one=2
END IF
Stat=DeleteEntityList(Ps,Pe,L1,Pt)

Stat= GenerateVarName(WsCircleEnt,Name$)

RecordFunctionOn
Stat= RecordDescr("CIRCLE: Radius two points")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,T2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,T2,WsGeomCenter)
END SELECT
IF No_radius_var THEN
	V1= FreeParameter("Radius",Radius)
	C1=Fillet(V1,Ps,1,Pe,1,Which_one,WsTRIMMED)
ELSE
	C1=Fillet(Radius_var$,Ps,1,Pe,1,Which_one,WsTRIMMED)
END IF
Stat= NameEntity(C1,Name$)
Stat= DeleteEntityList(Ps,Pe))
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("circle")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_loop

Leave:!
Stat=DeleteEntityList(Ps,Pe,L1,Pt)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

