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

!A
!A NAME:
!A
!A 	Center: Tangent	  VARIATIONAL
!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 	CENTER POINT: Pick center point.
!B
!B 	PICK TANGENT ELEMENT: Pick the entity that will be tangent to the
!B 		circle constructed.
!B

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

DIM Answer$[256]
DIM Name$[256]
DIM Tangent$[256]
DIM Center$[256]
DIM Destination$[256]


DEG

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


ActivateUndo
Circle_loop:!
stat= SetInputFormat("n4","")
E1=PickEntity("CENTER 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,Center$)

Pick_tangent:E1=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
Para1=LastPickPara
IF NOT ValidDependency(E1) THEN Pick_tangent
Stat= EntityNameCheck(E1,Tangent$)

Stat= GenerateVarName(WsCircleEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CIRCLE: Center tangent")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T1,WsGeomCenter)
END SELECT
Pickpt= ParameterPt(Tangent$,Para1)
C1=CenterTangent(Pc,Tangent$,Pickpt)
Stat= NameEntity(C1,Name$)
Stat=DeleteEntityList(Pickpt,Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Center$)
Stat= PlotEntity(Tangent$)

ActivateUndo
Stat= AdvanceUndoNumber("center tangent")
Stat= AddItemToUndo(WsUBCreateMode,C1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Circle_loop

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

