
! script name: vpksheets.d/vpkcirsphere
! var_solids: construct sphere defined by circle, start length, and end length

!A
!A NAME:
!A
!A 	Sphere: Circle	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a sphere or a part of a sphere, using the
!A 	picked circle as the reference for the center of the sphere.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CIRCLE: Pick the circle to be used as the reference for the
!B 		center of the sphere.
!B
!B 	STARTING LENGTH: Enter the controlling extent of the sphere along
!B 		the axis, negative measures backward from the starting point,
!B 		zero is the center or starting point.
!B
!B 	ENDING LENGTH: Enter the controlling extent of the sphere along the
!B 		axis, positive measures forward from the starting point, zero
!B 		is the center or starting point.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: sphere defined by a circle ")

DIM Destination$[256]
DIM Answer$[256]
DIM Slength$[256]
DIM Elength$[256]
DIM Circle$[256]
DIM Name$[256]


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


Stat= GLPlotOn
ActivateUndo
Cloop:!
Stat=SetInputFormat("n4","")
pcircle=PickSpecificEnt("PICK CIRCLE",WsPickCircles)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(pcircle) THEN Cloop
Stat= EntityNameCheck(pcircle,Circle$)

Radius=CircleRadius(pcircle)
Radius=ABS(Radius)

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

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

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Sphere from circle")
IF No_slength_var THEN
        V1= FreeParameter("Start Length",Start_length)
ELSE
        V1= FreeParameter("Start Length",Slength$)
END IF
IF No_elength_var THEN
        V2= FreeParameter("End Length",End_length)
ELSE
        V2= FreeParameter("End Length",Elength$)
END IF
S1=CircleSphere(Circle$,V1,V2)
RecordFunctionOff
IF ValidGeometry(S1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        G1=WPKMakeBsurf(S1)
        Stat= WPKNameBodyGroup(G1,Name$)
        Stat= WPKSetBodyParent(G1,1)
        Stat= DeleteEntityList(G1,S1)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
        DelLastVarRecord
ELSE
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("spherical sheet")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Cloop

Leave:!
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
