
! script name: dyn_solids.d/dynsphere
! 3dtopic: construct sphere

!A
!A NAME:
!A
!A 	Dynamic Sphere: Define
!A
!A DESCRIPTION:
!A
!A 	This script constructs a sphere or a part of a sphere.  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 or
!B 		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 or
!B 		starting point.
!B
!B 		NOTE: The starting length and ending length
!B 		should not exceed the radius of the sphere.
!B 		The default value indicates the limits.
!B
!B 	STARTING ANGLE: Enter the starting angle of the sphere.
!B 		The starting angle along with the angular extent are
!B 		the controlling factor for the sphere around the axis.
!B
!B 	ANGULAR EXTENT: Enter the number of degrees and the
!B 		direction ( + CCW, - CW ) from the starting
!B 		angle to the ending angle.  The angular extent
!B 		determines the ending angle.
!B
!B 	ROTATION ANGLE: Enter the orientation angle of the
!B 		axis of the sphere in the XY plane.
!B
!B 	AXIS TILT ANGLE: This represents the angle of tilt
!B 		of the axis line of the sphere with respect
!B 		to the XY plane.
!B
!B 	AXIS ROLL ANGLE: This represents the roll angle
!B 		around the axis line of the sphere.
!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: Dynamic 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_length1= GetDefault(WsDynamicLength1)
Dynamic_length2= GetDefault(WsDynamicLength2)
Dynamic_angle1= GetDefault(WsDynamicAng1Incr)
Dynamic_angle2= GetDefault(WsDynamicAng2Incr)
Dynamic_data1= GetDefault(WsDynamicData1)
Dynamic_data2= GetDefault(WsDynamicData2)

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

Stat= SetDefaults(WsDynamicLength1,Dynamic_radius)
Stat= SetDefaults(WsDynamicLength2,Dynamic_radius)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle)
Stat= SetDefaults(WsDynamicData1,Dynamic_angle)
Stat= SetDefaults(WsDynamicData2,Dynamic_angle)


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_extent=GetValue("ANGULAR EXTENT ( 90 180 360 ) ",Answer$)
IF ExitScript(Destination$) THEN Leave

Tilt_angles:!
Stat=SetInputFormat("n4b=","")
Stat=SetAngleEquals(Zangle1)
Zangle1=InputAngle("ROTATION ANGLE ( 0 90 180 270 ) ",WsSigned)
IF ExitScript(Destination$) THEN Leave

Zangle=Zangle1-90

Stat=SetAngleEquals(Xangle)
Xangle=InputAngle("AXIS TILT ANGLE ( 0 90 180 270 ) ",WsSigned)
IF ExitScript(Destination$) THEN Leave

Stat=SetAngleEquals(Yangle)
Yangle=InputAngle("AXIS ROLL ANGLE ( 0 90 180 270 ) ",WsSigned)
IF ExitScript(Destination$) THEN Leave


Place_sphere:!
Stat=DynLabel("R:"&VAL$(Radius)&":SL:"&VAL$(Start_length)&":EL:"&VAL$(End_length)&":RA:"&VAL$(Zangle+90)&":TA:"&VAL$(Xangle))
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
T1=AngleTransform(Pref,Xangle,Yangle,Zangle,WsWorkplaneVals)
E1=Sphere(T1,Radius,Start_length,End_length,Astart,Angle_extent)
Stat= MakeInvisible(E1)
PlotOn

Vnum= LastPickView
Params(0)= Radius
Params(1)= Start_length
Params(2)= End_length
Params(3)= Astart
Params(4)= Angle_extent
Params(5)= Xangle
Params(6)= Yangle
Params(7)= Zangle
Num_params=8
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynamicSphere,"PICK REFERENCE ",Params,Num_params)
IF (ExitScript(Destination$)) THEN
        Stat=DeleteEntity(E1,WsTrue)
	Stat=DeleteEntity(Pdest,WsTrue)
        Stat=DeleteEntity(Pref,WsTrue)
        IF Destination$= "BACKUP" THEN Tilt_angles
        GOTO Leave
END IF
Radius=Params(0)
Start_length=Params(1)
End_length=Params(2)
Astart=Params(3)
Angle_extent=Params(4)
Xangle=Params(5)
Yangle=Params(6)
Zangle=Params(7)

Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Pdest)

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

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

Leave:!
Stat=DynLabel("")
Stat=SetPickMask(WsPickGeometry)
Stat=SetInputFormat("n4","")
Stat= DeleteEntity(Pref)
Stat= DeleteEntity(Pdest)
Stat= SetDefaults(WsDynamicLength1,Dynamic_length1)
Stat= SetDefaults(WsDynamicLength2,Dynamic_length2)
Stat= SetDefaults(WsDynamicAng1Incr,Dynamic_angle1)
Stat= SetDefaults(WsDynamicAng2Incr,Dynamic_angle2)
Stat= SetDefaults(WsDynamicData1,Dynamic_data1)
Stat= SetDefaults(WsDynamicData2,Dynamic_data2)


IF NOT LEN(Destination$) THEN
        LOAD "typecontrol"
ELSE
        IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
        LOAD Destination$
END IF
END
