
! script name: pkdyn_solids.d/pkdynsphere
! solids: 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 distance from
!B 		the center of the sphere.
!B
!# see also - points.d/dyninput.hlp
!# see also - htdocs/help.d/parasolids.htm

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= 360

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,0.0)
Stat= SetDefaults(WsDynamicAng2Incr,0.0)
Stat= SetDefaults(WsDynamicData1,Dynamic_angle)
Stat= SetDefaults(WsDynamicData2,Dynamic_angle)


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



Place_sphere:!
PlotOff
Pref= PointXYZ(0,0,0)
Pdest= CopyEntity(Pref)
Stat= MakeInvisible(Pref)
Stat= MakeInvisible(Pdest)
T1=AngleTransform(Pref,0.0,0.0,0.0,WsWorkplaneVals)
E1=Sphere(T1,Radius,-Radius,Radius,0.0,360)
Stat= MakeInvisible(E1)
Stat= HideEntity(E1)
PlotOn

Vnum= LastPickView
Params(0)= Radius
Params(1)= -Radius
Params(2)= Radius
Params(3)= 0.0
Params(4)= 360
Params(5)= 0
Params(6)= 0
Params(7)= 0
Num_params=8
Stat=SetInputFormat("n4b","")
Stat=DynamicEntity(Vnum,E1,Pref,Pdest,WsDynamicSphere,"PICK REFERENCE ",Params,Num_params,0,WsTrue,WsFalse)
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

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

WPKClearErrorFlag
E2=WPKBasicSolid(E1)
Stat=DeleteEntity(E1)

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

Leave:!
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
