
! script name: dynvcircles.d/dyncenterpoint
! topic: construct circle defined by center and tangent point

!A
!A NAME:
!A
!A 	Dynamic Center: Point   Variational
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of unknown radius about a point
!A 	tangent to a known point.
!A
!A~ image location - images/centerandpoint.jpg
!B INSTRUCTIONS:
!B
!B
!C NOTES:
!C
!C 	The dynamic input mode is an option that may be turned off by
!C 	setting the variable "Grapical mode=0".  To set the variable,
!C 	under "Settings", select "Variables".  The selection box will appear
!C 	at this time.  Select "Graphical mode=1" and change the
!C 	setting to "0".  The dynamic input mode is the default whenever
!C 	Synergy is started.  This change is for this session of Synergy
!C 	only.
!C
!C 	The dynamic input mode may be turned off for future sessions of
!C 	Synergy by going to "Settings" and selecting "Constants".  The editor
!C 	will bring up the setconstants script.  The following line needs
!C 	to be modified (the 1.0 needs to be changed to 0.0):
!C
!C 		V10=CreateVariable("Graphical mode",WsSystemVars,1.0)
!C
!C 	to:
!C
!C 		V10=CreateVariable("Graphical mode",WsSystemVars,0.0)
!C
!C 	The line is near the middle of the script.
!C
!# see also - points.d/dyninput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic center: point ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point$[256]
DIM Center$[256]
DEG

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave


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


Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
DEG

Circle_loop:!
stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Pc=XyzInput("INPUT CENTER",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Circle_loop
E1= LastPickEnt
Para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Center$)
	Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Center$)
	Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)

IF NOT Graphical_mode THEN 
End_point:!
        Stat= PointInputMode(1)
        Pt=XyzInput("ENDING",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pt) THEN End_point
        E2= LastPickEnt
        Para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(E2) THEN
                 E2= CopyEntity(Pt)
                 Stat= EntityNameCheck(E2,Point$)
		 Pt_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(E2,Point$)
		 Pt_created= WsFalse
        END IF
        Stat=SetLastPoint(Pt)
ELSE
	PlotOff
	C1= RadiusCenter(1.0,Pc)
	Pt= ParameterPt(C1,0.0)
	Stat= MakeInvisible(C1)
	Stat= MakeInvisible(Pt)
	PlotOn

	Vnum= LastPickView
	stat= SetInputFormat("n4b","")
	Stat= PointInputMode(1)
	Stat=DynamicEntity(Vnum,C1,Pc,Pt,WsDynamicRadius)
	IF (ExitScript(Destination$)) THEN
        	Stat=DeleteEntity(C1,WsTrue)
		GOTO Leave
	END IF
        E2= LastPickEnt
        Para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(E2) THEN
                 E2= CopyEntity(Pt)
		 Stat= MakeVisible(E2)
                 Stat= EntityNameCheck(E2,Point$)
		 Pt_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(E2,Point$)
	         Pt_created= WsFalse
        END IF
	Stat=DeleteEntity(C1,WsTrue)
END IF
PlotOff
Stat=SetLastPoint(Pt)
Stat=DeleteEntity(Pc,WsTrue)
Stat=DeleteEntity(Pt,WsTrue)
PlotOn

Stat= GenerateVarName(WsCircleEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CIRCLE: Center tangent point")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point$,Para2,WsGeomCenter)
END SELECT
C1=CenterTangent(Pc,Pe,Pe)
Stat= NameEntity(C1,Name$)
Stat= DeleteEntityList(Pc,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("var circle")
	IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
	IF Pt_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point$)
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

Stat= PlotEntity(Center$)
Stat= PlotEntity(Point$)
Stat= PlotEntity(C1)
GOTO Circle_loop


Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
stat= SetInputFormat("n4","")
Stat= DeleteEntityList(Pc,Pe)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
