
! script name: dynvcircles.d/dyncircontour
! topic: construct circle contour defined by radius and center

!A
!A NAME:
!A
!A 	Dynamic Rad: Center  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a circle of a known radius about a point.
!A
!B INSTRUCTIONS:
!B
!B 	CIRCLE RADIUS: Enter radius of circle to be constructed.
!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: center ")

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


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

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

Start:!
ActivateUndo
Stat=SetPickMask(WsPickNoSurf)

Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)
Dynamic_angle= GetDefault(WsDynAngleDefault)
Dynamic_radius= GetDefault(WsDynRadiusDefault)
Stat= SetDefaults(WsDynamicLength1,Dynamic_radius)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle)

Circle_loop: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 Circle_loop
        	Stat= EntityNameCheck(C1,Radius_var$)
	END IF
        No_radius_var=0
END IF

Start_angle= 0
Angle_incr= 360.0

Place_circle:!
IF NOT Graphical_mode THEN 
	Stat= PointInputMode(1)
	Pref=XyzInput("CIRCLE CENTER",WsXyzInput)
	IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pref) THEN Line_loop
        Last_pick_ent= LastPickEnt
        Pick_para= LastPickPara
        Pick_return= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Last_pick_ent= CopyEntity(Pref)
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created= WsFalse
        END IF
        Stat=SetLastPoint(Pref)
ELSE
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
E1= RadiusCenter(Radius,Pdest)
Stat= MakeInvisible(E1)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
PlotOn
Stat=SetLastPoint(Pdest)

Vnum= LastPickView
Params(0)= Radius
Params(1)= Start_angle
Params(2)= Angle_incr
Num_params=3
Stat=SetInputFormat("n4b","")
Stat= PointInputMode(1)
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynRadCenter,"PICK CENTER ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
	IF Pc_created THEN Stat= DeleteEntity(Center$)
        Stat=DeleteEntity(E1,WsTrue)
        GOTO Leave
END IF
	Last_pick_ent= LastPickEnt
        Pick_para= LastPickPara
        Pick_return= CurrPickReturn
        Radius= Params(0)
        Start_angle= Params(1)
        Angle_incr= Params(2)
        No_angle_var=1
        IF NOT ValidDependency(Last_pick_ent) THEN
		 Last_pick_ent=CopyEntity(Pdest)
                 Stat= MakeVisible(Last_pick_ent)
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Center$)
		 Pc_created= WsFalse
        END IF
        Stat=SetLastPoint(Pdest)
	Stat= DeleteEntityList(Pdest,E1)
END IF
Stat=DeleteEntity(Pref)

Make_record:!
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CIRCLE CONTOUR: Radius center")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeomCenter)
CASE WsNearest
        Pc= ParameterReturnPt(Center$,Pick_para,WsNearest)
END SELECT
V2= FreeParameter("Start angle",Start_angle)
V3= FreeParameter("Angular increment",Angle_incr)
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
	C1= RadiusCenter(V1,Pc,V2,V3)
ELSE
	C1= RadiusCenter(Radius_var$,Pc,V2,V3)
END IF
G1= CreateGroup("",WsContourGroup)
Stat= AddToGroup(G1,C1)
Stat= AutoNameGroup(G1,Name$)
Stat= DeleteEntity(Pc,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Center$)
Stat= PlotEntity(G1)

ActivateUndo
Stat= AdvanceUndoNumber("var circle contour")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
Stat= AddGroupToUndo(WsUBCreateMode,G1,1,WsFalse)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)


GOTO Place_circle


Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
Stat= DeleteEntityList(Pref,Pdest)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
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
