
! script name: dynvcircles.d/dynamic2pts
! topic: construct arc defined by end points and radius

!A
!A NAME:
!A
!A 	Rad: Two Points with Dynamic endpoint.  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 	FIRST POINT ABS X,Y: Enter the X,Y coordinates of the first point,
!B 		which will be one of the end points of the arc constructed.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B	
!B		The +/- keys toggle the sign of the radius.
!B		The > key will increase the radius of the circle.
!B		The < key will decrease the radius of the circle.
!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 rad: two points ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Radius_var$[256]
REAL Params(0:10)

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

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
IF NOT Graphical_mode THEN LOAD "vcircles.d/rad2points"


Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_radius= GetDefault(WsDynRadiusDefault)

Stat= SetDefaults(WsDynamicLength1,Dynamic_radius)


DEG

Ask_radius:Stat=SetInputFormat("n4b=","")
Radius=InputRadius("CIRCLE RADIUS")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        Etype= EntityType(C1)
        IF Etype= WsCircleEnt THEN
                IF NOT ValidDependency(C1) THEN Ask_radius
                Stat= EntityNameCheck(C1,Radius_var$)
        END IF
        No_radius_var=0
END IF

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


PlotOff
Pe= PtIncrXyz(Ps,ABS(Radius),0.0,0.0)
Dir1= (Radius> 0)- (Radius< 0)
C1=RadiusTwoPoints(Radius,Ps,Pe,Dir1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
Stat= MakeInvisible(C1)
PlotOn

Vnum= LastPickView
stat= SetInputFormat("n4b","")
Params(0)= Radius
Params(1)= Dir1
Params(2)= WsFalse
Stat= PointInputMode(1)
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynTwoPtCircle,"PICK ENDPOINT",Params,Num_params)
IF (ExitScript(Destination$)) THEN 
	Stat=DeleteEntity(C1,WsTrue)
	GOTO Leave
END IF
Radius= Params(0)
Dir1= Params(1)
Which_one= 1
Radius= ((Dir1 >= 0)- (Dir1<0))*Radius
E2= LastPickEnt
Para2= LastPickPara
Pick_return2= CurrPickReturn
No_radius_var=1
PlotOff
Pt= ParameterPt(C1,0.5)
L1=LineTwoPoints(Ps,Pe,WsTRIMMED)
S1=PtLeftRight(L1,Pt)
IF S1=1 THEN
        Which_one=1
ELSE
        Which_one=2
END IF

IF NOT ValidDependency(E2) THEN
        E2= CopyEntity(Pe)
	Stat= MakeVisible(E2)
	Stat= EntityNameCheck(E2,Point2$)
	Pe_created= WsTrue
ELSE
        Stat= EntityNameCheck(E2,Point2$)
	Pe_created= WsFalse
END IF
Stat=DeleteEntity(L1)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(C1)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
PlotOn

Stat= GenerateVarName(WsCircleEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CIRCLE: Radius two points")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
V2= FreeParameter("Which one",Which_one)
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
        C1=Fillet(V1,Ps,1,Pe,1,V2,WsTRIMMED)
ELSE
        C1=Fillet(Radius_var$,Ps,1,Pe,1,V2,WsTRIMMED)
END IF
Stat= NameEntity(C1,Name$)
Stat= DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(C1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("var circle")
	IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
	IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
	Stat= AddItemToUndo(WsUBCreateMode,C1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= PlotEntity(C1)
GOTO Circle_loop

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
Stat= DeleteEntityList(Ps,Pe)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
