
! script name: circles.d/dynradcenter
! topic: construct circle defined by radius and center

!A
!A NAME:
!A
!A 	Dynamic Rad: Center
!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	CIRCLE CENTER: Pick the location of the circle center.
!B 		NOTE: To enter the xyz coordinates change the Input Method
!B		Combo Box to Rectangular, or type R.
!B 		See DYNAMIC INPUT OPTIONS.
!B
!B		The > key will increase the radius of the circle.
!B		The < key will decrease the radius of the circle.
!B		Ctrl B will allow the user to input the radius ralue.
!B		An existing radius may be selected graphically.
!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]
REAL Params(0:10)
DEG


Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
Radius=NamedVarVal("circle radius",WsSystemVars,1.0)
Ask_radius=NamedVarVal("ask circle radius",WsSystemVars,0.0)


ActivateUndo
Start:!
Dynamic_length1= GetDefault(WsDynamicLength1)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)

Dynamic_radius= GetDefault(WsDynRadiusDefault)
Dynamic_angle= GetDefault(WsDynAngleDefault)

Stat= SetDefaults(WsDynamicLength1,Dynamic_radius)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,5)

IF NOT Graphical_mode THEN 
   Circle_loop:Stat=SetInputFormat("n4b=","")
   Radius=InputRadius("CIRCLE RADIUS")
   IF (ExitScript(Destination$)) THEN Leave

   stat= SetInputFormat("n4b","")
   Pref=XyzInput("CIRCLE CENTER",WsXyzInput)
   IF (ExitScript(Destination$)) THEN Leave
   IF NOT ValidGeometry(Pref) THEN Circle_loop

   E1= RadiusCenter(Radius,Pref)
   Stat=DeleteEntity(Pref)
   ActivateUndo
   Stat= AdvanceUndoNumber("circle")
   Stat= AddItemToUndo(WsUBCreateMode,E1)
   GOTO Circle_loop

ELSE

IF Ask_radius THEN
    Stat=SetInputFormat("n4b=","")
    Radius=InputRadius("CIRCLE RADIUS")
    IF (ExitScript(Destination$)) THEN Leave
END IF

Astart=0.0
Angle= 360
Place_circle:!
IF Radius=0 THEN Radius= 1.0
Stat=DynLabel("Radius:"&VAL$(Radius)&":Astart:"&VAL$(Astart)&":Angle:"&VAL$(Angle)&":")
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
E1= RadiusCenter(Radius,Pdest,Astart,Angle)
Stat= MakeInvisible(E1)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
PlotOn
Stat=SetLastPoint(Pdest)

Vnum= LastPickView
Params(0)= Radius
Params(1)= Astart
Params(2)= Angle
Num_params=3
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynRadCenter,"PICK CENTER ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(E1,WsTrue)
        IF Destination$= "BACKUP" THEN Ask_data
        GOTO Leave
END IF
Radius= Params(0)
Astart= Params(1)
Angle= Params(2)
Stat= SetRadiusEquals(Radius)
Stat= MakeVisible(E1)
Stat=SetLastPoint(Pdest)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Pdest)
Stat= PlotEntity(E1)
ActivateUndo
Stat= AdvanceUndoNumber("circle")
Stat= AddItemToUndo(WsUBCreateMode,E1)
Vrad=CreateVariable("circle radius",WsSystemVars,Radius)
GOTO Place_circle
END IF
GOTO Leave

Ask_data:!
Stat=DynLabel("")
Stat=SetInputFormat("n4b=","")
Radius=InputRadius("CIRCLE RADIUS")
IF (ExitScript(Destination$)) THEN Leave
GOTO Start

Leave:!
Stat=DynLabel("")
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(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
