
! script name: vcircles.d/threetangents
! var_topic: construct circle tangent to three elements

!A
!A NAME:
!A
!A 	Three Tangents -- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of unknown radius tangent to three
!A 	elements.  The tangent element to be picked must be a circle, line,
!A 	or point.
!A
!A~ image location - images/3tangents.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST TANGENT ELEMENT: Pick one of the three elements that will
!B 		be tangent to the circle constructed.
!B
!B 	PICK SECOND TANGENT ELEMENT: Pick the second of the three elements
!B 		that will be tangent to the circle constructed.
!B
!B 	PICK THIRD TANGENT ELEMENT: Pick the third element that will be
!B 		tangent to the circle constructed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: three tangents ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name3$[256]
DIM Name$[256]

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

ActivateUndo
Ploop:!
Pick_tan1:Stat= SetInputFormat("n4","")
E1=PickEntity("PICK FIRST TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_tan1
Para1=LastPickPara
Stat= EntityNameCheck(E1,Name1$)

Pick_tan2:Stat= SetInputFormat("n4","")
E2=PickEntity("PICK SECOND TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Pick_tan2
Para2=LastPickPara
Stat= EntityNameCheck(E2,Name2$)

Pick_tan3:Stat= SetInputFormat("n4","")
E3=PickEntity("PICK THIRD TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E3) THEN Pick_tan3
Para3=LastPickPara
Stat= EntityNameCheck(E3,Name3$)


Stat= GenerateVarName(WsCircleEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CIRCLE: Three tangents")
Stat= SetRecDelLastExec
C1=ThreeTangents(Name1$,Para1,Name2$,Para2,Name3$,Para3,0)
Stat= NameEntity(C1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(C1)
Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
Stat= PlotEntity(Name3$)
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("circle")
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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

