
! script name: dyn_solids.d/dynaxissphere
! 3dtopic: construct sphere along an axis line

!A
!A NAME:
!A
!A 	Sphere: Sphere along an axis line.
!A
!A DESCRIPTION:
!A
!A 	This script constructs a sphere along an axis line.  A sphere
!A 	is the set of all points in 3d space equidistant from a fixed point.
!A
!B INSTRUCTIONS:
!B
!B 	RADIUS: Enter the radius, the measure of the constant
!B 		distance from the center of the sphere.
!B
!B 	STARTING LENGTH: Enter the controlling extent of the
!B 		sphere along the axis, negative measures backward
!B 		from the starting point, zero is the center
!B 		or starting point.
!B
!B 	ENDING LENGTH: Enter the controlling extent of the
!B 		sphere along the axis, positive measures forward
!B 		from the starting point, zero is the center
!B 		or starting point.
!B
!B 		NOTE: The starting length and ending length should
!B 		not exceed the radius of the sphere.  The default
!B 		value indicates the limits.
!B
!B 	STARTING ANGLE: Enter the starting angle of the sphere.
!B 		The starting angle along with the angular extent
!B 		are the controlling factor for the sphere around
!B 		the axis.
!B
!B 	ANGULAR EXTENT: Enter the number of degrees and the
!B 		direction ( + CCW, - CW ) from the starting angle
!B 		to the ending angle.  The angular extent determines
!B 		the ending angle.
!B
!C NOTES:
!C
!C 	The U contours of a sphere are the circles from the starting length
!C 	to the ending length.  The V contours of a sphere are the circles
!C 	formed from the starting angle to the ending angle.
!C
!# see also - points.d/dyninput.hlp

Stat=ChangeLabelStr("ScriptNameStatus","Function: axis line sphere ")

DIM Destination$[256]
DIM Answer$[256]
REAL Params(0:10)

Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
ELSE
        Radius= 1
END IF

Stat= GLPlotOn
Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Astart= 0
Angle= 180

Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)
Dynamic_angle= GetDefault(WsDynAngleDefault)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle)

Cloop:!

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

Stat=SetInputFormat("n4b=","")
Stat=SetEqualsValue(-Radius)
Start_length=GetValue("STARTING LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4b=","")
Stat=SetEqualsValue(Radius)
End_length=GetValue("ENDING LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetAngleEquals(Astart)
Astart=InputAngle("STARTING ANGLE ( 0 90 180 270 ) ")
IF ExitScript(Destination$) THEN Leave

Stat=SetInputFormat("n4b=","")
Stat=SetEqualsValue(Angle)
Angle=GetValue("ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave


Pick_axis:!
Stat=SetInputFormat("n4b","")
Ps=XyzInput("AXIS START",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Pick_axis
Stat=SetLastPoint(Ps)

PlotOff
Length1= Radius
Pe= PtIncrXyz(Ps,0.0,Length1,0.0)
Axis_line= LineTwoPoints(Ps,Pe)
C1=AxisLineSphere(Axis_line,Radius,Start_length,End_length,Astart,Angle,WsForward)
Stat= MakeInvisible(Axis_line)
Stat= MakeInvisible(C1)
Stat= MakeInvisible(Ps)
Stat= MakeInvisible(Pe)
PlotOn

Vnum= LastPickView
Params(0)= Radius
Params(1)= Start_length
Params(2)= End_length
Params(3)= Astart
Params(4)= Angle
Num_params=5
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,C1,Ps,Pe,WsDynAxisSphere,"PICK AXIS ENDPOINT ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(C1,WsTrue)
	Stat=DeleteEntity(Ps)
        Stat=DeleteEntity(Pe,WsTrue)
        Stat=DeleteEntity(Axis_line,WsTrue)
        IF Destination$= "BACKUP" THEN Pick_axis
        GOTO Leave
END IF
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)

WPKClearErrorFlag
S1=WPKMakeBsurf(C1)
Stat= DeleteEntity(C1,WsTrue)

ActivateUndo
Stat= AdvanceUndoNumber("sphere sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
GOTO Pick_axis

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Axis_line)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	IF Destination$= "BACKUP" THEN Start
	IF Destination$= "SCRIPTSTART" THEN Start
	LOAD Destination$
END IF
END
